From 82cd876419bb2604fd20aa97299e9c9d961669c0 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 10 Dec 2020 21:24:00 +0300 Subject: scripts: drop outdated header scrolling code --- src/main/assets/scripts.js | 84 ++++++---------------------------------------- 1 file changed, 11 insertions(+), 73 deletions(-) (limited to 'src') diff --git a/src/main/assets/scripts.js b/src/main/assets/scripts.js index ef02dca8..de4669b6 100644 --- a/src/main/assets/scripts.js +++ b/src/main/assets/scripts.js @@ -142,7 +142,7 @@ function initES() { pageTitle = document.title; } }; - es.addEventListener('msg', msg => { + es.addEventListener('msg', msg => { try { var jsonMsg = JSON.parse(msg.data); console.log('data: ' + msg.data); @@ -521,9 +521,9 @@ function likeMessage(e, mid) { if (confirm(i18n('message.likeThisMessage?'))) { fetch('/api/like?mid=' + mid + '&hash=' + document.getElementById('body').getAttribute('data-hash'), { - method: 'POST', - credentials: 'omit' - }) + method: 'POST', + credentials: 'omit' + }) .then(handleErrors) .then(function(response) { if (response.ok) { @@ -540,9 +540,9 @@ function likeMessage(e, mid) { function subscribeMessage(e, mid) { fetch('/api/subscribe?mid=' + mid + '&hash=' + document.getElementById('body').getAttribute('data-hash'), { - method: 'POST', - credentials: 'omit' - }) + method: 'POST', + credentials: 'omit' + }) .then(handleErrors) .then(function(response) { if (response.ok) { @@ -563,8 +563,8 @@ function setPopular(e, mid, popular) { fetch('/api/messages/set_popular?mid=' + mid + '&popular=' + popular + '&hash=' + document.getElementById('body').getAttribute('data-hash'), { - credentials: 'same-origin' - }) + credentials: 'same-origin' + }) .then(handleErrors) .then(function() { e.closest('article').append(resultMessage('OK!')); @@ -575,8 +575,8 @@ function setPopular(e, mid, popular) { function setPrivacy(e, mid) { fetch('/api/messages/set_privacy?mid=' + mid + '&hash=' + document.getElementById('body').getAttribute('data-hash'), { - credentials: 'same-origin' - }) + credentials: 'same-origin' + }) .then(handleErrors) .then(function() { e.closest('article').append(resultMessage('OK!')); @@ -876,66 +876,4 @@ ready(function() { initES(); embedAll(); - var elSelector = 'header', - elClassHidden = 'header--hidden', - elClassBackground = 'header--background', - throttleTimeout = 500, - element = document.querySelector(elSelector); - - if (element) { - - var dHeight = 0, - wHeight = 0, - wScrollCurrent = 0, - wScrollBefore = 0, - wScrollDiff = 0, - - throttle = function(delay, fn) { - var last, deferTimer; - return function() { - var context = this, args = arguments, now = +new Date; - if (last && now < last + delay) { - clearTimeout(deferTimer); - deferTimer = setTimeout( - function() { - last = now; - fn.apply(context, args); - }, - delay); - } else { - last = now; - fn.apply(context, args); - } - }; - }; - - window.addEventListener('scroll', throttle(throttleTimeout, function() { - dHeight = document.body.offsetHeight; - wHeight = window.innerHeight; - wScrollCurrent = window.pageYOffset; - wScrollDiff = wScrollBefore - wScrollCurrent; - - if (wScrollCurrent <= 0) { - // scrolled to the very top; element sticks to the top - element.classList.remove(elClassHidden); - element.classList.remove(elClassBackground); - } else if (wScrollDiff > 0 && element.classList.contains(elClassHidden)) { - // scrolled up; element slides in - element.classList.remove(elClassHidden); - element.classList.add(elClassBackground); - } else if (wScrollDiff < 0) { - // scrolled down - if (wScrollCurrent + wHeight >= dHeight && element.classList.contains(elClassHidden)) { - // scrolled to the very bottom; element slides in - element.classList.remove(elClassHidden); - element.classList.add(elClassBackground); - } else { - // scrolled down; element slides out - element.classList.add(elClassHidden); - } - } - - wScrollBefore = wScrollCurrent; - })); - } }); -- cgit v1.2.3