Changeset 3685:3f1bacac1ac3 for admin/js/common.js
- Timestamp:
- 01/27/18 11:59:30 (8 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
admin/js/common.js
r3648 r3685 3 3 // set base font-size of body (62.5% default, usually : 50% to 75%) 4 4 if (typeof dotclear_htmlFontSize !== 'undefined') { 5 document.documentElement.style.setProperty('--html-font-size',dotclear_htmlFontSize);5 document.documentElement.style.setProperty('--html-font-size', dotclear_htmlFontSize); 6 6 } 7 8 7 /* ChainHandler, py Peter van der Beken 9 8 -------------------------------------------------------- */ 10 9 function chainHandler(obj, handlerName, handler) { 11 obj[handlerName] = (function(existingFunction) { 12 return function() { 13 handler.apply(this, arguments); 14 if (existingFunction) 15 existingFunction.apply(this, arguments); 16 }; 17 })(handlerName in obj ? obj[handlerName] : null); 18 }; 19 10 obj[handlerName] = (function(existingFunction) { 11 return function() { 12 handler.apply(this, arguments); 13 if (existingFunction) existingFunction.apply(this, arguments); 14 }; 15 })(handlerName in obj ? obj[handlerName] : null); 16 }; 20 17 /* jQuery extensions 21 18 -------------------------------------------------------- */ 22 19 jQuery.fn.check = function() { 23 return this.each(function() { 24 if (this.checked != undefined) { this.checked = true; } 25 }); 20 return this.each(function() { 21 if (this.checked != undefined) { 22 this.checked = true; 23 } 24 }); 26 25 }; 27 26 jQuery.fn.unCheck = function() { 28 return this.each(function() { 29 if (this.checked != undefined) { this.checked = false; } 30 }); 27 return this.each(function() { 28 if (this.checked != undefined) { 29 this.checked = false; 30 } 31 }); 31 32 }; 32 33 jQuery.fn.setChecked = function(status) { 33 return this.each(function() { 34 if (this.checked != undefined) { this.checked = status; } 35 }); 34 return this.each(function() { 35 if (this.checked != undefined) { 36 this.checked = status; 37 } 38 }); 36 39 }; 37 40 jQuery.fn.toggleCheck = function() { 38 return this.each(function() { 39 if (this.checked != undefined) { this.checked = !this.checked; } 40 }); 41 }; 42 41 return this.each(function() { 42 if (this.checked != undefined) { 43 this.checked = !this.checked; 44 } 45 }); 46 }; 43 47 jQuery.fn.enableShiftClick = function() { 44 this.click( 45 function (event) { 46 if (event.shiftKey) { 47 if (dotclear.lastclicked != '') { 48 var range; 49 var trparent = $(this).parents('tr'); 50 if (trparent.nextAll('#'+dotclear.lastclicked).length != 0) 51 range = trparent.nextUntil('#'+dotclear.lastclicked); 52 else 53 range = trparent.prevUntil('#'+dotclear.lastclicked); 54 55 range.find('input[type=checkbox]').setChecked(dotclear.lastclickedstatus); 56 this.checked = dotclear.lastclickedstatus; 57 } 58 } else { 59 dotclear.lastclicked = $(this).parents('tr')[0].id; 60 dotclear.lastclickedstatus = this.checked; 61 } 62 return true; 63 }); 48 this.click(function(event) { 49 if (event.shiftKey) { 50 if (dotclear.lastclicked != '') { 51 var range; 52 var trparent = $(this).parents('tr'); 53 if (trparent.nextAll('#' + dotclear.lastclicked).length != 0) range = trparent.nextUntil('#' + dotclear.lastclicked); 54 else range = trparent.prevUntil('#' + dotclear.lastclicked); 55 range.find('input[type=checkbox]').setChecked(dotclear.lastclickedstatus); 56 this.checked = dotclear.lastclickedstatus; 57 } 58 } else { 59 dotclear.lastclicked = $(this).parents('tr')[0].id; 60 dotclear.lastclickedstatus = this.checked; 61 } 62 return true; 63 }); 64 64 } 65 66 jQuery.fn.toggleWithLegend = function(target,s) { 67 var defaults = { 68 img_on_src: dotclear.img_plus_src, 69 img_on_alt: dotclear.img_plus_alt, 70 img_off_src: dotclear.img_minus_src, 71 img_off_alt: dotclear.img_minus_alt, 72 unfolded_sections: dotclear.unfolded_sections, 73 hide: true, 74 speed: 0, 75 legend_click: false, 76 fn: false, // A function called on first display, 77 user_pref: false, 78 reverse_user_pref: false // Reverse cookie behavior 79 }; 80 var p = jQuery.extend(defaults,s); 81 82 if (!target) { return this; } 83 84 var set_cookie = p.hide ^ p.reverse_cookie; 85 if (p.cookie && jQuery.cookie(p.cookie)) { 86 p.hide = p.reverse_cookie; 87 } 88 89 var set_user_pref = p.hide ^ p.reverse_user_pref; 90 if (p.user_pref && p.unfolded_sections !== undefined && (p.user_pref in p.unfolded_sections)) { 91 p.hide = p.reverse_user_pref; 92 } 93 var toggle = function(i,speed) { 94 speed = speed || 0; 95 if (p.hide) { 96 $(i).get(0).src = p.img_on_src; 97 $(i).get(0).alt = p.img_on_alt; 98 target.addClass('hide'); 99 } else { 100 $(i).get(0).src = p.img_off_src; 101 $(i).get(0).alt = p.img_off_alt; 102 target.removeClass('hide'); 103 if (p.fn) { 104 p.fn.apply(target); 105 p.fn = false; 106 } 107 } 108 109 if (p.cookie && set_cookie) { 110 if (p.hide ^ p.reverse_cookie) { 111 jQuery.cookie(p.cookie,'',{expires: -1}); 112 } else { 113 jQuery.cookie(p.cookie,1,{expires: 30}); 114 } 115 } 116 p.hide = !p.hide; 117 }; 118 119 return this.each(function() { 120 var i = document.createElement('img'); 121 i.src = p.img_off_src; 122 i.alt = p.img_off_alt; 123 var a = document.createElement('a'); 124 a.href= '#'; 125 $(a).append(i); 126 $(a).css({ 127 border: 'none', 128 outline: 'none' 129 }); 130 131 var ctarget = p.legend_click ? this : a; 132 133 $(ctarget).css('cursor','pointer'); 134 if (p.legend_click) { 135 $(ctarget).find('label').css('cursor','pointer'); 136 } 137 $(ctarget).click(function() { 138 if (p.user_pref && set_user_pref) { 139 if (p.hide ^ p.reverse_user_pref) { 140 jQuery.post('services.php', 141 {'f':'setSectionFold','section':p.user_pref,'value':1,xd_check: dotclear.nonce}, 142 function(data) {}); 143 } else { 144 jQuery.post('services.php', 145 {'f':'setSectionFold','section':p.user_pref,'value':0,xd_check: dotclear.nonce}, 146 function(data) {}); 147 } 148 jQuery.cookie(p.user_pref,'',{expires: -1}); 149 } 150 toggle(i,p.speed); 151 return false; 152 }); 153 154 155 toggle($(i).get(0)); 156 $(this).prepend(' ').prepend(a); 157 }); 158 }; 159 65 jQuery.fn.toggleWithLegend = function(target, s) { 66 var defaults = { 67 img_on_src: dotclear.img_plus_src, 68 img_on_alt: dotclear.img_plus_alt, 69 img_off_src: dotclear.img_minus_src, 70 img_off_alt: dotclear.img_minus_alt, 71 unfolded_sections: dotclear.unfolded_sections, 72 hide: true, 73 speed: 0, 74 legend_click: false, 75 fn: false, // A function called on first display, 76 user_pref: false, 77 reverse_user_pref: false // Reverse cookie behavior 78 }; 79 var p = jQuery.extend(defaults, s); 80 if (!target) { 81 return this; 82 } 83 var set_cookie = p.hide ^ p.reverse_cookie; 84 if (p.cookie && jQuery.cookie(p.cookie)) { 85 p.hide = p.reverse_cookie; 86 } 87 var set_user_pref = p.hide ^ p.reverse_user_pref; 88 if (p.user_pref && p.unfolded_sections !== undefined && (p.user_pref in p.unfolded_sections)) { 89 p.hide = p.reverse_user_pref; 90 } 91 var toggle = function(i, speed) { 92 speed = speed || 0; 93 if (p.hide) { 94 $(i).get(0).src = p.img_on_src; 95 $(i).get(0).alt = p.img_on_alt; 96 target.addClass('hide'); 97 } else { 98 $(i).get(0).src = p.img_off_src; 99 $(i).get(0).alt = p.img_off_alt; 100 target.removeClass('hide'); 101 if (p.fn) { 102 p.fn.apply(target); 103 p.fn = false; 104 } 105 } 106 if (p.cookie && set_cookie) { 107 if (p.hide ^ p.reverse_cookie) { 108 jQuery.cookie(p.cookie, '', { 109 expires: -1 110 }); 111 } else { 112 jQuery.cookie(p.cookie, 1, { 113 expires: 30 114 }); 115 } 116 } 117 p.hide = !p.hide; 118 }; 119 return this.each(function() { 120 var i = document.createElement('img'); 121 i.src = p.img_off_src; 122 i.alt = p.img_off_alt; 123 var a = document.createElement('a'); 124 a.href = '#'; 125 $(a).append(i); 126 $(a).css({ 127 border: 'none', 128 outline: 'none' 129 }); 130 var ctarget = p.legend_click ? this : a; 131 $(ctarget).css('cursor', 'pointer'); 132 if (p.legend_click) { 133 $(ctarget).find('label').css('cursor', 'pointer'); 134 } 135 $(ctarget).click(function() { 136 if (p.user_pref && set_user_pref) { 137 if (p.hide ^ p.reverse_user_pref) { 138 jQuery.post('services.php', { 139 'f': 'setSectionFold', 140 'section': p.user_pref, 141 'value': 1, 142 xd_check: dotclear.nonce 143 }, function(data) {}); 144 } else { 145 jQuery.post('services.php', { 146 'f': 'setSectionFold', 147 'section': p.user_pref, 148 'value': 0, 149 xd_check: dotclear.nonce 150 }, function(data) {}); 151 } 152 jQuery.cookie(p.user_pref, '', { 153 expires: -1 154 }); 155 } 156 toggle(i, p.speed); 157 return false; 158 }); 159 toggle($(i).get(0)); 160 $(this).prepend(' ').prepend(a); 161 }); 162 }; 160 163 (function($) { 161 'use strict'; 162 163 $.expandContent = function(opts) { 164 var defaults = {}; 165 $.expandContent.options = $.extend({},defaults,opts); 166 167 if (opts==undefined || opts.callback==undefined || !$.isFunction(opts.callback)) { 168 return; 169 } 170 if (opts.line!=undefined) { 171 multipleExpander(opts.line,opts.lines); 172 } 173 opts.lines.each(function() { 174 singleExpander(this); 175 }); 176 } 177 178 var singleExpander = function singleExpander(line) { 179 $('<input type="image" src="'+dotclear.img_plus_src+'" alt="'+dotclear.img_plus_alt+'"/>') 180 .click(function(e) { 181 toggleArrow(this); 182 $.expandContent.options.callback.call(this,line); 183 e.preventDefault(); 184 }) 185 .prependTo($(line).children().get(0)); // first td 186 }; 187 188 var multipleExpander = function multipleExpander(line,lines) { 189 $('<input type="image" src="'+dotclear.img_plus_src+'" alt="'+dotclear.img_plus_alt+'"/>') 190 .click(function(e) { 191 var that = this; 192 var action = toggleArrow(this); 193 lines.each(function() { 194 toggleArrow(this.firstChild.firstChild,action); 195 $.expandContent.options.callback.call(that,this,action); 196 197 }); 198 e.preventDefault(); 199 }) 200 .prependTo($(line).children().get(0)); // first td 201 }; 202 203 var toggleArrow = function toggleArrow(button,action) { 204 action = action || ''; 205 if (action=='') { 206 if (button.alt==dotclear.img_plus_alt) { 207 action = 'open'; 208 } else { 209 action = 'close'; 210 } 211 } 212 213 if (action=='open') { 214 button.src = dotclear.img_minus_src; 215 button.alt = dotclear.img_minus_alt; 216 } else { 217 button.src = dotclear.img_plus_src; 218 button.alt = dotclear.img_plus_alt; 219 } 220 221 return action; 222 } 164 'use strict'; 165 $.expandContent = function(opts) { 166 var defaults = {}; 167 $.expandContent.options = $.extend({}, defaults, opts); 168 if (opts == undefined || opts.callback == undefined || !$.isFunction(opts.callback)) { 169 return; 170 } 171 if (opts.line != undefined) { 172 multipleExpander(opts.line, opts.lines); 173 } 174 opts.lines.each(function() { 175 singleExpander(this); 176 }); 177 } 178 var singleExpander = function singleExpander(line) { 179 $('<input type="image" src="' + dotclear.img_plus_src + '" alt="' + dotclear.img_plus_alt + '"/>').click(function(e) { 180 toggleArrow(this); 181 $.expandContent.options.callback.call(this, line); 182 e.preventDefault(); 183 }).prependTo($(line).children().get(0)); // first td 184 }; 185 var multipleExpander = function multipleExpander(line, lines) { 186 $('<input type="image" src="' + dotclear.img_plus_src + '" alt="' + dotclear.img_plus_alt + '"/>').click(function(e) { 187 var that = this; 188 var action = toggleArrow(this); 189 lines.each(function() { 190 toggleArrow(this.firstChild.firstChild, action); 191 $.expandContent.options.callback.call(that, this, action); 192 }); 193 e.preventDefault(); 194 }).prependTo($(line).children().get(0)); // first td 195 }; 196 var toggleArrow = function toggleArrow(button, action) { 197 action = action || ''; 198 if (action == '') { 199 if (button.alt == dotclear.img_plus_alt) { 200 action = 'open'; 201 } else { 202 action = 'close'; 203 } 204 } 205 if (action == 'open') { 206 button.src = dotclear.img_minus_src; 207 button.alt = dotclear.img_minus_alt; 208 } else { 209 button.src = dotclear.img_plus_src; 210 button.alt = dotclear.img_plus_alt; 211 } 212 return action; 213 } 223 214 })(jQuery); 224 225 215 jQuery.fn.helpViewer = function() { 226 if (this.length < 1) { 227 return this; 228 } 229 230 var p = { 231 img_on_src: dotclear.img_plus_src, 232 img_on_alt: dotclear.img_plus_alt, 233 img_off_src: dotclear.img_minus_src, 234 img_off_alt: dotclear.img_minus_alt 235 }; 236 var This = this; 237 var toggle = function() { 238 $('#content').toggleClass('with-help'); 239 if (document.all) { 240 if ($('#content').hasClass('with-help')) { 241 select = $('#content select:visible').hide(); 242 } else { 243 select.show(); 244 } 245 } 246 $('p#help-button span a').text($('#content').hasClass('with-help') ? dotclear.msg.help_hide : dotclear.msg.help); 247 sizeBox(); 248 return false; 249 }; 250 251 var sizeBox = function() { 252 This.css('height','auto'); 253 if ($('#wrapper').height() > This.height()) { 254 This.css('height',$('#wrapper').height() + 'px'); 255 } 256 }; 257 258 var textToggler = function(o) { 259 var i = $('<img src="'+p.img_on_src+'" alt="'+p.img_on_alt+'" />'); 260 o.css('cursor','pointer'); 261 var hide = true; 262 263 o.prepend(' ').prepend(i); 264 o.click(function() { 265 $(this).nextAll().each(function() { 266 if ($(this).is('h4')) { 267 return false; 268 } 269 $(this).toggle(); 270 sizeBox(); 271 return true; 272 }); 273 hide = !hide; 274 var img = $(this).find('img'); 275 if (!hide) { 276 img.attr('src',p.img_off_src); 277 } else { 278 img.attr('src',p.img_on_src); 279 } 280 }); 281 }; 282 283 this.addClass('help-box'); 284 this.find('>hr').remove(); 285 286 this.find('h4').each(function() { textToggler($(this)); }); 287 this.find('h4:first').nextAll('*:not(h4)').hide(); 288 sizeBox(); 289 290 var img = $('<p id="help-button"><span><a href="">'+dotclear.msg.help+'</a></span></p>'); 291 var select = $(); 292 img.click(function() { return toggle(); }); 293 294 $('#content').append(img); 295 296 // listen for scroll 297 var peInPage = $('#help-button').offset().top; 298 $('#help-button').addClass("floatable"); 299 var peInFloat = $('#help-button').offset().top - $(window).scrollTop(); 300 $('#help-button').removeClass("floatable"); 301 $(window).scroll( 302 function() { 303 if ($(window).scrollTop() >= peInPage - peInFloat ) { 304 $('#help-button').addClass("floatable"); 305 } else { 306 $('#help-button').removeClass("floatable"); 307 } 308 } 309 ); 310 311 return this; 312 }; 313 314 216 if (this.length < 1) { 217 return this; 218 } 219 var p = { 220 img_on_src: dotclear.img_plus_src, 221 img_on_alt: dotclear.img_plus_alt, 222 img_off_src: dotclear.img_minus_src, 223 img_off_alt: dotclear.img_minus_alt 224 }; 225 var This = this; 226 var toggle = function() { 227 $('#content').toggleClass('with-help'); 228 if (document.all) { 229 if ($('#content').hasClass('with-help')) { 230 select = $('#content select:visible').hide(); 231 } else { 232 select.show(); 233 } 234 } 235 $('p#help-button span a').text($('#content').hasClass('with-help') ? dotclear.msg.help_hide : dotclear.msg.help); 236 sizeBox(); 237 return false; 238 }; 239 var sizeBox = function() { 240 This.css('height', 'auto'); 241 if ($('#wrapper').height() > This.height()) { 242 This.css('height', $('#wrapper').height() + 'px'); 243 } 244 }; 245 var textToggler = function(o) { 246 var i = $('<img src="' + p.img_on_src + '" alt="' + p.img_on_alt + '" />'); 247 o.css('cursor', 'pointer'); 248 var hide = true; 249 o.prepend(' ').prepend(i); 250 o.click(function() { 251 $(this).nextAll().each(function() { 252 if ($(this).is('h4')) { 253 return false; 254 } 255 $(this).toggle(); 256 sizeBox(); 257 return true; 258 }); 259 hide = !hide; 260 var img = $(this).find('img'); 261 if (!hide) { 262 img.attr('src', p.img_off_src); 263 } else { 264 img.attr('src', p.img_on_src); 265 } 266 }); 267 }; 268 this.addClass('help-box'); 269 this.find('>hr').remove(); 270 this.find('h4').each(function() { 271 textToggler($(this)); 272 }); 273 this.find('h4:first').nextAll('*:not(h4)').hide(); 274 sizeBox(); 275 var img = $('<p id="help-button"><span><a href="">' + dotclear.msg.help + '</a></span></p>'); 276 var select = $(); 277 img.click(function() { 278 return toggle(); 279 }); 280 $('#content').append(img); 281 // listen for scroll 282 var peInPage = $('#help-button').offset().top; 283 $('#help-button').addClass("floatable"); 284 var peInFloat = $('#help-button').offset().top - $(window).scrollTop(); 285 $('#help-button').removeClass("floatable"); 286 $(window).scroll(function() { 287 if ($(window).scrollTop() >= peInPage - peInFloat) { 288 $('#help-button').addClass("floatable"); 289 } else { 290 $('#help-button').removeClass("floatable"); 291 } 292 }); 293 return this; 294 }; 315 295 /* Dotclear common object 316 296 -------------------------------------------------------- */ 317 297 var dotclear = { 318 msg: {}, 319 320 condSubmit: function(chkboxes,target) { 321 var checkboxes = $(chkboxes), 322 submitButt = $(target); 323 324 if (checkboxes === undefined || submitButt === undefined) { 325 return; 326 } 327 328 // Set initial state 329 submitButt.attr("disabled", !checkboxes.is(":checked")); 330 if (!checkboxes.is(":checked")) { 331 submitButt.addClass('disabled'); 332 } else { 333 submitButt.removeClass('disabled'); 334 } 335 336 checkboxes.click(function() { 337 // Update target state 338 submitButt.attr("disabled", !checkboxes.is(":checked")); 339 if (!checkboxes.is(":checked")) { 340 submitButt.addClass('disabled'); 341 } else { 342 submitButt.removeClass('disabled'); 343 } 344 }); 345 }, 346 347 hideLockable: function() { 348 $('div.lockable').each(function() { 349 var current_lockable_div = this; 350 $(this).find('p.form-note').hide(); 351 $(this).find('input').each(function() { 352 this.disabled = true; 353 $(this).width(($(this).width()-14) + 'px'); 354 355 var imgE = document.createElement('img'); 356 imgE.src = 'images/locker.png'; 357 imgE.style.position = 'absolute'; 358 imgE.style.top = '1.8em'; 359 imgE.style.left = ($(this).width()+14)+'px'; 360 imgE.alt=dotclear.msg.click_to_unlock; 361 $(imgE).css('cursor','pointer'); 362 363 $(imgE).click(function() { 364 $(this).hide(); 365 $(this).prev('input').each(function() { 366 this.disabled = false; 367 $(this).width(($(this).width()+14) + 'px'); 368 }); 369 $(current_lockable_div).find('p.form-note').show(); 370 }); 371 372 $(this).parent().css('position','relative'); 373 $(this).after(imgE); 374 }); 375 }); 376 }, 377 378 checkboxesHelpers: function(e, target, c, s) { 379 $(e).append(document.createTextNode(dotclear.msg.to_select)); 380 $(e).append(document.createTextNode(' ')); 381 382 $('<button type="button" class="checkbox-helper select-all">'+dotclear.msg.select_all+'</button>').click(function() { 383 if (target !== undefined) { 384 target.check(); 385 } else { 386 $(e).parents('form').find('input[type="checkbox"]').check(); 387 } 388 if (c !== undefined && s !== undefined) { 389 dotclear.condSubmit(c,s); 390 } 391 return false; 392 }).appendTo($(e)); 393 $(e).append(document.createTextNode(' ')); 394 395 $('<button type="button" class="checkbox-helper select-none">'+dotclear.msg.no_selection+'</button>').click(function() { 396 if (target !== undefined) { 397 target.unCheck(); 398 } else { 399 $(e).parents('form').find('input[type="checkbox"]').unCheck(); 400 } 401 if (c !== undefined && s !== undefined) { 402 dotclear.condSubmit(c,s); 403 } 404 return false; 405 }).appendTo($(e)); 406 $(e).append(document.createTextNode(' ')); 407 408 $('<button type="button" class="checkbox-helper select-reverse">'+dotclear.msg.invert_sel+'</button>').click(function() { 409 if (target !== undefined) { 410 target.toggleCheck(); 411 } else { 412 $(e).parents('form').find('input[type="checkbox"]').toggleCheck(); 413 } 414 if (c !== undefined && s !== undefined) { 415 dotclear.condSubmit(c,s); 416 } 417 return false; 418 }).appendTo($(e)); 419 }, 420 421 postsActionsHelper: function() { 422 $('#form-entries').submit(function() { 423 var action = $(this).find('select[name="action"]').val(); 424 if (action===undefined) { 425 return; 426 } 427 var checked = false; 428 429 $(this).find('input[name="entries[]"]').each(function() { 430 if (this.checked) { 431 checked = true; 432 } 433 }); 434 435 if (!checked) { return false; } 436 437 if (action == 'delete') { 438 return window.confirm(dotclear.msg.confirm_delete_posts.replace('%s',$('input[name="entries[]"]:checked').size())); 439 } 440 441 return true; 442 }); 443 }, 444 445 commentsActionsHelper: function() { 446 $('#form-comments').submit(function() { 447 var action = $(this).find('select[name="action"]').val(); 448 var checked = false; 449 450 $(this).find('input[name="comments[]"]').each(function() { 451 if (this.checked) { 452 checked = true; 453 } 454 }); 455 456 if (!checked) { return false; } 457 458 if (action == 'delete') { 459 return window.confirm(dotclear.msg.confirm_delete_comments.replace('%s',$('input[name="comments[]"]:checked').size())); 460 } 461 462 return true; 463 }); 464 }, 465 getCSSColor : function ( clazz) { 466 $('<div class="'+clazz+'" id="dotclear-obj-test-color" style="display:none"></div>').appendTo(document.body); 467 var tag2 = $('#dotclear-obj-test-color'); 468 var color = $.trim(tag2.css("color").toLowerCase()); 469 tag2.remove(); 470 if ( color.charAt(0) === '#') { 471 return color; 472 } 473 var result = /^rgb\((\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\)$/.exec(color); 474 if ( result === null) { 475 return ''; 476 } 477 var ret = '#'; 478 for ( var i = 1; i < 4; i++) { 479 var val = parseInt(result[i],10); 480 ret += (val < 16 ? '0'+val.toString(16) : val.toString(16)); 481 } 482 return ret; 483 }, 484 initFadeColor : function() { 485 dotclear.fadeColor = { 486 beginPassword : dotclear.getCSSColor('colorBeginPassword'), 487 endPassword : dotclear.getCSSColor('colorEndPassword'), 488 beginMessage : dotclear.getCSSColor('colorBeginMessage'), 489 endMessage : dotclear.getCSSColor('colorEndMessage'), 490 beginError : dotclear.getCSSColor('colorBeginError'), 491 endError : dotclear.getCSSColor('colorEndError'), 492 beginSuccess : dotclear.getCSSColor('colorBeginSuccess'), 493 endSuccess : dotclear.getCSSColor('colorEndSuccess'), 494 beginValidatorMsg : dotclear.getCSSColor('colorBeginValidatorMsg'), 495 endValidatorMsg : dotclear.getCSSColor('colorEndValidatorMsg'), 496 beginValidatorErr : dotclear.getCSSColor('colorBeginValidatorErr'), 497 endValidatorErr : dotclear.getCSSColor('colorEndValidatorErr'), 498 beginUserMail : dotclear.getCSSColor('colorBeginUserMail'), 499 endUserMail : dotclear.getCSSColor('colorEndUserMail') 500 }; 501 }}; 502 298 msg: {}, 299 condSubmit: function(chkboxes, target) { 300 var checkboxes = $(chkboxes), 301 submitButt = $(target); 302 if (checkboxes === undefined || submitButt === undefined) { 303 return; 304 } 305 // Set initial state 306 submitButt.attr("disabled", !checkboxes.is(":checked")); 307 if (!checkboxes.is(":checked")) { 308 submitButt.addClass('disabled'); 309 } else { 310 submitButt.removeClass('disabled'); 311 } 312 checkboxes.click(function() { 313 // Update target state 314 submitButt.attr("disabled", !checkboxes.is(":checked")); 315 if (!checkboxes.is(":checked")) { 316 submitButt.addClass('disabled'); 317 } else { 318 submitButt.removeClass('disabled'); 319 } 320 }); 321 }, 322 hideLockable: function() { 323 $('div.lockable').each(function() { 324 var current_lockable_div = this; 325 $(this).find('p.form-note').hide(); 326 $(this).find('input').each(function() { 327 this.disabled = true; 328 $(this).width(($(this).width() - 14) + 'px'); 329 var imgE = document.createElement('img'); 330 imgE.src = 'images/locker.png'; 331 imgE.style.position = 'absolute'; 332 imgE.style.top = '1.8em'; 333 imgE.style.left = ($(this).width() + 14) + 'px'; 334 imgE.alt = dotclear.msg.click_to_unlock; 335 $(imgE).css('cursor', 'pointer'); 336 $(imgE).click(function() { 337 $(this).hide(); 338 $(this).prev('input').each(function() { 339 this.disabled = false; 340 $(this).width(($(this).width() + 14) + 'px'); 341 }); 342 $(current_lockable_div).find('p.form-note').show(); 343 }); 344 $(this).parent().css('position', 'relative'); 345 $(this).after(imgE); 346 }); 347 }); 348 }, 349 checkboxesHelpers: function(e, target, c, s) { 350 $(e).append(document.createTextNode(dotclear.msg.to_select)); 351 $(e).append(document.createTextNode(' ')); 352 $('<button type="button" class="checkbox-helper select-all">' + dotclear.msg.select_all + '</button>').click(function() { 353 if (target !== undefined) { 354 target.check(); 355 } else { 356 $(e).parents('form').find('input[type="checkbox"]').check(); 357 } 358 if (c !== undefined && s !== undefined) { 359 dotclear.condSubmit(c, s); 360 } 361 return false; 362 }).appendTo($(e)); 363 $(e).append(document.createTextNode(' ')); 364 $('<button type="button" class="checkbox-helper select-none">' + dotclear.msg.no_selection + '</button>').click(function() { 365 if (target !== undefined) { 366 target.unCheck(); 367 } else { 368 $(e).parents('form').find('input[type="checkbox"]').unCheck(); 369 } 370 if (c !== undefined && s !== undefined) { 371 dotclear.condSubmit(c, s); 372 } 373 return false; 374 }).appendTo($(e)); 375 $(e).append(document.createTextNode(' ')); 376 $('<button type="button" class="checkbox-helper select-reverse">' + dotclear.msg.invert_sel + '</button>').click(function() { 377 if (target !== undefined) { 378 target.toggleCheck(); 379 } else { 380 $(e).parents('form').find('input[type="checkbox"]').toggleCheck(); 381 } 382 if (c !== undefined && s !== undefined) { 383 dotclear.condSubmit(c, s); 384 } 385 return false; 386 }).appendTo($(e)); 387 }, 388 postsActionsHelper: function() { 389 $('#form-entries').submit(function() { 390 var action = $(this).find('select[name="action"]').val(); 391 if (action === undefined) { 392 return; 393 } 394 var checked = false; 395 $(this).find('input[name="entries[]"]').each(function() { 396 if (this.checked) { 397 checked = true; 398 } 399 }); 400 if (!checked) { 401 return false; 402 } 403 if (action == 'delete') { 404 return window.confirm(dotclear.msg.confirm_delete_posts.replace('%s', $('input[name="entries[]"]:checked').size())); 405 } 406 return true; 407 }); 408 }, 409 commentsActionsHelper: function() { 410 $('#form-comments').submit(function() { 411 var action = $(this).find('select[name="action"]').val(); 412 var checked = false; 413 $(this).find('input[name="comments[]"]').each(function() { 414 if (this.checked) { 415 checked = true; 416 } 417 }); 418 if (!checked) { 419 return false; 420 } 421 if (action == 'delete') { 422 return window.confirm(dotclear.msg.confirm_delete_comments.replace('%s', $('input[name="comments[]"]:checked').size())); 423 } 424 return true; 425 }); 426 } 427 }; 503 428 /* On document ready 504 429 -------------------------------------------------------- */ 505 430 $(function() { 506 dotclear.initFadeColor(); 507 // remove class no-js from html tag; cf style/default.css for examples 508 $('body').removeClass('no-js').addClass('with-js'); 431 // remove class no-js from html tag; cf style/default.css for examples 432 $('body').removeClass('no-js').addClass('with-js'); 433 $('body').contents().each(function() { 434 if (this.nodeType == 8) { 435 var data = this.data; 436 data = data.replace(/ /g, ' ').replace(/\n/g, '<br/>'); 437 $('<span class="tooltip">' + $('#footer a').prop('title') + data + '</span>').appendTo('#footer a'); 438 } 439 }); 440 // manage outgoing links 441 $('a').filter(function() { 442 return ((this.hostname && this.hostname != location.hostname && !$(this).hasClass('modal') && !$(this).hasClass('modal-image')) || $(this).hasClass('outgoing')); 443 }).each(function() { 444 $(this).prop('title', $(this).prop('title') + ' (' + dotclear.msg.new_window + ')'); 445 if (!$(this).hasClass('outgoing')) { 446 $(this).append(' <img src="images/outgoing-blue.png" alt=""/>'); 447 } 448 }).click(function(e) { 449 e.preventDefault(); 450 window.open($(this).attr('href')); 451 }); 452 // Blog switcher 453 $('#switchblog').change(function() { 454 this.form.submit(); 455 }); 456 var menu_settings = { 457 img_on_src: dotclear.img_menu_off, 458 img_off_src: dotclear.img_menu_on, 459 legend_click: true, 460 speed: 100 461 } 462 $('#blog-menu h3:first').toggleWithLegend($('#blog-menu ul:first'), $.extend({ 463 user_pref: 'dc_blog_menu' 464 }, menu_settings)); 465 $('#system-menu h3:first').toggleWithLegend($('#system-menu ul:first'), $.extend({ 466 user_pref: 'dc_system_menu' 467 }, menu_settings)); 468 $('#plugins-menu h3:first').toggleWithLegend($('#plugins-menu ul:first'), $.extend({ 469 user_pref: 'dc_plugins_menu' 470 }, menu_settings)); 471 $('#favorites-menu h3:first').toggleWithLegend($('#favorites-menu ul:first'), $.extend({ 472 user_pref: 'dc_favorites_menu', 473 hide: false, 474 reverse_user_pref: true 475 }, menu_settings)); 476 $('#help').helpViewer(); 477 // Notices 478 $('p.success,p.warning,p.error,div.error').each(function() { 479 $(this).addClass('close-notice-parent'); 480 $(this).append('<button class="close-notice" type="button"><img src="images/close.png" alt="' + dotclear.msg.close_notice + '" /></button>'); 481 }); 482 $('button.close-notice').click(function(e) { 483 e.preventDefault(); 484 $(this).parent().hide(); 485 }); 486 // Password 487 $('form:has(input[type=password][name=your_pwd])').submit(function() { 488 var e = this.elements['your_pwd']; 489 if (e.value == '') { 490 $(e).addClass('missing').focusout(function() { 491 $(this).removeClass('missing') 492 }); 493 e.focus(); 494 return false; 495 } 496 return true; 497 }); 498 // Cope with ellipsis'ed cells 499 $('table .maximal').each(function() { 500 if (this.offsetWidth < this.scrollWidth) { 501 if (this.title == '') { 502 this.title = this.innerText; 503 $(this).addClass('ellipsis'); 504 } 505 } 506 }); 507 $('table .maximal.ellipsis a').each(function() { 508 if (this.title == '') { 509 this.title = this.innerText; 510 } 511 }) 512 // Advanced users 513 if (dotclear.hideMoreInfo) { 514 $('.more-info,.form-note:not(.warn,.warning,.info)').addClass('no-more-info'); 515 } 516 // Ajax loader activity indicator 517 if (dotclear.showAjaxLoader) { 518 $(document).ajaxStart(function() { 519 $('body').addClass('ajax-loader'); 520 $('div.ajax-loader').show(); 521 }); 522 $(document).ajaxStop(function() { 523 $('body').removeClass('ajax-loader'); 524 $('div.ajax-loader').hide(); 525 }); 526 } 527 // Main menu collapser 528 var objMain = $('#wrapper'); 509 529 510 $('body').contents().each(function() {511 if (this.nodeType==8) { 512 var data = this.data;513 data = data.replace(/ /g,' ').replace(/\n/g,'<br/>'); 514 $('<span class="tooltip">'+$('#footer a').prop('title')+data+'</span>').appendTo('#footer a'); 515 } 516 }); 530 function showSidebar() { 531 // Show sidebar 532 objMain.removeClass('hide-mm'); 533 $.cookie('sidebar-pref', null, { 534 expires: 30 535 }); 536 } 517 537 518 // manage outgoing links 519 $('a').filter(function() { 520 return ((this.hostname && this.hostname!=location.hostname 521 && !$(this).hasClass('modal') && !$(this).hasClass('modal-image')) 522 || $(this).hasClass('outgoing')); 523 }).each(function() { 524 $(this).prop('title',$(this).prop('title')+' ('+dotclear.msg.new_window+')'); 525 if (!$(this).hasClass('outgoing')) { 526 $(this).append(' <img src="images/outgoing-blue.png" alt=""/>'); 527 } 528 }).click(function(e) { 529 e.preventDefault(); 530 window.open($(this).attr('href')); 531 }); 532 533 // Blog switcher 534 $('#switchblog').change(function() { 535 this.form.submit(); 536 }); 537 538 var menu_settings = { 539 img_on_src: dotclear.img_menu_off, 540 img_off_src: dotclear.img_menu_on, 541 legend_click: true, 542 speed: 100 543 } 544 $('#blog-menu h3:first').toggleWithLegend($('#blog-menu ul:first'), 545 $.extend({user_pref:'dc_blog_menu'},menu_settings) 546 ); 547 $('#system-menu h3:first').toggleWithLegend($('#system-menu ul:first'), 548 $.extend({user_pref:'dc_system_menu'},menu_settings) 549 ); 550 $('#plugins-menu h3:first').toggleWithLegend($('#plugins-menu ul:first'), 551 $.extend({user_pref:'dc_plugins_menu'},menu_settings) 552 ); 553 $('#favorites-menu h3:first').toggleWithLegend($('#favorites-menu ul:first'), 554 $.extend({user_pref:'dc_favorites_menu',hide:false,reverse_user_pref:true},menu_settings) 555 ); 556 557 $('#help').helpViewer(); 558 559 // Notices 560 $('.message').backgroundFade({sColor: dotclear.fadeColor.beginMessage, eColor: dotclear.fadeColor.endMessage, steps:20}); 561 $('.error').backgroundFade({sColor: dotclear.fadeColor.beginError, eColor: dotclear.fadeColor.endError, steps:20}); 562 $('.success').backgroundFade({sColor: dotclear.fadeColor.beginSuccess, eColor: dotclear.fadeColor.endSuccess, steps:20}); 563 564 $('p.success,p.warning,p.error,div.error').each(function () { 565 $(this).addClass('close-notice-parent'); 566 $(this).append('<button class="close-notice" type="button"><img src="images/close.png" alt="'+dotclear.msg.close_notice+'" /></button>'); 567 }); 568 $('button.close-notice').click(function(e) { 569 e.preventDefault(); 570 $(this).parent().hide(); 571 }); 572 573 // Password 574 $('form:has(input[type=password][name=your_pwd])').submit(function() { 575 var e = this.elements['your_pwd']; 576 if (e.value == '') { 577 e.focus(); 578 $(e).backgroundFade({sColor: dotclear.fadeColor.beginPassword,eColor: dotclear.fadeColor.endPassword,steps:50},function() { 579 $(this).backgroundFade({sColor: dotclear.fadeColor.endPassword,eColor: dotclear.fadeColor.beginPassword}); 580 }); 581 return false; 582 } 583 return true; 584 }); 585 586 // Cope with ellipsis'ed cells 587 $('table .maximal').each(function() { 588 if (this.offsetWidth < this.scrollWidth) { 589 if (this.title == '') { 590 this.title = this.innerText; 591 $(this).addClass('ellipsis'); 592 } 593 } 594 }); 595 $('table .maximal.ellipsis a').each(function() { 596 if (this.title == '') { 597 this.title = this.innerText; 598 } 599 }) 600 601 // Advanced users 602 if (dotclear.hideMoreInfo) { 603 $('.more-info,.form-note:not(.warn,.warning,.info)').addClass('no-more-info'); 604 } 605 606 // Ajax loader activity indicator 607 if (dotclear.showAjaxLoader) { 608 $(document).ajaxStart(function() { 609 $('body').addClass('ajax-loader'); 610 $('div.ajax-loader').show(); 611 }); 612 $(document).ajaxStop(function() { 613 $('body').removeClass('ajax-loader'); 614 $('div.ajax-loader').hide(); 615 }); 616 } 617 618 // Main menu collapser 619 var objMain = $('#wrapper'); 620 function showSidebar(){ 621 // Show sidebar 622 objMain.removeClass('hide-mm'); 623 $.cookie('sidebar-pref',null,{expires:30}); 624 } 625 function hideSidebar(){ 626 // Hide sidebar 627 objMain.addClass('hide-mm'); 628 $.cookie('sidebar-pref','hide-mm',{expires:30}); 629 } 630 // Sidebar separator 631 var objSeparator = $('#collapser'); 632 objSeparator.click(function(e){ 633 e.preventDefault(); 634 if ( objMain.hasClass('hide-mm') ){ 635 showSidebar(); 636 $('#main-menu input#qx').focus(); 637 } 638 else { 639 hideSidebar(); 640 $('#content a.go_home').focus(); 641 } 642 }); 643 if ( $.cookie('sidebar-pref') == 'hide-mm' ){ 644 objMain.addClass('hide-mm'); 645 } else { 646 objMain.removeClass('hide-mm'); 647 } 648 // totop scroll 649 $(window).scroll(function() { 650 if($(this).scrollTop() != 0) { 651 $('#gototop').fadeIn(); 652 } else { 653 $('#gototop').fadeOut(); 654 } 655 }); 656 657 $('#gototop').click(function(e) { 658 $('body,html').animate({scrollTop:0},800); 659 e.preventDefault(); 660 }); 538 function hideSidebar() { 539 // Hide sidebar 540 objMain.addClass('hide-mm'); 541 $.cookie('sidebar-pref', 'hide-mm', { 542 expires: 30 543 }); 544 } 545 // Sidebar separator 546 var objSeparator = $('#collapser'); 547 objSeparator.click(function(e) { 548 e.preventDefault(); 549 if (objMain.hasClass('hide-mm')) { 550 showSidebar(); 551 $('#main-menu input#qx').focus(); 552 } else { 553 hideSidebar(); 554 $('#content a.go_home').focus(); 555 } 556 }); 557 if ($.cookie('sidebar-pref') == 'hide-mm') { 558 objMain.addClass('hide-mm'); 559 } else { 560 objMain.removeClass('hide-mm'); 561 } 562 // totop scroll 563 $(window).scroll(function() { 564 if ($(this).scrollTop() != 0) { 565 $('#gototop').fadeIn(); 566 } else { 567 $('#gototop').fadeOut(); 568 } 569 }); 570 $('#gototop').click(function(e) { 571 $('body,html').animate({ 572 scrollTop: 0 573 }, 800); 574 e.preventDefault(); 575 }); 661 576 });
Note: See TracChangeset
for help on using the changeset viewer.