Fix small warning in app.js + Add useful methods to html.js + Add maths.js to utils + Build

This commit is contained in:
Jérémy Minié
2019-06-25 14:21:03 -04:00
parent 206ced5b10
commit 7d47ae0d82
8 changed files with 54 additions and 1443 deletions

View File

@@ -94,3 +94,48 @@ export function getData(data) {
return data;
}
/**
* Returns an array containing all the parent nodes of the given node
* @param {object} node
* @return {array} parent nodes
*/
export function getParents(elem) {
// Set up a parent array
let parents = [];
// Push each parent element to the array
for ( ; elem && elem !== document; elem = elem.parentNode ) {
parents.push(elem);
}
// Return our parent array
return parents;
}
// https://gomakethings.com/how-to-get-the-closest-parent-element-with-a-matching-selector-using-vanilla-javascript/
export function queryClosestParent(elem, selector) {
// Element.matches() polyfill
if (!Element.prototype.matches) {
Element.prototype.matches =
Element.prototype.matchesSelector ||
Element.prototype.mozMatchesSelector ||
Element.prototype.msMatchesSelector ||
Element.prototype.oMatchesSelector ||
Element.prototype.webkitMatchesSelector ||
function(s) {
var matches = (this.document || this.ownerDocument).querySelectorAll(s),
i = matches.length;
while (--i >= 0 && matches.item(i) !== this) {}
return i > -1;
};
}
// Get the closest matching element
for ( ; elem && elem !== document; elem = elem.parentNode ) {
if ( elem.matches( selector ) ) return elem;
}
return null;
};

View File

@@ -0,0 +1,3 @@
export function lerp(start, end, amt){
return (1 - amt) * start + amt * end
}