📄 正在查看:twcms/plugin/editor_um/umeditor/dialogs/link/link.js
1(function(){
2 var utils = UM.utils;
3 function hrefStartWith(href, arr) {
4 href = href.replace(/^\s+|\s+$/g, '');
5 for (var i = 0, ai; ai = arr[i++];) {
6 if (href.indexOf(ai) == 0) {
7 return true;
8 }
9 }
10 return false;
11 }
12
13 UM.registerWidget('link', {
14 tpl: "<style type=\"text/css\">" +
15 ".edui-link-table{font-size: 12px;margin: 10px;line-height: 30px}" +
16 ".edui-link-txt{width:300px;height:21px;line-height:21px;border:1px solid #d7d7d7;}" +
17 "</style>" +
18 "<table class=\"edui-link-table\">" +
19 "<tr>" +
20 "<td><label for=\"href\"><%=lang_input_url%></label></td>" +
21 "<td><input class=\"edui-link-txt\" id=\"edui-link-Jhref\" type=\"text\" /></td>" +
22 "</tr>" +
23 "<tr>" +
24 "<td><label for=\"title\"><%=lang_input_title%></label></td>" +
25 "<td><input class=\"edui-link-txt\" id=\"edui-link-Jtitle\" type=\"text\"/></td>" +
26 "</tr>" +
27 "<tr>" +
28 "<td colspan=\"2\">" +
29 "<label for=\"target\"><%=lang_input_target%></label>" +
30 "<input id=\"edui-link-Jtarget\" type=\"checkbox\"/>" +
31 "</td>" +
32 "</tr>" +
33 // "<tr>" +
34 // "<td colspan=\"2\" id=\"edui-link-Jmsg\"></td>" +
35 // "</tr>" +
36 "</table>",
37 initContent: function (editor) {
38 var lang = editor.getLang('link');
39 if (lang) {
40 var html = $.parseTmpl(this.tpl, lang.static);
41 }
42 this.root().html(html);
43 },
44 initEvent: function (editor, $w) {
45 var link = editor.queryCommandValue('link');
46 if(link){
47 $('#edui-link-Jhref',$w).val(utils.html($(link).attr('href')));
48 $('#edui-link-Jtitle',$w).val($(link).attr('title'));
49 $(link).attr('target') == '_blank' && $('#edui-link-Jtarget').attr('checked',true)
50 }
51 },
52 buttons: {
53 'ok': {
54 exec: function (editor, $w) {
55 var href = $('#edui-link-Jhref').val().replace(/^\s+|\s+$/g, '');
56
57 if (href) {
58 editor.execCommand('link', {
59 'href': href,
60 'target': $("#edui-link-Jtarget:checked").length ? "_blank" : '_self',
61 'title': $("#edui-link-Jtitle").val().replace(/^\s+|\s+$/g, ''),
62 '_href': href
63 });
64 }
65 }
66 },
67 'cancel':{}
68 },
69 width: 400
70 })
71})();
72
73