36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
/**
|
|
* Alias for `document.querySelector`.
|
|
*
|
|
* @param q {string} the query string
|
|
* @returns {HTMLElement} the element identified by the query
|
|
*/
|
|
export const $ = q => document.querySelector(q);
|
|
|
|
/**
|
|
* Runs the given function once the page is loaded.
|
|
*
|
|
* This function can be used multiple times. It does not overwrite existing callbacks for the page load event.
|
|
*
|
|
* @param fun {function(...*): *} the function to run
|
|
*/
|
|
export const doAfterLoad = fun => {
|
|
const oldOnLoad = window.onload || (() => {});
|
|
|
|
window.onload = (() => {
|
|
oldOnLoad();
|
|
fun();
|
|
});
|
|
};
|
|
|
|
/**
|
|
* Returns the status that has the lowest index in the given list of statuses.
|
|
*
|
|
* @param statuses {string[]} the statuses to look the given statuses up in
|
|
* @param status1 {string} the first status
|
|
* @param status2 {string} the second status
|
|
* @returns {string} the status that has the lowest index in the given list of statuses
|
|
*/
|
|
export const mergeStates = (statuses, status1, status2) => {
|
|
return statuses[Math.min(statuses.indexOf(status1), statuses.indexOf(status2))];
|
|
};
|