Use different method for exporting JS

This commit is contained in:
Florine W. Dekker 2021-04-15 23:02:30 +02:00
parent 7b7934dba1
commit 47f6532171
Signed by: FWDekker
GPG Key ID: B1B567AF58D6EE0F
2 changed files with 13 additions and 9 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@fwdekker/template", "name": "@fwdekker/template",
"version": "1.0.0", "version": "1.0.1",
"description": "The base template for pages on fwdekker.com.", "description": "The base template for pages on fwdekker.com.",
"author": "Felix W. Dekker (https://fwdekker.com)", "author": "Felix W. Dekker (https://fwdekker.com)",
"license": "MIT", "license": "MIT",

View File

@ -15,7 +15,7 @@ const stringToHtml = function (string, query) {
* @param q {string} the query string * @param q {string} the query string
* @returns {HTMLElement} the element identified by the query string * @returns {HTMLElement} the element identified by the query string
*/ */
export const $ = q => document.querySelector(q); const $ = q => document.querySelector(q);
/** /**
* Runs the given function once the page is loaded. * Runs the given function once the page is loaded.
@ -25,16 +25,16 @@ export const $ = q => document.querySelector(q);
* *
* @param fun {function(...*): *} the function to run * @param fun {function(...*): *} the function to run
*/ */
export const doAfterLoad = function (fun) { const doAfterLoad = function (fun) {
if (document.readyState === "complete") { if (document.readyState === "complete") {
fun(); fun();
return; return;
} }
const oldOnLoad = window.onload || (() => { const oldOnLoad = onload || (() => {
}); });
window.onload = (() => { onload = (() => {
oldOnLoad(); oldOnLoad();
fun(); fun();
}); });
@ -49,7 +49,7 @@ export const doAfterLoad = function (fun) {
* @param [highlightPath] {String} the path to highlight together with its parents * @param [highlightPath] {String} the path to highlight together with its parents
* @returns {HTMLElement} a base navigation element that will eventually be filled with contents * @returns {HTMLElement} a base navigation element that will eventually be filled with contents
*/ */
export const nav = function (highlightPath = "") { const nav = function (highlightPath = "") {
const base = stringToHtml( const base = stringToHtml(
`<ul><li><a href="https://fwdekker.com/">` + `<ul><li><a href="https://fwdekker.com/">` +
`<div class="logo"><img class="logo" src="https://fwdekker.com/favicon.png" alt="FWDekker" /></div>` + `<div class="logo"><img class="logo" src="https://fwdekker.com/favicon.png" alt="FWDekker" /></div>` +
@ -108,7 +108,7 @@ const unpackEntry = function (entry, path = "/", highlightPath = "") {
* @param [description] {string} the description to display, possibly including HTML * @param [description] {string} the description to display, possibly including HTML
* @returns {HTMLElement} a header element * @returns {HTMLElement} a header element
*/ */
export const header = function ({title, description}) { const header = function ({title, description}) {
if (title === undefined && description === undefined) if (title === undefined && description === undefined)
return stringToHtml(`<header class="header"></header>`, "header"); return stringToHtml(`<header class="header"></header>`, "header");
@ -136,7 +136,7 @@ export const header = function ({title, description}) {
* privacy policy, or `undefined` if the default privacy policy should be used * privacy policy, or `undefined` if the default privacy policy should be used
* @returns {HTMLElement} a footer element * @returns {HTMLElement} a footer element
*/ */
export const footer = function ( const footer = function (
{ {
author, authorURL, license, licenseURL, vcs, vcsURL, version, author, authorURL, license, licenseURL, vcs, vcsURL, version,
privacyPolicyURL = undefined privacyPolicyURL = undefined
@ -176,7 +176,7 @@ const footerLink = function (prefix, text, url, suffix) {
/** /**
* Unhides the main element on the page and applies default display styling. * Unhides the main element on the page and applies default display styling.
*/ */
export const showPage = function () { const showPage = function () {
// Flex-based footer positioning, taken from https://stackoverflow.com/a/12253099 // Flex-based footer positioning, taken from https://stackoverflow.com/a/12253099
const main = $("main"); const main = $("main");
main.style.display = "flex"; main.style.display = "flex";
@ -185,3 +185,7 @@ export const showPage = function () {
$("#contents").style.flex = "1"; $("#contents").style.flex = "1";
} }
// Export to namespace
fwdekker = {stringToHtml, $, doAfterLoad, nav, header, footer, showPage};