Changeset 3880:e6d1f6d9d7df for admin/js/common.js
- Timestamp:
- 09/18/18 20:22:10 (7 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
admin/js/common.js
r3878 r3880 53 53 if (event.shiftKey) { 54 54 if (dotclear.lastclicked != '') { 55 var range; 56 var trparent = $(this).parents('tr'); 57 if (trparent.nextAll('#' + dotclear.lastclicked).length != 0) range = trparent.nextUntil('#' + dotclear.lastclicked); 58 else range = trparent.prevUntil('#' + dotclear.lastclicked); 55 let range; 56 const trparent = $(this).parents('tr'); 57 const id = `#${dotclear.lastclicked}`; 58 if (trparent.nextAll(id).length != 0) { 59 range = trparent.nextUntil(id); 60 } else { 61 range = trparent.prevUntil(id); 62 } 59 63 range.find('input[type=checkbox]').setChecked(dotclear.lastclickedstatus); 60 64 this.checked = dotclear.lastclickedstatus; … … 68 72 }; 69 73 jQuery.fn.toggleWithLegend = function(target, s) { 70 vardefaults = {74 const defaults = { 71 75 img_on_txt: dotclear.img_plus_txt, 72 76 img_on_alt: dotclear.img_plus_alt, … … 81 85 reverse_user_pref: false // Reverse cookie behavior 82 86 }; 83 varp = jQuery.extend(defaults, s);87 const p = jQuery.extend(defaults, s); 84 88 if (!target) { 85 89 return this; 86 90 } 87 varset_cookie = p.hide ^ p.reverse_cookie;91 const set_cookie = p.hide ^ p.reverse_cookie; 88 92 if (p.cookie && jQuery.cookie(p.cookie)) { 89 93 p.hide = p.reverse_cookie; 90 94 } 91 varset_user_pref = p.hide ^ p.reverse_user_pref;95 let set_user_pref = p.hide ^ p.reverse_user_pref; 92 96 if (p.user_pref && p.unfolded_sections !== undefined && (p.user_pref in p.unfolded_sections)) { 93 97 p.hide = p.reverse_user_pref; 94 98 } 95 vartoggle = function(i, speed) {99 const toggle = function(i, speed) { 96 100 speed = speed || 0; 97 varb = $(i).get(0);101 const b = $(i).get(0); 98 102 if (p.hide) { 99 103 b.firstChild.data = p.img_on_txt; … … 125 129 }; 126 130 return this.each(function() { 127 varb = document.createElement('button');131 const b = document.createElement('button'); 128 132 b.setAttribute('type', 'button'); 129 133 b.className = 'details-cmd'; 130 134 b.value = p.img_on_txt; 131 135 b.setAttribute('aria-label', p.img_on_alt); 132 vart = document.createTextNode(p.img_on_txt);136 const t = document.createTextNode(p.img_on_txt); 133 137 b.appendChild(t); 134 138 135 varctarget = p.legend_click ? this : b;139 const ctarget = p.legend_click ? this : b; 136 140 $(ctarget).css('cursor', 'pointer'); 137 141 if (p.legend_click) { … … 141 145 if (p.user_pref && set_user_pref) { 142 146 jQuery.post('services.php', { 143 'f': 'setSectionFold',144 'section': p.user_pref,145 'value': (p.hide ^ p.reverse_user_pref ? 1 : 0),147 f: 'setSectionFold', 148 section: p.user_pref, 149 value: (p.hide ^ p.reverse_user_pref ? 1 : 0), 146 150 xd_check: dotclear.nonce 147 151 }, function() {}); … … 158 162 }); 159 163 }; 164 160 165 (function($) { 161 166 $.expandContent = function(opts) { … … 170 175 }); 171 176 }; 172 var singleExpander = function singleExpander(line, callback) {173 $( '<button type="button" class="details-cmd" aria-label="' + dotclear.img_plus_alt + '">' + dotclear.img_plus_txt + '</button>').click(function(e) {177 const singleExpander = function(line, callback) { 178 $(`<button type="button" class="details-cmd" aria-label="${dotclear.img_plus_alt}">${dotclear.img_plus_txt}</button>`).click(function(e) { 174 179 toggleArrow(this); 175 180 callback(line, '', e); … … 177 182 }).prependTo($(line).children().get(0)); // first td 178 183 }; 179 var multipleExpander = function multipleExpander(line, lines, callback) {180 $( '<button type="button" class="details-cmd" aria-label="' + dotclear.img_plus_alt + '">' + dotclear.img_plus_txt + '</button>').click(function(e) {184 const multipleExpander = function(line, lines, callback) { 185 $(`<button type="button" class="details-cmd" aria-label="${dotclear.img_plus_alt}">${dotclear.img_plus_txt}</button>`).click(function(e) { 181 186 var action = toggleArrow(this); 182 187 lines.each(function() { … … 187 192 }).prependTo($(line).children().get(0)); // first td 188 193 }; 189 var toggleArrow = function toggleArrow(button, action) {194 const toggleArrow = function(button, action) { 190 195 action = action || ''; 191 196 if (action == '') { … … 212 217 return this; 213 218 } 214 var p = { 219 let select = $(); 220 const p = { 215 221 img_on_txt: dotclear.img_plus_txt, 216 222 img_on_alt: dotclear.img_plus_alt, … … 218 224 img_off_alt: dotclear.img_minus_alt 219 225 }; 220 varThis = this;221 vartoggle = function() {226 const This = this; 227 const toggle = function() { 222 228 $('#content').toggleClass('with-help'); 223 229 if (document.all) { … … 232 238 return false; 233 239 }; 234 varsizeBox = function() {240 const sizeBox = function() { 235 241 This.css('height', 'auto'); 236 242 if ($('#wrapper').height() > This.height()) { … … 238 244 } 239 245 }; 240 vartextToggler = function(o) {241 var b = $('<button type="button" class="details-cmd" aria-label="' + p.img_on_alt + '">' + p.img_on_txt + '</button>');246 const textToggler = function(o) { 247 const b = $(`<button type="button" class="details-cmd" aria-label="${p.img_on_alt}">${p.img_on_txt}</button>`); 242 248 o.css('cursor', 'pointer'); 243 varhide = true;249 let hide = true; 244 250 o.prepend(' ').prepend(b); 245 251 o.click(function() { … … 253 259 }); 254 260 hide = !hide; 255 varimg = $(this).find('button.details-cmd');261 const img = $(this).find('button.details-cmd'); 256 262 if (!hide) { 257 263 img.html(p.img_off_txt); … … 272 278 this.find('h4:first').nextAll('*:not(h4)').hide(); 273 279 sizeBox(); 274 var img = $('<p id="help-button"><span><a href="">' + dotclear.msg.help + '</a></span></p>'); 275 var select = $(); 280 const img = $(`<p id="help-button"><span><a href="">${dotclear.msg.help}</a></span></p>`); 276 281 img.click(function(e) { 277 282 e.preventDefault(); … … 280 285 $('#content').append(img); 281 286 // listen for scroll 282 varpeInPage = $('#help-button').offset().top;287 const peInPage = $('#help-button').offset().top; 283 288 $('#help-button').addClass('floatable'); 284 varpeInFloat = $('#help-button').offset().top - $(window).scrollTop();289 const peInFloat = $('#help-button').offset().top - $(window).scrollTop(); 285 290 $('#help-button').removeClass('floatable'); 286 291 $(window).scroll(function() { … … 293 298 return this; 294 299 }; 300 295 301 /* Dotclear common object 296 302 -------------------------------------------------------- */ 297 vardotclear = {303 const dotclear = { 298 304 msg: {}, 305 299 306 enterKeyInForm: function(frm_id, ok_id, cancel_id) { 300 307 $(frm_id + ':not(' + cancel_id + ')').keyup(function(e) { … … 306 313 }); 307 314 }, 315 308 316 condSubmit: function(chkboxes, target) { 309 varcheckboxes = $(chkboxes),317 const checkboxes = $(chkboxes), 310 318 submitButt = $(target); 311 319 if (checkboxes === undefined || submitButt === undefined) { … … 329 337 }); 330 338 }, 339 331 340 hideLockable: function() { 332 341 $('div.lockable').each(function() { 333 varcurrent_lockable_div = this;342 const current_lockable_div = this; 334 343 $(this).find('p.form-note').hide(); 335 344 $(this).find('input').each(function() { 336 345 this.disabled = true; 337 $(this).width( ($(this).width() - 14) + 'px');338 varimgE = document.createElement('img');346 $(this).width(`${$(this).width() - 14}px`); 347 const imgE = document.createElement('img'); 339 348 imgE.src = 'images/locker.png'; 340 349 imgE.style.position = 'absolute'; 341 350 imgE.style.top = '1.8em'; 342 imgE.style.left = ($(this).width() + 14) + 'px';351 imgE.style.left = `${$(this).width() + 14}px`; 343 352 imgE.alt = dotclear.msg.click_to_unlock; 344 353 $(imgE).css('cursor', 'pointer'); … … 356 365 }); 357 366 }, 367 358 368 checkboxesHelpers: function(e, target, c, s) { 359 369 $(e).append(document.createTextNode(dotclear.msg.to_select)); 360 370 $(e).append(document.createTextNode(' ')); 361 $( '<button type="button" class="checkbox-helper select-all">' + dotclear.msg.select_all + '</button>').click(function() {371 $(`<button type="button" class="checkbox-helper select-all">${dotclear.msg.select_all}</button>`).click(function() { 362 372 if (target !== undefined) { 363 373 target.check(); … … 371 381 }).appendTo($(e)); 372 382 $(e).append(document.createTextNode(' ')); 373 $( '<button type="button" class="checkbox-helper select-none">' + dotclear.msg.no_selection + '</button>').click(function() {383 $(`<button type="button" class="checkbox-helper select-none">${dotclear.msg.no_selection}</button>`).click(function() { 374 384 if (target !== undefined) { 375 385 target.unCheck(); … … 383 393 }).appendTo($(e)); 384 394 $(e).append(document.createTextNode(' ')); 385 $( '<button type="button" class="checkbox-helper select-reverse">' + dotclear.msg.invert_sel + '</button>').click(function() {395 $(`<button type="button" class="checkbox-helper select-reverse">${dotclear.msg.invert_sel}</button>`).click(function() { 386 396 if (target !== undefined) { 387 397 target.toggleCheck(); … … 395 405 }).appendTo($(e)); 396 406 }, 407 397 408 postsActionsHelper: function() { 398 409 $('#form-entries').submit(function() { 399 varaction = $(this).find('select[name="action"]').val();410 const action = $(this).find('select[name="action"]').val(); 400 411 if (action === undefined) { 401 412 return; 402 413 } 403 varchecked = false;414 let checked = false; 404 415 $(this).find('input[name="entries[]"]').each(function() { 405 416 if (this.checked) { … … 416 427 }); 417 428 }, 429 418 430 commentsActionsHelper: function() { 419 431 $('#form-comments').submit(function() { 420 varaction = $(this).find('select[name="action"]').val();421 varchecked = false;432 const action = $(this).find('select[name="action"]').val(); 433 let checked = false; 422 434 $(this).find('input[name="comments[]"]').each(function() { 423 435 if (this.checked) { … … 434 446 }); 435 447 }, 448 436 449 outgoingLinks: function(target) { 437 450 $(target).filter(function() { 438 451 return ((this.hostname && this.hostname != location.hostname && !$(this).hasClass('modal') && !$(this).hasClass('modal-image')) || $(this).hasClass('outgoing')); 439 452 }).each(function() { 440 $(this).prop('title', $(this).prop('title') + ' (' + dotclear.msg.new_window + ')');453 $(this).prop('title', `${$(this).prop('title')} (${dotclear.msg.new_window})`); 441 454 if (!$(this).hasClass('outgoing')) { 442 455 $(this).append(' <img class="outgoing-js" src="images/outgoing-link.svg" alt=""/>'); … … 458 471 459 472 // Cope with options 460 varopt = $.extend({473 const opt = $.extend({ 461 474 /* sibling: define if the given element is a sibling of the badge or it's parent 462 475 * true: use $elt.after() to add badge … … 495 508 496 509 // Set some constants 497 const classid = 'span.badge.badge-' + opt.id; // Pseudo unique class510 const classid = `span.badge.badge-${opt.id}`; // Pseudo unique class 498 511 499 512 // Set badgeable class to elt parent's (if sibling) or elt itself, if it is necessary 500 var$parent = (opt.sibling ? $elt.parent() : $elt);513 const $parent = (opt.sibling ? $elt.parent() : $elt); 501 514 if (!opt.inline && !opt.remove && !$parent.hasClass('badgeable')) { 502 515 $parent.addClass('badgeable'); … … 504 517 505 518 // Remove existing badge if exists 506 var$badge = (opt.sibling ? $parent.children(classid) : $elt.children(classid));519 const $badge = (opt.sibling ? $parent.children(classid) : $elt.children(classid)); 507 520 if ($badge.length) { 508 521 $badge.remove(); … … 512 525 if (!opt.remove && opt.value !== null) { 513 526 // Compose badge classes 514 const cls = 'badge badge-' + opt.id + ' ' +515 (opt.inline ? 'badge-inline' : 'badge-block') + 516 (opt.icon ? ' badge-icon' : '') + 517 (opt.type !== '' ? ' badge-' + opt.type : '') + 518 (opt.left ? ' badge-left' : '') + 519 (opt.noborder ? ' badge-noborder' : '') + 520 (opt.small ? ' badge-small' : '') + 521 (opt.classes !== '' ? ' ' + opt.classes : '');527 const cls = `badge badge-${opt.id} \ 528 ${opt.inline ? 'badge-inline' : 'badge-block'}\ 529 ${opt.icon ? ' badge-icon' : ''}\ 530 ${opt.type !== '' ? ` badge-${opt.type}` : ''}\ 531 ${opt.left ? ' badge-left' : ''}\ 532 ${opt.noborder ? ' badge-noborder' : ''}\ 533 ${opt.small ? ' badge-small' : ''}\ 534 ${opt.classes !== '' ? ` ${opt.classes}` : ''}`; 522 535 // Compose badge 523 const xml = '<span class="' + cls + '" aria-hidden="true">' + opt.value + '</span>';536 const xml = `<span class="${cls}" aria-hidden="true">${opt.value}</span>`; 524 537 if (opt.sibling) { 525 538 // Add badge after it's sibling … … 531 544 } 532 545 } 533 534 }; 546 }; 547 535 548 /* On document ready 536 549 -------------------------------------------------------- */ … … 540 553 $('body').contents().each(function() { 541 554 if (this.nodeType == 8) { 542 vardata = this.data;555 let data = this.data; 543 556 data = data.replace(/ /g, ' ').replace(/\n/g, '<br/>'); 544 $( '<span class="tooltip" aria-hidden="true">' + $('#footer a').prop('title') + data + '</span>').appendTo('#footer a');557 $(`<span class="tooltip" aria-hidden="true">${$('#footer a').prop('title')}${data}</span>`).appendTo('#footer a'); 545 558 } 546 559 }); … … 559 572 this.form.submit(); 560 573 }); 561 varmenu_settings = {574 const menu_settings = { 562 575 img_on_src: dotclear.img_menu_off, 563 576 img_off_src: dotclear.img_menu_on, … … 583 596 $('p.success,p.warning,p.error,div.error').each(function() { 584 597 $(this).addClass('close-notice-parent'); 585 $(this).append( '<button class="close-notice" type="button"><img src="images/close.png" alt="' + dotclear.msg.close_notice + '" /></button>');598 $(this).append(`<button class="close-notice" type="button"><img src="images/close.png" alt="${dotclear.msg.close_notice}" /></button>`); 586 599 }); 587 600 $('button.close-notice').click(function(e) { … … 591 604 // Password 592 605 $('form:has(input[type=password][name=your_pwd])').submit(function() { 593 vare = this.elements.your_pwd;606 const e = this.elements.your_pwd; 594 607 if (e.value == '') { 595 608 $(e).addClass('missing').focusout(function() { … … 631 644 } 632 645 // Main menu collapser 633 varobjMain = $('#wrapper');646 const objMain = $('#wrapper'); 634 647 635 648 function showSidebar() { … … 649 662 } 650 663 // Sidebar separator 651 var objSeparator = $('#collapser'); 652 objSeparator.click(function(e) { 664 $('#collapser').click(function(e) { 653 665 e.preventDefault(); 654 666 if (objMain.hasClass('hide-mm')) {
Note: See TracChangeset
for help on using the changeset viewer.