You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.8 KiB

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