Dotclear

source: admin/js/jsToolBar/jsToolBar.dotclear.js @ 723:2be9bce19715

Revision 723:2be9bce19715, 10.3 KB checked in by Franck <carnet.franck.paul@…>, 14 years ago (diff)

Title attribute missing on add link in wysiwyg mode, fixes #1169

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

Sites map