Cleanup artifacts from node build flow
This commit is contained in:
23
web/js/app.mjs
Normal file
23
web/js/app.mjs
Normal file
@ -0,0 +1,23 @@
|
||||
import {library, dom} from '@fortawesome/fontawesome-svg-core/index.es';
|
||||
import {fas} from '@fortawesome/free-solid-svg-icons/index.es';
|
||||
import {far} from '@fortawesome/free-regular-svg-icons/index.es';
|
||||
library.add(fas, far);
|
||||
|
||||
// Old application code
|
||||
import './main.mjs';
|
||||
|
||||
// New application code
|
||||
import Theme from './theme.mjs';
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
Theme.init();
|
||||
|
||||
// Replace any existing <i> tags with <svg> and set up a MutationObserver to
|
||||
// continue doing this as the DOM changes.
|
||||
dom.watch();
|
||||
|
||||
document.getElementById('theme-switch-btn').addEventListener('click', () => {
|
||||
Theme.swap();
|
||||
});
|
||||
});
|
||||
|
1210
web/js/main.mjs
Normal file
1210
web/js/main.mjs
Normal file
File diff suppressed because it is too large
Load Diff
42
web/js/theme.mjs
Normal file
42
web/js/theme.mjs
Normal file
@ -0,0 +1,42 @@
|
||||
export default class {
|
||||
/**
|
||||
* @property {boolean} #dark Interal state for dark theme activation.
|
||||
* @private
|
||||
*/
|
||||
static #dark = false;
|
||||
|
||||
/**
|
||||
* Inialize the theme class.
|
||||
*/
|
||||
static init() {
|
||||
// Check LocalStorage for dark theme selection
|
||||
if (localStorage.getItem('darkTheme') === 'true') {
|
||||
// Update page theme
|
||||
this.set(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set page theme and update local storage variable.
|
||||
*
|
||||
* @param {boolean} dark Whether to activate dark theme.
|
||||
*/
|
||||
static set(dark = false) {
|
||||
// Swap CSS to selected theme
|
||||
document.getElementById('pagestyle')
|
||||
.setAttribute('href', 'static/css/' + (dark ? 'dark' : 'main') + '.css');
|
||||
|
||||
// Update local storage
|
||||
localStorage.setItem('darkTheme', dark);
|
||||
|
||||
// Update internal state
|
||||
this.#dark = dark;
|
||||
}
|
||||
|
||||
/**
|
||||
* Swap page theme.
|
||||
*/
|
||||
static swap() {
|
||||
this.set(!this.#dark);
|
||||
}
|
||||
}
|
18
web/js/util.js
Normal file
18
web/js/util.js
Normal file
@ -0,0 +1,18 @@
|
||||
export function isOverflown(element) {
|
||||
return element.scrollHeight > element.clientHeight || element.scrollWidth > element.clientWidth;
|
||||
}
|
||||
|
||||
export function setProgressBar(bar, progress, text = '') {
|
||||
const progPos = (-1 * (1 - progress) * bar.scrollWidth).toString();
|
||||
const progStr = (progress * 100).toString();
|
||||
bar.setAttribute('aria-valuenow', progStr);
|
||||
bar.style.transform = 'translateX(' + progPos + 'px)';
|
||||
bar.textContent = text;
|
||||
}
|
||||
|
||||
export function secondsToStr(seconds) {
|
||||
seconds = Math.floor(seconds);
|
||||
const mins = Math.floor(seconds / 60);
|
||||
const secs = seconds % 60;
|
||||
return ('00' + mins).slice(-2) + ':' + ('00' + secs).slice(-2);
|
||||
}
|
Reference in New Issue
Block a user