Repository URL to install this package:
|
Version:
2.7.3 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
const exotic_1 = require("exotic");
/**
* also available from 'fbjs'
*/
exports.canUseDOM = typeof window === 'object' && exotic_1.isObj(window.document) && exotic_1.isFunction(window.document.createElement);
/**
* @description sometimes this throws, so we wrap this one function and scope the easily-deopted of trycatch
*/
function removeElement(element) {
try {
document.body.removeChild(element);
return true;
} catch (objectOrDomException) {
//
return false;
}
}
exports.removeElement = removeElement;
/**
* @todo @@perf at least cache/memoize these functions to reduce dom reads
*/
function getElementOrCreate(id) {
return document.getElementById(id) || document.createElement('div');
}
exports.getElementOrCreate = getElementOrCreate;
function hasElementFor(idOrElement) {
return exotic_1.isString(idOrElement) ? !!document.getElementById(idOrElement) : document.body.contains(idOrElement);
}
exports.hasElementFor = hasElementFor;
function getElemetFor(id) {
return document.getElementById(id);
}
exports.getElemetFor = getElemetFor;
function appendToBodyIfRequired(node) {
if (!hasElementFor(node)) {
console.warn('did not have the dom in the body - if you are using `<Portal id="eh">`, then you should have an element with <div id="eh"> in the html body. this warning can be ignored in @skava/ui');
document.body.appendChild(node);
} else {// console.debug('has node already')
}
}
exports.appendToBodyIfRequired = appendToBodyIfRequired; //# sourceMappingURL=deps.js.map