Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
ftdomdelegate
Advanced tools
FT's dom delegate library is a component for binding to events on all target elements matching the given selector, irrespective of whether anything exists in the DOM at registration time or not. This allows developers to implement the event delegation pattern.
To import ftdomdelegate:
import Delegate from 'ftdomdelegate';
let myDel = new Delegate(document.body);
To instantiate Delegate
on the body
and listen to some events:
function handleButtonClicks(event) {
// Do some things
}
function handleTouchMove(event) {
// Do some other things
}
document.addEventListener('DOMContentLoaded', function() {
var delegate = new Delegate(document.body);
delegate.on('click', 'button', handleButtonClicks);
// Listen to all touch move
// events that reach the body
delegate.on('touchmove', handleTouchMove);
});
A cool trick to handle images that fail to load:
function handleImageFail() {
this.style.display = 'none';
}
document.addEventListener('DOMContentLoaded', function() {
var delegate = new Delegate(document.body);
delegate.on('error', 'img', handleImageFail);
});
eventType (string)
The event to listen for e.g. mousedown
, mouseup
, mouseout
, error
, click
, etc.
selector (string)
Any kind of valid CSS selector supported by matchesSelector
. Some selectors, like #id
or tag
will use optimized functions internally that check for straight matches between the ID or tag name of elements.
null
is also accepted and will match the root element set by root()
. Passing a handler function into .on
's second argument is equivalent to .on(eventType, null, handler)
.
handler (function)
Function that will handle the specified event on elements matching the given selector. The function will receive two arguments: the native event object and the target element, in that order.
useCapture (boolean)
Whether or not to listen during the capturing (pass in true
) or bubbling phase (pass in false
). If no value passed in, it will fallback to a 'sensible default', which is true
for error
, blur
and focus
events and false
for all other types.
Calling off
with no arguments will remove all registered listeners, effectively resetting the instance.
eventType (string)
Remove handlers for events matching this type considering the other parameters.
selector (string)
Only remove listeners registered with the given selector, among the other arguments.
If null passed listeners registered to the root element will be removed. Passing in a function into off
's second parameter is equivalent to .off(eventType, null, handler[, useCapture])
(the third parameter will be ignored).
handler (function)
Only remove listeners registered with the given handler function, among the other arguments. If not provided, remove all handlers.
useCapture (boolean)
Only remove listeners with useCapture
set to the value passed in. If not provided, remove listeners added with useCapture
set to true
and false
.
element (Node)
Set the delegate's root node. If no element passed in the root node will be deleted and the event listeners will be removed.
Short hand for off() and root(), ie both with no parameters. Used to reset the delegate object.
FT DOM Delegate was developed by FT Labs, part of the Financial Times. It's now maintained by the Origami Team. The developers of ftdomdelegate were Matthew Andrews and Matthew Caruana Galizia. Test engineering by Sam Giles. The API is influenced by jQuery Live.
State | Major Version | Last Minor Release | Migration guide |
---|---|---|---|
✨ active | 4 | N/A | migrate to v4 |
⚠ maintained | 3 | 3.1.0 | migrate to v3 |
╳ deprecated | 2 | 2.2.1 | N/A |
╳ deprecated | 1 | 1.0.6 | N/A |
FAQs
FT's dom delegate library is a library for creating and binding to events on all target elements matching the given selector.
The npm package ftdomdelegate receives a total of 2,251 weekly downloads. As such, ftdomdelegate popularity was classified as popular.
We found that ftdomdelegate 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.