Security News
CISA Brings KEV Data to GitHub
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
dom-event-helpers
Advanced tools
A super tiny DOM event helper library.
npm install dom-event-helpers
Note: This library is written as ES2015 code and published as such to
npm.
That means, code from dom-event-helpers
must not be excluded from
compilation.
If you're using webpack and babel, that could look like:
{
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules\/(?!dom-event-helpers)/,
loader: 'babel-loader'
}
]
}
}
import { ready, on, off, delegate, dispatch } from 'dom-event-helpers';
ready(listener: function): void
Registers a listener to be called once the DOM is ready.
Unlike DOMContentLoaded
, this also works when called after the DOM was loaded.
ready(function () {
console.log('DOM is ready!');
});
on(target: EventTarget, type: string, listener: EventListener[, options: object]): function
Registers a listener
for the event type
on target
with options
.
options
is always an object that specifies characteristics about the event
listener, see https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener.
If one of the options isn't supported by the browser, the behavior is as follows:
capture
: Always supported.once
: Will be polyfilled.passive
: Will be ignored.The function returns another function which can be used to unregister the event listener.
const target = document.querySelector('.my-button');
const listener = function () {
console.log('My Button clicked');
};
const options = {
once: true
};
const remove = on(
target,
'click',
listener,
options
);
remove(); // Remove event listener
off(target: EventTarget, type: string, listener: EventListener[, options: object]): void
Removes a listener previously registered via on()
.
off(
target,
'click',
listener,
options
);
delegate(target: EventTarget, type: string, selector: string, listener: EventListener[, options: object]): function
Registers a listener
for the event type
on target
with options
that
processes events from descendant elements of target
matching the specified
selector
.
The function returns another function which can be used to unregister the event listener.
const listener = function () {
console.log('My Button clicked');
};
const options = {
passive: true
};
const remove = delegate(
document, // Listen on document
'click',
'.my-button',
listener,
options
);
remove(); // Remove event listener
dispatch(target: EventTarget, type: string[, eventInit: CustomEventInit]): function
Dispatches a CustomEvent
type
at the specified target
optionally using the eventInit
options.
dispatch(document, 'click');
dispatch(
document.querySelector('.my-button'),
'my:event',
{
bubbles: true,
cancelable: true,
detail: {
foo: 'bar'
}
}
);
Copyright (c) 2018 Jan Sorgalla. Released under the MIT license.
FAQs
A super tiny DOM event helper library.
The npm package dom-event-helpers receives a total of 17 weekly downloads. As such, dom-event-helpers popularity was classified as not popular.
We found that dom-event-helpers demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.