function searchClick(e) { document.getElementById('box_search').classList.toggle('show'); e.firstElementChild.classList.toggle('icon-search'); } function barClick() { document.querySelector('.mobile_nav_content').classList.toggle('open'); } // window.onscroll = function() { // scrollNav(); // } document.addEventListener('scroll', function(){ scrollNav(); }) function scrollNav() { var scroll = window.pageYOffset; var menu = document.querySelector('header'); var menuY = menu.offsetHeight; var nav = document.querySelector('.main_nav'); if (nav) { if (scroll > menuY - 40) { nav.classList.add('fixed'); } else { nav.classList.remove('fixed'); } } } function sourceClick(e) { var link = e.getAttribute('data-link'); (link, "_blank"); } function loadNewsBox(box, news_id) { if (!box) return false; var elmBox = document.getElementById(box); if (elmBox && elmBox.length < 0 || elmBox.getAttribute('data-lazy') == "loading") return false; elmBox.setAttribute("data-lazy", "loading"); var xhttp; var url = document.getElementById(box).tagName != 'DIV' ? '/ajax/getLayout' : (location.protocol + '//' + location.host + location.pathname); // url = location.protocol + '//'+window.location.hostname+url; // console.log(url); xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.getElementById(box).outerHTML = this.responseText; } }; xhttp.open("GET", url + "?boxloader=" + box + "&id=" + news_id, true); xhttp.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhttp.send(null); } function scrollLayzier() { var lazy_thumb = document.getElementsByClassName("lazy_thumb"); for (var i = 0; i < lazy_thumb.length; i++) { if (lazy_thumb[i].getBoundingClientRect().top - document.documentElement.clientHeight <= document.documentElement.clientHeight) { var news_id = lazy_thumb[i].getAttribute('data-news-id') ? lazy_thumb[i].getAttribute('data-news-id') : 0 loadNewsBox(lazy_thumb[i].getAttribute('id'), news_id) } } } window.addEventListener("DOMContentLoaded", function () { // navScroll(); scrollLayzier(); scrollNav() var elements = document.getElementsByTagName('a'); for (var i = 0, len = elements.length; i < len; i++) { if (elements[i].getAttribute('data-slug')) { elements[i].onclick = function () { // stuff var h = screen.height; (this.getAttribute('data-slug'), "Match", "menubar=no,width=640,height=" + h + ",toolbar=no"); return false; } } } }, false); window.addEventListener("scroll", function () { // navScroll(); var menu = document.querySelector('main'); var menuY = menu.getBoundingClientRect().top; var next_news = document.getElementById('box_next_up'); if(next_news){ if (menuY - 40 < 0){ next_news.classList.add('fixed'); }else{ next_news.classList.remove('fixed'); } } scrollLayzier() }, false); /* Select custom */ if (document.querySelector('.--select-wrapper')) { document.querySelector('.--select-wrapper').addEventListener('click', function () { this.querySelector('.--select').classList.toggle('open'); }); for (const option of document.querySelectorAll(".--option")) { option.addEventListener('click', function () { if (!this.classList.contains('selected')) { if (this.parentNode.querySelector('.--option.selected')) this.parentNode.querySelector('.--option.selected').classList.remove('selected'); this.classList.add('selected'); this.closest('.--select').querySelector('.--select__trigger span').textContent = this.textContent; if (url = this.getAttribute('data-url')) window.location.href= url; } }) } window.addEventListener('click', function (e) { const select = document.querySelector('.--select') if (!select.contains(e.target)) { select.classList.remove('open'); } }); } (function timeOutReloadUser(){ var s=0; setInterval(function(){ s++; if(s==1200) { // Reload page 1200s not working location.reload(); } }, 1000); function restart(){s=0;} document.querySelector("body").addEventListener("click", restart); document.querySelector("body").addEventListener("mouseenter", restart); document.querySelector("body").addEventListener("mouseover", restart); document.querySelector("body").addEventListener("keypress", restart); document.addEventListener('scroll', restart); })();