Skip to content

Commit

Permalink
Rename element to target
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamWr committed Apr 11, 2024
1 parent c6eee57 commit 3736c8d
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/scriptlets/trusted-dispatch-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import {
* @trustedScriptlet trusted-dispatch-event
*
* @description
* Dispatches a custom event on a specified element.
* Dispatches a custom event on a specified target.
*
* ### Syntax
* ```text
* example.org#%#//scriptlet('trusted-dispatch-event', event[, element])
* example.org#%#//scriptlet('trusted-dispatch-event', event[, target])
* ```
*
* - `event` — required, name of the event to dispatch
* - `element` — optional, CSS selector of the element or a window object to dispatch the event on
* - `target` — optional, CSS selector of the element or a window object to dispatch the event on
* if not set then "document" is used
*
* ### Examples
Expand Down Expand Up @@ -43,7 +43,7 @@ import {
export function trustedDispatchEvent(
source: Source,
event: string,
element: string,
target: string,
) {
if (!event) {
return;
Expand All @@ -57,10 +57,10 @@ export function trustedDispatchEvent(
const customEvent = new Event(event);

let elToDispatch;
if (element === 'window') {
if (target === 'window') {
elToDispatch = window;
} else if (element) {
elToDispatch = document.querySelector(element);
} else if (target) {
elToDispatch = document.querySelector(target);
} else {
elToDispatch = document;
}
Expand All @@ -74,7 +74,7 @@ export function trustedDispatchEvent(
};

const wrapper = (
target: typeof EventTarget.prototype.addEventListener,
eventTarget: typeof EventTarget.prototype.addEventListener,
thisArg: Element,
args: string[],
) => {
Expand All @@ -85,7 +85,7 @@ export function trustedDispatchEvent(
dispatch();
}, 1);
}
return Reflect.apply(target, thisArg, args);
return Reflect.apply(eventTarget, thisArg, args);
};

const handler = {
Expand Down

0 comments on commit 3736c8d

Please sign in to comment.