1const vmg = { 2 isTouchDevice: function() { 3 return (('ontouchstart' in window) || 4 (navigator.maxTouchPoints > 0) || 5 (navigator.msMaxTouchPoints > 0)); 6 }, 7 8 initNav: function() { 9 var ticking = false; 10 11 function fixedNav(lastKnownScrollPosition) { 12 if (lastKnownScrollPosition > 20) { 13 document.body.classList.add('fixed-nav'); 14 } else { 15 document.body.classList.remove('fixed-nav') 16 } 17 } 18 fixedNav(window.scrollY); 19 20 document.addEventListener('scroll', function(e) { 21 var lastKnownScrollPosition = window.scrollY; 22 23 if (!ticking) { 24 window.requestAnimationFrame(function() { 25 fixedNav(lastKnownScrollPosition); 26 ticking = false; 27 }); 28 29 ticking = true; 30 } 31 }); 32 33 document.querySelector('.site-header__nav-search a').addEventListener('click', function(event) { 34 event.preventDefault(); 35 let form = event.target.closest('.site-header__nav-search'); 36 if (form) { 37 form.classList.toggle('search-state-open'); 38 if (form.classList.contains('search-state-open')) { 39 form.querySelector('input[type=search]').focus(); 40 } 41 } 42 }); 43 44 document.querySelectorAll('.site-header__nav-search input[type=search]').forEach(searchField => searchField.addEventListener('blur', function(event) { 45 setTimeout(function() { 46 let form = event.target.closest('.search-state-open'); 47 if (form) { 48 form.classList.remove('search-state-open'); 49 } 50 }, 100); 51 })); 52 53 document.querySelector('.site_header__menu-button').addEventListener('click', function(event) { 54 document.body.classList.toggle('menu-state-open'); 55 if (document.body.classList.contains('menu-state-open')) { 56 document.documentElement.classList.add('force-fixed-nav'); 57 } else { 58 document.documentElement.classList.remove('force-fixed-nav'); 59 } 60 event.preventDefault(); 61 }); 62 63 vmg.updateMainNavDOMPosition(); 64 document.addEventListener('resize', vmg.updateMainNavDOMPosition); 65 66 67 document.querySelectorAll('.menu .menu-item-has-children > a').forEach(submenu => submenu.addEventListener('click', function(event) { 68 if (!vmg.isTouchDevice() && document.querySelector('.site_header__menu-button').offsetParent === null) return; 69 var mparent = this.closest('.menu-item-has-children') 70 mparent.classList.toggle('submenu-state-open'); 71 this.blur(); 72 event.preventDefault(); 73 return false; 74 })); 75 76 document.querySelectorAll('.site-footer__nav .more-link').forEach(moreLink => moreLink.addEventListener('click', function(event) { 77 event.preventDefault(); 78 event.target.closest('.site-footer__nav').classList.add('more-open'); 79 })); 80 }, 81 82 updateMainNavDOMPosition: function() { 83 let menu = document.querySelector('.site-header__nav-wrapper'); 84 if (!menu) return; 85 if (document.querySelector('.site_header__menu-button').offsetParent === null) { 86 if (menu.parentElement.classList.contains('.site-header__row')) return; 87 } else { 88 if (menu.parentElement.classList.contains('site-header__nav-mobile')) return; 89 document.querySelector('.site-header__nav-mobile').prepend(menu); 90 } 91 }, 92 93 updateScrollBarWidth: function() { 94 document.body.setAttribute('style', '--scroll-bar: ' + (window.innerWidth - document.body.clientWidth) + 'px'); 95 }, 96 97 initShareBar: function() { 98 let shareBar = document.querySelector('.heateor_sss_vertical_sharing'); 99 let mainContent = document.querySelector('main.editor-content'); 100 101 if (shareBar && mainContent) { 102 document.addEventListener('scroll', function(event) { 103 let mainContentPosition = mainContent.getBoundingClientRect(); 104 if (mainContentPosition.top<50) { 105 if (!document.body.classList.contains('sticky-share-bar')) { 106 document.body.classList.add('sticky-share-bar') 107 } 108 } else { 109 if (document.body.classList.contains('sticky-share-bar')) { 110 document.body.classList.remove('sticky-share-bar') 111 } 112 } 113 }) 114 } 115 }, 116 117 initPostsList: function() { 118 document.addEventListener('submit', function(e) { 119 var postsListForm = e.target.closest('.posts-list-form'); 120 if (postsListForm) { 121 if (postsListForm.classList.contains('state--loading')) { 122 return; 123 } 124 postsListForm.classList.add('state--loading'); 125 126 fetch(postsListForm.getAttribute('action') + '?' + new URLSearchParams(new FormData(postsListForm)).toString(), { 127 method: postsListForm.getAttribute('method'), 128 }) 129 .then(res=>res.text()) 130 .then(function (html) { 131 postsListForm.classList.remove('state--loading'); 132 133 var parser = new DOMParser(); 134 var updatedDoc = parser.parseFromString(html, 'text/html'); 135 var newData = updatedDoc.querySelector('.posts-list'); 136 137 if (newData) { 138 var actionInput = postsListForm.querySelector('input[name=action]'); 139 if (actionInput && actionInput.value=='load_more_posts') { 140 postsListForm.querySelector('.posts-list__more').replaceWith(...newData.children); 141 } else { 142 postsListForm.querySelector('.posts-list').replaceWith(newData); 143 } 144 } 145 }) 146 .catch(function (err) { 147 postsListForm.classList.remove('state--loading'); 148 }); 149 150 e.preventDefault(); 151 } 152 }); 153 154 document.addEventListener('click', function(e) { 155 var submit = e.target.closest('.posts-list-form *[type=submit]'); 156 if (!submit) return; 157 var postsListForm = submit.closest('.posts-list-form'); 158 var actionInput = postsListForm.querySelector('input[name=action]'); 159 if (actionInput) { 160 actionInput.value = e.target.value; 161 } 162 }); 163 }, 164 165 initPostsListPagination: function() { 166 document.addEventListener('click', function(event) { 167 if (event.target.classList.contains('js-load-more')) { 168 event.preventDefault(); 169 if (event.target.classList.contains('state--loading')) return false;
170 event.target.classList.add('state--loading'); 171 172 fetch(event.target.attributes.href.value) 173 .then(res => res.text()) 174 .then(html => { 175 var parser = new DOMParser(); 176 var newdoc = parser.parseFromString(html, 'text/html'); 177 var newPosts = newdoc.querySelector('.posts-list'); 178 event.target.classList.remove('state--loading') 179 if (newPosts) { 180 document.querySelector('.posts-list').innerHTML += newdoc.querySelector('.posts-list').innerHTML; 181 } 182 var newPagination = newdoc.querySelector('.pagination'); 183 if (newPagination) { 184 document.querySelector('.pagination').innerHTML = newPagination.innerHTML; 185 } else { 186 document.querySelector('.pagination').innerHTML = ''; 187 } 188 }) 189 .catch(err => { 190 event.target.classList.remove('state--loading') 191 }) 192 } 193 }); 194 }, 195 196 initAccordion:function() { 197 document.addEventListener('click', function(event) { 198 if (event.target.closest('.js-accordion__item-toggle')) { 199 event.preventDefault(); 200 var aitem = event.target.closest('.accordion__item'); 201 if (!aitem) return false; 202 aitem.classList.toggle('state--open'); 203 } 204 }); 205 }, 206 207 init: function() { 208 document.body.classList.toggle('is-touch-device', vmg.isTouchDevice()); 209 if (!(window.CSS && CSS.supports('color', 'var(--fake-var)'))) { 210 document.body.classList.add('no-var-support'); 211 } 212 213 document.addEventListener('resize', vmg.updateScrollBarWidth); 214 vmg.updateScrollBarWidth(); 215 216 vmg.initNav(); 217 document.dispatchEvent(new CustomEvent("cra_js_loaded", {})); 218 vmg.initShareBar(); 219 vmg.initAccordion(); 220 vmg.initPostsList(); 221 vmg.initPostsListPagination(); 222 223 document.body.classList.remove('no-transitions'); 224 }, 225 226 ready:function(callback){ 227 if (document.readyState!='loading') return callback(); 228 document.addEventListener('DOMContentLoaded', callback); 229 } 230} 231 232vmg.ready(vmg.init);
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.