hugo-learn.js 2.4 KB

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