Dotclear

Changeset 3880:e6d1f6d9d7df for themes


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

Location:
themes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • themes/berlin/js/berlin.js

    r3709 r3880  
    55// Show/Hide main menu 
    66$('.header__nav'). 
    7 before('<button id="hamburger" type="button"><span class="visually-hidden">' + dotclear_berlin_navigation + '</span></button>'). 
     7before(`<button id="hamburger" type="button"><span class="visually-hidden">${dotclear_berlin_navigation}</span></button>`). 
    88toggle(); 
    99$('#hamburger').click(function() { 
     
    1212}); 
    1313// Show/Hide sidebar on small screens 
    14 $('#main').prepend('<button id="offcanvas-on" type="button"><span class="visually-hidden">' + dotclear_berlin_show_menu + '</span></button>'); 
     14$('#main').prepend(`<button id="offcanvas-on" type="button"><span class="visually-hidden">${dotclear_berlin_show_menu}</span></button>`); 
    1515$('#offcanvas-on').click(function() { 
    16   var btn = $('<button id="offcanvas-off" type="button"><span class="visually-hidden">' + dotclear_berlin_hide_menu + '</span></button>'); 
     16  const btn = $(`<button id="offcanvas-off" type="button"><span class="visually-hidden">${dotclear_berlin_hide_menu}</span></button>`); 
    1717  $('#wrapper').addClass('off-canvas'); 
    1818  $('#footer').addClass('off-canvas'); 
  • themes/default/js/post.js

    r3706 r3880  
    55  $('#comment-form p:has(input[type=submit][name=preview],button[type=submit][name=preview])'). 
    66  before( 
    7     '<p class="remember"><input type="checkbox" id="c_remember" name="c_remember" /> ' + 
    8     '<label for="c_remember">' + post_remember_str + '</label>' + 
    9     '</p>' 
     7`<p class="remember"><input type="checkbox" id="c_remember" name="c_remember" /> 
     8<label for="c_remember">${post_remember_str}</label> 
     9</p>` 
    1010  ); 
    1111 
     
    4646 
    4747  function setCookie() { 
    48     var name = $('#c_name').val(); 
    49     var mail = $('#c_mail').val(); 
    50     var site = $('#c_site').val(); 
    51     var cpath = $('link[rel=top]').attr('href'); 
     48    const name = $('#c_name').val(); 
     49    const mail = $('#c_mail').val(); 
     50    const site = $('#c_site').val(); 
     51    let cpath = $('link[rel=top]').attr('href'); 
    5252    if (!cpath) { 
    5353      cpath = '/'; 
     
    7373      return false; 
    7474    } 
    75  
    76     var s = c.split('\n'); 
    77  
     75    const s = c.split('\n'); 
    7876    if (s.length != 3) { 
    7977      dropCookie(); 
    8078      return false; 
    8179    } 
    82  
    8380    return s; 
    8481  } 
  • themes/ductile/ductile.js

    r3706 r3880  
    22'use strict'; 
    33 
    4 $(function() { 
    5   var create_name = function(text) { 
     4$(document).ready(function() { 
     5  if ($(window).width() < 1024) { 
    66 
    7     // Convert text to lower case. 
    8     var name = text.toLowerCase(); 
     7    const create_name = function(text) { 
    98 
    10     // Remove leading and trailing spaces, and any non-alphanumeric 
    11     // characters except for ampersands, spaces and dashes. 
    12     name = name.replace(/^\s+|\s+$|[^a-z0-9&\s-]/g, ''); 
     9      // Convert text to lower case. 
     10      let name = text.toLowerCase(); 
    1311 
    14     // Replace '&' with 'and'. 
    15     name = name.replace(/&/g, 'and'); 
     12      // Remove leading and trailing spaces, and any non-alphanumeric 
     13      // characters except for ampersands, spaces and dashes. 
     14      name = name.replace(/^\s+|\s+$|[^a-z0-9&\s-]/g, ''); 
    1615 
    17     // Replaces spaces with dashes. 
    18     name = name.replace(/\s/g, '-'); 
     16      // Replace '&' with 'and'. 
     17      name = name.replace(/&/g, 'and'); 
    1918 
    20     // Squash any duplicate dashes. 
    21     name = name.replace(/(-)+\1/g, '$1'); 
     19      // Replaces spaces with dashes. 
     20      name = name.replace(/\s/g, '-'); 
    2221 
    23     return name; 
    24   }; 
     22      // Squash any duplicate dashes. 
     23      name = name.replace(/(-)+\1/g, '$1'); 
    2524 
    26   var add_link = function() { 
     25      return name; 
     26    }; 
    2727 
    28     // Convert the h2 element text into a value that 
    29     // is safe to use in a name attribute. 
    30     var name = create_name($(this).text()); 
     28    // Set toggle class to each #sidebar h2 
     29    $('#sidebar div div h2').addClass('toggle'); 
    3130 
    32     // Create a name attribute in the following sibling 
    33     // to act as a fragment anchor. 
    34     $(this).next().attr('name', name); 
     31    // Hide all h2.toggle siblings 
     32    $('#sidebar div div h2').nextAll().hide(); 
    3533 
    36     // Replace the h2.toggle element with a link to the 
    37     // fragment anchor.  Use the h2 text to create the 
    38     // link title attribute. 
    39     $(this).html( 
    40       '<a href="#' + name + '" title="Reveal ' + 
    41       $(this).text() + ' content">' + 
    42       $(this).html() + '</a>'); 
    43   }; 
     34    // Add a link to each h2.toggle element. 
     35    $('h2.toggle').each(function() { 
    4436 
    45   var toggle = function(event) { 
    46     event.preventDefault(); 
     37      // Convert the h2 element text into a value that 
     38      // is safe to use in a name attribute. 
     39      const name = create_name($(this).text()); 
    4740 
    48     // Toggle the 'expanded' class of the h2.toggle 
    49     // element, then apply the slideToggle effect 
    50     // to all siblings. 
    51     $(this).toggleClass('expanded'). 
    52     nextAll().slideToggle('fast'); 
    53   }; 
     41      // Create a name attribute in the following sibling 
     42      // to act as a fragment anchor. 
     43      $(this).next().attr('name', name); 
    5444 
    55   var remove_focus = function() { 
    56     // Use the blur() method to remove focus. 
    57     $(this).blur(); 
    58   }; 
     45      // Replace the h2.toggle element with a link to the 
     46      // fragment anchor.  Use the h2 text to create the 
     47      // link title attribute. 
     48      $(this).html( 
     49        '<a href="#' + name + '" title="Reveal ' + 
     50        $(this).text() + ' content">' + 
     51        $(this).html() + '</a>'); 
     52    }); 
    5953 
    60   $(document).ready(function() { 
    61     if ($(window).width() < 1024) { 
     54    // Add a click event handler to all h2.toggle elements. 
     55    $('h2.toggle').click(function(event) { 
     56      event.preventDefault(); 
     57      // Toggle the 'expanded' class of the h2.toggle 
     58      // element, then apply the slideToggle effect 
     59      // to all siblings. 
     60      $(this).toggleClass('expanded'). 
     61      nextAll().slideToggle('fast'); 
     62    }); 
    6263 
    63       // Set toggle class to each #sidebar h2 
    64       $('#sidebar div div h2').addClass('toggle'); 
    65  
    66       // Hide all h2.toggle siblings 
    67       $('#sidebar div div h2').nextAll().hide(); 
    68  
    69       // Add a link to each h2.toggle element. 
    70       $('h2.toggle').each(add_link); 
    71  
    72       // Add a click event handler to all h2.toggle elements. 
    73       $('h2.toggle').click(toggle); 
    74  
    75       // Remove the focus from the link tag when accessed with a mouse. 
    76       $('h2.toggle a').mouseup(remove_focus); 
    77     } 
    78   }); 
    79  
     64    // Remove the focus from the link tag when accessed with a mouse. 
     65    $('h2.toggle a').mouseup(function() { 
     66      // Use the blur() method to remove focus. 
     67      $(this).blur(); 
     68    }); 
     69  } 
    8070}); 
Note: See TracChangeset for help on using the changeset viewer.

Sites map