Dotclear

source: admin/js/common.js @ 1395:7ec3d08b54d0

Revision 1395:7ec3d08b54d0, 9.0 KB checked in by Dsls, 11 years ago (diff)

Added alternate text for unlock image, closes #1544

Line 
1/* ChainHandler, py Peter van der Beken
2-------------------------------------------------------- */
3function chainHandler(obj, handlerName, handler) {
4     obj[handlerName] = (function(existingFunction) {
5          return function() {
6               handler.apply(this, arguments);
7               if (existingFunction)
8                    existingFunction.apply(this, arguments);
9          };
10     })(handlerName in obj ? obj[handlerName] : null);
11};
12
13/* jQuery extensions
14-------------------------------------------------------- */
15jQuery.fn.check = function() {
16     return this.each(function() {
17          if (this.checked != undefined) { this.checked = true; }
18     });
19};
20jQuery.fn.unCheck = function() {
21     return this.each(function() {
22          if (this.checked != undefined) { this.checked = false; }
23     });
24};
25jQuery.fn.setChecked = function(status) {
26     return this.each(function() {
27          if (this.checked != undefined) { this.checked = status; }
28     });
29};
30jQuery.fn.toggleCheck = function() {
31     return this.each(function() {
32          if (this.checked != undefined) { this.checked = !this.checked; }
33     });
34};
35
36jQuery.fn.enableShiftClick = function() {
37     this.click(
38     function (event) {
39          if (event.shiftKey) {
40               if (dotclear.lastclicked != '') {
41                    var range;
42                    var trparent = $(this).parents('tr');
43                    if (trparent.nextAll('#'+dotclear.lastclicked).length != 0)
44                         range = trparent.nextUntil('#'+dotclear.lastclicked);
45                    else
46                         range = trparent.prevUntil('#'+dotclear.lastclicked);
47
48                    range.find('input[type=checkbox]').setChecked(dotclear.lastclickedstatus);
49                    this.checked = dotclear.lastclickedstatus;
50               }
51          } else {
52               dotclear.lastclicked = $(this).parents('tr')[0].id;
53               dotclear.lastclickedstatus = this.checked;
54          }
55          return true;
56     });
57}
58
59jQuery.fn.toggleWithLegend = function(target,s) {
60     var defaults = {
61          img_on_src: dotclear.img_plus_src,
62          img_on_alt: dotclear.img_plus_alt,
63          img_off_src: dotclear.img_minus_src,
64          img_off_alt: dotclear.img_minus_alt,
65          hide: true,
66          speed: 0,
67          legend_click: false,
68          fn: false, // A function called on first display,
69          cookie: false,
70          reverse_cookie: false // Reverse cookie behavior
71     };
72     var p = jQuery.extend(defaults,s);
73
74     if (!target) { return this; }
75
76     var set_cookie = p.hide ^ p.reverse_cookie;
77     if (p.cookie && jQuery.cookie(p.cookie)) {
78          p.hide = p.reverse_cookie;
79     }
80
81     var toggle = function(i,speed) {
82          speed = speed || 0;
83          if (p.hide) {
84               $(i).get(0).src = p.img_on_src;
85               $(i).get(0).alt = p.img_on_alt;
86               target.hide(speed);
87          } else {
88               $(i).get(0).src = p.img_off_src;
89               $(i).get(0).alt = p.img_off_alt;
90               target.show(speed);
91               if (p.fn) {
92                    p.fn.apply(target);
93                    p.fn = false;
94               }
95          }
96
97          if (p.cookie && set_cookie) {
98               if (p.hide ^ p.reverse_cookie) {
99                    jQuery.cookie(p.cookie,'',{expires: -1});
100               } else {
101                    jQuery.cookie(p.cookie,1,{expires: 30});
102               }
103          }
104
105          p.hide = !p.hide;
106     };
107
108     return this.each(function() {
109          var i = document.createElement('img');
110          i.src = p.img_off_src;
111          i.alt = p.img_off_alt;
112          var a = document.createElement('a');
113          a.href= '#';
114          $(a).append(i);
115          $(a).css({
116               border: 'none',
117               outline: 'none'
118          });
119
120          var ctarget = p.legend_click ? this : a;
121
122          $(ctarget).css('cursor','pointer');
123          $(ctarget).click(function() {
124               toggle(i,p.speed);
125               return false;
126          });
127
128
129          toggle($(i).get(0));
130          $(this).prepend(' ').prepend(a);
131     });
132};
133
134jQuery.fn.helpViewer = function() {
135     if (this.length < 1) {
136          return this;
137     }
138
139     var p = {
140          img_on_src: dotclear.img_plus_src,
141          img_on_alt: dotclear.img_plus_alt,
142          img_off_src: dotclear.img_minus_src,
143          img_off_alt: dotclear.img_minus_alt
144     };
145     var This = this;
146     var toggle = function() {
147          $('#content').toggleClass('with-help');
148          if (document.all) {
149               if ($('#content').hasClass('with-help')) {
150                    select = $('#content select:visible').hide();
151               } else {
152                    select.show();
153               }
154          }
155          $('p#help-button span').text($('#content').hasClass('with-help') ? dotclear.msg.help_hide : dotclear.msg.help);
156          sizeBox();
157          return false;
158     };
159
160     var sizeBox = function() {
161          This.css('height','auto');
162          if ($('#main').height() > This.height()) {
163               This.css('height',$('#main').height() + 'px');
164          }
165     };
166
167     var textToggler = function(o) {
168          var i = $('<img src="'+p.img_on_src+'" alt="'+p.img_on_alt+'" />');
169          o.css('cursor','pointer');
170          var hide = true;
171
172          o.prepend(' ').prepend(i);
173          o.click(function() {
174               $(this).nextAll().each(function() {
175                    if ($(this).is('h3')) {
176                         return false;
177                    }
178                    $(this).toggle();
179                    sizeBox();
180                    return true;
181               });
182               hide = !hide;
183               var img = $(this).find('img');
184               if (!hide) {
185                    img.attr('src',p.img_off_src);
186               } else {
187                    img.attr('src',p.img_on_src);
188               }
189          });
190     };
191
192     this.addClass('help-box');
193     this.find('>hr').remove();
194
195     this.find('h3').each(function() { textToggler($(this)); });
196     this.find('h3:first').nextAll('*:not(h3)').hide();
197     sizeBox();
198
199     var img = $('<p id="help-button"><span>'+dotclear.msg.help+'</span></p>');
200     var select = $();
201     img.click(function() { return toggle(); });
202
203     $('#content').append(img);
204
205     return this;
206};
207
208/* Dotclear common object
209-------------------------------------------------------- */
210var dotclear = {
211     msg: {},
212
213     hideLockable: function() {
214          $('div.lockable').each(function() {
215               var current_lockable_div = this;
216               $(this).find('p.form-note').hide();
217               $(this).find('input').each(function() {
218                    this.disabled = true;
219                    $(this).width(($(this).width()-14) + 'px');
220
221                    var imgE = document.createElement('img');
222                    imgE.src = 'images/locker.png';
223                    imgE.style.position = 'absolute';
224                    imgE.style.top = '1.7em';
225                    imgE.style.left = ($(this).width()+4)+'px';
226                    imgE.alt=dotclear.msg.click_to_unlock;
227                    $(imgE).css('cursor','pointer');
228
229                    $(imgE).click(function() {
230                         $(this).hide();
231                         $(this).prev('input').each(function() {
232                              this.disabled = false;
233                              $(this).width(($(this).width()+14) + 'px');
234                         });
235                         $(current_lockable_div).find('p.form-note').show();
236                    });
237
238                    $(this).parent().css('position','relative');
239                    $(this).after(imgE);
240               });
241          });
242     },
243
244     checkboxesHelpers: function(e) {
245          var a = document.createElement('a');
246          a.href='#';
247          $(a).append(document.createTextNode(dotclear.msg.select_all));
248          a.onclick = function() {
249               $(this).parents('form').find('input[type="checkbox"]').check();
250               return false;
251          };
252          $(e).append(a);
253
254          $(e).append(document.createTextNode(' - '));
255
256          a = document.createElement('a');
257          a.href='#';
258          $(a).append(document.createTextNode(dotclear.msg.no_selection));
259          a.onclick = function() {
260               $(this).parents('form').find('input[type="checkbox"]').unCheck();
261               return false;
262          };
263          $(e).append(a);
264
265          $(e).append(document.createTextNode(' - '));
266
267          a = document.createElement('a');
268          a.href='#';
269          $(a).append(document.createTextNode(dotclear.msg.invert_sel));
270          a.onclick = function() {
271               $(this).parents('form').find('input[type="checkbox"]').toggleCheck();
272               return false;
273          };
274          $(e).append(a);
275     },
276
277     postsActionsHelper: function() {
278          $('#form-entries').submit(function() {
279               var action = $(this).find('select[name="action"]').val();
280               var checked = false;
281
282               $(this).find('input[name="entries[]"]').each(function() {
283                    if (this.checked) {
284                         checked = true;
285                    }
286               });
287
288               if (!checked) { return false; }
289
290               if (action == 'delete') {
291                    return window.confirm(dotclear.msg.confirm_delete_posts.replace('%s',$('input[name="entries[]"]:checked').size()));
292               }
293
294               return true;
295          });
296     },
297
298     commentsActionsHelper: function() {
299          $('#form-comments').submit(function() {
300               var action = $(this).find('select[name="action"]').val();
301               var checked = false;
302
303               $(this).find('input[name="comments[]"]').each(function() {
304                    if (this.checked) {
305                         checked = true;
306                    }
307               });
308
309               if (!checked) { return false; }
310
311               if (action == 'delete') {
312                    return window.confirm(dotclear.msg.confirm_delete_comments.replace('%s',$('input[name="comments[]"]:checked').size()));
313               }
314
315               return true;
316          });
317     }
318};
319
320/* On document ready
321-------------------------------------------------------- */
322$(function() {
323     // Blog switcher
324     $('#switchblog').change(function() {
325          this.form.submit();
326     });
327
328     var menu_settings = {
329          img_on_src: dotclear.img_menu_off,
330          img_off_src: dotclear.img_menu_on,
331          legend_click: true,
332          speed: 100
333     }
334     $('#blog-menu h3:first').toggleWithLegend($('#blog-menu ul:first'),
335          $.extend({cookie:'dc_blog_menu'},menu_settings)
336     );
337     $('#system-menu h3:first').toggleWithLegend($('#system-menu ul:first'),
338          $.extend({cookie:'dc_system_menu'},menu_settings)
339     );
340     $('#plugins-menu h3:first').toggleWithLegend($('#plugins-menu ul:first'),
341          $.extend({cookie:'dc_plugins_menu'},menu_settings)
342     );
343     $('#favorites-menu h3:first').toggleWithLegend($('#favorites-menu ul:first'),
344          $.extend({cookie:'dc_favorites_menu',hide:false,reverse_cookie:true},menu_settings)
345     );
346
347     $('#help').helpViewer();
348
349     $('.message').backgroundFade({sColor:'#cccccc',eColor:'#666666',steps:20});
350     $('.error').backgroundFade({sColor:'#ffeee3',eColor:'#ffdec8',steps:20});
351
352     $('form:has(input[type=password][name=your_pwd])').submit(function() {
353          var e = this.elements['your_pwd'];
354          if (e.value == '') {
355               e.focus();
356               $(e).backgroundFade({sColor:'#ffffff',eColor:'#ff9999',steps:50},function() {
357                    $(this).backgroundFade({sColor:'#ff9999',eColor:'#ffffff'});
358               });
359               return false;
360          }
361          return true;
362     });
363});
364
Note: See TracBrowser for help on using the repository browser.

Sites map