//////////////////////////////////// // // Variables // // var sidebar_items = []; //////////////////////////////////// // // Functions // // /** * Function to copy the id hash to clipboard */ function copyAnchor(element) { var $temp = $(""); $("body").append($temp); $temp.val(window.location.href.split('#')[0] + '#' + $(element).attr("id")).select(); document.execCommand("copy"); $temp.remove(); } /** * Smooth scroll on click to anchor * @params element */ function smoothScrollToAnchor(element) { element.click(function () { if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) { var target = $(this.hash); target = target.length ? target : $('[name=' + this.hash.slice(1) + ']'); if (target.length) { window.history.pushState(null, null, target.selector); // update the url to match the hash clicked //animate $('html, body').animate({ scrollTop: target.offset().top - 210 }, 500); return false; } } }); } /** * Smooth scroll on page load to anchor if there is an anchor in the URL */ function checkIfHash() { if (window.location.hash) { $('html, body').animate({ scrollTop: ($(window.location.hash).offset().top - 210) + 'px' }, 500, 'swing'); } } /** * Pull out header text and put into array (sidebar_items) * @params element */ function getHeaderTextAndAnchor(element) { element.each(function (i, e) { var item = $(e); var step = { text: item.text(), id: item.attr('id') }; sidebar_items.push(step); }); } /** * Pull out header text and put into array (sidebar_items) * @params element */ function populateSidebarList() { $(".--sidebar-list").html( sidebar_items.map(function (step) { return ('