Select Git revision
events.js 1005 B
/** Monster 1.17.1, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{validateInstance,validateString}from"../types/validate.js";import{findClosestByAttribute}from"./attributes.js";import{getDocument}from"./util.js";function fireEvent(e,t){var n;getDocument();if(e instanceof HTMLElement)"click"!==t?(n=new Event(validateString(t),{bubbles:!0,cancelable:!0}),e.dispatchEvent(n)):e.click();else{if(!(e instanceof HTMLCollection||e instanceof NodeList))throw new TypeError("value is not an instance of HTMLElement or HTMLCollection");for(var o of e)fireEvent(o,t)}}function findTargetElementFromEvent(e,t,n){if(validateInstance(e,Event),"function"!=typeof e.composedPath)throw new Error("unsupported event");e=e.composedPath()?.[0];if(e instanceof HTMLElement)return findClosestByAttribute(e,t,n)}assignToNamespace("Monster.DOM",findTargetElementFromEvent,fireEvent);export{Monster,findTargetElementFromEvent,fireEvent};