1 | /* Change link button actions |
---|
2 | -------------------------------------------------------- */ |
---|
3 | jsToolBar.prototype.elements.link.data = {}; |
---|
4 | jsToolBar.prototype.elements.link.fncall = {}; |
---|
5 | jsToolBar.prototype.elements.link.open_url = 'popup_link.php'; |
---|
6 | |
---|
7 | jsToolBar.prototype.elements.link.popup = function (args) { |
---|
8 | window.the_toolbar = this; |
---|
9 | args = args || ''; |
---|
10 | |
---|
11 | this.elements.link.data = {}; |
---|
12 | var url = this.elements.link.open_url+args; |
---|
13 | |
---|
14 | var p_win = window.open(url,'dc_popup', |
---|
15 | 'alwaysRaised=yes,dependent=yes,toolbar=yes,height=420,width=520,'+ |
---|
16 | 'menubar=no,resizable=yes,scrollbars=yes,status=no'); |
---|
17 | }; |
---|
18 | |
---|
19 | jsToolBar.prototype.elements.link.fn.wiki = function() { |
---|
20 | this.elements.link.popup.call(this,'?hreflang='+this.elements.link.default_hreflang); |
---|
21 | }; |
---|
22 | jsToolBar.prototype.elements.link.fncall.wiki = function() { |
---|
23 | var data = this.elements.link.data; |
---|
24 | |
---|
25 | if (data.href == '') { return; } |
---|
26 | |
---|
27 | var etag = '|'+data.href; |
---|
28 | if (data.hreflang) { etag += '|'+data.hreflang; } |
---|
29 | |
---|
30 | if (data.title) { |
---|
31 | if (!data.hreflang) { etag += '|'; } |
---|
32 | etag += '|'+data.title; |
---|
33 | } |
---|
34 | |
---|
35 | if (data.content) { |
---|
36 | this.encloseSelection('['+data.content,etag+']'); |
---|
37 | } else { |
---|
38 | this.encloseSelection('[',etag+']'); |
---|
39 | } |
---|
40 | }; |
---|
41 | |
---|
42 | jsToolBar.prototype.elements.link.fn.xhtml = function() { |
---|
43 | this.elements.link.popup.call(this,'?hreflang='+this.elements.link.default_hreflang); |
---|
44 | }; |
---|
45 | jsToolBar.prototype.elements.link.fncall.xhtml = function() { |
---|
46 | var data = this.elements.link.data; |
---|
47 | |
---|
48 | if (data.href == '') { return; } |
---|
49 | |
---|
50 | var stag = '<a href="'+data.href+'"'; |
---|
51 | |
---|
52 | if (data.hreflang) { stag += ' hreflang="'+data.hreflang+'"'; } |
---|
53 | if (data.title) { stag += ' title="'+data.title+'"'; } |
---|
54 | stag += '>'; |
---|
55 | var etag = '</a>'; |
---|
56 | |
---|
57 | if (data.content) { |
---|
58 | this.encloseSelection('','',function() { |
---|
59 | return stag + data.content + etag; |
---|
60 | }); |
---|
61 | } else { |
---|
62 | this.encloseSelection(stag,etag); |
---|
63 | } |
---|
64 | }; |
---|
65 | |
---|
66 | jsToolBar.prototype.elements.link.fn.wysiwyg = function() { |
---|
67 | var href, title, hreflang; |
---|
68 | href = title = hreflang = ''; |
---|
69 | hreflang = this.elements.link.default_hreflang; |
---|
70 | |
---|
71 | var a = this.getAncestor(); |
---|
72 | |
---|
73 | if (a.tagName == 'a') { |
---|
74 | href= a.tag.href || ''; |
---|
75 | title = a.tag.title || ''; |
---|
76 | hreflang = a.tag.hreflang || ''; |
---|
77 | } |
---|
78 | |
---|
79 | this.elements.link.popup.call(this,'?href='+href+'&hreflang='+hreflang+'&title='+title); |
---|
80 | }; |
---|
81 | jsToolBar.prototype.elements.link.fncall.wysiwyg = function() { |
---|
82 | var data = this.elements.link.data; |
---|
83 | |
---|
84 | var a = this.getAncestor(); |
---|
85 | |
---|
86 | if (a.tagName == 'a') { |
---|
87 | if (data.href == '') { |
---|
88 | // Remove link |
---|
89 | this.replaceNodeByContent(a.tag); |
---|
90 | this.iwin.focus(); |
---|
91 | return; |
---|
92 | } else { |
---|
93 | // Update link |
---|
94 | a.tag.href = data.href; |
---|
95 | if (data.hreflang) { |
---|
96 | a.tag.setAttribute('hreflang',data.hreflang); |
---|
97 | } else { |
---|
98 | a.tag.removeAttribute('hreflang'); |
---|
99 | } |
---|
100 | if (data.title) { |
---|
101 | a.tag.setAttribute('title',data.title); |
---|
102 | } else { |
---|
103 | a.tag.removeAttribute('title'); |
---|
104 | } |
---|
105 | return; |
---|
106 | } |
---|
107 | } |
---|
108 | |
---|
109 | // Create link |
---|
110 | if (data.content) { |
---|
111 | var n = document.createTextNode(data.content); |
---|
112 | } else { |
---|
113 | var n = this.getSelectedNode(); |
---|
114 | } |
---|
115 | var a = this.iwin.document.createElement('a'); |
---|
116 | a.href = data.href; |
---|
117 | if (data.hreflang) a.setAttribute('hreflang',data.hreflang); |
---|
118 | a.appendChild(n); |
---|
119 | this.insertNode(a); |
---|
120 | }; |
---|
121 | jsToolBar.prototype.getAncestor = function() { |
---|
122 | var res = {}; |
---|
123 | var range, commonAncestorContainer; |
---|
124 | |
---|
125 | if (this.iwin.getSelection) { //gecko |
---|
126 | var selection = this.iwin.getSelection(); |
---|
127 | range = selection.getRangeAt(0); |
---|
128 | commonAncestorContainer = range.commonAncestorContainer; |
---|
129 | while (commonAncestorContainer.nodeType != 1) { |
---|
130 | commonAncestorContainer = commonAncestorContainer.parentNode; |
---|
131 | } |
---|
132 | } else { //ie |
---|
133 | range = this.iwin.document.selection.createRange(); |
---|
134 | commonAncestorContainer = range.parentElement(); |
---|
135 | } |
---|
136 | |
---|
137 | var ancestorTagName = commonAncestorContainer.tagName.toLowerCase(); |
---|
138 | while (ancestorTagName!='a' && ancestorTagName!='body') { |
---|
139 | commonAncestorContainer = commonAncestorContainer.parentNode; |
---|
140 | ancestorTagName = commonAncestorContainer.tagName.toLowerCase(); |
---|
141 | } |
---|
142 | |
---|
143 | res.tag = commonAncestorContainer; |
---|
144 | res.tagName = ancestorTagName; |
---|
145 | |
---|
146 | return res; |
---|
147 | }; |
---|
148 | |
---|
149 | /* Image selector |
---|
150 | -------------------------------------------------------- */ |
---|
151 | jsToolBar.prototype.elements.img_select = { |
---|
152 | type: 'button', |
---|
153 | title: 'Image chooser', |
---|
154 | fn: {}, |
---|
155 | fncall: {}, |
---|
156 | open_url: 'media.php?popup=1', |
---|
157 | data: {}, |
---|
158 | popup: function() { |
---|
159 | window.the_toolbar = this; |
---|
160 | this.elements.img_select.data = {}; |
---|
161 | |
---|
162 | var p_win = window.open(this.elements.img_select.open_url,'dc_popup', |
---|
163 | 'alwaysRaised=yes,dependent=yes,toolbar=yes,height=500,width=760,'+ |
---|
164 | 'menubar=no,resizable=yes,scrollbars=yes,status=no'); |
---|
165 | } |
---|
166 | }; |
---|
167 | jsToolBar.prototype.elements.img_select.fn.wiki = function() { |
---|
168 | this.elements.img_select.popup.call(this); |
---|
169 | }; |
---|
170 | jsToolBar.prototype.elements.img_select.fncall.wiki = function() { |
---|
171 | var d = this.elements.img_select.data; |
---|
172 | if (d.src == undefined) { return; } |
---|
173 | |
---|
174 | this.encloseSelection('','',function(str) { |
---|
175 | var alt = (str) ? str : d.title; |
---|
176 | var res = '(('+d.src+'|'+alt; |
---|
177 | |
---|
178 | if (d.alignment == 'left') { |
---|
179 | res += '|L'; |
---|
180 | } else if (d.alignment == 'right') { |
---|
181 | res += '|R'; |
---|
182 | } else if (d.alignment == 'center') { |
---|
183 | res += '|C'; |
---|
184 | } else if (d.description) { |
---|
185 | res += '|'; |
---|
186 | } |
---|
187 | |
---|
188 | if (d.description) { |
---|
189 | res += '|'+d.description; |
---|
190 | } |
---|
191 | |
---|
192 | res += '))'; |
---|
193 | |
---|
194 | if (d.link) { |
---|
195 | var ltitle = (alt) ? '||'+alt : ''; |
---|
196 | res = '['+res+'|'+d.url+ltitle+']'; |
---|
197 | } |
---|
198 | |
---|
199 | return res; |
---|
200 | }); |
---|
201 | }; |
---|
202 | jsToolBar.prototype.elements.img_select.fn.xhtml = function() { |
---|
203 | this.elements.img_select.popup.call(this); |
---|
204 | }; |
---|
205 | jsToolBar.prototype.elements.img_select.fncall.xhtml = function() { |
---|
206 | var d = this.elements.img_select.data; |
---|
207 | if (d.src == undefined) { return; } |
---|
208 | |
---|
209 | this.encloseSelection('','',function(str) { |
---|
210 | var alt = (str) ? str : d.title; |
---|
211 | var res = '<img src="'+d.src+'" alt="'+alt.replace('&','&').replace('>','>').replace('<','<').replace('"','"')+'"'; |
---|
212 | |
---|
213 | if (d.alignment == 'left') { |
---|
214 | res += ' style="float: left; margin: 0 1em 1em 0;"'; |
---|
215 | } else if (d.alignment == 'right') { |
---|
216 | res += ' style="float: right; margin: 0 0 1em 1em;"'; |
---|
217 | } else if (d.alignment == 'center') { |
---|
218 | res += ' style="margin: 0 auto; display: block;"'; |
---|
219 | } |
---|
220 | |
---|
221 | if (d.description) { |
---|
222 | res += ' title="'+d.description.replace('&','&').replace('>','>').replace('<','<').replace('"','"')+'"'; |
---|
223 | } |
---|
224 | |
---|
225 | res += ' />'; |
---|
226 | |
---|
227 | if (d.link) { |
---|
228 | var ltitle = (alt) ? ' title="'+alt.replace('&','&').replace('>','>').replace('<','<').replace('"','"')+'"' : ''; |
---|
229 | res = '<a href="'+d.url+'"'+ltitle+'>'+res+'</a>'; |
---|
230 | } |
---|
231 | |
---|
232 | return res; |
---|
233 | }); |
---|
234 | }; |
---|
235 | |
---|
236 | jsToolBar.prototype.elements.img.fn.wysiwyg = function() { |
---|
237 | var src = this.elements.img.prompt.call(this); |
---|
238 | if (!src) { return; } |
---|
239 | |
---|
240 | var img = this.iwin.document.createElement('img'); |
---|
241 | img.src = src; |
---|
242 | img.setAttribute('alt',this.getSelectedText()); |
---|
243 | |
---|
244 | this.insertNode(img); |
---|
245 | }; |
---|
246 | |
---|
247 | jsToolBar.prototype.elements.img_select.fn.wysiwyg = function() { |
---|
248 | this.elements.img_select.popup.call(this); |
---|
249 | }; |
---|
250 | jsToolBar.prototype.elements.img_select.fncall.wysiwyg = function() { |
---|
251 | var d = this.elements.img_select.data; |
---|
252 | var alt = (this.getSelectedText()) ? this.getSelectedText() : d.title; |
---|
253 | if (d.src == undefined) { return; } |
---|
254 | |
---|
255 | var img = this.iwin.document.createElement('img'); |
---|
256 | img.src = d.src; |
---|
257 | img.setAttribute('alt',alt); |
---|
258 | |
---|
259 | |
---|
260 | if (d.alignment == 'left') { |
---|
261 | if (img.style.styleFloat != undefined) { |
---|
262 | img.style.styleFloat = 'left'; |
---|
263 | } else { |
---|
264 | img.style.cssFloat = 'left'; |
---|
265 | } |
---|
266 | img.style.marginTop = 0; |
---|
267 | img.style.marginRight = '1em'; |
---|
268 | img.style.marginBottom = '1em'; |
---|
269 | img.style.marginLeft = 0; |
---|
270 | } else if (d.alignment == 'right') { |
---|
271 | if (img.style.styleFloat != undefined) { |
---|
272 | img.style.styleFloat = 'right'; |
---|
273 | } else { |
---|
274 | img.style.cssFloat = 'right'; |
---|
275 | } |
---|
276 | img.style.marginTop = 0; |
---|
277 | img.style.marginRight = 0; |
---|
278 | img.style.marginBottom = '1em'; |
---|
279 | img.style.marginLeft = '1em'; |
---|
280 | } else if (d.alignment == 'center') { |
---|
281 | img.style.marginTop = 0; |
---|
282 | img.style.marginRight = 'auto'; |
---|
283 | img.style.marginBottom = 0; |
---|
284 | img.style.marginLeft = 'auto'; |
---|
285 | img.style.display = 'block'; |
---|
286 | } |
---|
287 | |
---|
288 | if (d.description) { |
---|
289 | img.setAttribute('title',d.description); |
---|
290 | } |
---|
291 | |
---|
292 | if (d.link) { |
---|
293 | var a = this.iwin.document.createElement('a'); |
---|
294 | a.href = d.url; |
---|
295 | if (alt) { |
---|
296 | a.setAttribute('title',alt); |
---|
297 | } |
---|
298 | a.appendChild(img); |
---|
299 | this.insertNode(a); |
---|
300 | } else { |
---|
301 | this.insertNode(img); |
---|
302 | } |
---|
303 | }; |
---|
304 | |
---|
305 | // MP3 helpers |
---|
306 | jsToolBar.prototype.elements.mp3_insert = { fncall: {}, data: {} }; |
---|
307 | jsToolBar.prototype.elements.mp3_insert.fncall.wiki = function() { |
---|
308 | var d = this.elements.mp3_insert.data; |
---|
309 | if (d.player == undefined) { return; } |
---|
310 | |
---|
311 | this.encloseSelection('','',function(str) { |
---|
312 | return '\n///html\n' + d.player + '///\n'; |
---|
313 | }); |
---|
314 | }; |
---|
315 | jsToolBar.prototype.elements.mp3_insert.fncall.xhtml = function() { |
---|
316 | var d = this.elements.mp3_insert.data; |
---|
317 | if (d.player == undefined) { return; } |
---|
318 | |
---|
319 | this.encloseSelection('','',function(str) { |
---|
320 | return '\n' + d.player + '\n'; |
---|
321 | }); |
---|
322 | }; |
---|
323 | jsToolBar.prototype.elements.mp3_insert.fncall.wysiwyg = function() { |
---|
324 | return; |
---|
325 | }; |
---|
326 | |
---|
327 | // FLV helpers |
---|
328 | jsToolBar.prototype.elements.flv_insert = { fncall: {}, data: {} }; |
---|
329 | jsToolBar.prototype.elements.flv_insert.fncall.wiki = function() { |
---|
330 | var d = this.elements.flv_insert.data; |
---|
331 | if (d.player == undefined) { return; } |
---|
332 | |
---|
333 | this.encloseSelection('','',function(str) { |
---|
334 | return '\n///html\n' + d.player + '///\n'; |
---|
335 | }); |
---|
336 | }; |
---|
337 | jsToolBar.prototype.elements.flv_insert.fncall.xhtml = function() { |
---|
338 | var d = this.elements.flv_insert.data; |
---|
339 | if (d.player == undefined) { return; } |
---|
340 | |
---|
341 | this.encloseSelection('','',function(str) { |
---|
342 | return '\n' + d.player + '\n'; |
---|
343 | }); |
---|
344 | }; |
---|
345 | jsToolBar.prototype.elements.flv_insert.fncall.wysiwyg = function() { |
---|
346 | return; |
---|
347 | }; |
---|
348 | |
---|
349 | |
---|
350 | /* Posts selector |
---|
351 | -------------------------------------------------------- */ |
---|
352 | jsToolBar.prototype.elements.post_link = { |
---|
353 | type: 'button', |
---|
354 | title: 'Link to an entry', |
---|
355 | fn: {}, |
---|
356 | open_url: 'popup_posts.php', |
---|
357 | data: {}, |
---|
358 | popup: function() { |
---|
359 | window.the_toolbar = this; |
---|
360 | this.elements.img_select.data = {}; |
---|
361 | |
---|
362 | var p_win = window.open(this.elements.post_link.open_url,'dc_popup', |
---|
363 | 'alwaysRaised=yes,dependent=yes,toolbar=yes,height=500,width=760,'+ |
---|
364 | 'menubar=no,resizable=yes,scrollbars=yes,status=no'); |
---|
365 | } |
---|
366 | }; |
---|
367 | jsToolBar.prototype.elements.post_link.fn.wiki = function() { |
---|
368 | this.elements.post_link.popup.call(this); |
---|
369 | }; |
---|
370 | jsToolBar.prototype.elements.post_link.fn.xhtml = function() { |
---|
371 | this.elements.post_link.popup.call(this); |
---|
372 | }; |
---|
373 | jsToolBar.prototype.elements.post_link.fn.wysiwyg = function() { |
---|
374 | this.elements.post_link.popup.call(this); |
---|
375 | }; |
---|
376 | |
---|
377 | // Last space element |
---|
378 | jsToolBar.prototype.elements.space3 = {type: 'space'}; |
---|