1 /** 2 * link dialog 3 * @author yiminghe@gmail.com 4 */ 5 KISSY.add("editor/plugin/link/dialog", function (S, Editor, Overlay4E, Utils) { 6 7 var Dialog = Overlay4E.Dialog, 8 _ke_saved_href = Utils._ke_saved_href, 9 MIDDLE = "vertical-align:middle;", 10 bodyHtml = "<div style='padding:20px 20px 0 20px'>" + 11 "<p>" + 12 "<label>" + 13 "链接网址: " + 14 "<input " + 15 " data-verify='^(https?://[^\\s]+)|(#.+)$' " + 16 " data-warning='请输入合适的网址格式' " + 17 "class='ks-editor-link-url ks-editor-input' " + 18 "style='width:390px;" + 19 MIDDLE + 20 "'" + 21 " />" + 22 "</label>" + 23 "</p>" + 24 "<p " + 25 "style='margin: 15px 0 10px 0px;'>" + 26 "<label>" + 27 "链接名称: " + 28 "<input class='ks-editor-link-title ks-editor-input' style='width:100px;" + 29 MIDDLE + "'>" + 30 "</label> " + 31 "<label>" + 32 "<input " + 33 "class='ks-editor-link-blank' " + 34 "style='vertical-align: middle; margin-left: 21px;' " + 35 "type='checkbox'/>" + 36 " 在新窗口打开链接" + 37 "</label>" + 38 "</p>" + 39 "</div>", 40 footHtml = "<div style='padding:5px 20px 20px;'>" + 41 "<a " + 42 "href='javascript:void(\'确定\')' " + 43 "class='ks-editor-link-ok ks-editor-button ks-inline-block' " + 44 "style='margin-left:65px;margin-right:20px;'>确定</a> " + 45 "<a " + 46 "href='javascript:void(\'取消\')' " + 47 "class='ks-editor-link-cancel ks-editor-button ks-inline-block'>取消</a>" + 48 "</div>"; 49 50 function LinkDialog(editor,config) { 51 var self = this; 52 self.editor = editor; 53 self.config=config||{}; 54 Editor.Utils.lazyRun(self, "_prepareShow", "_real"); 55 } 56 57 S.augment(LinkDialog, { 58 _prepareShow:function () { 59 var self = this, 60 d = new Dialog({ 61 autoRender:true, 62 width:500, 63 headerContent:"链接", 64 bodyContent:bodyHtml, 65 footerContent:footHtml, 66 mask:true 67 }); 68 self.dialog = d; 69 var body = d.get("body"), 70 foot = d.get("footer"); 71 d.urlEl = body.one(".ks-editor-link-url"); 72 d.urlTitle = body.one(".ks-editor-link-title"); 73 d.targetEl = body.one(".ks-editor-link-blank"); 74 var cancel = foot.one(".ks-editor-link-cancel"), 75 ok = foot.one(".ks-editor-link-ok"); 76 ok.on("click", self._link, self); 77 cancel.on("click", function (ev) { 78 ev && ev.halt(); 79 d.hide(); 80 }); 81 Editor.Utils.placeholder(d.urlEl, "http://"); 82 }, 83 84 _link:function (ev) { 85 ev.halt(); 86 var self = this, 87 d = self.dialog, 88 url = d.urlEl.val(); 89 if (!Editor.Utils.verifyInputs(d.get("el").all("input"))) { 90 return; 91 } 92 d.hide(); 93 var attr = { 94 href:url, 95 target:d.targetEl[0].checked ? "_blank" : "_self", 96 title:S.trim(d.urlTitle.val()) 97 }; 98 // ie9 focus 不同步,hide后等会才能恢复焦点 99 setTimeout(function () { 100 Utils.applyLink(self.editor, attr, self._selectedEl); 101 }, 0); 102 }, 103 104 _real:function () { 105 var self = this, 106 cfg = self.config, 107 d = self.dialog, 108 _selectedEl = self._selectedEl; 109 //是修改行为 110 if (_selectedEl) { 111 var url = _selectedEl.attr(_ke_saved_href) || _selectedEl.attr("href"); 112 Editor.Utils.valInput(d.urlEl, url); 113 d.urlTitle.val(_selectedEl.attr("title") || ""); 114 d.targetEl[0].checked = (_selectedEl.attr("target") == "_blank"); 115 } else { 116 Editor.Utils.resetInput(d.urlEl); 117 d.urlTitle.val(""); 118 if (cfg.target) { 119 d.targetEl[0].checked = true; 120 } 121 } 122 d.show(); 123 }, 124 show:function (_selectedEl) { 125 var self = this; 126 self._selectedEl = _selectedEl; 127 self._prepareShow(); 128 } 129 }); 130 return LinkDialog; 131 }, { 132 requires:['editor', '../overlay/', './utils'] 133 });