From 9f2cbaa676748c7757beec56dac572499687d569 Mon Sep 17 00:00:00 2001 From: Yehonal Date: Sun, 17 Feb 2019 23:06:03 +0100 Subject: Fixed toc script --- assets/js/toc.js | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/assets/js/toc.js b/assets/js/toc.js index ac46c78..bf8fbec 100644 --- a/assets/js/toc.js +++ b/assets/js/toc.js @@ -1,6 +1,8 @@ // https://github.com/ghiculescu/jekyll-table-of-contents (function ($) { $.fn.toc = function (options) { + var element = $(this); + setTimeout(function () { var defaults = { noBackToTopLinks: false, @@ -30,21 +32,20 @@ var headers = $(settings.headers).filter(function () { // get all headers with an ID - var previousSiblingName = $(this).prev().attr("name"); + var previousSiblingName = element.prev().attr("name"); if (!this.id && previousSiblingName) { - this.id = $(this).attr("id", previousSiblingName.replace(/\./g, "-")); + this.id = element.attr("id", previousSiblingName.replace(/\./g, "-")); } // Yehonal if (!this.id) { - this.id = $(this).text().replace(/\W/g, '_'); + this.id = element.text().replace(/\W/g, '_'); } return this.id; - }), - output = $(this); - if (!headers.length || headers.length < settings.minimumHeaders || !output.length) { - $(this).hide(); + }); + if (!headers.length || headers.length < settings.minimumHeaders || !element.length) { + element.hide(); return; } @@ -52,21 +53,6 @@ settings.showEffect = 'none'; } - var render = { - show: function () { - output.hide().html(html).show(settings.showSpeed); - }, - slideDown: function () { - output.hide().html(html).slideDown(settings.showSpeed); - }, - fadeIn: function () { - output.hide().html(html).fadeIn(settings.showSpeed); - }, - none: function () { - output.html(html); - } - }; - var get_level = function (ele) { return parseInt(ele.nodeName.replace("H", ""), 10); }; @@ -113,7 +99,22 @@ }); } + var render = { + show: function () { + element.hide().html(html).show(settings.showSpeed); + }, + slideDown: function () { + element.hide().html(html).slideDown(settings.showSpeed); + }, + fadeIn: function () { + element.hide().html(html).fadeIn(settings.showSpeed); + }, + none: function () { + element.html(html).show(); + } + }; + render[settings.showEffect](); }, 0); } -})(jQuery); \ No newline at end of file +})(jQuery); -- cgit