/** * TITLE: * @component: Table of Contents * * AUTHOR: * Citizens Advice: Front-end * * DESCRIPTION: * Populating Table of contents: * TOC will be added if the advisor is logged in * * README: * * * API: * * */ 'use strict'; $(document).ready(function () { var TableOfContents = (function () { var tocItems = $('h2 .ref-heading__heading'); var tocItemsID = $('h2.ref-heading'); var adviceContent = $('.articleContent'); var advisorLogin = ($('input[name*="astat"]').val()); var tocArray = []; var tocList; function addingToTOC(text, id) { $.each(text, function (i, item) { var tempObj = { id: id[i].id, content: item.textContent }; tocArray.push(tempObj); }); }; function populateTOC() { var tempItems = ''; addingToTOC(tocItems, tocItemsID); if (tocArray.length >= 1) { tocArray.forEach(function (item) { tempItems += '