toolbar.js 1.6 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 '<div id="##" class="edui-toolbar %%" onselectstart="return false;" onmousedown="return $$._onMouseDown(event, this);">' +
  28. buff.join('') +
  29. '</div>'
  30. },
  31. postRender: function (){
  32. var box = this.getDom();
  33. for (var i=0; i<this.items.length; i++) {
  34. this.items[i].postRender();
  35. }
  36. uiUtils.makeUnselectable(box);
  37. },
  38. _onMouseDown: function (e){
  39. var target = e.target || e.srcElement,
  40. tagName = target && target.tagName && target.tagName.toLowerCase();
  41. if (tagName == 'input' || tagName == 'object' || tagName == 'object') {
  42. return false;
  43. }
  44. }
  45. };
  46. utils.inherits(Toolbar, UIBase);
  47. })();