diff --git a/exampleSite/config.toml b/exampleSite/config.toml index 895634c4e1..2c441940e9 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -19,7 +19,6 @@ relativeURLs = true disableLandingPageButton = true disableMermaid = false customMermaidURL = "https://unpkg.com/mermaid@8.8.0/dist/mermaid.min.js" - mermaidInitialize = "{ \"securityLevel\": \"loose\", \"startOnLoad\": true }" titleSeparator = "::" themeVariant = "relearn" diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index 65bdf01f46..a4b9c5a3d1 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -64,8 +64,6 @@ - - {{ if (or (and (ne .Params.disableMermaid nil) (not .Params.disableMermaid)) (not .Site.Params.disableMermaid)) }} {{ if isset .Params "custommermaidurl" }} @@ -83,11 +81,11 @@ {{ end }} {{ end }} + {{ partial "custom-footer.html" . }} diff --git a/static/js/hugo-relearn.js b/static/js/hugo-relearn.js deleted file mode 100644 index 26c75f93fc..0000000000 --- a/static/js/hugo-relearn.js +++ /dev/null @@ -1,98 +0,0 @@ -// Get Parameters from some url -var getUrlParameter = function getUrlParameter(sPageURL) { - var url = sPageURL.split('?'); - var obj = {}; - if (url.length == 2) { - var sURLVariables = url[1].split('&'), - sParameterName, - i; - for (i = 0; i < sURLVariables.length; i++) { - sParameterName = sURLVariables[i].split('='); - obj[sParameterName[0]] = sParameterName[1]; - } - } - return obj; -}; - -// Execute actions on images generated from Markdown pages -var images = $("div#body-inner img").not(".inline"); -// Wrap image inside a featherlight (to get a full size view in a popup) -images.wrap(function(){ - var image =$(this); - var o = getUrlParameter(image[0].src); - var f = o['featherlight']; - // IF featherlight is false, do not use feather light - if (f != 'false') { - if (!image.parent("a").length) { - return ""; - } - } -}); - -// Change styles, depending on parameters set to the image -images.each(function(index){ - var image = $(this) - var o = getUrlParameter(image[0].src); - if (typeof o !== "undefined") { - var h = o["height"]; - var w = o["width"]; - var c = o["classes"]; - image.css("width", function() { - if (typeof w !== "undefined") { - return w; - } else { - return "auto"; - } - }); - image.css("height", function() { - if (typeof h !== "undefined") { - return h; - } else { - return "auto"; - } - }); - if (typeof c !== "undefined") { - var classes = c.split(','); - for (i = 0; i < classes.length; i++) { - image.addClass(classes[i]); - } - } - } -}); - -// Stick the top to the top of the screen when scrolling -$(document).ready(function(){ - $("#top-bar").sticky({topSpacing:0, zIndex: 1000}); -}); - - -jQuery(document).ready(function() { - // Add link button for every - var text, clip = new ClipboardJS('.anchor'); - $("h1~h2,h1~h3,h1~h4,h1~h5,h1~h6").append(function(index, html){ - var element = $(this); - var url = encodeURI(document.location.origin + document.location.pathname); - var link = url + "#"+element[0].id; - return " " + - "" + - "" - ; - }); - - $(".anchor").on('mouseleave', function(e) { - $(this).attr('aria-label', null).removeClass('tooltipped tooltipped-s tooltipped-w'); - }); - - clip.on('success', function(e) { - e.clearSelection(); - $(e.trigger).attr('aria-label', 'Link copied to clipboard!').addClass('tooltipped tooltipped-s'); - }); - - $('code.language-mermaid').each(function(index, element) { - var content = $(element).html().replace(/&/g, '&'); - $(element).parent().replaceWith('
' + content + '
'); - }); - if (mermaid) { - mermaid.init(undefined, $('.mermaid')); - } -}); diff --git a/static/js/relearn.js b/static/js/relearn.js index 94c5100ee3..2b58a092a8 100644 --- a/static/js/relearn.js +++ b/static/js/relearn.js @@ -98,6 +98,80 @@ function restoreTabSelections() { } } +function initMermaid() { + $('code.language-mermaid').each(function(index, element) { + var content = $(element).html().replace(/&/g, '&'); + $(element).parent().replaceWith('
' + content + '
'); + }); + + if (mermaid) { + mermaid.mermaidAPI.initialize( Object.assign( {}, mermaid.mermaidAPI.getSiteConfig(), { startOnLoad: true } ) ); + mermaid.contentLoaded(); + } +} + +// Get Parameters from some url +var getUrlParameter = function getUrlParameter(sPageURL) { + var url = sPageURL.split('?'); + var obj = {}; + if (url.length == 2) { + var sURLVariables = url[1].split('&'), + sParameterName, + i; + for (i = 0; i < sURLVariables.length; i++) { + sParameterName = sURLVariables[i].split('='); + obj[sParameterName[0]] = sParameterName[1]; + } + } + return obj; +}; + +// Execute actions on images generated from Markdown pages +var images = $("div#body-inner img").not(".inline"); +// Wrap image inside a featherlight (to get a full size view in a popup) +images.wrap(function(){ + var image =$(this); + var o = getUrlParameter(image[0].src); + var f = o['featherlight']; + // IF featherlight is false, do not use feather light + if (f != 'false') { + if (!image.parent("a").length) { + return ""; + } + } +}); + +// Change styles, depending on parameters set to the image +images.each(function(index){ + var image = $(this) + var o = getUrlParameter(image[0].src); + if (typeof o !== "undefined") { + var h = o["height"]; + var w = o["width"]; + var c = o["classes"]; + image.css("width", function() { + if (typeof w !== "undefined") { + return w; + } else { + return "auto"; + } + }); + image.css("height", function() { + if (typeof h !== "undefined") { + return h; + } else { + return "auto"; + } + }); + if (typeof c !== "undefined") { + var classes = c.split(','); + for (i = 0; i < classes.length; i++) { + image.addClass(classes[i]); + } + } + } +}); + // for the window resize $(window).resize(function() { setMenuHeight(); @@ -133,8 +207,9 @@ $(window).resize(function() { })(jQuery, 'smartresize'); -jQuery(document).ready(function() { +jQuery(function() { restoreTabSelections(); + initMermaid(); jQuery('#sidebar .category-icon').on('click', function() { $( this ).toggleClass("fa-angle-down fa-angle-right") ; @@ -226,6 +301,8 @@ jQuery(document).ready(function() { } } + $(".highlightable").highlight(sessionStorage.getItem('search-value'), { element: 'mark' }); + // clipboard var clipInit = false; $('code').each(function() { @@ -400,25 +477,40 @@ jQuery(document).ready(function() { $(document).ready($.proxy(anchorScrolls, 'init')); })(window.document, window.history, window.location); -}); + // Stick the top to the top of the screen when scrolling + jQuery("#top-bar").sticky({topSpacing:0, zIndex: 1000}); + + // Add link button for every + var text, clip = new ClipboardJS('.anchor'); + $("h1~h2,h1~h3,h1~h4,h1~h5,h1~h6").append(function(index, html){ + var element = $(this); + var url = encodeURI(document.location.origin + document.location.pathname); + var link = url + "#"+element[0].id; + return " " + + "" + + "" + ; + }); + + $(".anchor").on('mouseleave', function(e) { + $(this).attr('aria-label', null).removeClass('tooltipped tooltipped-s tooltipped-w'); + }); + + clip.on('success', function(e) { + e.clearSelection(); + $(e.trigger).attr('aria-label', 'Link copied to clipboard!').addClass('tooltipped tooltipped-s'); + }); + + $('a[rel="lightbox"]').featherlight({ + root: 'section#body' + }); -jQuery(window).on('load', function() { - // store this page in session sessionStorage.setItem(jQuery('body').data('url'), 1); // loop through the sessionStorage and see if something should be marked as visited for (var url in sessionStorage) { if (sessionStorage.getItem(url) == 1) jQuery('[data-nav-id="' + url + '"]').addClass('visited'); } - - - $(".highlightable").highlight(sessionStorage.getItem('search-value'), { element: 'mark' }); -}); - -$(function() { - $('a[rel="lightbox"]').featherlight({ - root: 'section#body' - }); }); jQuery.extend({