Dotclear

source: plugins/dcLegacyEditor/js/jsToolBar/jsToolBar.dotclear.js @ 3361:23cff72066bd

Revision 3361:23cff72066bd, 10.4 KB checked in by franck <carnet.franck.paul@…>, 9 years ago (diff)

Add 'l' and 'm' accesskey for legacy editor toolbar, respectively for 'insert link' and 'select media' buttons

Line 
1/* Change link button actions
2-------------------------------------------------------- */
3jsToolBar.prototype.elements.link.data = {};
4jsToolBar.prototype.elements.link.fncall = {};
5jsToolBar.prototype.elements.link.open_url = 'popup_link.php?plugin_id=dcLegacyEditor';
6
7jsToolBar.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
19jsToolBar.prototype.elements.link.fn.wiki = function() {
20     this.elements.link.popup.call(this,'&hreflang='+this.elements.link.default_hreflang);
21};
22jsToolBar.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
42jsToolBar.prototype.elements.link.fn.xhtml = function() {
43     this.elements.link.popup.call(this,'&hreflang='+this.elements.link.default_hreflang);
44};
45jsToolBar.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
66jsToolBar.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};
81jsToolBar.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     if (data.title) a.setAttribute('title',data.title);
119     a.appendChild(n);
120     this.insertNode(a);
121};
122jsToolBar.prototype.getAncestor = function() {
123     var res = {};
124     var range, commonAncestorContainer;
125
126     if (this.iwin.getSelection) { //gecko
127          var selection = this.iwin.getSelection();
128          range = selection.getRangeAt(0);
129          commonAncestorContainer = range.commonAncestorContainer;
130          while (commonAncestorContainer.nodeType != 1) {
131               commonAncestorContainer = commonAncestorContainer.parentNode;
132          }
133     } else { //ie
134          range = this.iwin.document.selection.createRange();
135          commonAncestorContainer = range.parentElement();
136     }
137
138     var ancestorTagName = commonAncestorContainer.tagName.toLowerCase();
139     while (ancestorTagName!='a' && ancestorTagName!='body') {
140          commonAncestorContainer = commonAncestorContainer.parentNode;
141          ancestorTagName = commonAncestorContainer.tagName.toLowerCase();
142     }
143
144     res.tag = commonAncestorContainer;
145     res.tagName = ancestorTagName;
146
147     return res;
148};
149
150/* Image selector
151-------------------------------------------------------- */
152jsToolBar.prototype.elements.img_select = {
153     type: 'button',
154     title: 'Image chooser',
155     accesskey: 'm',
156     fn: {},
157     fncall: {},
158     open_url: 'media.php?popup=1&plugin_id=dcLegacyEditor',
159     data: {},
160     popup: function() {
161          window.the_toolbar = this;
162          this.elements.img_select.data = {};
163
164          var p_win = window.open(this.elements.img_select.open_url,'dc_popup',
165          'alwaysRaised=yes,dependent=yes,toolbar=yes,height=500,width=760,'+
166          'menubar=no,resizable=yes,scrollbars=yes,status=no');
167     }
168};
169jsToolBar.prototype.elements.img_select.fn.wiki = function() {
170     this.elements.img_select.popup.call(this);
171};
172jsToolBar.prototype.elements.img_select.fncall.wiki = function() {
173     var d = this.elements.img_select.data;
174     if (d.src == undefined) { return; }
175
176     this.encloseSelection('','',function(str) {
177          var alt = (str) ? str : d.title;
178          var res = '(('+d.src+'|'+alt;
179
180          if (d.alignment == 'left') {
181               res += '|L';
182          } else if (d.alignment == 'right') {
183               res += '|R';
184          } else if (d.alignment == 'center') {
185               res += '|C';
186          } else if (d.description) {
187               res += '|';
188          }
189
190          if (d.description) {
191               res += '|'+d.description;
192          }
193
194          res += '))';
195
196          if (d.link) {
197               var ltitle = (alt) ? '||'+alt : '';
198               res = '['+res+'|'+d.url+ltitle+']';
199          }
200
201          return res;
202     });
203};
204jsToolBar.prototype.elements.img_select.fn.xhtml = function() {
205     this.elements.img_select.popup.call(this);
206};
207jsToolBar.prototype.elements.img_select.fncall.xhtml = function() {
208     var d = this.elements.img_select.data;
209     if (d.src == undefined) { return; }
210
211     this.encloseSelection('','',function(str) {
212          var alt = (str) ? str : d.title;
213          var res = '<img src="'+d.src+'" alt="'+alt.replace('&','&amp;').replace('>','&gt;').replace('<','&lt;').replace('"','&quot;')+'"';
214
215          if (d.alignment == 'left') {
216               res += ' style="float: left; margin: 0 1em 1em 0;"';
217          } else if (d.alignment == 'right') {
218               res += ' style="float: right; margin: 0 0 1em 1em;"';
219          } else if (d.alignment == 'center') {
220               res += ' style="margin: 0 auto; display: block;"';
221          }
222
223          if (d.description) {
224               res += ' title="'+d.description.replace('&','&amp;').replace('>','&gt;').replace('<','&lt;').replace('"','&quot;')+'"';
225          }
226
227          res += ' />';
228
229          if (d.link) {
230               var ltitle = (alt) ? ' title="'+alt.replace('&','&amp;').replace('>','&gt;').replace('<','&lt;').replace('"','&quot;')+'"' : '';
231               res = '<a href="'+d.url+'"'+ltitle+'>'+res+'</a>';
232          }
233
234          return res;
235     });
236};
237
238jsToolBar.prototype.elements.img.fn.wysiwyg = function() {
239     var src = this.elements.img.prompt.call(this);
240     if (!src) { return; }
241
242     var img = this.iwin.document.createElement('img');
243     img.src = src;
244     img.setAttribute('alt',this.getSelectedText());
245
246     this.insertNode(img);
247};
248
249jsToolBar.prototype.elements.img_select.fn.wysiwyg = function() {
250     this.elements.img_select.popup.call(this);
251};
252jsToolBar.prototype.elements.img_select.fncall.wysiwyg = function() {
253     var d = this.elements.img_select.data;
254     var alt = (this.getSelectedText()) ? this.getSelectedText() : d.title;
255     if (d.src == undefined) { return; }
256
257     var img = this.iwin.document.createElement('img');
258     img.src = d.src;
259     img.setAttribute('alt',alt);
260
261
262     if (d.alignment == 'left') {
263          if (img.style.styleFloat != undefined) {
264               img.style.styleFloat = 'left';
265          } else {
266               img.style.cssFloat = 'left';
267          }
268          img.style.marginTop = 0;
269          img.style.marginRight = '1em';
270          img.style.marginBottom = '1em';
271          img.style.marginLeft = 0;
272     } else if (d.alignment == 'right') {
273          if (img.style.styleFloat != undefined) {
274               img.style.styleFloat = 'right';
275          } else {
276               img.style.cssFloat = 'right';
277          }
278          img.style.marginTop = 0;
279          img.style.marginRight = 0;
280          img.style.marginBottom = '1em';
281          img.style.marginLeft = '1em';
282     } else if (d.alignment == 'center') {
283          img.style.marginTop = 0;
284          img.style.marginRight = 'auto';
285          img.style.marginBottom = 0;
286          img.style.marginLeft = 'auto';
287          img.style.display = 'block';
288     }
289
290     if (d.description) {
291          img.setAttribute('title',d.description);
292     }
293
294     if (d.link) {
295          var a = this.iwin.document.createElement('a');
296          a.href = d.url;
297          if (alt) {
298               a.setAttribute('title',alt);
299          }
300          a.appendChild(img);
301          this.insertNode(a);
302     } else {
303          this.insertNode(img);
304     }
305};
306
307// MP3 helpers
308jsToolBar.prototype.elements.mp3_insert = { fncall: {}, data: {} };
309jsToolBar.prototype.elements.mp3_insert.fncall.wiki = function() {
310     var d = this.elements.mp3_insert.data;
311     if (d.player == undefined) { return; }
312
313     this.encloseSelection('','',function(str) {
314          return '\n///html\n' + d.player + '///\n';
315     });
316};
317jsToolBar.prototype.elements.mp3_insert.fncall.xhtml = function() {
318     var d = this.elements.mp3_insert.data;
319     if (d.player == undefined) { return; }
320
321     this.encloseSelection('','',function(str) {
322          return '\n' + d.player + '\n';
323     });
324};
325jsToolBar.prototype.elements.mp3_insert.fncall.wysiwyg = function() {
326     return;
327};
328
329// FLV helpers
330jsToolBar.prototype.elements.flv_insert = { fncall: {}, data: {} };
331jsToolBar.prototype.elements.flv_insert.fncall.wiki = function() {
332     var d = this.elements.flv_insert.data;
333     if (d.player == undefined) { return; }
334
335     this.encloseSelection('','',function(str) {
336          return '\n///html\n' + d.player + '///\n';
337     });
338};
339jsToolBar.prototype.elements.flv_insert.fncall.xhtml = function() {
340     var d = this.elements.flv_insert.data;
341     if (d.player == undefined) { return; }
342
343     this.encloseSelection('','',function(str) {
344          return '\n' + d.player + '\n';
345     });
346};
347jsToolBar.prototype.elements.flv_insert.fncall.wysiwyg = function() {
348     return;
349};
350
351
352/* Posts selector
353-------------------------------------------------------- */
354jsToolBar.prototype.elements.post_link = {
355     type: 'button',
356     title: 'Link to an entry',
357     fn: {},
358     open_url: 'popup_posts.php?plugin_id=dcLegacyEditor',
359     data: {},
360     popup: function() {
361          window.the_toolbar = this;
362          this.elements.img_select.data = {};
363
364          var p_win = window.open(this.elements.post_link.open_url,'dc_popup',
365          'alwaysRaised=yes,dependent=yes,toolbar=yes,height=500,width=760,'+
366          'menubar=no,resizable=yes,scrollbars=yes,status=no');
367     }
368};
369jsToolBar.prototype.elements.post_link.fn.wiki = function() {
370     this.elements.post_link.popup.call(this);
371};
372jsToolBar.prototype.elements.post_link.fn.xhtml = function() {
373     this.elements.post_link.popup.call(this);
374};
375jsToolBar.prototype.elements.post_link.fn.wysiwyg = function() {
376     this.elements.post_link.popup.call(this);
377};
378
379// Last space element
380jsToolBar.prototype.elements.space3 = {
381     type:'space',
382     format:{
383          wysiwyg:true,
384          wiki:true,
385          xhtml:true
386     }
387};
Note: See TracBrowser for help on using the repository browser.

Sites map