//= require ../lib/_jquery //= require ../lib/_imagesloaded.min ;(function () { 'use strict'; var htmlPattern = /<[^>]*>/g; var loaded = false; var debounce = function(func, waitTime) { var timeout = false; return function() { if (timeout === false) { setTimeout(function() { func(); timeout = false; }, waitTime); timeout = true; } }; }; var closeToc = function() { $(".toc-wrapper").removeClass('open'); $("#nav-button").removeClass('open'); }; function loadToc($toc, tocLinkSelector, tocListSelector, scrollOffset) { var headerHeights = {}; var pageHeight = 0; var windowHeight = 0; var originalTitle = document.title; var recacheHeights = function() { headerHeights = {}; pageHeight = $(document).height(); windowHeight = $(window).height(); $toc.find(tocLinkSelector).each(function() { var targetId = $(this).attr('href'); if (targetId[0] === "#") { headerHeights[targetId] = $("#" + $.escapeSelector(targetId.substring(1))).offset().top; } }); }; var refreshToc = function() { var currentTop = $(document).scrollTop() + scrollOffset; if (currentTop + windowHeight >= pageHeight) { // at bottom of page, so just select last header by making currentTop very large // this fixes the problem where the last header won't ever show as active if its content // is shorter than the window height currentTop = pageHeight + 1000; } var best = null; for (var name in headerHeights) { if ((headerHeights[name] < currentTop && headerHeights[name] > headerHeights[best]) || best === null) { best = name; } } // Catch the initial load case if (currentTop == scrollOffset && !loaded) { best = window.location.hash; loaded = true; } var $best = $toc.find("[href='" + best + "']").first(); if (!$best.hasClass("active")) { // .active is applied to the ToC link we're currently on, and its parent