1 /** 2 * link editor support for kissy editor ,innovation from google doc and ckeditor 3 * @author yiminghe@gmail.com 4 */ 5 KISSY.add("editor/plugin/link/index", function (S, Editor, Bubble, Utils, DialogLoader) { 6 7 var $ = S.all, 8 tipHtml = '<a ' + 9 'href="" ' 10 + ' target="_blank" ' + 11 'class="ks-editor-bubble-url">' + 12 '在新窗口查看' + 13 '</a> – ' 14 + ' <span ' + 15 'class="ks-editor-bubble-link ks-editor-bubble-change">' + 16 '编辑' + 17 '</span> | ' 18 + ' <span ' + 19 'class="ks-editor-bubble-link ks-editor-bubble-remove">' + 20 '去除' + 21 '</span>'; 22 23 function checkLink(lastElement) { 24 lastElement = $(lastElement); 25 return lastElement.closest('a', undefined); 26 } 27 28 function LinkPlugin(config) { 29 this.config=config||{}; 30 } 31 32 S.augment(LinkPlugin, { 33 renderUI:function (editor) { 34 editor.addButton("link", { 35 tooltip:"插入链接", 36 listeners:{ 37 click:function () { 38 showLinkEditDialog(); 39 40 } 41 }, 42 mode:Editor.WYSIWYG_MODE 43 }); 44 45 var self=this; 46 47 function showLinkEditDialog(selectedEl) { 48 DialogLoader.useDialog(editor, "link", 49 self.config, 50 selectedEl); 51 } 52 53 editor.addBubble("link", checkLink, { 54 listeners:{ 55 afterRenderUI:function () { 56 var bubble = this, 57 el = bubble.get("contentEl"); 58 59 el.html(tipHtml); 60 61 var tipUrl = el.one(".ks-editor-bubble-url"), 62 tipChange = el.one(".ks-editor-bubble-change"), 63 tipRemove = el.one(".ks-editor-bubble-remove"); 64 65 //ie focus not lose 66 Editor.Utils.preventFocus(el); 67 68 tipChange.on("click", function (ev) { 69 showLinkEditDialog(bubble.get("editorSelectedEl")); 70 ev.halt(); 71 }); 72 73 tipRemove.on("click", function (ev) { 74 Utils.removeLink(editor, bubble.get("editorSelectedEl")); 75 ev.halt(); 76 }); 77 78 bubble.on("show", function () { 79 var a = bubble.get("editorSelectedEl"); 80 if (!a) { 81 return; 82 } 83 var href = a.attr(Utils._ke_saved_href) || 84 a.attr("href"); 85 tipUrl.html(href); 86 tipUrl.attr("href", href); 87 }); 88 } 89 90 } 91 }); 92 } 93 }); 94 95 return LinkPlugin; 96 }, { 97 requires:['editor', '../bubble/', 98 './utils', '../dialogLoader/', '../button/'] 99 });