]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/js/tinymce/themes/advanced/js/link.js
WordPress 3.8.3-scripts
[autoinstalls/wordpress.git] / wp-includes / js / tinymce / themes / advanced / js / link.js
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, href = f.href.value.replace(/ /g, '%20');
35
36                 tinyMCEPopup.restoreSelection();
37                 e = ed.dom.getParent(ed.selection.getNode(), 'A');
38
39                 // Remove element if there is no href
40                 if (!f.href.value) {
41                         if (e) {
42                                 b = ed.selection.getBookmark();
43                                 ed.dom.remove(e, 1);
44                                 ed.selection.moveToBookmark(b);
45                                 tinyMCEPopup.execCommand("mceEndUndoLevel");
46                                 tinyMCEPopup.close();
47                                 return;
48                         }
49                 }
50
51                 // Create new anchor elements
52                 if (e == null) {
53                         ed.getDoc().execCommand("unlink", false, null);
54                         tinyMCEPopup.execCommand("mceInsertLink", false, "#mce_temp_url#", {skip_undo : 1});
55
56                         tinymce.each(ed.dom.select("a"), function(n) {
57                                 if (ed.dom.getAttrib(n, 'href') == '#mce_temp_url#') {
58                                         e = n;
59
60                                         ed.dom.setAttribs(e, {
61                                                 href : href,
62                                                 title : f.linktitle.value,
63                                                 target : f.target_list ? getSelectValue(f, "target_list") : null,
64                                                 'class' : f.class_list ? getSelectValue(f, "class_list") : null
65                                         });
66                                 }
67                         });
68                 } else {
69                         ed.dom.setAttribs(e, {
70                                 href : href,
71                                 title : f.linktitle.value
72                         });
73         
74                         if (f.target_list) {
75                                 ed.dom.setAttrib(e, 'target', getSelectValue(f, "target_list"));
76                         }
77
78                         if (f.class_list) {
79                                 ed.dom.setAttrib(e, 'class', getSelectValue(f, "class_list"));
80                         }
81                 }
82
83                 // Don't move caret if selection was image
84                 if (e.childNodes.length != 1 || e.firstChild.nodeName != 'IMG') {
85                         ed.focus();
86                         ed.selection.select(e);
87                         ed.selection.collapse(0);
88                         tinyMCEPopup.storeSelection();
89                 }
90
91                 tinyMCEPopup.execCommand("mceEndUndoLevel");
92                 tinyMCEPopup.close();
93         },
94
95         checkPrefix : function(n) {
96                 if (n.value && Validator.isEmail(n) && !/^\s*mailto:/i.test(n.value) && confirm(tinyMCEPopup.getLang('advanced_dlg.link_is_email')))
97                         n.value = 'mailto:' + n.value;
98
99                 if (/^\s*www\./i.test(n.value) && confirm(tinyMCEPopup.getLang('advanced_dlg.link_is_external')))
100                         n.value = 'http://' + n.value;
101         },
102
103         fillFileList : function(id, l) {
104                 var dom = tinyMCEPopup.dom, lst = dom.get(id), v, cl;
105
106                 l = window[l];
107
108                 if (l && l.length > 0) {
109                         lst.options[lst.options.length] = new Option('', '');
110
111                         tinymce.each(l, function(o) {
112                                 lst.options[lst.options.length] = new Option(o[0], o[1]);
113                         });
114                 } else
115                         dom.remove(dom.getParent(id, 'tr'));
116         },
117
118         fillClassList : function(id) {
119                 var dom = tinyMCEPopup.dom, lst = dom.get(id), v, cl;
120
121                 if (v = tinyMCEPopup.getParam('theme_advanced_styles')) {
122                         cl = [];
123
124                         tinymce.each(v.split(';'), function(v) {
125                                 var p = v.split('=');
126
127                                 cl.push({'title' : p[0], 'class' : p[1]});
128                         });
129                 } else
130                         cl = tinyMCEPopup.editor.dom.getClasses();
131
132                 if (cl.length > 0) {
133                         lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('not_set'), '');
134
135                         tinymce.each(cl, function(o) {
136                                 lst.options[lst.options.length] = new Option(o.title || o['class'], o['class']);
137                         });
138                 } else
139                         dom.remove(dom.getParent(id, 'tr'));
140         },
141
142         fillTargetList : function(id) {
143                 var dom = tinyMCEPopup.dom, lst = dom.get(id), v;
144
145                 lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('not_set'), '');
146                 lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('advanced_dlg.link_target_same'), '_self');
147                 lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('advanced_dlg.link_target_blank'), '_blank');
148
149                 if (v = tinyMCEPopup.getParam('theme_advanced_link_targets')) {
150                         tinymce.each(v.split(','), function(v) {
151                                 v = v.split('=');
152                                 lst.options[lst.options.length] = new Option(v[0], v[1]);
153                         });
154                 }
155         }
156 };
157
158 LinkDialog.preInit();
159 tinyMCEPopup.onInit.add(LinkDialog.init, LinkDialog);