summaryrefslogtreecommitdiff
path: root/html/content/js/Utils/dom.js
diff options
context:
space:
mode:
Diffstat (limited to 'html/content/js/Utils/dom.js')
-rw-r--r--html/content/js/Utils/dom.js68
1 files changed, 0 insertions, 68 deletions
diff --git a/html/content/js/Utils/dom.js b/html/content/js/Utils/dom.js
deleted file mode 100644
index 78f3562..0000000
--- a/html/content/js/Utils/dom.js
+++ /dev/null
@@ -1,68 +0,0 @@
-define(function () {
- const reduce = (elements, fn, initialValue) => {
- return Array.prototype.reduce.call(elements, fn, initialValue);
- }
-
- const forEach = (elements, fn) => {
- Array.prototype.forEach.call(elements, fn);
- }
- const map = (elements, fn) => {
- return Array.prototype.map.call(elements, fn);
- }
-
- const replace = (toReplace, replacement) => {
- var parentElement = toReplace.parentElement
- if (parentElement) {
- parentElement.replaceChild(replacement, toReplace);
- }
- }
-
- const matches = (element, selector) => {
- var m = element.matches
- || Element.prototype.matchesSelector
- || Element.prototype.mozMatchesSelector
- || Element.prototype.msMatchesSelector
- || Element.prototype.oMatchesSelector
- || Element.prototype.webkitMatchesSelector;
- return m.call(element, selector);
- }
-
- const closest = (element, selector) => {
- while (element) {
- if (matches(element, selector)) {
- return element;
- } else {
- element = element.parentElement;
- }
- }
- return null;
- }
- const isFunction = (input) => (typeof input === "function");
- const dispatchEvent = (eventName, data) => {
- let event;
- if (window.CustomEvent && isFunction(window.CustomEvent)) {
- event = new CustomEvent(eventName, { detail: data, cancelable: true, bubbles: false });
- } else {
- event = document.createEvent('CustomEvent');
- event.initCustomEvent(eventName, false, true, data);
- }
- return window.document.dispatchEvent(event);
- }
-
- const parseHtml = (htmlString) => {
- const c = document.createElement('div');
- c.innerHTML = htmlString.trim();
- return c.firstChild;
- }
-
- return {
- dispatchEvent,
- closest,
- matches,
- reduce,
- map,
- forEach,
- replace,
- parseHtml
- };
-}); \ No newline at end of file