[0] | 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) |
---|
[131] | 8 | existingFunction.apply(this, arguments); |
---|
[0] | 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); |
---|
[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] | 59 | jQuery.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; |
---|
[297] | 86 | target.hide(speed, positionFooter); |
---|
[0] | 87 | } else { |
---|
| 88 | $(i).get(0).src = p.img_off_src; |
---|
| 89 | $(i).get(0).alt = p.img_off_alt; |
---|
[297] | 90 | target.show(speed, positionFooter); |
---|
[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() { |
---|
[299] | 124 | toggle(i,p.speed, positionFooter); |
---|
[0] | 125 | return false; |
---|
| 126 | }); |
---|
[131] | 127 | |
---|
| 128 | |
---|
[0] | 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 | } |
---|
[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 | } |
---|
| 155 | sizeBox(); |
---|
| 156 | return false; |
---|
| 157 | }; |
---|
[131] | 158 | |
---|
[0] | 159 | var sizeBox = function() { |
---|
| 160 | This.css('height','auto'); |
---|
| 161 | if ($('body').height() > This.height()) { |
---|
| 162 | This.css('height',$('body').height() + 'px'); |
---|
| 163 | } |
---|
| 164 | }; |
---|
[131] | 165 | |
---|
[0] | 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; |
---|
[131] | 170 | |
---|
[0] | 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 | }; |
---|
[131] | 190 | |
---|
[0] | 191 | this.addClass('help-box'); |
---|
| 192 | this.find('>hr').remove(); |
---|
[131] | 193 | |
---|
[0] | 194 | this.find('h3').each(function() { textToggler($(this)); }); |
---|
| 195 | this.find('h3:first').nextAll('*:not(h3)').hide(); |
---|
| 196 | sizeBox(); |
---|
[131] | 197 | |
---|
[3] | 198 | var img = $('<span id="help-button">'+dotclear.msg.help+'</span>'); |
---|
[0] | 199 | var select = $(); |
---|
| 200 | img.click(function() { return toggle(); }); |
---|
[131] | 201 | |
---|
[0] | 202 | $('#content').append(img); |
---|
[131] | 203 | |
---|
[0] | 204 | return this; |
---|
| 205 | }; |
---|
| 206 | |
---|
| 207 | /* Dotclear common object |
---|
| 208 | -------------------------------------------------------- */ |
---|
| 209 | var dotclear = { |
---|
| 210 | msg: {}, |
---|
[131] | 211 | |
---|
[0] | 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'); |
---|
[131] | 219 | |
---|
[0] | 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'); |
---|
[131] | 226 | |
---|
[0] | 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 | }); |
---|
[131] | 235 | |
---|
[0] | 236 | $(this).parent().css('position','relative'); |
---|
| 237 | $(this).after(imgE); |
---|
| 238 | }); |
---|
| 239 | }); |
---|
| 240 | }, |
---|
[131] | 241 | |
---|
[0] | 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); |
---|
[131] | 251 | |
---|
[0] | 252 | $(e).append(document.createTextNode(' - ')); |
---|
[131] | 253 | |
---|
[0] | 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); |
---|
[131] | 262 | |
---|
[0] | 263 | $(e).append(document.createTextNode(' - ')); |
---|
[131] | 264 | |
---|
[0] | 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 | }, |
---|
[131] | 274 | |
---|
[0] | 275 | postsActionsHelper: function() { |
---|
| 276 | $('#form-entries').submit(function() { |
---|
| 277 | var action = $(this).find('select[name="action"]').val(); |
---|
| 278 | var checked = false; |
---|
[131] | 279 | |
---|
[0] | 280 | $(this).find('input[name="entries[]"]').each(function() { |
---|
| 281 | if (this.checked) { |
---|
| 282 | checked = true; |
---|
| 283 | } |
---|
| 284 | }); |
---|
[131] | 285 | |
---|
[0] | 286 | if (!checked) { return false; } |
---|
[131] | 287 | |
---|
[0] | 288 | if (action == 'delete') { |
---|
| 289 | return window.confirm(dotclear.msg.confirm_delete_posts.replace('%s',$('input[name="entries[]"]:checked').size())); |
---|
| 290 | } |
---|
[131] | 291 | |
---|
[0] | 292 | return true; |
---|
| 293 | }); |
---|
| 294 | }, |
---|
[131] | 295 | |
---|
[0] | 296 | commentsActionsHelper: function() { |
---|
| 297 | $('#form-comments').submit(function() { |
---|
| 298 | var action = $(this).find('select[name="action"]').val(); |
---|
| 299 | var checked = false; |
---|
[131] | 300 | |
---|
[0] | 301 | $(this).find('input[name="comments[]"]').each(function() { |
---|
| 302 | if (this.checked) { |
---|
| 303 | checked = true; |
---|
| 304 | } |
---|
| 305 | }); |
---|
[131] | 306 | |
---|
[0] | 307 | if (!checked) { return false; } |
---|
[131] | 308 | |
---|
[0] | 309 | if (action == 'delete') { |
---|
| 310 | return window.confirm(dotclear.msg.confirm_delete_comments.replace('%s',$('input[name="comments[]"]:checked').size())); |
---|
| 311 | } |
---|
[131] | 312 | |
---|
[0] | 313 | return true; |
---|
| 314 | }); |
---|
| 315 | } |
---|
| 316 | }; |
---|
| 317 | |
---|
[234] | 318 | /* Sticky footer |
---|
| 319 | -------------------------------------------------------- */ |
---|
| 320 | function positionFooter() { |
---|
[888] | 321 | $('#footer').constantfooter(); |
---|
[234] | 322 | } |
---|
| 323 | |
---|
[0] | 324 | /* On document ready |
---|
| 325 | -------------------------------------------------------- */ |
---|
| 326 | $(function() { |
---|
| 327 | // Blog switcher |
---|
| 328 | $('#switchblog').change(function() { |
---|
| 329 | this.form.submit(); |
---|
| 330 | }); |
---|
[131] | 331 | |
---|
[0] | 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'), |
---|
[297] | 339 | $.extend({cookie:'dc_blog_menu'},menu_settings) |
---|
[0] | 340 | ); |
---|
| 341 | $('#system-menu h3:first').toggleWithLegend($('#system-menu ul:first'), |
---|
[297] | 342 | $.extend({cookie:'dc_system_menu'},menu_settings) |
---|
[0] | 343 | ); |
---|
| 344 | $('#plugins-menu h3:first').toggleWithLegend($('#plugins-menu ul:first'), |
---|
[297] | 345 | $.extend({cookie:'dc_plugins_menu'},menu_settings) |
---|
[0] | 346 | ); |
---|
[3] | 347 | $('#favorites-menu h3:first').toggleWithLegend($('#favorites-menu ul:first'), |
---|
[297] | 348 | $.extend({cookie:'dc_favorites_menu',hide:false,reverse_cookie:true},menu_settings) |
---|
[3] | 349 | ); |
---|
[131] | 350 | |
---|
[0] | 351 | $('#help').helpViewer(); |
---|
[131] | 352 | |
---|
[0] | 353 | $('.message').backgroundFade({sColor:'#cccccc',eColor:'#666666',steps:20}); |
---|
| 354 | $('.error').backgroundFade({sColor:'#f5e5e5',eColor:'#e5bfbf',steps:20}); |
---|
[131] | 355 | |
---|
[0] | 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 | }); |
---|
[131] | 367 | |
---|
| 368 | // Sticky footer |
---|
| 369 | positionFooter(); |
---|
| 370 | $(window).resize(positionFooter); |
---|
[0] | 371 | }); |
---|
| 372 | |
---|