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