1 | tinyMCEPopup.requireLangPack(); |
---|
2 | |
---|
3 | var LinkDialog = { |
---|
4 | preInit : function() { |
---|
5 | var url; |
---|
6 | |
---|
7 | if (url = tinyMCEPopup.getParam("external_link_list_url")) |
---|
8 | document.write('<script language="javascript" type="text/javascript" src="' + tinyMCEPopup.editor.documentBaseURI.toAbsolute(url) + '"></script>'); |
---|
9 | }, |
---|
10 | |
---|
11 | init : function() { |
---|
12 | var f = document.forms[0], ed = tinyMCEPopup.editor; |
---|
13 | |
---|
14 | // Setup browse button |
---|
15 | document.getElementById('hrefbrowsercontainer').innerHTML = getBrowserHTML('hrefbrowser', 'href', 'file', 'theme_advanced_link'); |
---|
16 | if (isVisible('hrefbrowser')) |
---|
17 | document.getElementById('href').style.width = '180px'; |
---|
18 | |
---|
19 | this.fillClassList('class_list'); |
---|
20 | this.fillFileList('link_list', 'tinyMCELinkList'); |
---|
21 | this.fillTargetList('target_list'); |
---|
22 | |
---|
23 | if (e = ed.dom.getParent(ed.selection.getNode(), 'A')) { |
---|
24 | f.href.value = ed.dom.getAttrib(e, 'href'); |
---|
25 | f.linktitle.value = ed.dom.getAttrib(e, 'title'); |
---|
26 | f.insert.value = ed.getLang('update'); |
---|
27 | selectByValue(f, 'link_list', f.href.value); |
---|
28 | selectByValue(f, 'target_list', ed.dom.getAttrib(e, 'target')); |
---|
29 | selectByValue(f, 'class_list', ed.dom.getAttrib(e, 'class')); |
---|
30 | } |
---|
31 | }, |
---|
32 | |
---|
33 | update : function() { |
---|
34 | var f = document.forms[0], ed = tinyMCEPopup.editor, e, b; |
---|
35 | |
---|
36 | // Remove element if there is no href |
---|
37 | if (!f.href.value) { |
---|
38 | e = ed.dom.getParent(ed.selection.getNode(), 'A'); |
---|
39 | if (e) { |
---|
40 | tinyMCEPopup.execCommand("mceBeginUndoLevel"); |
---|
41 | b = ed.selection.getBookmark(); |
---|
42 | ed.dom.remove(e, 1); |
---|
43 | ed.selection.moveToBookmark(b); |
---|
44 | tinyMCEPopup.execCommand("mceEndUndoLevel"); |
---|
45 | tinyMCEPopup.close(); |
---|
46 | return; |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | ed.execCommand('mceInsertLink', false, { |
---|
51 | href : f.href.value, |
---|
52 | title : f.linktitle.value, |
---|
53 | target : f.target_list ? f.target_list.options[f.target_list.selectedIndex].value : null, |
---|
54 | 'class' : f.class_list ? f.class_list.options[f.class_list.selectedIndex].value : null |
---|
55 | }); |
---|
56 | |
---|
57 | tinyMCEPopup.close(); |
---|
58 | }, |
---|
59 | |
---|
60 | checkPrefix : function(n) { |
---|
61 | if (n.value && Validator.isEmail(n) && !/^\s*mailto:/i.test(n.value) && confirm(tinyMCEPopup.getLang('advanced_dlg.link_is_email'))) |
---|
62 | n.value = 'mailto:' + n.value; |
---|
63 | |
---|
64 | if (/^\s*www./i.test(n.value) && confirm(tinyMCEPopup.getLang('advanced_dlg.link_is_external'))) |
---|
65 | n.value = 'http://' + n.value; |
---|
66 | }, |
---|
67 | |
---|
68 | fillFileList : function(id, l) { |
---|
69 | var dom = tinyMCEPopup.dom, lst = dom.get(id), v, cl; |
---|
70 | |
---|
71 | l = window[l]; |
---|
72 | |
---|
73 | if (l && l.length > 0) { |
---|
74 | lst.options[lst.options.length] = new Option('', ''); |
---|
75 | |
---|
76 | tinymce.each(l, function(o) { |
---|
77 | lst.options[lst.options.length] = new Option(o[0], o[1]); |
---|
78 | }); |
---|
79 | } else |
---|
80 | dom.remove(dom.getParent(id, 'tr')); |
---|
81 | }, |
---|
82 | |
---|
83 | fillClassList : function(id) { |
---|
84 | var dom = tinyMCEPopup.dom, lst = dom.get(id), v, cl; |
---|
85 | |
---|
86 | if (v = tinyMCEPopup.getParam('theme_advanced_styles')) { |
---|
87 | cl = []; |
---|
88 | |
---|
89 | tinymce.each(v.split(';'), function(v) { |
---|
90 | var p = v.split('='); |
---|
91 | |
---|
92 | cl.push({'title' : p[0], 'class' : p[1]}); |
---|
93 | }); |
---|
94 | } else |
---|
95 | cl = tinyMCEPopup.editor.dom.getClasses(); |
---|
96 | |
---|
97 | if (cl.length > 0) { |
---|
98 | lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('not_set'), ''); |
---|
99 | |
---|
100 | tinymce.each(cl, function(o) { |
---|
101 | lst.options[lst.options.length] = new Option(o.title || o['class'], o['class']); |
---|
102 | }); |
---|
103 | } else |
---|
104 | dom.remove(dom.getParent(id, 'tr')); |
---|
105 | }, |
---|
106 | |
---|
107 | fillTargetList : function(id) { |
---|
108 | var dom = tinyMCEPopup.dom, lst = dom.get(id), v; |
---|
109 | |
---|
110 | lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('not_set'), ''); |
---|
111 | lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('advanced_dlg.link_target_same'), '_self'); |
---|
112 | lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('advanced_dlg.link_target_blank'), '_blank'); |
---|
113 | |
---|
114 | if (v = tinyMCEPopup.getParam('theme_advanced_link_targets')) { |
---|
115 | tinymce.each(v.split(','), function(v) { |
---|
116 | v = v.split('='); |
---|
117 | html += '<option value="' + v[1] + '">' + v[0] + '</option>'; |
---|
118 | }); |
---|
119 | } |
---|
120 | } |
---|
121 | }; |
---|
122 | |
---|
123 | LinkDialog.preInit(); |
---|
124 | tinyMCEPopup.onInit.add(LinkDialog.init, LinkDialog); |
---|