[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, |
---|
[1699] | 65 | unfolded_sections: dotclear.unfolded_sections, |
---|
[0] | 66 | hide: true, |
---|
| 67 | speed: 0, |
---|
| 68 | legend_click: false, |
---|
| 69 | fn: false, // A function called on first display, |
---|
[1699] | 70 | user_pref: false, |
---|
[1923] | 71 | reverse_user_pref: false // Reverse cookie behavior |
---|
[0] | 72 | }; |
---|
| 73 | var p = jQuery.extend(defaults,s); |
---|
[131] | 74 | |
---|
[0] | 75 | if (!target) { return this; } |
---|
[131] | 76 | |
---|
[0] | 77 | var set_cookie = p.hide ^ p.reverse_cookie; |
---|
| 78 | if (p.cookie && jQuery.cookie(p.cookie)) { |
---|
| 79 | p.hide = p.reverse_cookie; |
---|
| 80 | } |
---|
[1699] | 81 | |
---|
| 82 | var set_user_pref = p.hide ^ p.reverse_user_pref; |
---|
[1781] | 83 | if (p.user_pref && p.unfolded_sections !== undefined && (p.user_pref in p.unfolded_sections)) { |
---|
[1699] | 84 | p.hide = p.reverse_user_pref; |
---|
| 85 | } |
---|
[297] | 86 | var toggle = function(i,speed) { |
---|
[0] | 87 | speed = speed || 0; |
---|
| 88 | if (p.hide) { |
---|
| 89 | $(i).get(0).src = p.img_on_src; |
---|
| 90 | $(i).get(0).alt = p.img_on_alt; |
---|
[1140] | 91 | target.hide(speed); |
---|
[0] | 92 | } else { |
---|
| 93 | $(i).get(0).src = p.img_off_src; |
---|
| 94 | $(i).get(0).alt = p.img_off_alt; |
---|
[1140] | 95 | target.show(speed); |
---|
[0] | 96 | if (p.fn) { |
---|
| 97 | p.fn.apply(target); |
---|
| 98 | p.fn = false; |
---|
| 99 | } |
---|
| 100 | } |
---|
[131] | 101 | |
---|
[0] | 102 | if (p.cookie && set_cookie) { |
---|
| 103 | if (p.hide ^ p.reverse_cookie) { |
---|
| 104 | jQuery.cookie(p.cookie,'',{expires: -1}); |
---|
| 105 | } else { |
---|
| 106 | jQuery.cookie(p.cookie,1,{expires: 30}); |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | p.hide = !p.hide; |
---|
| 110 | }; |
---|
[131] | 111 | |
---|
[0] | 112 | return this.each(function() { |
---|
| 113 | var i = document.createElement('img'); |
---|
| 114 | i.src = p.img_off_src; |
---|
| 115 | i.alt = p.img_off_alt; |
---|
| 116 | var a = document.createElement('a'); |
---|
| 117 | a.href= '#'; |
---|
| 118 | $(a).append(i); |
---|
| 119 | $(a).css({ |
---|
| 120 | border: 'none', |
---|
| 121 | outline: 'none' |
---|
| 122 | }); |
---|
[131] | 123 | |
---|
[0] | 124 | var ctarget = p.legend_click ? this : a; |
---|
[131] | 125 | |
---|
[0] | 126 | $(ctarget).css('cursor','pointer'); |
---|
[1525] | 127 | if (p.legend_click) { |
---|
| 128 | $(ctarget).find('label').css('cursor','pointer'); |
---|
| 129 | } |
---|
[0] | 130 | $(ctarget).click(function() { |
---|
[1699] | 131 | if (p.user_pref && set_user_pref) { |
---|
| 132 | if (p.hide ^ p.reverse_user_pref) { |
---|
| 133 | jQuery.post('services.php', |
---|
| 134 | {'f':'setSectionFold','section':p.user_pref,'value':1,xd_check: dotclear.nonce}, |
---|
| 135 | function(data) {}); |
---|
| 136 | } else { |
---|
| 137 | jQuery.post('services.php', |
---|
| 138 | {'f':'setSectionFold','section':p.user_pref,'value':0,xd_check: dotclear.nonce}, |
---|
| 139 | function(data) {}); |
---|
| 140 | } |
---|
| 141 | jQuery.cookie(p.user_pref,'',{expires: -1}); |
---|
| 142 | } |
---|
[1140] | 143 | toggle(i,p.speed); |
---|
[0] | 144 | return false; |
---|
| 145 | }); |
---|
[131] | 146 | |
---|
| 147 | |
---|
[0] | 148 | toggle($(i).get(0)); |
---|
| 149 | $(this).prepend(' ').prepend(a); |
---|
| 150 | }); |
---|
| 151 | }; |
---|
| 152 | |
---|
| 153 | jQuery.fn.helpViewer = function() { |
---|
| 154 | if (this.length < 1) { |
---|
| 155 | return this; |
---|
| 156 | } |
---|
[131] | 157 | |
---|
[0] | 158 | var p = { |
---|
| 159 | img_on_src: dotclear.img_plus_src, |
---|
| 160 | img_on_alt: dotclear.img_plus_alt, |
---|
| 161 | img_off_src: dotclear.img_minus_src, |
---|
| 162 | img_off_alt: dotclear.img_minus_alt |
---|
| 163 | }; |
---|
| 164 | var This = this; |
---|
| 165 | var toggle = function() { |
---|
| 166 | $('#content').toggleClass('with-help'); |
---|
| 167 | if (document.all) { |
---|
| 168 | if ($('#content').hasClass('with-help')) { |
---|
| 169 | select = $('#content select:visible').hide(); |
---|
| 170 | } else { |
---|
| 171 | select.show(); |
---|
| 172 | } |
---|
| 173 | } |
---|
[1303] | 174 | $('p#help-button span').text($('#content').hasClass('with-help') ? dotclear.msg.help_hide : dotclear.msg.help); |
---|
[0] | 175 | sizeBox(); |
---|
| 176 | return false; |
---|
| 177 | }; |
---|
[131] | 178 | |
---|
[0] | 179 | var sizeBox = function() { |
---|
| 180 | This.css('height','auto'); |
---|
[1002] | 181 | if ($('#main').height() > This.height()) { |
---|
| 182 | This.css('height',$('#main').height() + 'px'); |
---|
[0] | 183 | } |
---|
| 184 | }; |
---|
[131] | 185 | |
---|
[0] | 186 | var textToggler = function(o) { |
---|
| 187 | var i = $('<img src="'+p.img_on_src+'" alt="'+p.img_on_alt+'" />'); |
---|
| 188 | o.css('cursor','pointer'); |
---|
| 189 | var hide = true; |
---|
[131] | 190 | |
---|
[0] | 191 | o.prepend(' ').prepend(i); |
---|
| 192 | o.click(function() { |
---|
| 193 | $(this).nextAll().each(function() { |
---|
[1573] | 194 | if ($(this).is('h4')) { |
---|
[0] | 195 | return false; |
---|
| 196 | } |
---|
| 197 | $(this).toggle(); |
---|
| 198 | sizeBox(); |
---|
| 199 | return true; |
---|
| 200 | }); |
---|
| 201 | hide = !hide; |
---|
| 202 | var img = $(this).find('img'); |
---|
| 203 | if (!hide) { |
---|
| 204 | img.attr('src',p.img_off_src); |
---|
| 205 | } else { |
---|
| 206 | img.attr('src',p.img_on_src); |
---|
| 207 | } |
---|
| 208 | }); |
---|
| 209 | }; |
---|
[131] | 210 | |
---|
[0] | 211 | this.addClass('help-box'); |
---|
| 212 | this.find('>hr').remove(); |
---|
[131] | 213 | |
---|
[1573] | 214 | this.find('h4').each(function() { textToggler($(this)); }); |
---|
| 215 | this.find('h4:first').nextAll('*:not(h4)').hide(); |
---|
[0] | 216 | sizeBox(); |
---|
[131] | 217 | |
---|
[1303] | 218 | var img = $('<p id="help-button"><span>'+dotclear.msg.help+'</span></p>'); |
---|
[0] | 219 | var select = $(); |
---|
| 220 | img.click(function() { return toggle(); }); |
---|
[131] | 221 | |
---|
[0] | 222 | $('#content').append(img); |
---|
[131] | 223 | |
---|
[0] | 224 | return this; |
---|
| 225 | }; |
---|
| 226 | |
---|
| 227 | /* Dotclear common object |
---|
| 228 | -------------------------------------------------------- */ |
---|
| 229 | var dotclear = { |
---|
| 230 | msg: {}, |
---|
[131] | 231 | |
---|
[0] | 232 | hideLockable: function() { |
---|
| 233 | $('div.lockable').each(function() { |
---|
| 234 | var current_lockable_div = this; |
---|
| 235 | $(this).find('p.form-note').hide(); |
---|
| 236 | $(this).find('input').each(function() { |
---|
| 237 | this.disabled = true; |
---|
| 238 | $(this).width(($(this).width()-14) + 'px'); |
---|
[131] | 239 | |
---|
[0] | 240 | var imgE = document.createElement('img'); |
---|
| 241 | imgE.src = 'images/locker.png'; |
---|
| 242 | imgE.style.position = 'absolute'; |
---|
| 243 | imgE.style.top = '1.7em'; |
---|
[1761] | 244 | imgE.style.left = ($(this).width()+12)+'px'; |
---|
[1395] | 245 | imgE.alt=dotclear.msg.click_to_unlock; |
---|
[0] | 246 | $(imgE).css('cursor','pointer'); |
---|
[131] | 247 | |
---|
[0] | 248 | $(imgE).click(function() { |
---|
| 249 | $(this).hide(); |
---|
| 250 | $(this).prev('input').each(function() { |
---|
| 251 | this.disabled = false; |
---|
| 252 | $(this).width(($(this).width()+14) + 'px'); |
---|
| 253 | }); |
---|
| 254 | $(current_lockable_div).find('p.form-note').show(); |
---|
| 255 | }); |
---|
[131] | 256 | |
---|
[0] | 257 | $(this).parent().css('position','relative'); |
---|
| 258 | $(this).after(imgE); |
---|
| 259 | }); |
---|
| 260 | }); |
---|
| 261 | }, |
---|
[131] | 262 | |
---|
[1818] | 263 | checkboxesHelpers: function(e, target) { |
---|
[1556] | 264 | $(e).append(document.createTextNode(dotclear.msg.to_select)); |
---|
| 265 | $(e).append(document.createTextNode(' ')); |
---|
| 266 | |
---|
[1818] | 267 | target = target || $(e).parents('form').find('input[type="checkbox"]'); |
---|
| 268 | |
---|
[0] | 269 | var a = document.createElement('a'); |
---|
| 270 | a.href='#'; |
---|
| 271 | $(a).append(document.createTextNode(dotclear.msg.select_all)); |
---|
| 272 | a.onclick = function() { |
---|
[1818] | 273 | target.check(); |
---|
[0] | 274 | return false; |
---|
| 275 | }; |
---|
| 276 | $(e).append(a); |
---|
[131] | 277 | |
---|
[1556] | 278 | $(e).append(document.createTextNode(' | ')); |
---|
[131] | 279 | |
---|
[0] | 280 | a = document.createElement('a'); |
---|
| 281 | a.href='#'; |
---|
| 282 | $(a).append(document.createTextNode(dotclear.msg.no_selection)); |
---|
| 283 | a.onclick = function() { |
---|
[1818] | 284 | target.unCheck(); |
---|
[0] | 285 | return false; |
---|
| 286 | }; |
---|
| 287 | $(e).append(a); |
---|
[131] | 288 | |
---|
[0] | 289 | $(e).append(document.createTextNode(' - ')); |
---|
[131] | 290 | |
---|
[0] | 291 | a = document.createElement('a'); |
---|
| 292 | a.href='#'; |
---|
| 293 | $(a).append(document.createTextNode(dotclear.msg.invert_sel)); |
---|
| 294 | a.onclick = function() { |
---|
[1818] | 295 | target.toggleCheck(); |
---|
[0] | 296 | return false; |
---|
| 297 | }; |
---|
| 298 | $(e).append(a); |
---|
| 299 | }, |
---|
[131] | 300 | |
---|
[0] | 301 | postsActionsHelper: function() { |
---|
| 302 | $('#form-entries').submit(function() { |
---|
| 303 | var action = $(this).find('select[name="action"]').val(); |
---|
| 304 | var checked = false; |
---|
[131] | 305 | |
---|
[0] | 306 | $(this).find('input[name="entries[]"]').each(function() { |
---|
| 307 | if (this.checked) { |
---|
| 308 | checked = true; |
---|
| 309 | } |
---|
| 310 | }); |
---|
[131] | 311 | |
---|
[0] | 312 | if (!checked) { return false; } |
---|
[131] | 313 | |
---|
[0] | 314 | if (action == 'delete') { |
---|
| 315 | return window.confirm(dotclear.msg.confirm_delete_posts.replace('%s',$('input[name="entries[]"]:checked').size())); |
---|
| 316 | } |
---|
[131] | 317 | |
---|
[0] | 318 | return true; |
---|
| 319 | }); |
---|
| 320 | }, |
---|
[131] | 321 | |
---|
[0] | 322 | commentsActionsHelper: function() { |
---|
| 323 | $('#form-comments').submit(function() { |
---|
| 324 | var action = $(this).find('select[name="action"]').val(); |
---|
| 325 | var checked = false; |
---|
[131] | 326 | |
---|
[0] | 327 | $(this).find('input[name="comments[]"]').each(function() { |
---|
| 328 | if (this.checked) { |
---|
| 329 | checked = true; |
---|
| 330 | } |
---|
| 331 | }); |
---|
[131] | 332 | |
---|
[0] | 333 | if (!checked) { return false; } |
---|
[131] | 334 | |
---|
[0] | 335 | if (action == 'delete') { |
---|
| 336 | return window.confirm(dotclear.msg.confirm_delete_comments.replace('%s',$('input[name="comments[]"]:checked').size())); |
---|
| 337 | } |
---|
[131] | 338 | |
---|
[0] | 339 | return true; |
---|
| 340 | }); |
---|
| 341 | } |
---|
| 342 | }; |
---|
| 343 | |
---|
| 344 | /* On document ready |
---|
| 345 | -------------------------------------------------------- */ |
---|
| 346 | $(function() { |
---|
[1603] | 347 | // remove class no-js from html tag; cf style/default.css for examples |
---|
[1798] | 348 | $('body').removeClass('no-js').addClass('with-js'); |
---|
| 349 | |
---|
[1603] | 350 | $('#wrapper').contents().each(function() { |
---|
| 351 | if (this.nodeType==8) { |
---|
[1871] | 352 | $('#footer a[href!="help.php"]').attr('title', $('#footer a[href!="help.php"]').attr('title') + this.data ); |
---|
[1603] | 353 | } |
---|
| 354 | }); |
---|
| 355 | |
---|
[0] | 356 | // Blog switcher |
---|
| 357 | $('#switchblog').change(function() { |
---|
| 358 | this.form.submit(); |
---|
| 359 | }); |
---|
[131] | 360 | |
---|
[0] | 361 | var menu_settings = { |
---|
| 362 | img_on_src: dotclear.img_menu_off, |
---|
| 363 | img_off_src: dotclear.img_menu_on, |
---|
| 364 | legend_click: true, |
---|
| 365 | speed: 100 |
---|
| 366 | } |
---|
| 367 | $('#blog-menu h3:first').toggleWithLegend($('#blog-menu ul:first'), |
---|
[1699] | 368 | $.extend({user_pref:'dc_blog_menu'},menu_settings) |
---|
[0] | 369 | ); |
---|
| 370 | $('#system-menu h3:first').toggleWithLegend($('#system-menu ul:first'), |
---|
[1699] | 371 | $.extend({user_pref:'dc_system_menu'},menu_settings) |
---|
[0] | 372 | ); |
---|
| 373 | $('#plugins-menu h3:first').toggleWithLegend($('#plugins-menu ul:first'), |
---|
[1699] | 374 | $.extend({user_pref:'dc_plugins_menu'},menu_settings) |
---|
[0] | 375 | ); |
---|
[3] | 376 | $('#favorites-menu h3:first').toggleWithLegend($('#favorites-menu ul:first'), |
---|
[1699] | 377 | $.extend({user_pref:'dc_favorites_menu',hide:false,reverse_user_pref:true},menu_settings) |
---|
[3] | 378 | ); |
---|
[131] | 379 | |
---|
[0] | 380 | $('#help').helpViewer(); |
---|
[131] | 381 | |
---|
[1760] | 382 | $('.message').backgroundFade({sColor:'#cccccc',eColor:'#676e78',steps:20}); |
---|
[1516] | 383 | $('.error').backgroundFade({sColor:'#ffdec8',eColor:'#ffbaba',steps:20}); |
---|
[1635] | 384 | $('.success').backgroundFade({sColor:'#9BCA1C',eColor:'#bee74b',steps:20}); |
---|
[131] | 385 | |
---|
[0] | 386 | $('form:has(input[type=password][name=your_pwd])').submit(function() { |
---|
| 387 | var e = this.elements['your_pwd']; |
---|
| 388 | if (e.value == '') { |
---|
| 389 | e.focus(); |
---|
[1516] | 390 | $(e).backgroundFade({sColor:'#ffffff',eColor:'#ffbaba',steps:50},function() { |
---|
| 391 | $(this).backgroundFade({sColor:'#ffbaba',eColor:'#ffffff'}); |
---|
[0] | 392 | }); |
---|
| 393 | return false; |
---|
| 394 | } |
---|
| 395 | return true; |
---|
| 396 | }); |
---|
| 397 | |
---|
[1861] | 398 | // Main menu collapser |
---|
| 399 | var objMain = $('#wrapper'); |
---|
| 400 | function showSidebar(){ |
---|
| 401 | // Show sidebar |
---|
| 402 | objMain.removeClass('hide-mm'); |
---|
| 403 | $.cookie('sidebar-pref',null,{expires:30}); |
---|
| 404 | } |
---|
| 405 | function hideSidebar(){ |
---|
| 406 | // Hide sidebar |
---|
| 407 | objMain.addClass('hide-mm'); |
---|
| 408 | $.cookie('sidebar-pref','hide-mm',{expires:30}); |
---|
| 409 | } |
---|
| 410 | // Sidebar separator |
---|
| 411 | var objSeparator = $('#collapser'); |
---|
| 412 | objSeparator.click(function(e){ |
---|
| 413 | e.preventDefault(); |
---|
| 414 | if ( objMain.hasClass('hide-mm') ){ |
---|
| 415 | showSidebar(); |
---|
| 416 | } |
---|
| 417 | else { |
---|
| 418 | hideSidebar(); |
---|
| 419 | } |
---|
[1862] | 420 | }).css('height', objSeparator.parent().parent().parent().outerHeight() + 'px'); |
---|
[1861] | 421 | if ( $.cookie('sidebar-pref') == 'hide-mm' ){ |
---|
| 422 | objMain.addClass('hide-mm'); |
---|
| 423 | } else { |
---|
| 424 | objMain.removeClass('hide-mm'); |
---|
| 425 | } |
---|
| 426 | |
---|
[1871] | 427 | }); |
---|