import { AeroElement } from "./AeroElement.js";
import { WebPage } from "./WebPage.js";
import { clearChildNodes } from "./aero.js";
/*
export const MENUS = ["Home", "Technology", "Applications", "Team", "Contact"];
export const HREF = ["/index.html", "/technology.html", "/applications.html", "/team.html", "/contact.html"];
*/
/**
*
*/
export class HeaderV2 extends AeroElement {
/** @type{HTMLHeadElement} */
headerNode;
/**
* @type{Nav}
*/
nav;
/**
* @type{Social}
*/
social;
/**
* @type {boolean}
*/
isNavVisible;
/**
* @type{String}
* Color of the flat elements (icon/logo)
*/
flatColor;
/**
*
* @param {HTMLElement} sources
*/
constructor(page, sources) {
super();
this.flatColor = "black";
let val;
this.theme = (val = sources.getAttribute("theme")) ? val : "light";
switch (this.theme) {
default:
case "light": this.flatColor = "black"; break;
case "dark": this.flatColor = "white"; break;
}
this.logo = (val = sources.getAttribute("logo")) ? val : "light";
/* CSS requirements */
page.css_requireStylesheet("/aero/Header.css");
/* build nodes */
this.headerNode = document.createElement('header');
this.headerNode.setAttribute("theme", this.theme);
this.isLandscape = page.isLandscape;
/* build menus */
let node = sources.firstChild;
while (node) {
if (node.nodeName.toLowerCase() == "nav") {
this.nav = new Nav(node);
}
else if (node.nodeName.toLowerCase() == "social") {
this.social = new Social(node);
}
/* save next node */
node = node.nextSibling;
}
this.draw(page, sources);
}
/**
*
* @param {WebPage} page
* @param {HTMLElement} sourceNode
*
* @returns {HTMLElement}
*/
html_getNode() {
/* return wrapper node */
return this.headerNode;
}
load() { /* nothing to load here */ }
/**
*
* @param {WebPage} page
* @returns {}
*/
render(page) {
if (page.isLandscape != this.isLandscape) { // repaint
this.isLandscape = page.isLandscape;
clearChildNodes(this.headerNode);
this.draw();
}
}
draw() {
const placeholderNode = document.createElement("div");
placeholderNode.classList.add("aero-header-placeholder");
this.headerNode.appendChild(placeholderNode);
const flyingNode = document.createElement("div");
flyingNode.classList.add("aero-header-flying");
const barNode = document.createElement("div");
barNode.classList.add("aero-header-bar");
if (this.isLandscape) {
this.drawLandscape(barNode);
}
else {
this.drawPortrait(barNode);
}
flyingNode.appendChild(barNode);
this.headerNode.appendChild(flyingNode);
let lastKnowScrollY = 0;
let deltaScrollY = 0;
let upwardDeltaScrollY = 0;
let ticking = false;
let barPositionY = 0;
let previousMove = 0; /* O :undefined, -1:upward, +1:downward */
const udpateBarPosition = function (y) { flyingNode.style.top = `${y}px`; }
window.addEventListener("scroll", function (e) {
deltaScrollY = window.scrollY - lastKnowScrollY;
lastKnowScrollY = window.scrollY;
if (deltaScrollY < 0) { /* going upward, deltaScrollY < 0 */
//if(previousMove != -1){ barPositionY = -68; }
barPositionY -= deltaScrollY;
//previousMove = -1;
}
else { /* downward, deltaScrollY > 0 */
barPositionY -= deltaScrollY;
//previousMove = 1;
}
if (barPositionY > 0) { barPositionY = 0; }
if (barPositionY < -65) { barPositionY = -65; }
console.log(`barPositionY: ${barPositionY}`);
if (!ticking) {
window.requestAnimationFrame(function () {
udpateBarPosition(barPositionY);
ticking = false;
});
}
ticking = true;
});
}
drawLandscape(barNode) {
/*