REPRESENTATION
anurag@vridii.com
function addToMobile(folder) {
let href = folder.getAttribute("href"),
hrefAdjusted = href.replace("-folder/", ""),
text = folder.innerText,
mobileFolder = document.querySelector(`[data-folder="${href}"]`),
backButton = mobileFolder.querySelector(".header-menu-nav-folder-content > *:first-of-type");
//If it exists already
if (mobileFolder.querySelector(`[href="${href}"]`)) return;
let newLinkContainer = document.createElement("div"),
newLink = `All ${text}`;
newLinkContainer.classList = "container header-menu-nav-item header-menu-nav-item--external";
newLinkContainer.innerHTML = newLink;
insertAfter(newLinkContainer, backButton);
}
/* Select All Folder Links &*/
function setFolderLinks() {
folders = document.querySelectorAll('.header-display-desktop .header-nav-folder-title[href*="-folder/"]');
for (folder of folders) {
addToMobile(folder);
folder.addEventListener("click", createEventListener);
}
}
/* Insert After Helper Function */
function insertAfter(newNode, existingNode) {
existingNode.parentNode.insertBefore(newNode, existingNode.nextSibling);
}
setFolderLinks();
})();