Dotclear

source: admin/js/common.js @ 1516:eb9653ff7459

Revision 1516:eb9653ff7459, 9.0 KB checked in by Anne Kozlika <kozlika@…>, 12 years ago (diff)

Antispam: pardon my fault, css should be in plugin css only.
Messages: colors change.

RevLine 
[0]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)
[131]8                    existingFunction.apply(this, arguments);
[0]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);
[131]47
[0]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
[297]59jQuery.fn.toggleWithLegend = function(target,s) {
[0]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);
[131]73
[0]74     if (!target) { return this; }
[131]75
[0]76     var set_cookie = p.hide ^ p.reverse_cookie;
77     if (p.cookie && jQuery.cookie(p.cookie)) {
78          p.hide = p.reverse_cookie;
79     }
[131]80
[297]81     var toggle = function(i,speed) {
[0]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;
[1140]86               target.hide(speed);
[0]87          } else {
88               $(i).get(0).src = p.img_off_src;
89               $(i).get(0).alt = p.img_off_alt;
[1140]90               target.show(speed);
[0]91               if (p.fn) {
92                    p.fn.apply(target);
93                    p.fn = false;
94               }
95          }
[131]96
[0]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          }
[131]104
[0]105          p.hide = !p.hide;
106     };
[131]107
[0]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          });
[131]119
[0]120          var ctarget = p.legend_click ? this : a;
[131]121
[0]122          $(ctarget).css('cursor','pointer');
123          $(ctarget).click(function() {
[1140]124               toggle(i,p.speed);
[0]125               return false;
126          });
[131]127
128
[0]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     }
[131]138
[0]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          }
[1303]155          $('p#help-button span').text($('#content').hasClass('with-help') ? dotclear.msg.help_hide : dotclear.msg.help);
[0]156          sizeBox();
157          return false;
158     };
[131]159
[0]160     var sizeBox = function() {
161          This.css('height','auto');
[1002]162          if ($('#main').height() > This.height()) {
163               This.css('height',$('#main').height() + 'px');
[0]164          }
165     };
[131]166
[0]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;
[131]171
[0]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     };
[131]191
[0]192     this.addClass('help-box');
193     this.find('>hr').remove();
[131]194
[0]195     this.find('h3').each(function() { textToggler($(this)); });
196     this.find('h3:first').nextAll('*:not(h3)').hide();
197     sizeBox();
[131]198
[1303]199     var img = $('<p id="help-button"><span>'+dotclear.msg.help+'</span></p>');
[0]200     var select = $();
201     img.click(function() { return toggle(); });
[131]202
[0]203     $('#content').append(img);
[131]204
[0]205     return this;
206};
207
208/* Dotclear common object
209-------------------------------------------------------- */
210var dotclear = {
211     msg: {},
[131]212
[0]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');
[131]220
[0]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';
[1395]226                    imgE.alt=dotclear.msg.click_to_unlock;
[0]227                    $(imgE).css('cursor','pointer');
[131]228
[0]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                    });
[131]237
[0]238                    $(this).parent().css('position','relative');
239                    $(this).after(imgE);
240               });
241          });
242     },
[131]243
[0]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);
[131]253
[0]254          $(e).append(document.createTextNode(' - '));
[131]255
[0]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);
[131]264
[0]265          $(e).append(document.createTextNode(' - '));
[131]266
[0]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     },
[131]276
[0]277     postsActionsHelper: function() {
278          $('#form-entries').submit(function() {
279               var action = $(this).find('select[name="action"]').val();
280               var checked = false;
[131]281
[0]282               $(this).find('input[name="entries[]"]').each(function() {
283                    if (this.checked) {
284                         checked = true;
285                    }
286               });
[131]287
[0]288               if (!checked) { return false; }
[131]289
[0]290               if (action == 'delete') {
291                    return window.confirm(dotclear.msg.confirm_delete_posts.replace('%s',$('input[name="entries[]"]:checked').size()));
292               }
[131]293
[0]294               return true;
295          });
296     },
[131]297
[0]298     commentsActionsHelper: function() {
299          $('#form-comments').submit(function() {
300               var action = $(this).find('select[name="action"]').val();
301               var checked = false;
[131]302
[0]303               $(this).find('input[name="comments[]"]').each(function() {
304                    if (this.checked) {
305                         checked = true;
306                    }
307               });
[131]308
[0]309               if (!checked) { return false; }
[131]310
[0]311               if (action == 'delete') {
312                    return window.confirm(dotclear.msg.confirm_delete_comments.replace('%s',$('input[name="comments[]"]:checked').size()));
313               }
[131]314
[0]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     });
[131]327
[0]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'),
[297]335          $.extend({cookie:'dc_blog_menu'},menu_settings)
[0]336     );
337     $('#system-menu h3:first').toggleWithLegend($('#system-menu ul:first'),
[297]338          $.extend({cookie:'dc_system_menu'},menu_settings)
[0]339     );
340     $('#plugins-menu h3:first').toggleWithLegend($('#plugins-menu ul:first'),
[297]341          $.extend({cookie:'dc_plugins_menu'},menu_settings)
[0]342     );
[3]343     $('#favorites-menu h3:first').toggleWithLegend($('#favorites-menu ul:first'),
[297]344          $.extend({cookie:'dc_favorites_menu',hide:false,reverse_cookie:true},menu_settings)
[3]345     );
[131]346
[0]347     $('#help').helpViewer();
[131]348
[0]349     $('.message').backgroundFade({sColor:'#cccccc',eColor:'#666666',steps:20});
[1516]350     $('.error').backgroundFade({sColor:'#ffdec8',eColor:'#ffbaba',steps:20});
[131]351
[0]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();
[1516]356               $(e).backgroundFade({sColor:'#ffffff',eColor:'#ffbaba',steps:50},function() {
357                    $(this).backgroundFade({sColor:'#ffbaba',eColor:'#ffffff'});
[0]358               });
359               return false;
360          }
361          return true;
362     });
363});
364
Note: See TracBrowser for help on using the repository browser.

Sites map