1 | /* ChainHandler, py Peter van der Beken |
---|
2 | -------------------------------------------------------- */ |
---|
3 | function 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 | -------------------------------------------------------- */ |
---|
15 | jQuery.fn.check = function() { |
---|
16 | return this.each(function() { |
---|
17 | if (this.checked != undefined) { this.checked = true; } |
---|
18 | }); |
---|
19 | }; |
---|
20 | jQuery.fn.unCheck = function() { |
---|
21 | return this.each(function() { |
---|
22 | if (this.checked != undefined) { this.checked = false; } |
---|
23 | }); |
---|
24 | }; |
---|
25 | jQuery.fn.setChecked = function(status) { |
---|
26 | return this.each(function() { |
---|
27 | if (this.checked != undefined) { this.checked = status; } |
---|
28 | }); |
---|
29 | }; |
---|
30 | jQuery.fn.toggleCheck = function() { |
---|
31 | return this.each(function() { |
---|
32 | if (this.checked != undefined) { this.checked = !this.checked; } |
---|
33 | }); |
---|
34 | }; |
---|
35 | |
---|
36 | jQuery.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 | |
---|
59 | jQuery.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 | if (p.legend_click) { |
---|
124 | $(ctarget).find('label').css('cursor','pointer'); |
---|
125 | } |
---|
126 | $(ctarget).click(function() { |
---|
127 | toggle(i,p.speed); |
---|
128 | return false; |
---|
129 | }); |
---|
130 | |
---|
131 | |
---|
132 | toggle($(i).get(0)); |
---|
133 | $(this).prepend(' ').prepend(a); |
---|
134 | }); |
---|
135 | }; |
---|
136 | |
---|
137 | jQuery.fn.helpViewer = function() { |
---|
138 | if (this.length < 1) { |
---|
139 | return this; |
---|
140 | } |
---|
141 | |
---|
142 | var p = { |
---|
143 | img_on_src: dotclear.img_plus_src, |
---|
144 | img_on_alt: dotclear.img_plus_alt, |
---|
145 | img_off_src: dotclear.img_minus_src, |
---|
146 | img_off_alt: dotclear.img_minus_alt |
---|
147 | }; |
---|
148 | var This = this; |
---|
149 | var toggle = function() { |
---|
150 | $('#content').toggleClass('with-help'); |
---|
151 | if (document.all) { |
---|
152 | if ($('#content').hasClass('with-help')) { |
---|
153 | select = $('#content select:visible').hide(); |
---|
154 | } else { |
---|
155 | select.show(); |
---|
156 | } |
---|
157 | } |
---|
158 | $('p#help-button span').text($('#content').hasClass('with-help') ? dotclear.msg.help_hide : dotclear.msg.help); |
---|
159 | sizeBox(); |
---|
160 | return false; |
---|
161 | }; |
---|
162 | |
---|
163 | var sizeBox = function() { |
---|
164 | This.css('height','auto'); |
---|
165 | if ($('#main').height() > This.height()) { |
---|
166 | This.css('height',$('#main').height() + 'px'); |
---|
167 | } |
---|
168 | }; |
---|
169 | |
---|
170 | var textToggler = function(o) { |
---|
171 | var i = $('<img src="'+p.img_on_src+'" alt="'+p.img_on_alt+'" />'); |
---|
172 | o.css('cursor','pointer'); |
---|
173 | var hide = true; |
---|
174 | |
---|
175 | o.prepend(' ').prepend(i); |
---|
176 | o.click(function() { |
---|
177 | $(this).nextAll().each(function() { |
---|
178 | if ($(this).is('h4')) { |
---|
179 | return false; |
---|
180 | } |
---|
181 | $(this).toggle(); |
---|
182 | sizeBox(); |
---|
183 | return true; |
---|
184 | }); |
---|
185 | hide = !hide; |
---|
186 | var img = $(this).find('img'); |
---|
187 | if (!hide) { |
---|
188 | img.attr('src',p.img_off_src); |
---|
189 | } else { |
---|
190 | img.attr('src',p.img_on_src); |
---|
191 | } |
---|
192 | }); |
---|
193 | }; |
---|
194 | |
---|
195 | this.addClass('help-box'); |
---|
196 | this.find('>hr').remove(); |
---|
197 | |
---|
198 | this.find('h4').each(function() { textToggler($(this)); }); |
---|
199 | this.find('h4:first').nextAll('*:not(h4)').hide(); |
---|
200 | sizeBox(); |
---|
201 | |
---|
202 | var img = $('<p id="help-button"><span>'+dotclear.msg.help+'</span></p>'); |
---|
203 | var select = $(); |
---|
204 | img.click(function() { return toggle(); }); |
---|
205 | |
---|
206 | $('#content').append(img); |
---|
207 | |
---|
208 | return this; |
---|
209 | }; |
---|
210 | |
---|
211 | /* Dotclear common object |
---|
212 | -------------------------------------------------------- */ |
---|
213 | var dotclear = { |
---|
214 | msg: {}, |
---|
215 | |
---|
216 | hideLockable: function() { |
---|
217 | $('div.lockable').each(function() { |
---|
218 | var current_lockable_div = this; |
---|
219 | $(this).find('p.form-note').hide(); |
---|
220 | $(this).find('input').each(function() { |
---|
221 | this.disabled = true; |
---|
222 | $(this).width(($(this).width()-14) + 'px'); |
---|
223 | |
---|
224 | var imgE = document.createElement('img'); |
---|
225 | imgE.src = 'images/locker.png'; |
---|
226 | imgE.style.position = 'absolute'; |
---|
227 | imgE.style.top = '1.7em'; |
---|
228 | imgE.style.left = ($(this).width()+4)+'px'; |
---|
229 | imgE.alt=dotclear.msg.click_to_unlock; |
---|
230 | $(imgE).css('cursor','pointer'); |
---|
231 | |
---|
232 | $(imgE).click(function() { |
---|
233 | $(this).hide(); |
---|
234 | $(this).prev('input').each(function() { |
---|
235 | this.disabled = false; |
---|
236 | $(this).width(($(this).width()+14) + 'px'); |
---|
237 | }); |
---|
238 | $(current_lockable_div).find('p.form-note').show(); |
---|
239 | }); |
---|
240 | |
---|
241 | $(this).parent().css('position','relative'); |
---|
242 | $(this).after(imgE); |
---|
243 | }); |
---|
244 | }); |
---|
245 | }, |
---|
246 | |
---|
247 | checkboxesHelpers: function(e) { |
---|
248 | $(e).append(document.createTextNode(dotclear.msg.to_select)); |
---|
249 | $(e).append(document.createTextNode(' ')); |
---|
250 | |
---|
251 | var a = document.createElement('a'); |
---|
252 | a.href='#'; |
---|
253 | $(a).append(document.createTextNode(dotclear.msg.select_all)); |
---|
254 | a.onclick = function() { |
---|
255 | $(this).parents('form').find('input[type="checkbox"]').check(); |
---|
256 | return false; |
---|
257 | }; |
---|
258 | $(e).append(a); |
---|
259 | |
---|
260 | $(e).append(document.createTextNode(' | ')); |
---|
261 | |
---|
262 | a = document.createElement('a'); |
---|
263 | a.href='#'; |
---|
264 | $(a).append(document.createTextNode(dotclear.msg.no_selection)); |
---|
265 | a.onclick = function() { |
---|
266 | $(this).parents('form').find('input[type="checkbox"]').unCheck(); |
---|
267 | return false; |
---|
268 | }; |
---|
269 | $(e).append(a); |
---|
270 | |
---|
271 | $(e).append(document.createTextNode(' - ')); |
---|
272 | |
---|
273 | a = document.createElement('a'); |
---|
274 | a.href='#'; |
---|
275 | $(a).append(document.createTextNode(dotclear.msg.invert_sel)); |
---|
276 | a.onclick = function() { |
---|
277 | $(this).parents('form').find('input[type="checkbox"]').toggleCheck(); |
---|
278 | return false; |
---|
279 | }; |
---|
280 | $(e).append(a); |
---|
281 | }, |
---|
282 | |
---|
283 | postsActionsHelper: function() { |
---|
284 | $('#form-entries').submit(function() { |
---|
285 | var action = $(this).find('select[name="action"]').val(); |
---|
286 | var checked = false; |
---|
287 | |
---|
288 | $(this).find('input[name="entries[]"]').each(function() { |
---|
289 | if (this.checked) { |
---|
290 | checked = true; |
---|
291 | } |
---|
292 | }); |
---|
293 | |
---|
294 | if (!checked) { return false; } |
---|
295 | |
---|
296 | if (action == 'delete') { |
---|
297 | return window.confirm(dotclear.msg.confirm_delete_posts.replace('%s',$('input[name="entries[]"]:checked').size())); |
---|
298 | } |
---|
299 | |
---|
300 | return true; |
---|
301 | }); |
---|
302 | }, |
---|
303 | |
---|
304 | commentsActionsHelper: function() { |
---|
305 | $('#form-comments').submit(function() { |
---|
306 | var action = $(this).find('select[name="action"]').val(); |
---|
307 | var checked = false; |
---|
308 | |
---|
309 | $(this).find('input[name="comments[]"]').each(function() { |
---|
310 | if (this.checked) { |
---|
311 | checked = true; |
---|
312 | } |
---|
313 | }); |
---|
314 | |
---|
315 | if (!checked) { return false; } |
---|
316 | |
---|
317 | if (action == 'delete') { |
---|
318 | return window.confirm(dotclear.msg.confirm_delete_comments.replace('%s',$('input[name="comments[]"]:checked').size())); |
---|
319 | } |
---|
320 | |
---|
321 | return true; |
---|
322 | }); |
---|
323 | } |
---|
324 | }; |
---|
325 | |
---|
326 | /* On document ready |
---|
327 | -------------------------------------------------------- */ |
---|
328 | $(function() { |
---|
329 | // remove class no-js from html tag |
---|
330 | $('body').removeClass('no-js'); |
---|
331 | |
---|
332 | // Blog switcher |
---|
333 | $('#switchblog').change(function() { |
---|
334 | this.form.submit(); |
---|
335 | }); |
---|
336 | |
---|
337 | var menu_settings = { |
---|
338 | img_on_src: dotclear.img_menu_off, |
---|
339 | img_off_src: dotclear.img_menu_on, |
---|
340 | legend_click: true, |
---|
341 | speed: 100 |
---|
342 | } |
---|
343 | $('#blog-menu h3:first').toggleWithLegend($('#blog-menu ul:first'), |
---|
344 | $.extend({cookie:'dc_blog_menu'},menu_settings) |
---|
345 | ); |
---|
346 | $('#system-menu h3:first').toggleWithLegend($('#system-menu ul:first'), |
---|
347 | $.extend({cookie:'dc_system_menu'},menu_settings) |
---|
348 | ); |
---|
349 | $('#plugins-menu h3:first').toggleWithLegend($('#plugins-menu ul:first'), |
---|
350 | $.extend({cookie:'dc_plugins_menu'},menu_settings) |
---|
351 | ); |
---|
352 | $('#favorites-menu h3:first').toggleWithLegend($('#favorites-menu ul:first'), |
---|
353 | $.extend({cookie:'dc_favorites_menu',hide:false,reverse_cookie:true},menu_settings) |
---|
354 | ); |
---|
355 | |
---|
356 | $('#help').helpViewer(); |
---|
357 | |
---|
358 | $('.message').backgroundFade({sColor:'#cccccc',eColor:'#666666',steps:20}); |
---|
359 | $('.error').backgroundFade({sColor:'#ffdec8',eColor:'#ffbaba',steps:20}); |
---|
360 | $('.success').backgroundFade({sColor:'#91ff4d',eColor:'#baff8e',steps:20}); |
---|
361 | |
---|
362 | $('form:has(input[type=password][name=your_pwd])').submit(function() { |
---|
363 | var e = this.elements['your_pwd']; |
---|
364 | if (e.value == '') { |
---|
365 | e.focus(); |
---|
366 | $(e).backgroundFade({sColor:'#ffffff',eColor:'#ffbaba',steps:50},function() { |
---|
367 | $(this).backgroundFade({sColor:'#ffbaba',eColor:'#ffffff'}); |
---|
368 | }); |
---|
369 | return false; |
---|
370 | } |
---|
371 | return true; |
---|
372 | }); |
---|
373 | }); |
---|
374 | |
---|