Dotclear


Ignore:
Timestamp:
02/16/18 16:01:59 (8 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

use strict and no more linter warnings/errors as far as possible

File:
1 edited

Legend:

Unmodified
Added
Removed
  • themes/ductile/ductile.js

    r2566 r3706  
     1/*global $ */ 
     2'use strict'; 
     3 
    14$(function() { 
    2      var create_name = function(text) { 
     5  var create_name = function(text) { 
    36 
    4           // Convert text to lower case. 
    5           var name = text.toLowerCase(); 
     7    // Convert text to lower case. 
     8    var name = text.toLowerCase(); 
    69 
    7           // Remove leading and trailing spaces, and any non-alphanumeric 
    8           // characters except for ampersands, spaces and dashes. 
    9           name = name.replace(/^\s+|\s+$|[^a-z0-9&\s-]/g, ''); 
     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, ''); 
    1013 
    11           // Replace '&' with 'and'. 
    12           name = name.replace(/&/g, 'and'); 
     14    // Replace '&' with 'and'. 
     15    name = name.replace(/&/g, 'and'); 
    1316 
    14           // Replaces spaces with dashes. 
    15           name = name.replace(/\s/g, '-'); 
     17    // Replaces spaces with dashes. 
     18    name = name.replace(/\s/g, '-'); 
    1619 
    17           // Squash any duplicate dashes. 
    18           name = name.replace(/(-)+\1/g, "$1"); 
     20    // Squash any duplicate dashes. 
     21    name = name.replace(/(-)+\1/g, '$1'); 
    1922 
    20           return name; 
    21      }; 
     23    return name; 
     24  }; 
    2225 
    23      var add_link = function() { 
     26  var add_link = function() { 
    2427 
    25           // Convert the h2 element text into a value that 
    26           // is safe to use in a name attribute. 
    27           var name = create_name($(this).text()); 
     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()); 
    2831 
    29           // Create a name attribute in the following sibling 
    30           // to act as a fragment anchor. 
    31           $(this).next().attr('name', name); 
     32    // Create a name attribute in the following sibling 
     33    // to act as a fragment anchor. 
     34    $(this).next().attr('name', name); 
    3235 
    33           // Replace the h2.toggle element with a link to the 
    34           // fragment anchor.  Use the h2 text to create the 
    35           // link title attribute. 
    36           $(this).html( 
    37                '<a href="#' + name + '" title="Reveal ' + 
    38                $(this).text() + ' content">' + 
    39                $(this).html() + '</a>'); 
    40      }; 
     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  }; 
    4144 
    42      var toggle = function(event) { 
    43           event.preventDefault(); 
     45  var toggle = function(event) { 
     46    event.preventDefault(); 
    4447 
    45           // Toggle the 'expanded' class of the h2.toggle 
    46           // element, then apply the slideToggle effect 
    47           // to all siblings. 
    48           $(this).toggleClass('expanded'). 
    49                nextAll().slideToggle('fast'); 
    50      }; 
     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  }; 
    5154 
    52      var remove_focus = function() { 
    53        // Use the blur() method to remove focus. 
    54        $(this).blur(); 
    55      }; 
     55  var remove_focus = function() { 
     56    // Use the blur() method to remove focus. 
     57    $(this).blur(); 
     58  }; 
    5659 
    57      $(document).ready (function () { 
    58           if ($(window).width() < 1024) { 
     60  $(document).ready(function() { 
     61    if ($(window).width() < 1024) { 
    5962 
    60                // Set toggle class to each #sidebar h2 
    61                $("#sidebar div div h2").addClass('toggle'); 
     63      // Set toggle class to each #sidebar h2 
     64      $('#sidebar div div h2').addClass('toggle'); 
    6265 
    63                // Hide all h2.toggle siblings 
    64                $('#sidebar div div h2').nextAll().hide(); 
     66      // Hide all h2.toggle siblings 
     67      $('#sidebar div div h2').nextAll().hide(); 
    6568 
    66                // Add a link to each h2.toggle element. 
    67                $('h2.toggle').each(add_link); 
     69      // Add a link to each h2.toggle element. 
     70      $('h2.toggle').each(add_link); 
    6871 
    69                // Add a click event handler to all h2.toggle elements. 
    70                $('h2.toggle').click(toggle); 
     72      // Add a click event handler to all h2.toggle elements. 
     73      $('h2.toggle').click(toggle); 
    7174 
    72                // Remove the focus from the link tag when accessed with a mouse. 
    73                $('h2.toggle a').mouseup(remove_focus); 
    74           } 
    75      }) 
     75      // Remove the focus from the link tag when accessed with a mouse. 
     76      $('h2.toggle a').mouseup(remove_focus); 
     77    } 
     78  }); 
    7679 
    7780}); 
Note: See TracChangeset for help on using the changeset viewer.

Sites map