Dotclear


Ignore:
Timestamp:
09/18/18 20:22:10 (7 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Use let and const rather than var (ES2015/ES6), use template string where is more efficient

File:
1 edited

Legend:

Unmodified
Added
Removed
  • admin/js/common.js

    r3878 r3880  
    5353    if (event.shiftKey) { 
    5454      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        } 
    5963        range.find('input[type=checkbox]').setChecked(dotclear.lastclickedstatus); 
    6064        this.checked = dotclear.lastclickedstatus; 
     
    6872}; 
    6973jQuery.fn.toggleWithLegend = function(target, s) { 
    70   var defaults = { 
     74  const defaults = { 
    7175    img_on_txt: dotclear.img_plus_txt, 
    7276    img_on_alt: dotclear.img_plus_alt, 
     
    8185    reverse_user_pref: false // Reverse cookie behavior 
    8286  }; 
    83   var p = jQuery.extend(defaults, s); 
     87  const p = jQuery.extend(defaults, s); 
    8488  if (!target) { 
    8589    return this; 
    8690  } 
    87   var set_cookie = p.hide ^ p.reverse_cookie; 
     91  const set_cookie = p.hide ^ p.reverse_cookie; 
    8892  if (p.cookie && jQuery.cookie(p.cookie)) { 
    8993    p.hide = p.reverse_cookie; 
    9094  } 
    91   var set_user_pref = p.hide ^ p.reverse_user_pref; 
     95  let set_user_pref = p.hide ^ p.reverse_user_pref; 
    9296  if (p.user_pref && p.unfolded_sections !== undefined && (p.user_pref in p.unfolded_sections)) { 
    9397    p.hide = p.reverse_user_pref; 
    9498  } 
    95   var toggle = function(i, speed) { 
     99  const toggle = function(i, speed) { 
    96100    speed = speed || 0; 
    97     var b = $(i).get(0); 
     101    const b = $(i).get(0); 
    98102    if (p.hide) { 
    99103      b.firstChild.data = p.img_on_txt; 
     
    125129  }; 
    126130  return this.each(function() { 
    127     var b = document.createElement('button'); 
     131    const b = document.createElement('button'); 
    128132    b.setAttribute('type', 'button'); 
    129133    b.className = 'details-cmd'; 
    130134    b.value = p.img_on_txt; 
    131135    b.setAttribute('aria-label', p.img_on_alt); 
    132     var t = document.createTextNode(p.img_on_txt); 
     136    const t = document.createTextNode(p.img_on_txt); 
    133137    b.appendChild(t); 
    134138 
    135     var ctarget = p.legend_click ? this : b; 
     139    const ctarget = p.legend_click ? this : b; 
    136140    $(ctarget).css('cursor', 'pointer'); 
    137141    if (p.legend_click) { 
     
    141145      if (p.user_pref && set_user_pref) { 
    142146        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), 
    146150          xd_check: dotclear.nonce 
    147151        }, function() {}); 
     
    158162  }); 
    159163}; 
     164 
    160165(function($) { 
    161166  $.expandContent = function(opts) { 
     
    170175    }); 
    171176  }; 
    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) { 
    174179      toggleArrow(this); 
    175180      callback(line, '', e); 
     
    177182    }).prependTo($(line).children().get(0)); // first td 
    178183  }; 
    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) { 
    181186      var action = toggleArrow(this); 
    182187      lines.each(function() { 
     
    187192    }).prependTo($(line).children().get(0)); // first td 
    188193  }; 
    189   var toggleArrow = function toggleArrow(button, action) { 
     194  const toggleArrow = function(button, action) { 
    190195    action = action || ''; 
    191196    if (action == '') { 
     
    212217    return this; 
    213218  } 
    214   var p = { 
     219  let select = $(); 
     220  const p = { 
    215221    img_on_txt: dotclear.img_plus_txt, 
    216222    img_on_alt: dotclear.img_plus_alt, 
     
    218224    img_off_alt: dotclear.img_minus_alt 
    219225  }; 
    220   var This = this; 
    221   var toggle = function() { 
     226  const This = this; 
     227  const toggle = function() { 
    222228    $('#content').toggleClass('with-help'); 
    223229    if (document.all) { 
     
    232238    return false; 
    233239  }; 
    234   var sizeBox = function() { 
     240  const sizeBox = function() { 
    235241    This.css('height', 'auto'); 
    236242    if ($('#wrapper').height() > This.height()) { 
     
    238244    } 
    239245  }; 
    240   var textToggler = 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>`); 
    242248    o.css('cursor', 'pointer'); 
    243     var hide = true; 
     249    let hide = true; 
    244250    o.prepend(' ').prepend(b); 
    245251    o.click(function() { 
     
    253259      }); 
    254260      hide = !hide; 
    255       var img = $(this).find('button.details-cmd'); 
     261      const img = $(this).find('button.details-cmd'); 
    256262      if (!hide) { 
    257263        img.html(p.img_off_txt); 
     
    272278  this.find('h4:first').nextAll('*:not(h4)').hide(); 
    273279  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>`); 
    276281  img.click(function(e) { 
    277282    e.preventDefault(); 
     
    280285  $('#content').append(img); 
    281286  // listen for scroll 
    282   var peInPage = $('#help-button').offset().top; 
     287  const peInPage = $('#help-button').offset().top; 
    283288  $('#help-button').addClass('floatable'); 
    284   var peInFloat = $('#help-button').offset().top - $(window).scrollTop(); 
     289  const peInFloat = $('#help-button').offset().top - $(window).scrollTop(); 
    285290  $('#help-button').removeClass('floatable'); 
    286291  $(window).scroll(function() { 
     
    293298  return this; 
    294299}; 
     300 
    295301/* Dotclear common object 
    296302-------------------------------------------------------- */ 
    297 var dotclear = { 
     303const dotclear = { 
    298304  msg: {}, 
     305 
    299306  enterKeyInForm: function(frm_id, ok_id, cancel_id) { 
    300307    $(frm_id + ':not(' + cancel_id + ')').keyup(function(e) { 
     
    306313    }); 
    307314  }, 
     315 
    308316  condSubmit: function(chkboxes, target) { 
    309     var checkboxes = $(chkboxes), 
     317    const checkboxes = $(chkboxes), 
    310318      submitButt = $(target); 
    311319    if (checkboxes === undefined || submitButt === undefined) { 
     
    329337    }); 
    330338  }, 
     339 
    331340  hideLockable: function() { 
    332341    $('div.lockable').each(function() { 
    333       var current_lockable_div = this; 
     342      const current_lockable_div = this; 
    334343      $(this).find('p.form-note').hide(); 
    335344      $(this).find('input').each(function() { 
    336345        this.disabled = true; 
    337         $(this).width(($(this).width() - 14) + 'px'); 
    338         var imgE = document.createElement('img'); 
     346        $(this).width(`${$(this).width() - 14}px`); 
     347        const imgE = document.createElement('img'); 
    339348        imgE.src = 'images/locker.png'; 
    340349        imgE.style.position = 'absolute'; 
    341350        imgE.style.top = '1.8em'; 
    342         imgE.style.left = ($(this).width() + 14) + 'px'; 
     351        imgE.style.left = `${$(this).width() + 14}px`; 
    343352        imgE.alt = dotclear.msg.click_to_unlock; 
    344353        $(imgE).css('cursor', 'pointer'); 
     
    356365    }); 
    357366  }, 
     367 
    358368  checkboxesHelpers: function(e, target, c, s) { 
    359369    $(e).append(document.createTextNode(dotclear.msg.to_select)); 
    360370    $(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() { 
    362372      if (target !== undefined) { 
    363373        target.check(); 
     
    371381    }).appendTo($(e)); 
    372382    $(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() { 
    374384      if (target !== undefined) { 
    375385        target.unCheck(); 
     
    383393    }).appendTo($(e)); 
    384394    $(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() { 
    386396      if (target !== undefined) { 
    387397        target.toggleCheck(); 
     
    395405    }).appendTo($(e)); 
    396406  }, 
     407 
    397408  postsActionsHelper: function() { 
    398409    $('#form-entries').submit(function() { 
    399       var action = $(this).find('select[name="action"]').val(); 
     410      const action = $(this).find('select[name="action"]').val(); 
    400411      if (action === undefined) { 
    401412        return; 
    402413      } 
    403       var checked = false; 
     414      let checked = false; 
    404415      $(this).find('input[name="entries[]"]').each(function() { 
    405416        if (this.checked) { 
     
    416427    }); 
    417428  }, 
     429 
    418430  commentsActionsHelper: function() { 
    419431    $('#form-comments').submit(function() { 
    420       var action = $(this).find('select[name="action"]').val(); 
    421       var checked = false; 
     432      const action = $(this).find('select[name="action"]').val(); 
     433      let checked = false; 
    422434      $(this).find('input[name="comments[]"]').each(function() { 
    423435        if (this.checked) { 
     
    434446    }); 
    435447  }, 
     448 
    436449  outgoingLinks: function(target) { 
    437450    $(target).filter(function() { 
    438451      return ((this.hostname && this.hostname != location.hostname && !$(this).hasClass('modal') && !$(this).hasClass('modal-image')) || $(this).hasClass('outgoing')); 
    439452    }).each(function() { 
    440       $(this).prop('title', $(this).prop('title') + ' (' + dotclear.msg.new_window + ')'); 
     453      $(this).prop('title', `${$(this).prop('title')} (${dotclear.msg.new_window})`); 
    441454      if (!$(this).hasClass('outgoing')) { 
    442455        $(this).append('&nbsp;<img class="outgoing-js" src="images/outgoing-link.svg" alt=""/>'); 
     
    458471 
    459472    // Cope with options 
    460     var opt = $.extend({ 
     473    const opt = $.extend({ 
    461474      /* sibling: define if the given element is a sibling of the badge or it's parent 
    462475       *  true: use $elt.after() to add badge 
     
    495508 
    496509    // Set some constants 
    497     const classid = 'span.badge.badge-' + opt.id; // Pseudo unique class 
     510    const classid = `span.badge.badge-${opt.id}`; // Pseudo unique class 
    498511 
    499512    // 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); 
    501514    if (!opt.inline && !opt.remove && !$parent.hasClass('badgeable')) { 
    502515      $parent.addClass('badgeable'); 
     
    504517 
    505518    // 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)); 
    507520    if ($badge.length) { 
    508521      $badge.remove(); 
     
    512525    if (!opt.remove && opt.value !== null) { 
    513526      // 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}` : ''}`; 
    522535      // 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>`; 
    524537      if (opt.sibling) { 
    525538        // Add badge after it's sibling 
     
    531544    } 
    532545  } 
    533  
    534 }; 
     546}; 
     547 
    535548/* On document ready 
    536549-------------------------------------------------------- */ 
     
    540553  $('body').contents().each(function() { 
    541554    if (this.nodeType == 8) { 
    542       var data = this.data; 
     555      let data = this.data; 
    543556      data = data.replace(/ /g, '&nbsp;').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'); 
    545558    } 
    546559  }); 
     
    559572    this.form.submit(); 
    560573  }); 
    561   var menu_settings = { 
     574  const menu_settings = { 
    562575    img_on_src: dotclear.img_menu_off, 
    563576    img_off_src: dotclear.img_menu_on, 
     
    583596  $('p.success,p.warning,p.error,div.error').each(function() { 
    584597    $(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>`); 
    586599  }); 
    587600  $('button.close-notice').click(function(e) { 
     
    591604  // Password 
    592605  $('form:has(input[type=password][name=your_pwd])').submit(function() { 
    593     var e = this.elements.your_pwd; 
     606    const e = this.elements.your_pwd; 
    594607    if (e.value == '') { 
    595608      $(e).addClass('missing').focusout(function() { 
     
    631644  } 
    632645  // Main menu collapser 
    633   var objMain = $('#wrapper'); 
     646  const objMain = $('#wrapper'); 
    634647 
    635648  function showSidebar() { 
     
    649662  } 
    650663  // Sidebar separator 
    651   var objSeparator = $('#collapser'); 
    652   objSeparator.click(function(e) { 
     664  $('#collapser').click(function(e) { 
    653665    e.preventDefault(); 
    654666    if (objMain.hasClass('hide-mm')) { 
Note: See TracChangeset for help on using the changeset viewer.

Sites map