bgneal@312
|
1 /* Functions for the advlink plugin popup */
|
bgneal@312
|
2
|
bgneal@312
|
3 tinyMCEPopup.requireLangPack();
|
bgneal@312
|
4
|
bgneal@312
|
5 var templates = {
|
bgneal@312
|
6 "window.open" : "window.open('${url}','${target}','${options}')"
|
bgneal@312
|
7 };
|
bgneal@312
|
8
|
bgneal@312
|
9 function preinit() {
|
bgneal@312
|
10 var url;
|
bgneal@312
|
11
|
bgneal@312
|
12 if (url = tinyMCEPopup.getParam("external_link_list_url"))
|
bgneal@312
|
13 document.write('<script language="javascript" type="text/javascript" src="' + tinyMCEPopup.editor.documentBaseURI.toAbsolute(url) + '"></script>');
|
bgneal@312
|
14 }
|
bgneal@312
|
15
|
bgneal@312
|
16 function changeClass() {
|
bgneal@312
|
17 var f = document.forms[0];
|
bgneal@312
|
18
|
bgneal@312
|
19 f.classes.value = getSelectValue(f, 'classlist');
|
bgneal@312
|
20 }
|
bgneal@312
|
21
|
bgneal@312
|
22 function init() {
|
bgneal@312
|
23 tinyMCEPopup.resizeToInnerSize();
|
bgneal@312
|
24
|
bgneal@312
|
25 var formObj = document.forms[0];
|
bgneal@312
|
26 var inst = tinyMCEPopup.editor;
|
bgneal@312
|
27 var elm = inst.selection.getNode();
|
bgneal@312
|
28 var action = "insert";
|
bgneal@312
|
29 var html;
|
bgneal@312
|
30
|
bgneal@312
|
31 document.getElementById('hrefbrowsercontainer').innerHTML = getBrowserHTML('hrefbrowser','href','file','advlink');
|
bgneal@312
|
32 document.getElementById('popupurlbrowsercontainer').innerHTML = getBrowserHTML('popupurlbrowser','popupurl','file','advlink');
|
bgneal@312
|
33 document.getElementById('linklisthrefcontainer').innerHTML = getLinkListHTML('linklisthref','href');
|
bgneal@312
|
34 document.getElementById('anchorlistcontainer').innerHTML = getAnchorListHTML('anchorlist','href');
|
bgneal@312
|
35 document.getElementById('targetlistcontainer').innerHTML = getTargetListHTML('targetlist','target');
|
bgneal@312
|
36
|
bgneal@312
|
37 // Link list
|
bgneal@312
|
38 html = getLinkListHTML('linklisthref','href');
|
bgneal@312
|
39 if (html == "")
|
bgneal@312
|
40 document.getElementById("linklisthrefrow").style.display = 'none';
|
bgneal@312
|
41 else
|
bgneal@312
|
42 document.getElementById("linklisthrefcontainer").innerHTML = html;
|
bgneal@312
|
43
|
bgneal@312
|
44 // Resize some elements
|
bgneal@312
|
45 if (isVisible('hrefbrowser'))
|
bgneal@312
|
46 document.getElementById('href').style.width = '260px';
|
bgneal@312
|
47
|
bgneal@312
|
48 if (isVisible('popupurlbrowser'))
|
bgneal@312
|
49 document.getElementById('popupurl').style.width = '180px';
|
bgneal@312
|
50
|
bgneal@312
|
51 elm = inst.dom.getParent(elm, "A");
|
bgneal@312
|
52 if (elm != null && elm.nodeName == "A")
|
bgneal@312
|
53 action = "update";
|
bgneal@312
|
54
|
bgneal@312
|
55 formObj.insert.value = tinyMCEPopup.getLang(action, 'Insert', true);
|
bgneal@312
|
56
|
bgneal@312
|
57 setPopupControlsDisabled(true);
|
bgneal@312
|
58
|
bgneal@312
|
59 if (action == "update") {
|
bgneal@312
|
60 var href = inst.dom.getAttrib(elm, 'href');
|
bgneal@312
|
61 var onclick = inst.dom.getAttrib(elm, 'onclick');
|
bgneal@312
|
62
|
bgneal@312
|
63 // Setup form data
|
bgneal@312
|
64 setFormValue('href', href);
|
bgneal@312
|
65 setFormValue('title', inst.dom.getAttrib(elm, 'title'));
|
bgneal@312
|
66 setFormValue('id', inst.dom.getAttrib(elm, 'id'));
|
bgneal@312
|
67 setFormValue('style', inst.dom.getAttrib(elm, "style"));
|
bgneal@312
|
68 setFormValue('rel', inst.dom.getAttrib(elm, 'rel'));
|
bgneal@312
|
69 setFormValue('rev', inst.dom.getAttrib(elm, 'rev'));
|
bgneal@312
|
70 setFormValue('charset', inst.dom.getAttrib(elm, 'charset'));
|
bgneal@312
|
71 setFormValue('hreflang', inst.dom.getAttrib(elm, 'hreflang'));
|
bgneal@312
|
72 setFormValue('dir', inst.dom.getAttrib(elm, 'dir'));
|
bgneal@312
|
73 setFormValue('lang', inst.dom.getAttrib(elm, 'lang'));
|
bgneal@312
|
74 setFormValue('tabindex', inst.dom.getAttrib(elm, 'tabindex', typeof(elm.tabindex) != "undefined" ? elm.tabindex : ""));
|
bgneal@312
|
75 setFormValue('accesskey', inst.dom.getAttrib(elm, 'accesskey', typeof(elm.accesskey) != "undefined" ? elm.accesskey : ""));
|
bgneal@312
|
76 setFormValue('type', inst.dom.getAttrib(elm, 'type'));
|
bgneal@312
|
77 setFormValue('onfocus', inst.dom.getAttrib(elm, 'onfocus'));
|
bgneal@312
|
78 setFormValue('onblur', inst.dom.getAttrib(elm, 'onblur'));
|
bgneal@312
|
79 setFormValue('onclick', onclick);
|
bgneal@312
|
80 setFormValue('ondblclick', inst.dom.getAttrib(elm, 'ondblclick'));
|
bgneal@312
|
81 setFormValue('onmousedown', inst.dom.getAttrib(elm, 'onmousedown'));
|
bgneal@312
|
82 setFormValue('onmouseup', inst.dom.getAttrib(elm, 'onmouseup'));
|
bgneal@312
|
83 setFormValue('onmouseover', inst.dom.getAttrib(elm, 'onmouseover'));
|
bgneal@312
|
84 setFormValue('onmousemove', inst.dom.getAttrib(elm, 'onmousemove'));
|
bgneal@312
|
85 setFormValue('onmouseout', inst.dom.getAttrib(elm, 'onmouseout'));
|
bgneal@312
|
86 setFormValue('onkeypress', inst.dom.getAttrib(elm, 'onkeypress'));
|
bgneal@312
|
87 setFormValue('onkeydown', inst.dom.getAttrib(elm, 'onkeydown'));
|
bgneal@312
|
88 setFormValue('onkeyup', inst.dom.getAttrib(elm, 'onkeyup'));
|
bgneal@312
|
89 setFormValue('target', inst.dom.getAttrib(elm, 'target'));
|
bgneal@312
|
90 setFormValue('classes', inst.dom.getAttrib(elm, 'class'));
|
bgneal@312
|
91
|
bgneal@312
|
92 // Parse onclick data
|
bgneal@312
|
93 if (onclick != null && onclick.indexOf('window.open') != -1)
|
bgneal@312
|
94 parseWindowOpen(onclick);
|
bgneal@312
|
95 else
|
bgneal@312
|
96 parseFunction(onclick);
|
bgneal@312
|
97
|
bgneal@312
|
98 // Select by the values
|
bgneal@312
|
99 selectByValue(formObj, 'dir', inst.dom.getAttrib(elm, 'dir'));
|
bgneal@312
|
100 selectByValue(formObj, 'rel', inst.dom.getAttrib(elm, 'rel'));
|
bgneal@312
|
101 selectByValue(formObj, 'rev', inst.dom.getAttrib(elm, 'rev'));
|
bgneal@312
|
102 selectByValue(formObj, 'linklisthref', href);
|
bgneal@312
|
103
|
bgneal@312
|
104 if (href.charAt(0) == '#')
|
bgneal@312
|
105 selectByValue(formObj, 'anchorlist', href);
|
bgneal@312
|
106
|
bgneal@312
|
107 addClassesToList('classlist', 'advlink_styles');
|
bgneal@312
|
108
|
bgneal@312
|
109 selectByValue(formObj, 'classlist', inst.dom.getAttrib(elm, 'class'), true);
|
bgneal@312
|
110 selectByValue(formObj, 'targetlist', inst.dom.getAttrib(elm, 'target'), true);
|
bgneal@312
|
111 } else
|
bgneal@312
|
112 addClassesToList('classlist', 'advlink_styles');
|
bgneal@312
|
113 }
|
bgneal@312
|
114
|
bgneal@312
|
115 function checkPrefix(n) {
|
bgneal@312
|
116 if (n.value && Validator.isEmail(n) && !/^\s*mailto:/i.test(n.value) && confirm(tinyMCEPopup.getLang('advlink_dlg.is_email')))
|
bgneal@312
|
117 n.value = 'mailto:' + n.value;
|
bgneal@312
|
118
|
bgneal@312
|
119 if (/^\s*www\./i.test(n.value) && confirm(tinyMCEPopup.getLang('advlink_dlg.is_external')))
|
bgneal@312
|
120 n.value = 'http://' + n.value;
|
bgneal@312
|
121 }
|
bgneal@312
|
122
|
bgneal@312
|
123 function setFormValue(name, value) {
|
bgneal@312
|
124 document.forms[0].elements[name].value = value;
|
bgneal@312
|
125 }
|
bgneal@312
|
126
|
bgneal@312
|
127 function parseWindowOpen(onclick) {
|
bgneal@312
|
128 var formObj = document.forms[0];
|
bgneal@312
|
129
|
bgneal@312
|
130 // Preprocess center code
|
bgneal@312
|
131 if (onclick.indexOf('return false;') != -1) {
|
bgneal@312
|
132 formObj.popupreturn.checked = true;
|
bgneal@312
|
133 onclick = onclick.replace('return false;', '');
|
bgneal@312
|
134 } else
|
bgneal@312
|
135 formObj.popupreturn.checked = false;
|
bgneal@312
|
136
|
bgneal@312
|
137 var onClickData = parseLink(onclick);
|
bgneal@312
|
138
|
bgneal@312
|
139 if (onClickData != null) {
|
bgneal@312
|
140 formObj.ispopup.checked = true;
|
bgneal@312
|
141 setPopupControlsDisabled(false);
|
bgneal@312
|
142
|
bgneal@312
|
143 var onClickWindowOptions = parseOptions(onClickData['options']);
|
bgneal@312
|
144 var url = onClickData['url'];
|
bgneal@312
|
145
|
bgneal@312
|
146 formObj.popupname.value = onClickData['target'];
|
bgneal@312
|
147 formObj.popupurl.value = url;
|
bgneal@312
|
148 formObj.popupwidth.value = getOption(onClickWindowOptions, 'width');
|
bgneal@312
|
149 formObj.popupheight.value = getOption(onClickWindowOptions, 'height');
|
bgneal@312
|
150
|
bgneal@312
|
151 formObj.popupleft.value = getOption(onClickWindowOptions, 'left');
|
bgneal@312
|
152 formObj.popuptop.value = getOption(onClickWindowOptions, 'top');
|
bgneal@312
|
153
|
bgneal@312
|
154 if (formObj.popupleft.value.indexOf('screen') != -1)
|
bgneal@312
|
155 formObj.popupleft.value = "c";
|
bgneal@312
|
156
|
bgneal@312
|
157 if (formObj.popuptop.value.indexOf('screen') != -1)
|
bgneal@312
|
158 formObj.popuptop.value = "c";
|
bgneal@312
|
159
|
bgneal@312
|
160 formObj.popuplocation.checked = getOption(onClickWindowOptions, 'location') == "yes";
|
bgneal@312
|
161 formObj.popupscrollbars.checked = getOption(onClickWindowOptions, 'scrollbars') == "yes";
|
bgneal@312
|
162 formObj.popupmenubar.checked = getOption(onClickWindowOptions, 'menubar') == "yes";
|
bgneal@312
|
163 formObj.popupresizable.checked = getOption(onClickWindowOptions, 'resizable') == "yes";
|
bgneal@312
|
164 formObj.popuptoolbar.checked = getOption(onClickWindowOptions, 'toolbar') == "yes";
|
bgneal@312
|
165 formObj.popupstatus.checked = getOption(onClickWindowOptions, 'status') == "yes";
|
bgneal@312
|
166 formObj.popupdependent.checked = getOption(onClickWindowOptions, 'dependent') == "yes";
|
bgneal@312
|
167
|
bgneal@312
|
168 buildOnClick();
|
bgneal@312
|
169 }
|
bgneal@312
|
170 }
|
bgneal@312
|
171
|
bgneal@312
|
172 function parseFunction(onclick) {
|
bgneal@312
|
173 var formObj = document.forms[0];
|
bgneal@312
|
174 var onClickData = parseLink(onclick);
|
bgneal@312
|
175
|
bgneal@312
|
176 // TODO: Add stuff here
|
bgneal@312
|
177 }
|
bgneal@312
|
178
|
bgneal@312
|
179 function getOption(opts, name) {
|
bgneal@312
|
180 return typeof(opts[name]) == "undefined" ? "" : opts[name];
|
bgneal@312
|
181 }
|
bgneal@312
|
182
|
bgneal@312
|
183 function setPopupControlsDisabled(state) {
|
bgneal@312
|
184 var formObj = document.forms[0];
|
bgneal@312
|
185
|
bgneal@312
|
186 formObj.popupname.disabled = state;
|
bgneal@312
|
187 formObj.popupurl.disabled = state;
|
bgneal@312
|
188 formObj.popupwidth.disabled = state;
|
bgneal@312
|
189 formObj.popupheight.disabled = state;
|
bgneal@312
|
190 formObj.popupleft.disabled = state;
|
bgneal@312
|
191 formObj.popuptop.disabled = state;
|
bgneal@312
|
192 formObj.popuplocation.disabled = state;
|
bgneal@312
|
193 formObj.popupscrollbars.disabled = state;
|
bgneal@312
|
194 formObj.popupmenubar.disabled = state;
|
bgneal@312
|
195 formObj.popupresizable.disabled = state;
|
bgneal@312
|
196 formObj.popuptoolbar.disabled = state;
|
bgneal@312
|
197 formObj.popupstatus.disabled = state;
|
bgneal@312
|
198 formObj.popupreturn.disabled = state;
|
bgneal@312
|
199 formObj.popupdependent.disabled = state;
|
bgneal@312
|
200
|
bgneal@312
|
201 setBrowserDisabled('popupurlbrowser', state);
|
bgneal@312
|
202 }
|
bgneal@312
|
203
|
bgneal@312
|
204 function parseLink(link) {
|
bgneal@312
|
205 link = link.replace(new RegExp(''', 'g'), "'");
|
bgneal@312
|
206
|
bgneal@312
|
207 var fnName = link.replace(new RegExp("\\s*([A-Za-z0-9\.]*)\\s*\\(.*", "gi"), "$1");
|
bgneal@312
|
208
|
bgneal@312
|
209 // Is function name a template function
|
bgneal@312
|
210 var template = templates[fnName];
|
bgneal@312
|
211 if (template) {
|
bgneal@312
|
212 // Build regexp
|
bgneal@312
|
213 var variableNames = template.match(new RegExp("'?\\$\\{[A-Za-z0-9\.]*\\}'?", "gi"));
|
bgneal@312
|
214 var regExp = "\\s*[A-Za-z0-9\.]*\\s*\\(";
|
bgneal@312
|
215 var replaceStr = "";
|
bgneal@312
|
216 for (var i=0; i<variableNames.length; i++) {
|
bgneal@312
|
217 // Is string value
|
bgneal@312
|
218 if (variableNames[i].indexOf("'${") != -1)
|
bgneal@312
|
219 regExp += "'(.*)'";
|
bgneal@312
|
220 else // Number value
|
bgneal@312
|
221 regExp += "([0-9]*)";
|
bgneal@312
|
222
|
bgneal@312
|
223 replaceStr += "$" + (i+1);
|
bgneal@312
|
224
|
bgneal@312
|
225 // Cleanup variable name
|
bgneal@312
|
226 variableNames[i] = variableNames[i].replace(new RegExp("[^A-Za-z0-9]", "gi"), "");
|
bgneal@312
|
227
|
bgneal@312
|
228 if (i != variableNames.length-1) {
|
bgneal@312
|
229 regExp += "\\s*,\\s*";
|
bgneal@312
|
230 replaceStr += "<delim>";
|
bgneal@312
|
231 } else
|
bgneal@312
|
232 regExp += ".*";
|
bgneal@312
|
233 }
|
bgneal@312
|
234
|
bgneal@312
|
235 regExp += "\\);?";
|
bgneal@312
|
236
|
bgneal@312
|
237 // Build variable array
|
bgneal@312
|
238 var variables = [];
|
bgneal@312
|
239 variables["_function"] = fnName;
|
bgneal@312
|
240 var variableValues = link.replace(new RegExp(regExp, "gi"), replaceStr).split('<delim>');
|
bgneal@312
|
241 for (var i=0; i<variableNames.length; i++)
|
bgneal@312
|
242 variables[variableNames[i]] = variableValues[i];
|
bgneal@312
|
243
|
bgneal@312
|
244 return variables;
|
bgneal@312
|
245 }
|
bgneal@312
|
246
|
bgneal@312
|
247 return null;
|
bgneal@312
|
248 }
|
bgneal@312
|
249
|
bgneal@312
|
250 function parseOptions(opts) {
|
bgneal@312
|
251 if (opts == null || opts == "")
|
bgneal@312
|
252 return [];
|
bgneal@312
|
253
|
bgneal@312
|
254 // Cleanup the options
|
bgneal@312
|
255 opts = opts.toLowerCase();
|
bgneal@312
|
256 opts = opts.replace(/;/g, ",");
|
bgneal@312
|
257 opts = opts.replace(/[^0-9a-z=,]/g, "");
|
bgneal@312
|
258
|
bgneal@312
|
259 var optionChunks = opts.split(',');
|
bgneal@312
|
260 var options = [];
|
bgneal@312
|
261
|
bgneal@312
|
262 for (var i=0; i<optionChunks.length; i++) {
|
bgneal@312
|
263 var parts = optionChunks[i].split('=');
|
bgneal@312
|
264
|
bgneal@312
|
265 if (parts.length == 2)
|
bgneal@312
|
266 options[parts[0]] = parts[1];
|
bgneal@312
|
267 }
|
bgneal@312
|
268
|
bgneal@312
|
269 return options;
|
bgneal@312
|
270 }
|
bgneal@312
|
271
|
bgneal@312
|
272 function buildOnClick() {
|
bgneal@312
|
273 var formObj = document.forms[0];
|
bgneal@312
|
274
|
bgneal@312
|
275 if (!formObj.ispopup.checked) {
|
bgneal@312
|
276 formObj.onclick.value = "";
|
bgneal@312
|
277 return;
|
bgneal@312
|
278 }
|
bgneal@312
|
279
|
bgneal@312
|
280 var onclick = "window.open('";
|
bgneal@312
|
281 var url = formObj.popupurl.value;
|
bgneal@312
|
282
|
bgneal@312
|
283 onclick += url + "','";
|
bgneal@312
|
284 onclick += formObj.popupname.value + "','";
|
bgneal@312
|
285
|
bgneal@312
|
286 if (formObj.popuplocation.checked)
|
bgneal@312
|
287 onclick += "location=yes,";
|
bgneal@312
|
288
|
bgneal@312
|
289 if (formObj.popupscrollbars.checked)
|
bgneal@312
|
290 onclick += "scrollbars=yes,";
|
bgneal@312
|
291
|
bgneal@312
|
292 if (formObj.popupmenubar.checked)
|
bgneal@312
|
293 onclick += "menubar=yes,";
|
bgneal@312
|
294
|
bgneal@312
|
295 if (formObj.popupresizable.checked)
|
bgneal@312
|
296 onclick += "resizable=yes,";
|
bgneal@312
|
297
|
bgneal@312
|
298 if (formObj.popuptoolbar.checked)
|
bgneal@312
|
299 onclick += "toolbar=yes,";
|
bgneal@312
|
300
|
bgneal@312
|
301 if (formObj.popupstatus.checked)
|
bgneal@312
|
302 onclick += "status=yes,";
|
bgneal@312
|
303
|
bgneal@312
|
304 if (formObj.popupdependent.checked)
|
bgneal@312
|
305 onclick += "dependent=yes,";
|
bgneal@312
|
306
|
bgneal@312
|
307 if (formObj.popupwidth.value != "")
|
bgneal@312
|
308 onclick += "width=" + formObj.popupwidth.value + ",";
|
bgneal@312
|
309
|
bgneal@312
|
310 if (formObj.popupheight.value != "")
|
bgneal@312
|
311 onclick += "height=" + formObj.popupheight.value + ",";
|
bgneal@312
|
312
|
bgneal@312
|
313 if (formObj.popupleft.value != "") {
|
bgneal@312
|
314 if (formObj.popupleft.value != "c")
|
bgneal@312
|
315 onclick += "left=" + formObj.popupleft.value + ",";
|
bgneal@312
|
316 else
|
bgneal@312
|
317 onclick += "left='+(screen.availWidth/2-" + (formObj.popupwidth.value/2) + ")+',";
|
bgneal@312
|
318 }
|
bgneal@312
|
319
|
bgneal@312
|
320 if (formObj.popuptop.value != "") {
|
bgneal@312
|
321 if (formObj.popuptop.value != "c")
|
bgneal@312
|
322 onclick += "top=" + formObj.popuptop.value + ",";
|
bgneal@312
|
323 else
|
bgneal@312
|
324 onclick += "top='+(screen.availHeight/2-" + (formObj.popupheight.value/2) + ")+',";
|
bgneal@312
|
325 }
|
bgneal@312
|
326
|
bgneal@312
|
327 if (onclick.charAt(onclick.length-1) == ',')
|
bgneal@312
|
328 onclick = onclick.substring(0, onclick.length-1);
|
bgneal@312
|
329
|
bgneal@312
|
330 onclick += "');";
|
bgneal@312
|
331
|
bgneal@312
|
332 if (formObj.popupreturn.checked)
|
bgneal@312
|
333 onclick += "return false;";
|
bgneal@312
|
334
|
bgneal@312
|
335 // tinyMCE.debug(onclick);
|
bgneal@312
|
336
|
bgneal@312
|
337 formObj.onclick.value = onclick;
|
bgneal@312
|
338
|
bgneal@312
|
339 if (formObj.href.value == "")
|
bgneal@312
|
340 formObj.href.value = url;
|
bgneal@312
|
341 }
|
bgneal@312
|
342
|
bgneal@312
|
343 function setAttrib(elm, attrib, value) {
|
bgneal@312
|
344 var formObj = document.forms[0];
|
bgneal@312
|
345 var valueElm = formObj.elements[attrib.toLowerCase()];
|
bgneal@312
|
346 var dom = tinyMCEPopup.editor.dom;
|
bgneal@312
|
347
|
bgneal@312
|
348 if (typeof(value) == "undefined" || value == null) {
|
bgneal@312
|
349 value = "";
|
bgneal@312
|
350
|
bgneal@312
|
351 if (valueElm)
|
bgneal@312
|
352 value = valueElm.value;
|
bgneal@312
|
353 }
|
bgneal@312
|
354
|
bgneal@312
|
355 // Clean up the style
|
bgneal@312
|
356 if (attrib == 'style')
|
bgneal@312
|
357 value = dom.serializeStyle(dom.parseStyle(value), 'a');
|
bgneal@312
|
358
|
bgneal@312
|
359 dom.setAttrib(elm, attrib, value);
|
bgneal@312
|
360 }
|
bgneal@312
|
361
|
bgneal@312
|
362 function getAnchorListHTML(id, target) {
|
bgneal@312
|
363 var inst = tinyMCEPopup.editor;
|
bgneal@312
|
364 var nodes = inst.dom.select('a.mceItemAnchor,img.mceItemAnchor'), name, i;
|
bgneal@312
|
365 var html = "";
|
bgneal@312
|
366
|
bgneal@312
|
367 html += '<select id="' + id + '" name="' + id + '" class="mceAnchorList" o2nfocus="tinyMCE.addSelectAccessibility(event, this, window);" onchange="this.form.' + target + '.value=';
|
bgneal@312
|
368 html += 'this.options[this.selectedIndex].value;">';
|
bgneal@312
|
369 html += '<option value="">---</option>';
|
bgneal@312
|
370
|
bgneal@312
|
371 for (i=0; i<nodes.length; i++) {
|
bgneal@312
|
372 if ((name = inst.dom.getAttrib(nodes[i], "name")) != "")
|
bgneal@312
|
373 html += '<option value="#' + name + '">' + name + '</option>';
|
bgneal@312
|
374 }
|
bgneal@312
|
375
|
bgneal@312
|
376 html += '</select>';
|
bgneal@312
|
377
|
bgneal@312
|
378 return html;
|
bgneal@312
|
379 }
|
bgneal@312
|
380
|
bgneal@312
|
381 function insertAction() {
|
bgneal@312
|
382 var inst = tinyMCEPopup.editor;
|
bgneal@312
|
383 var elm, elementArray, i;
|
bgneal@312
|
384
|
bgneal@312
|
385 elm = inst.selection.getNode();
|
bgneal@312
|
386 checkPrefix(document.forms[0].href);
|
bgneal@312
|
387
|
bgneal@312
|
388 elm = inst.dom.getParent(elm, "A");
|
bgneal@312
|
389
|
bgneal@312
|
390 // Remove element if there is no href
|
bgneal@312
|
391 if (!document.forms[0].href.value) {
|
bgneal@312
|
392 tinyMCEPopup.execCommand("mceBeginUndoLevel");
|
bgneal@312
|
393 i = inst.selection.getBookmark();
|
bgneal@312
|
394 inst.dom.remove(elm, 1);
|
bgneal@312
|
395 inst.selection.moveToBookmark(i);
|
bgneal@312
|
396 tinyMCEPopup.execCommand("mceEndUndoLevel");
|
bgneal@312
|
397 tinyMCEPopup.close();
|
bgneal@312
|
398 return;
|
bgneal@312
|
399 }
|
bgneal@312
|
400
|
bgneal@312
|
401 tinyMCEPopup.execCommand("mceBeginUndoLevel");
|
bgneal@312
|
402
|
bgneal@312
|
403 // Create new anchor elements
|
bgneal@312
|
404 if (elm == null) {
|
bgneal@312
|
405 inst.getDoc().execCommand("unlink", false, null);
|
bgneal@312
|
406 tinyMCEPopup.execCommand("CreateLink", false, "#mce_temp_url#", {skip_undo : 1});
|
bgneal@312
|
407
|
bgneal@312
|
408 elementArray = tinymce.grep(inst.dom.select("a"), function(n) {return inst.dom.getAttrib(n, 'href') == '#mce_temp_url#';});
|
bgneal@312
|
409 for (i=0; i<elementArray.length; i++)
|
bgneal@312
|
410 setAllAttribs(elm = elementArray[i]);
|
bgneal@312
|
411 } else
|
bgneal@312
|
412 setAllAttribs(elm);
|
bgneal@312
|
413
|
bgneal@312
|
414 // Don't move caret if selection was image
|
bgneal@312
|
415 if (elm.childNodes.length != 1 || elm.firstChild.nodeName != 'IMG') {
|
bgneal@312
|
416 inst.focus();
|
bgneal@312
|
417 inst.selection.select(elm);
|
bgneal@312
|
418 inst.selection.collapse(0);
|
bgneal@312
|
419 tinyMCEPopup.storeSelection();
|
bgneal@312
|
420 }
|
bgneal@312
|
421
|
bgneal@312
|
422 tinyMCEPopup.execCommand("mceEndUndoLevel");
|
bgneal@312
|
423 tinyMCEPopup.close();
|
bgneal@312
|
424 }
|
bgneal@312
|
425
|
bgneal@312
|
426 function setAllAttribs(elm) {
|
bgneal@312
|
427 var formObj = document.forms[0];
|
bgneal@312
|
428 var href = formObj.href.value;
|
bgneal@312
|
429 var target = getSelectValue(formObj, 'targetlist');
|
bgneal@312
|
430
|
bgneal@312
|
431 setAttrib(elm, 'href', href);
|
bgneal@312
|
432 setAttrib(elm, 'title');
|
bgneal@312
|
433 setAttrib(elm, 'target', target == '_self' ? '' : target);
|
bgneal@312
|
434 setAttrib(elm, 'id');
|
bgneal@312
|
435 setAttrib(elm, 'style');
|
bgneal@312
|
436 setAttrib(elm, 'class', getSelectValue(formObj, 'classlist'));
|
bgneal@312
|
437 setAttrib(elm, 'rel');
|
bgneal@312
|
438 setAttrib(elm, 'rev');
|
bgneal@312
|
439 setAttrib(elm, 'charset');
|
bgneal@312
|
440 setAttrib(elm, 'hreflang');
|
bgneal@312
|
441 setAttrib(elm, 'dir');
|
bgneal@312
|
442 setAttrib(elm, 'lang');
|
bgneal@312
|
443 setAttrib(elm, 'tabindex');
|
bgneal@312
|
444 setAttrib(elm, 'accesskey');
|
bgneal@312
|
445 setAttrib(elm, 'type');
|
bgneal@312
|
446 setAttrib(elm, 'onfocus');
|
bgneal@312
|
447 setAttrib(elm, 'onblur');
|
bgneal@312
|
448 setAttrib(elm, 'onclick');
|
bgneal@312
|
449 setAttrib(elm, 'ondblclick');
|
bgneal@312
|
450 setAttrib(elm, 'onmousedown');
|
bgneal@312
|
451 setAttrib(elm, 'onmouseup');
|
bgneal@312
|
452 setAttrib(elm, 'onmouseover');
|
bgneal@312
|
453 setAttrib(elm, 'onmousemove');
|
bgneal@312
|
454 setAttrib(elm, 'onmouseout');
|
bgneal@312
|
455 setAttrib(elm, 'onkeypress');
|
bgneal@312
|
456 setAttrib(elm, 'onkeydown');
|
bgneal@312
|
457 setAttrib(elm, 'onkeyup');
|
bgneal@312
|
458
|
bgneal@312
|
459 // Refresh in old MSIE
|
bgneal@312
|
460 if (tinyMCE.isMSIE5)
|
bgneal@312
|
461 elm.outerHTML = elm.outerHTML;
|
bgneal@312
|
462 }
|
bgneal@312
|
463
|
bgneal@312
|
464 function getSelectValue(form_obj, field_name) {
|
bgneal@312
|
465 var elm = form_obj.elements[field_name];
|
bgneal@312
|
466
|
bgneal@312
|
467 if (!elm || elm.options == null || elm.selectedIndex == -1)
|
bgneal@312
|
468 return "";
|
bgneal@312
|
469
|
bgneal@312
|
470 return elm.options[elm.selectedIndex].value;
|
bgneal@312
|
471 }
|
bgneal@312
|
472
|
bgneal@312
|
473 function getLinkListHTML(elm_id, target_form_element, onchange_func) {
|
bgneal@312
|
474 if (typeof(tinyMCELinkList) == "undefined" || tinyMCELinkList.length == 0)
|
bgneal@312
|
475 return "";
|
bgneal@312
|
476
|
bgneal@312
|
477 var html = "";
|
bgneal@312
|
478
|
bgneal@312
|
479 html += '<select id="' + elm_id + '" name="' + elm_id + '"';
|
bgneal@312
|
480 html += ' class="mceLinkList" onfoc2us="tinyMCE.addSelectAccessibility(event, this, window);" onchange="this.form.' + target_form_element + '.value=';
|
bgneal@312
|
481 html += 'this.options[this.selectedIndex].value;';
|
bgneal@312
|
482
|
bgneal@312
|
483 if (typeof(onchange_func) != "undefined")
|
bgneal@312
|
484 html += onchange_func + '(\'' + target_form_element + '\',this.options[this.selectedIndex].text,this.options[this.selectedIndex].value);';
|
bgneal@312
|
485
|
bgneal@312
|
486 html += '"><option value="">---</option>';
|
bgneal@312
|
487
|
bgneal@312
|
488 for (var i=0; i<tinyMCELinkList.length; i++)
|
bgneal@312
|
489 html += '<option value="' + tinyMCELinkList[i][1] + '">' + tinyMCELinkList[i][0] + '</option>';
|
bgneal@312
|
490
|
bgneal@312
|
491 html += '</select>';
|
bgneal@312
|
492
|
bgneal@312
|
493 return html;
|
bgneal@312
|
494
|
bgneal@312
|
495 // tinyMCE.debug('-- image list start --', html, '-- image list end --');
|
bgneal@312
|
496 }
|
bgneal@312
|
497
|
bgneal@312
|
498 function getTargetListHTML(elm_id, target_form_element) {
|
bgneal@312
|
499 var targets = tinyMCEPopup.getParam('theme_advanced_link_targets', '').split(';');
|
bgneal@312
|
500 var html = '';
|
bgneal@312
|
501
|
bgneal@312
|
502 html += '<select id="' + elm_id + '" name="' + elm_id + '" onf2ocus="tinyMCE.addSelectAccessibility(event, this, window);" onchange="this.form.' + target_form_element + '.value=';
|
bgneal@312
|
503 html += 'this.options[this.selectedIndex].value;">';
|
bgneal@312
|
504 html += '<option value="_self">' + tinyMCEPopup.getLang('advlink_dlg.target_same') + '</option>';
|
bgneal@312
|
505 html += '<option value="_blank">' + tinyMCEPopup.getLang('advlink_dlg.target_blank') + ' (_blank)</option>';
|
bgneal@312
|
506 html += '<option value="_parent">' + tinyMCEPopup.getLang('advlink_dlg.target_parent') + ' (_parent)</option>';
|
bgneal@312
|
507 html += '<option value="_top">' + tinyMCEPopup.getLang('advlink_dlg.target_top') + ' (_top)</option>';
|
bgneal@312
|
508
|
bgneal@312
|
509 for (var i=0; i<targets.length; i++) {
|
bgneal@312
|
510 var key, value;
|
bgneal@312
|
511
|
bgneal@312
|
512 if (targets[i] == "")
|
bgneal@312
|
513 continue;
|
bgneal@312
|
514
|
bgneal@312
|
515 key = targets[i].split('=')[0];
|
bgneal@312
|
516 value = targets[i].split('=')[1];
|
bgneal@312
|
517
|
bgneal@312
|
518 html += '<option value="' + key + '">' + value + ' (' + key + ')</option>';
|
bgneal@312
|
519 }
|
bgneal@312
|
520
|
bgneal@312
|
521 html += '</select>';
|
bgneal@312
|
522
|
bgneal@312
|
523 return html;
|
bgneal@312
|
524 }
|
bgneal@312
|
525
|
bgneal@312
|
526 // While loading
|
bgneal@312
|
527 preinit();
|
bgneal@312
|
528 tinyMCEPopup.onInit.add(init);
|