X-Git-Url: https://www.kengrimes.com/gitweb/?p=kengrimes.com%2Ftheme.git;a=blobdiff_plain;f=static%2Fjs%2Fspeedy.js;fp=static%2Fjs%2Fspeedy.js;h=069b2d46e8cb630fc8fb29ad610e10e57ab301ad;hp=0000000000000000000000000000000000000000;hb=f9e1ed5e957f44d6cc608156ed922d0c08da7d73;hpb=3bb959dc9aa6955c1d67f45d811a1af7496f3d80 diff --git a/static/js/speedy.js b/static/js/speedy.js new file mode 100644 index 0000000..069b2d4 --- /dev/null +++ b/static/js/speedy.js @@ -0,0 +1,55 @@ +/** +* @file main.js +* @author Ken Grimes +* @license AGPL-3.0 +* @copyright 2018 - Ken Grimes +* @summmary Script for populating text to summary box on svg:hover +*/ +'use strict' +window.onload = () => { + const header = document.body.getElementsByTagName('header').item(0) + const nav = document.body.getElementsByTagName('nav').item(0) + const main = document.body.getElementsByTagName('main').item(0) + const navAnchors = Array.from(nav.getElementsByTagName('div').item(0).getElementsByTagName('a')) + const pageDisplay = nav.getElementsByTagName('footer').item(0) + const currentPageName = `${pageDisplay.innerHTML}` + const updateNav = () => navAnchors.forEach((a) => { + const summary = a.getElementsByTagName('summary').item(0).innerHTML + const svg = a.getElementsByTagName('svg').item(0) + a.addEventListener('mouseover', () => pageDisplay.innerHTML = summary) + a.addEventListener('mousedown', () => pageDisplay.innerHTML = summary) + a.addEventListener('mouseout', () => pageDisplay.innerHTML = currentPageName) + }) + updateNav() + + let oldScrollY = window.scrollY + const _downDelay = 15 + let downDelay = 0 + const _upDelay = 5 + let upDelay = _upDelay + const navUp = () => nav.style.top = Math.min(parseInt(nav.style.top,10) + (oldScrollY - window.scrollY), 0) + 'px' + const navDown = () => nav.style.top = Math.max(parseInt(nav.style.top,10) - (window.scrollY - oldScrollY), -nav.offsetHeight) + 'px' + nav.style.top = 0 + 'px' + window.onscroll = () => { + if (window.matchMedia("(orientation: portrait)").matches) { + if (window.scrollY < oldScrollY) /* up */ { + if (upDelay-- <= 0) + downDelay = _downDelay + navUp() + } + else { + upDelay = _upDelay + if(downDelay-- <= 0) + navDown() + else + navUp() + } + oldScrollY = window.scrollY + } + } +} + +const resizeIFrame = (iframe) => { + iframe.style.height = 0 + iframe.style.height = (iframe.contentWindow.document.body.scrollHeight * 1.2) + 'px'; +}