toolbar.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. (function() {
  2. var utils = baidu.editor.utils,
  3. uiUtils = baidu.editor.ui.uiUtils,
  4. UIBase = baidu.editor.ui.UIBase,
  5. Toolbar = (baidu.editor.ui.Toolbar = function(options) {
  6. this.initOptions(options);
  7. this.initToolbar();
  8. });
  9. Toolbar.prototype = {
  10. items: null,
  11. initToolbar: function() {
  12. this.items = this.items || [];
  13. this.initUIBase();
  14. },
  15. add: function(item, index) {
  16. if (index === undefined) {
  17. this.items.push(item);
  18. } else {
  19. this.items.splice(index, 0, item);
  20. }
  21. },
  22. getHtmlTpl: function() {
  23. var buff = [];
  24. for (var i = 0; i < this.items.length; i++) {
  25. buff[i] = this.items[i].renderHtml();
  26. }
  27. return (
  28. '<div id="##" class="edui-toolbar %%" onselectstart="return false;" onmousedown="return $$._onMouseDown(event, this);">' +
  29. buff.join("") +
  30. "</div>"
  31. );
  32. },
  33. postRender: function() {
  34. var box = this.getDom();
  35. for (var i = 0; i < this.items.length; i++) {
  36. this.items[i].postRender();
  37. }
  38. uiUtils.makeUnselectable(box);
  39. },
  40. _onMouseDown: function(e) {
  41. var target = e.target || e.srcElement,
  42. tagName = target && target.tagName && target.tagName.toLowerCase();
  43. if (tagName == "input" || tagName == "object" || tagName == "object") {
  44. return false;
  45. }
  46. }
  47. };
  48. utils.inherits(Toolbar, UIBase);
  49. })();