mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
split utils
This commit is contained in:
parent
8c558e6b34
commit
120bf4a7eb
12 changed files with 858 additions and 834 deletions
30
utils/nodeUtils.js
Normal file
30
utils/nodeUtils.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
"use strict";
|
||||
// FMG utils related to nodes
|
||||
|
||||
// remove parent element (usually if child is clicked)
|
||||
function removeParent() {
|
||||
this.parentNode.parentNode.removeChild(this.parentNode);
|
||||
}
|
||||
|
||||
// polyfill for composedPath
|
||||
function getComposedPath(node) {
|
||||
let parent;
|
||||
if (node.parentNode) parent = node.parentNode;
|
||||
else if (node.host) parent = node.host;
|
||||
else if (node.defaultView) parent = node.defaultView;
|
||||
if (parent !== undefined) return [node].concat(getComposedPath(parent));
|
||||
return [node];
|
||||
}
|
||||
|
||||
// get next unused id
|
||||
function getNextId(core, i = 1) {
|
||||
while (document.getElementById(core + i)) i++;
|
||||
return core + i;
|
||||
}
|
||||
|
||||
function getAbsolutePath(href) {
|
||||
if (!href) return "";
|
||||
const link = document.createElement("a");
|
||||
link.href = href;
|
||||
return link.href;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue