2019-03-24 17:15:47 -04:00
|
|
|
import modular from 'modujs';
|
2016-03-16 12:11:23 -04:00
|
|
|
import * as modules from './modules';
|
2019-03-24 17:15:47 -04:00
|
|
|
import globals from './globals';
|
2024-01-11 11:45:46 +01:00
|
|
|
import { debounce } from './utils/tickers';
|
2023-04-05 12:23:25 +02:00
|
|
|
import { $html } from './utils/dom';
|
2023-04-05 15:06:51 -04:00
|
|
|
import { ENV, FONT, CUSTOM_EVENT, CSS_CLASS } from './config'
|
2022-09-27 11:11:31 -04:00
|
|
|
import { isFontLoadingAPIAvailable, loadFonts } from './utils/fonts';
|
2015-04-09 16:45:55 -04:00
|
|
|
|
2019-03-24 17:15:47 -04:00
|
|
|
const app = new modular({
|
2024-01-11 11:45:46 +01:00
|
|
|
modules,
|
2019-03-24 17:15:47 -04:00
|
|
|
});
|
2015-04-09 16:45:55 -04:00
|
|
|
|
2024-03-26 18:30:36 -04:00
|
|
|
function init() {
|
|
|
|
|
bindEvents();
|
|
|
|
|
globals();
|
|
|
|
|
setViewportSizes();
|
|
|
|
|
|
|
|
|
|
app.init(app);
|
|
|
|
|
|
|
|
|
|
$html.classList.add(CSS_CLASS.LOADED, CSS_CLASS.READY);
|
|
|
|
|
$html.classList.remove(CSS_CLASS.LOADING);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Debug focus
|
|
|
|
|
*/
|
|
|
|
|
// document.addEventListener(
|
|
|
|
|
// "focusin",
|
|
|
|
|
// function () {
|
|
|
|
|
// console.log('focused: ', document.activeElement)
|
|
|
|
|
// }, true
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Eagerly load the following fonts.
|
|
|
|
|
*/
|
|
|
|
|
if (isFontLoadingAPIAvailable) {
|
|
|
|
|
loadFonts(FONT.EAGER, ENV.IS_DEV).then((eagerFonts) => {
|
|
|
|
|
$html.classList.add(CSS_CLASS.FONTS_LOADED);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Debug fonts loading
|
|
|
|
|
*/
|
|
|
|
|
// if (ENV.IS_DEV) {
|
|
|
|
|
// console.group('Eager fonts loaded!', eagerFonts.length, '/', document.fonts.size);
|
|
|
|
|
// console.group('State of eager fonts:');
|
|
|
|
|
// eagerFonts.forEach(font => console.log(font.family, font.style, font.weight, font.status));
|
|
|
|
|
// console.groupEnd();
|
|
|
|
|
// console.group('State of all fonts:');
|
|
|
|
|
// document.fonts.forEach(font => console.log(font.family, font.style, font.weight, font.status));
|
|
|
|
|
// console.groupEnd();
|
|
|
|
|
// }
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
|
// Global events
|
|
|
|
|
////////////////
|
|
|
|
|
function bindEvents() {
|
|
|
|
|
|
|
|
|
|
// Resize event
|
|
|
|
|
const resizeEndEvent = new CustomEvent(CUSTOM_EVENT.RESIZE_END)
|
|
|
|
|
window.addEventListener(
|
|
|
|
|
"resize",
|
|
|
|
|
debounce(() => {
|
|
|
|
|
window.dispatchEvent(resizeEndEvent)
|
|
|
|
|
}, 200, false)
|
|
|
|
|
)
|
|
|
|
|
window.addEventListener(
|
|
|
|
|
"resize",
|
|
|
|
|
onResize
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onResize() {
|
|
|
|
|
setViewportSizes()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setViewportSizes() {
|
2024-01-11 11:45:46 +01:00
|
|
|
|
|
|
|
|
// Document styles
|
|
|
|
|
const documentStyles = document.documentElement.style;
|
|
|
|
|
|
|
|
|
|
// Viewport width
|
|
|
|
|
const vw = document.body.clientWidth * 0.01;
|
|
|
|
|
documentStyles.setProperty('--vw', `${vw}px`);
|
|
|
|
|
|
|
|
|
|
// Return if browser supports vh, svh, dvh, & lvh
|
|
|
|
|
if (ENV.SUPPORTS_VH) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Viewport height
|
|
|
|
|
const svh = document.documentElement.clientHeight * 0.01;
|
|
|
|
|
documentStyles.setProperty('--svh', `${svh}px`);
|
2024-03-26 18:30:36 -04:00
|
|
|
|
|
|
|
|
const dvh = window.innerHeight * 0.01;
|
2024-01-11 11:45:46 +01:00
|
|
|
documentStyles.setProperty('--dvh', `${dvh}px`);
|
|
|
|
|
|
|
|
|
|
if (document.body) {
|
|
|
|
|
const fixed = document.createElement('div');
|
|
|
|
|
fixed.style.width = '1px';
|
|
|
|
|
fixed.style.height = '100vh';
|
|
|
|
|
fixed.style.position = 'fixed';
|
|
|
|
|
fixed.style.left = '0';
|
|
|
|
|
fixed.style.top = '0';
|
|
|
|
|
fixed.style.bottom = '0';
|
|
|
|
|
fixed.style.visibility = 'hidden';
|
|
|
|
|
|
|
|
|
|
document.body.appendChild(fixed);
|
|
|
|
|
|
|
|
|
|
var fixedHeight = fixed.clientHeight;
|
|
|
|
|
|
|
|
|
|
fixed.remove();
|
|
|
|
|
|
|
|
|
|
const lvh = fixedHeight * 0.01;
|
|
|
|
|
|
|
|
|
|
documentStyles.setProperty('--lvh', `${lvh}px`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-26 18:30:36 -04:00
|
|
|
////////////////
|
|
|
|
|
// Execute
|
|
|
|
|
////////////////
|
2024-01-11 11:45:46 +01:00
|
|
|
window.addEventListener('load', () => {
|
2021-03-05 09:30:54 -05:00
|
|
|
const $style = document.getElementById('main-css');
|
2019-05-23 10:06:45 -04:00
|
|
|
|
2021-04-09 15:23:45 -04:00
|
|
|
if ($style) {
|
|
|
|
|
if ($style.isLoaded) {
|
2020-05-26 15:22:14 -04:00
|
|
|
init();
|
2021-04-09 15:23:45 -04:00
|
|
|
} else {
|
2024-01-11 11:45:46 +01:00
|
|
|
$style.addEventListener('load', init);
|
2021-04-09 15:23:45 -04:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
console.warn('The "main-css" stylesheet not found');
|
2020-05-26 15:22:14 -04:00
|
|
|
}
|
2023-08-08 15:34:01 -04:00
|
|
|
});
|