hugo-learn.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. // Execute actions on images generated from Markdown pages
  19. var images = $("div#body-inner img").not(".inline");
  20. // Wrap image inside a featherlight (to get a full size view in a popup)
  21. images.wrap(function(){
  22. var image =$(this);
  23. if (!image.parent("a").length) {
  24. return "<a href='" + image[0].src + "' data-featherlight='image'></a>";
  25. }
  26. });
  27. // Change styles, depending on parameters set to the image
  28. images.each(function(index){
  29. var image = $(this)
  30. var o = getUrlParameter(image[0].src);
  31. if (typeof o !== "undefined") {
  32. var h = o["height"];
  33. var w = o["width"];
  34. var c = o["classes"];
  35. image.css("width", function() {
  36. if (typeof w !== "undefined") {
  37. return w;
  38. } else {
  39. return "auto";
  40. }
  41. });
  42. image.css("height", function() {
  43. if (typeof h !== "undefined") {
  44. return h;
  45. } else {
  46. return "auto";
  47. }
  48. });
  49. if (typeof c !== "undefined") {
  50. var classes = c.split(',');
  51. for (i = 0; i < classes.length; i++) {
  52. image.addClass(classes[i]);
  53. }
  54. }
  55. }
  56. });
  57. // Stick the top to the top of the screen when scrolling
  58. $(document).ready(function(){
  59. $("#top-bar").sticky({topSpacing:0, zIndex: 1000});
  60. });
  61. jQuery(document).ready(function() {
  62. // Add link button for every
  63. var text, clip = new Clipboard('.anchor');
  64. $("h1~h2,h1~h3,h1~h4,h1~h5,h1~h6").append(function(index, html){
  65. var element = $(this);
  66. var url = encodeURI(document.location.origin + document.location.pathname);
  67. var link = url + "#"+element[0].id;
  68. return " <span class='anchor' data-clipboard-text='"+link+"'>" +
  69. "<i class='fas fa-link fa-lg'></i>" +
  70. "</span>"
  71. ;
  72. });
  73. $(".anchor").on('mouseleave', function(e) {
  74. $(this).attr('aria-label', null).removeClass('tooltipped tooltipped-s tooltipped-w');
  75. });
  76. clip.on('success', function(e) {
  77. e.clearSelection();
  78. $(e.trigger).attr('aria-label', 'Link copied to clipboard!').addClass('tooltipped tooltipped-s');
  79. });
  80. });