1(function (root, factory) { 2 var api = factory(); 3 4 if (typeof module === 'object' && module.exports) { 5 module.exports = api; 6 return; 7 } 8 9 root.PersolMenuEnhancements = api; 10 api.init(root.document, root); 11}(typeof self !== 'undefined' ? self : this, function () { 12 'use strict'; 13 14 var HASH_PREFIX = '#menu-produtos'; 15 16 function parseCategoryHash(hash) { 17 hash = String(hash || '').toLowerCase(); 18 19 if (hash === HASH_PREFIX) return ''; 20 if (hash.indexOf(HASH_PREFIX + '-') !== 0) return null; 21 22 try { 23 return decodeURIComponent(hash.slice(HASH_PREFIX.length + 1)).trim(); 24 } catch (error) { 25 return null; 26 } 27 } 28 29 function findCategoryLine(lines, categorySlug) { 30 for (var index = 0; index < lines.length; index += 1) { 31 if (lines[index].getAttribute('data-product-category') === categorySlug) { 32 return lines[index]; 33 } 34 } 35 36 return null; 37 } 38 39 function openCategoryMenu(doc, win, categorySlug) { 40 if (!doc || !win) return false; 41 42 var desktopMenu = doc.getElementById('menu-mobile'); 43 var mobileMenu = doc.getElementById('menu-mobile-mobile'); 44 var mobile = win.innerWidth <= 1023; 45 var targetMenu = mobile ? mobileMenu : desktopMenu; 46 var button = doc.querySelector('#header .open-prods-list'); 47 48 if (!targetMenu) return false; 49 50 if (desktopMenu) desktopMenu.classList.remove('open', 'opening', 'closing'); 51 if (mobileMenu) mobileMenu.classList.remove('open', 'opening', 'closing'); 52 53 targetMenu.classList.add('open'); 54 55 if (button) { 56 button.classList.add('is-active'); 57 button.setAttribute('aria-expanded', 'true'); 58 } 59 60 doc.documentElement.classList.add('menu-open'); 61 doc.body.classList.add('menu-open'); 62 63 var lines = targetMenu.querySelectorAll('[data-product-category]'); 64 var selectedLine = categorySlug ? findCategoryLine(lines, categorySlug) : null; 65 66 for (var index = 0; index < lines.length; index += 1) { 67 lines[index].classList.remove('active', 'closed', 'is-active'); 68 var products = lines[index].querySelector('.prods'); 69 if (products) products.classList.remove('is-open'); 70 } 71 72 if (mobile) { 73 var productPanel = targetMenu.querySelector('.prods-menu'); 74 if (productPanel) productPanel.classList.add('is-open'); 75 76 if (selectedLine) { 77 selectedLine.classList.add('is-active'); 78 var selectedProducts = selectedLine.querySelector('.prods'); 79 if (selectedProducts) selectedProducts.classList.add('is-open'); 80 } 81 } else if (selectedLine) { 82 for (var lineIndex = 0; lineIndex < lines.length; lineIndex += 1) { 83 if (lines[lineIndex] === selectedLine) { 84 lines[lineIndex].classList.add('active'); 85 } else { 86 lines[lineIndex].classList.add('closed'); 87 } 88 } 89 } 90 91 if (selectedLine) showDefaultImage(selectedLine); 92 93 return true; 94 } 95 96 function showDefaultImage(line) { 97 var image = line ? line.querySelector('.image-prod') : null; 98 if (!image) return false; 99 100 var defaultImage = image.getAttribute('data-menu-default'); 101 if (!defaultImage) return false; 102 103 if (image.getAttribute('src') !== defaultImage) { 104 image.setAttribute('src', defaultImage); 105 } 106 107 return true; 108 } 109 110 function showProductImage(link) { 111 if (!link) return false; 112 113 var url = (link.getAttribute('data-menu-img') || '').trim(); 114 var line = link.closest('.line'); 115 var image = line ? line.querySelector('.image-prod') : null; 116 if (!url || !image) return false; 117 118 var links = line.querySelectorAll('.prod-open-image'); 119 for (var index = 0; index < links.length; index += 1) { 120 links[index].classList.remove('is-hover'); 121 } 122 123 link.classList.add('is-hover'); 124 if (image.getAttribute('src') !== url) image.setAttribute('src', url); 125 return true; 126 } 127 128 function resetProductImage(products) { 129 var line = products ? products.closest('.line') : null; 130 var image = line ? line.querySelector('.image-prod') : null; 131 if (!line || !image) return false;
132 133 var links = line.querySelectorAll('.prod-open-image'); 134 for (var index = 0; index < links.length; index += 1) { 135 links[index].classList.remove('is-hover'); 136 } 137 138 var defaultImage = image.getAttribute('data-menu-default'); 139 if (defaultImage && image.getAttribute('src') !== defaultImage) { 140 image.setAttribute('src', defaultImage); 141 } 142 143 return true; 144 } 145 146 function initMenuImages(doc) { 147 var menu = doc.getElementById('menu-mobile'); 148 if (!menu) return; 149 150 function explore(event) { 151 var link = event.target && event.target.closest ? event.target.closest('.prod-open-image[data-menu-img]') : null; 152 if (link) showProductImage(link); 153 } 154 155 function leave(event) { 156 var products = event.target && event.target.closest ? event.target.closest('.prods') : null; 157 if (!products || (event.relatedTarget && products.contains(event.relatedTarget))) return; 158 resetProductImage(products); 159 } 160 161 menu.addEventListener('mouseover', explore); 162 menu.addEventListener('focusin', explore); 163 menu.addEventListener('mouseout', leave); 164 menu.addEventListener('focusout', leave); 165 menu.addEventListener('click', function (event) { 166 var line = event.target && event.target.closest ? event.target.closest('[data-product-category]') : null; 167 if (line) showDefaultImage(line); 168 }); 169 } 170 171 function init(doc, win) { 172 if (!doc || !win) return; 173 174 function openFromLocation() { 175 var category = parseCategoryHash(win.location.hash); 176 if (category !== null) openCategoryMenu(doc, win, category); 177 } 178 179 function ready() { 180 initMenuImages(doc); 181 openFromLocation(); 182 win.addEventListener('hashchange', openFromLocation); 183 } 184 185 if (doc.readyState === 'loading') { 186 doc.addEventListener('DOMContentLoaded', ready, { once: true }); 187 } else { 188 ready(); 189 } 190 } 191 192 return { 193 init: init, 194 parseCategoryHash: parseCategoryHash, 195 openCategoryMenu: openCategoryMenu, 196 showDefaultImage: showDefaultImage, 197 showProductImage: showProductImage, 198 resetProductImage: resetProductImage 199 }; 200}));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.