1function throttle(fn, wait) { 2 var time = Date.now(); 3 return function() { 4 if ((time + wait - Date.now()) < 0) { 5 fn(); 6 time = Date.now(); 7 } 8 } 9} 10 11(function() { 12 let filters = {}; 13 let galleryBlocks = []; 14 let filterContainer; 15 let filterFixed = false; 16 let filterContainerTop = 0; 17 document.addEventListener('DOMContentLoaded', function() { 18 let filterElms = document.querySelectorAll('.pn-player-gallery-filter-item'); 19 filterContainer = document.querySelector('.pn-player-gallery-filter-container'); 20 galleryBlocks = document.querySelectorAll('.pn-sp-player-gallery-container'); 21 if (!filterContainer) return; 22 filterElms.forEach(function(node) { 23 filters[node.getAttribute('data-toggle')] = node; 24 node.addEventListener('click', handleFilterClick); 25 26 }); 27 filterContainerTop = filterContainer.offsetTop; 28 console.log(filterContainerTop); 29 document.addEventListener('scroll', throttle(function() { 30 if (document.documentElement.scrollTop >= filterContainerTop && !filterFixed) { 31 filterContainer.classList.add('fixed'); 32 filterFixed = true; 33 } else if (document.documentElement.scrollTop <= filterContainerTop && filterFixed) { 34 filterContainer.classList.remove('fixed'); 35 filterFixed = false; 36 } 37 }, 50)); 38 }); 39 function handleFilterClick(event) { 40 if (event.target && event.target.getAttribute) { 41 const toggle = event.currentTarget.getAttribute('data-toggle'); 42 for (let position in filters) { 43 if (position === toggle && !filters[position].classList.contains('active')) { 44 filters[position].classList.add('active') 45 } else if (position !== toggle) { 46 filters[position].classList.remove('active'); 47 } 48 } 49 50 galleryBlocks.forEach(function (node) { 51 if (node.getAttribute('data-position') === toggle) { 52 //node.scrollIntoView({ behavior: "smooth"}) 53 console.log(node.getBoundingClientRect().top); 54 document.documentElement.scrollTo({ 55 top: node.offsetTop - 100, 56 behavior: "smooth" 57 }) 58 // document.documentElement.scrollBy({ top: -100 }); 59 } 60 }); 61 62 63 /* filters.forEach(function(node) { 64 if (node.getAttribute('data-position') === toggle && !node.classList.contains('active')) { 65 node.classList.add('active') 66 } else { 67 node.classList.remove('active') 68 } 69 });*/ 70//document.querySelectorAll('.pn-sp-player-gallery-container') 71 72 } 73 } 74 75})();
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.