1 /** 2 * ElementPath for debug. 3 * @author yiminghe@gmail.com 4 */ 5 KISSY.add("editor/plugin/elementPath/index", function (S, Editor) { 6 var Node = S.Node; 7 var CLASS = "ks-editor-element-path"; 8 9 function ElementPaths(cfg) { 10 var self = this; 11 self.cfg = cfg; 12 self._cache = []; 13 self._init(); 14 } 15 16 S.augment(ElementPaths, { 17 _init:function () { 18 var self = this, 19 cfg = self.cfg, 20 editor = cfg.editor; 21 self.holder = new Node("<span>"); 22 self.holder.appendTo(editor.get("statusBarEl"), undefined); 23 editor.on("selectionChange", self._selectionChange, self); 24 Editor.Utils.sourceDisable(editor, self); 25 }, 26 disable:function () { 27 this.holder.css("visibility", "hidden"); 28 }, 29 enable:function () { 30 this.holder.css("visibility", ""); 31 }, 32 _selectionChange:function (ev) { 33 var self = this, 34 cfg = self.cfg, 35 editor = cfg.editor, 36 statusDom = self.holder, 37 elementPath = ev.path, 38 elements = elementPath.elements, 39 element, i, 40 cache = self._cache; 41 for (i = 0; i < cache.length; i++) { 42 cache[i].remove(); 43 } 44 self._cache = []; 45 // For each element into the elements path. 46 for (i = 0; i < elements.length; i++) { 47 element = elements[i]; 48 // 考虑 fake objects 49 var type = element.attr("_ke_real_element_type") || element.nodeName(), 50 a = new Node("<a " + 51 "href='javascript(\"" + 52 type + "\")' " + 53 "class='" + 54 CLASS + "'>" + 55 type + 56 "</a>"); 57 self._cache.push(a); 58 (function (element) { 59 a.on("click", function (ev2) { 60 ev2.halt(); 61 editor.focus(); 62 setTimeout(function () { 63 editor.getSelection().selectElement(element); 64 }, 50); 65 }); 66 })(element); 67 statusDom.prepend(a); 68 } 69 }, 70 destroy:function () { 71 this.holder.remove(); 72 } 73 }); 74 75 function ElementPathPlugin() { 76 77 } 78 79 S.augment(ElementPathPlugin, { 80 renderUI:function (editor) { 81 var elemPath = new ElementPaths({ 82 editor:editor 83 }); 84 editor.on("destroy", function () { 85 elemPath.destroy(); 86 }); 87 } 88 }); 89 90 return ElementPathPlugin; 91 92 }, { 93 requires:['editor'] 94 });