Initial Commit
[ancientarts.git] / hugo / hugo / public / js / speedy.js
1 /**
2 * @file main.js
3 * @author Ken Grimes
4 * @license AGPL-3.0
5 * @copyright 2018 - Ken Grimes
6 * @summmary Script for populating text to summary box on svg:hover
7 */
8 'use strict'
9 window.onload = () => {
10 const header = document.body.getElementsByTagName('header').item(0)
11 const nav = document.body.getElementsByTagName('nav').item(0)
12 const main = document.body.getElementsByTagName('main').item(0)
13 const navAnchors = Array.from(nav.getElementsByTagName('div').item(0).getElementsByTagName('a'))
14 const pageDisplay = nav.getElementsByTagName('footer').item(0)
15 const currentPageName = `${pageDisplay.innerHTML}`
16 const updateNav = () => navAnchors.forEach((a) => {
17 const summary = a.getElementsByTagName('summary').item(0).innerHTML
18 const svg = a.getElementsByTagName('svg').item(0)
19 a.addEventListener('mouseover', () => pageDisplay.innerHTML = summary)
20 a.addEventListener('mousedown', () => pageDisplay.innerHTML = summary)
21 a.addEventListener('mouseout', () => pageDisplay.innerHTML = currentPageName)
22 })
23 updateNav()
24
25 let oldScrollY = window.scrollY
26 const _downDelay = 32
27 let downDelay = _downDelay
28 const _upDelay = 16
29 let upDelay = 0
30 nav.style.top = '0px'
31 let top = 0
32 const navUpdate = () => {
33 if (window.matchMedia("(orientation: portrait)").matches) {
34 if (window.scrollY < oldScrollY) /* up */ {
35 if (top === 0)
36 downDelay = _downDelay
37 else if (upDelay-- <= 0) {
38 top = Math.min(top + (oldScrollY - window.scrollY), 0)
39 nav.style.top = top + 'px'
40 }
41 }
42 else if (window.scrollY > oldScrollY) /* down */{
43 if (downDelay-- <= 0) {
44 top = Math.max(top - (window.scrollY - oldScrollY), -nav.offsetHeight)
45 nav.style.top = top + 'px'
46 }
47 upDelay = _upDelay
48 }
49 window.requestAnimationFrame(navUpdate)
50 }
51 else {
52 if (top != 0) {
53 top = 0
54 nav.style.top = '0px'
55 upDelay = _upDelay
56 downDelay = _downDelay
57 }
58 setTimeout(navUpdate, 1000)
59 }
60 oldScrollY = window.scrollY
61 }
62 navUpdate();
63 }
64
65 const resizeIFrame = (iframe) => {
66 iframe.style.height = 0
67 iframe.style.height = (iframe.contentWindow.document.body.scrollHeight * 1.2) + 'px';
68 }