github.com/mweagle/Sparta@v1.15.0/docs/js/hugo-learn.js (about)

     1  // Get Parameters from some url
     2  var getUrlParameter = function getUrlParameter(sPageURL) {
     3      var url = sPageURL.split('?');
     4      var obj = {};
     5      if (url.length == 2) {
     6        var sURLVariables = url[1].split('&'),
     7            sParameterName,
     8            i;
     9        for (i = 0; i < sURLVariables.length; i++) {
    10            sParameterName = sURLVariables[i].split('=');
    11            obj[sParameterName[0]] = sParameterName[1];
    12        }
    13        return obj;
    14      } else {
    15        return undefined;
    16      }
    17  };
    18  
    19  // Execute actions on images generated from Markdown pages
    20  var images = $("div#body-inner img").not(".inline");
    21  // Wrap image inside a featherlight (to get a full size view in a popup)
    22  images.wrap(function(){
    23    var image =$(this);
    24    var o = getUrlParameter(image[0].src);
    25    var f = o['featherlight'];
    26    // IF featherlight is false, do not use feather light
    27    if (f != 'false') {
    28      if (!image.parent("a").length) {
    29        return "<a href='" + image[0].src + "' data-featherlight='image'></a>";
    30      }
    31    }
    32  });
    33  
    34  // Change styles, depending on parameters set to the image
    35  images.each(function(index){
    36    var image = $(this)
    37    var o = getUrlParameter(image[0].src);
    38    if (typeof o !== "undefined") {
    39      var h = o["height"];
    40      var w = o["width"];
    41      var c = o["classes"];
    42      image.css("width", function() {
    43        if (typeof w !== "undefined") {
    44          return w;
    45        } else {
    46          return "auto";
    47        }
    48      });
    49      image.css("height", function() {
    50        if (typeof h !== "undefined") {
    51          return h;
    52        } else {
    53          return "auto";
    54        }
    55      });
    56      if (typeof c !== "undefined") {
    57        var classes = c.split(',');
    58        for (i = 0; i < classes.length; i++) {
    59          image.addClass(classes[i]);
    60        }
    61      }
    62    }
    63  });
    64  
    65  // Stick the top to the top of the screen when  scrolling
    66  $(document).ready(function(){
    67    $("#top-bar").sticky({topSpacing:0, zIndex: 1000});
    68  });
    69  
    70  
    71  jQuery(document).ready(function() {
    72    // Add link button for every
    73    var text, clip = new ClipboardJS('.anchor');
    74    $("h1~h2,h1~h3,h1~h4,h1~h5,h1~h6").append(function(index, html){
    75      var element = $(this);
    76      var url = encodeURI(document.location.origin + document.location.pathname);
    77      var link = url + "#"+element[0].id;
    78      return " <span class='anchor' data-clipboard-text='"+link+"'>" +
    79        "<i class='fas fa-link fa-lg'></i>" +
    80        "</span>"
    81      ;
    82    });
    83  
    84    $(".anchor").on('mouseleave', function(e) {
    85      $(this).attr('aria-label', null).removeClass('tooltipped tooltipped-s tooltipped-w');
    86    });
    87  
    88    clip.on('success', function(e) {
    89        e.clearSelection();
    90        $(e.trigger).attr('aria-label', 'Link copied to clipboard!').addClass('tooltipped tooltipped-s');
    91    });
    92    $('code.language-mermaid').each(function(index, element) {
    93      var content = $(element).html().replace(/&amp;/g, '&');
    94      $(element).parent().replaceWith('<div class="mermaid" align="center">' + content + '</div>');
    95    });
    96  });