major refactor, speedycard pagination beta testing
[kengrimes.com/theme.git] / static / 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 = 15
27 let downDelay = 0
28 const _upDelay = 5
29 let upDelay = _upDelay
30 const navUp = () => nav.style.top = Math.min(parseInt(nav.style.top,10) + (oldScrollY - window.scrollY), 0) + 'px'
31 const navDown = () => nav.style.top = Math.max(parseInt(nav.style.top,10) - (window.scrollY - oldScrollY), -nav.offsetHeight) + 'px'
32 nav.style.top = 0 + 'px'
33 window.onscroll = () => {
34 if (window.matchMedia("(orientation: portrait)").matches) {
35 if (window.scrollY < oldScrollY) /* up */ {
36 if (upDelay-- <= 0)
37 downDelay = _downDelay
38 navUp()
39 }
40 else {
41 upDelay = _upDelay
42 if(downDelay-- <= 0)
43 navDown()
44 else
45 navUp()
46 }
47 oldScrollY = window.scrollY
48 }
49 }
50 }
51
52 const resizeIFrame = (iframe) => {
53 iframe.style.height = 0
54 iframe.style.height = (iframe.contentWindow.document.body.scrollHeight * 1.2) + 'px';
55 }