1 /** 2 * checkbox source editor for kissy editor 3 * @author yiminghe@gmail.com 4 */ 5 KISSY.add("editor/plugin/checkboxSourcearea/index", function (S, Editor) { 6 var Node = S.Node; 7 8 var SOURCE_MODE = Editor.SOURCE_MODE , 9 WYSIWYG_MODE = Editor.WYSIWYG_MODE; 10 11 function CheckboxSourceArea(editor) { 12 var self = this; 13 self.editor = editor; 14 self._init(); 15 } 16 17 S.augment(CheckboxSourceArea, { 18 _init:function () { 19 var self = this, 20 editor = self.editor, 21 statusBarEl = editor.get("statusBarEl"); 22 self.holder = new Node("<span " + 23 "style='zoom:1;display:inline-block;height:22px;line-height:22px;'>" + 24 "<input style='margin:0 5px;vertical-align:middle;' " + 25 "type='checkbox' />" + 26 "<span style='vertical-align:middle;'>编辑源代码</span></span>") 27 .appendTo(statusBarEl); 28 var el = self.el = self.holder.one("input"); 29 el.on("click", self._check, self); 30 editor.on("wysiwygMode", self._wysiwygmode, self); 31 editor.on("sourceMode", self._sourcemode, self); 32 }, 33 _sourcemode:function () { 34 this.el.attr("checked", true); 35 }, 36 _wysiwygmode:function () { 37 this.el.attr("checked", false); 38 }, 39 _check:function () { 40 var self = this, 41 editor = self.editor, 42 el = self.el; 43 if (el.attr("checked")) { 44 editor.set("mode", SOURCE_MODE); 45 } else { 46 editor.set("mode", WYSIWYG_MODE); 47 } 48 }, 49 destroy:function () { 50 this.holder.remove(); 51 } 52 }); 53 54 function CheckboxSourceAreaPlugin(){ 55 56 } 57 58 S.augment(CheckboxSourceAreaPlugin,{ 59 renderUI:function(editor){ 60 61 var c = new CheckboxSourceArea(editor); 62 editor.on("destroy", function () { 63 c.destroy(); 64 }); 65 } 66 }); 67 68 return CheckboxSourceAreaPlugin; 69 }, { 70 requires:["editor"] 71 }); 72