summaryrefslogtreecommitdiff
path: root/_includes/scripts/lib/toc.js
diff options
context:
space:
mode:
authorKarl Hallsby <karl@hallsby.com>2021-10-03 00:10:58 -0500
committerKarl Hallsby <karl@hallsby.com>2021-10-03 02:16:53 -0500
commita10ad0a99ba6e44a35253c3bcaff80c90e99348e (patch)
tree005e05a70fb1fe24a5a7c44dc1d2d14c9e1d88ed /_includes/scripts/lib/toc.js
parentb9b34a65fbe55ce78d353ce2b7eb51f6884bd272 (diff)
Revert ALL jekyll-text-theme configuration files
I am changing the theme of the site, and need to revert these changes to make everything work. Revert "Add jekyll-text-theme YAML files" This reverts commit 61b34a5f260db45575d448d766ea29c0fb273ed3. Revert "Bring all of jekyll-text-theme _includes into site" This reverts commit c6bf5f7c895287d2028f6024265913b59784a154. Revert "Bring all of jekyll-text-theme assets to site" This reverts commit 7b69c2e5975f98da09d932ba6c70bdd71b1601a7. Remove jekyll text theme from Gemfile
Diffstat (limited to '_includes/scripts/lib/toc.js')
-rw-r--r--_includes/scripts/lib/toc.js107
1 files changed, 0 insertions, 107 deletions
diff --git a/_includes/scripts/lib/toc.js b/_includes/scripts/lib/toc.js
deleted file mode 100644
index fb43857..0000000
--- a/_includes/scripts/lib/toc.js
+++ /dev/null
@@ -1,107 +0,0 @@
-(function() {
- var SOURCES = window.TEXT_VARIABLES.sources;
- window.Lazyload.js(SOURCES.jquery, function() {
- function toc(options) {
- var $root = this, $window = $(window), $scrollTarget, $scroller, $tocUl = $('<ul class="toc toc--ellipsis"></ul>'), $tocLi, $headings, $activeLast, $activeCur,
- selectors = 'h1,h2,h3', container = 'body', scrollTarget = window, scroller = 'html, body', disabled = false,
- headingsPos, scrolling = false, hasRendered = false, hasInit = false;
-
- function setOptions(options) {
- var _options = options || {};
- _options.selectors && (selectors = _options.selectors);
- _options.container && (container = _options.container);
- _options.scrollTarget && (scrollTarget = _options.scrollTarget);
- _options.scroller && (scroller = _options.scroller);
- _options.disabled !== undefined && (disabled = _options.disabled);
- $headings = $(container).find(selectors).filter('[id]');
- $scrollTarget = $(scrollTarget);
- $scroller = $(scroller);
- }
- function calc() {
- headingsPos = [];
- $headings.each(function() {
- headingsPos.push(Math.floor($(this).position().top));
- });
- }
- function setState(element, disabled) {
- var scrollTop = $scrollTarget.scrollTop(), i;
- if (disabled || !headingsPos || headingsPos.length < 1) { return; }
- if (element) {
- $activeCur = element;
- } else {
- for (i = 0; i < headingsPos.length; i++) {
- if (scrollTop >= headingsPos[i]) {
- $activeCur = $tocLi.eq(i);
- } else {
- $activeCur || ($activeCur = $tocLi.eq(i));
- break;
- }
- }
- }
- $activeLast && $activeLast.removeClass('active');
- ($activeLast = $activeCur).addClass('active');
- }
- function render() {
- if(!hasRendered) {
- $root.append($tocUl);
- $headings.each(function() {
- var $this = $(this);
- $tocUl.append($('<li></li>').addClass('toc-' + $this.prop('tagName').toLowerCase())
- .append($('<a></a>').text($this.text()).attr('href', '#' + $this.prop('id'))));
- });
- $tocLi = $tocUl.children('li');
- $tocUl.on('click', 'a', function(e) {
- e.preventDefault();
- var $this = $(this);
- scrolling = true;
- setState($this.parent());
- $scroller.scrollToAnchor($this.attr('href'), 400, function() {
- scrolling = false;
- });
- });
- }
- hasRendered = true;
- }
- function init() {
- var interval, timeout;
- if(!hasInit) {
- render(); calc(); setState(null, scrolling);
- // run calc every 100 millisecond
- interval = setInterval(function() {
- calc();
- }, 100);
- timeout = setTimeout(function() {
- clearInterval(interval);
- }, 45000);
- window.pageLoad.then(function() {
- setTimeout(function() {
- clearInterval(interval);
- clearTimeout(timeout);
- }, 3000);
- });
- $scrollTarget.on('scroll', function() {
- disabled || setState(null, scrolling);
- });
- $window.on('resize', window.throttle(function() {
- if (!disabled) {
- render(); calc(); setState(null, scrolling);
- }
- }, 100));
- }
- hasInit = true;
- }
-
- setOptions(options);
- if (!disabled) {
- init();
- }
- $window.on('resize', window.throttle(function() {
- init();
- }, 200));
- return {
- setOptions: setOptions
- };
- }
- $.fn.toc = toc;
- });
-})();