1 /** 2 * Adds a heading tag around a selection or insertion point line. 3 * Requires the tag-name string to be passed in as a value argument (i.e. "H1", "H6") 4 * @author yiminghe@gmail.com 5 */ 6 KISSY.add("editor/plugin/heading/cmd", function (S, Editor) { 7 return { 8 init:function (editor) { 9 if (!editor.hasCommand("heading")) { 10 editor.addCommand("heading", { 11 exec:function (editor, tag) { 12 editor.execCommand("save"); 13 if (tag != "p") { 14 var currentValue = editor.queryCommandValue("heading"); 15 } 16 if (tag == currentValue) { 17 tag = "p"; 18 } 19 new Editor.Style({ 20 element:tag 21 }).apply(editor.get("document")[0]); 22 editor.execCommand("save"); 23 } 24 }); 25 26 var queryCmd = Editor.Utils.getQueryCmd("heading"); 27 28 editor.addCommand(queryCmd, { 29 exec:function (editor) { 30 var selection = editor.getSelection(); 31 if (selection && !selection.isInvalid) { 32 var startElement = selection.getStartElement(); 33 var currentPath = new Editor.ElementPath(startElement); 34 var block = currentPath.block || currentPath.blockLimit; 35 var nodeName = block && block.nodeName() || ""; 36 if (nodeName.match(/^h\d$/) || nodeName == "p") { 37 return nodeName; 38 } 39 } 40 } 41 }); 42 } 43 44 45 } 46 }; 47 }, { 48 requires:['editor'] 49 });