Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- document.addEventListener('DOMContentLoaded', function() {
- document.querySelectorAll('.popup-menu-sublevels .popup-sublevels-item').forEach(function(element) {
- let category = element.dataset.category;
- let subcategory = element.dataset.subcategory;
- if (category !== "" && subcategory !== "") {
- document.querySelectorAll('.nav-menu-item-wrap').forEach(function(menuItem) {
- let currentCategory = menuItem.dataset.category;
- let sublevelsHiddenContainer = menuItem.querySelector('.menu-sublevels-hidden');
- if (category === currentCategory) {
- sublevelsHiddenContainer.appendChild(element.cloneNode(true));
- }
- });
- }
- });
- document.querySelectorAll('.nav-menu-item-wrap').forEach(function(menuItem) {
- let subcategoryNames = [];
- let sublevelsWrap = menuItem.querySelector('.menu-sublevels-wrap');
- let sublevels = menuItem.querySelectorAll('.popup-sublevels-item');
- sublevels.forEach(function(sublevel) {
- subcategoryNames.push(sublevel.dataset.subcategory);
- });
- let uniqueArr = Array.from(new Set(subcategoryNames));
- uniqueArr.forEach(function(subcategoryName) {
- sublevelsWrap.innerHTML += `
- <div class="menu-sublevels-box">
- <div class="menu-sublevels-box-title subtitle-2">${subcategoryName}</div>
- <div class="menu-sublevels-box-body"></div>
- </div>
- `;
- });
- });
- document.querySelectorAll('.nav-menu-item-wrap').forEach(function(menuItem) {
- let boxes = menuItem.querySelectorAll('.menu-sublevels-box');
- let sublevels = menuItem.querySelectorAll('.menu-sublevels-hidden .popup-sublevels-item');
- boxes.forEach(function(box) {
- let boxBody = box.querySelector('.menu-sublevels-box-body');
- let boxSubcategory = box.querySelector('.menu-sublevels-box-title').textContent;
- sublevels.forEach(function(sublevel) {
- let subcategory = sublevel.dataset.subcategory;
- if (subcategory === boxSubcategory) {
- boxBody.appendChild(sublevel.cloneNode(true));
- }
- });
- });
- });
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement