1 /** 2 * Encapsulate KISSY toggle button for kissy editor 3 * @author yiminghe@gmail.com 4 */ 5 KISSY.add("editor/plugin/button/index", function (S, Editor, Button) { 6 /** 7 * 将 button ui 和点击功能分离 8 */ 9 Editor.prototype.addButton = function (id, cfg, ButtonType) { 10 11 if (ButtonType === undefined) { 12 ButtonType = Button; 13 } 14 15 16 var self = this, 17 prefixCls = self.get("prefixCls") + "editor-", 18 b = new ButtonType(S.mix({ 19 render:self.get("toolBarEl"), 20 elAttrs:{ 21 hideFocus:'hideFocus' 22 }, 23 autoRender:true, 24 content:'<span ' + 25 'class="' + prefixCls + 'toolbar-item ' + 26 prefixCls + 'toolbar-' + id + 27 '"></span' + 28 '>', 29 elCls:prefixCls + 'toolbar-button', 30 prefixCls:prefixCls, 31 editor:self 32 }, cfg)), contentEl = b.get("el").one("span"); 33 34 // preserver selection in editor iframe 35 // magic happens when tabIndex and unselectable are both set 36 b.get("el").unselectable(); 37 38 b.on("afterContentClsChange", function (e) { 39 contentEl[0].className = prefixCls + 'toolbar-item ' + 40 prefixCls + 'toolbar-' + e.newVal; 41 }); 42 43 if (b.get("mode") == Editor.WYSIWYG_MODE) { 44 self.on("wysiwygMode", function () { 45 b.set("disabled", false); 46 }); 47 self.on("sourceMode", function () { 48 b.set("disabled", true); 49 }); 50 } 51 52 self.addControl(id + "/button", b); 53 54 return b; 55 }; 56 57 return Button; 58 }, { 59 requires:['editor', 'button'] 60 }); 61