Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dom-delegate

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dom-delegate

Create and manage a DOM event delegator.

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.3K
decreased by-2.54%
Maintainers
1
Weekly downloads
 
Created
Source

Delegate

Delegate is a simple, easy-to-use component for binding to events on all target elements matching the given selector, irrespective of whether they exist at registration time or not. This allows developers to implement the event delegation pattern.

Delegate is developed by FT Labs, part of the Financial Times.

Compatibility

The library has been deployed as part of the FT Web App and is tried and tested on the following browsers:

  • Safari 5 +
  • Mobile Safari on iOS 3 +
  • Chrome 1 +
  • Chrome on iOS 5 +
  • Chrome on Android 4.0 +
  • Opera 11.5 +
  • Opera Mobile 11.5 +
  • Firefox 4 +
  • Internet Explorer 9 +
  • Android Browser on Android 2 +
  • PlayBook OS 1 +

Usage

Include delegate.js in your JavaScript bundle or add it to your HTML page like this:

<script type='application/javascript' src='/path/to/fastclick.js'></script>

The script must be loaded prior to instantiating a Delegate object.

To instantiate Delegate on the body:

window.addEventListener('load', function() {
	new Delegate(document.body);
}, false);

Google Closure Compiler

Delegate supports compilation with ADVANCED_OPTIMIZATIONS ('advanced mode'), which should reduce its size by about 70% (60% gzipped). Note that exposure of the Delegate variable isn't forced therefore you must compile it along with all of your code.

AMD

Delegate has AMD (Asynchronous Module Definition) support. This allows it to be lazy-loaded with an AMD loader, such as RequireJS.

Component

Delegate comes with support for installation via the Component package manager.

NPM

Installation via the Node Package Manager is supported, although Component is preferred as this is not strictly a Node packagage. Due to a naming conflict, Delegate is available as dom-delegate.

Tests

Tests are run using buster and sit in _tests/. To run the tests statically:

$ cd delegate/
$ buster static -c _tests/buster.js
Starting server on http://localhost:8282/

...then point your browser to http://localhost:8282/.

API

.on(eventType, selector[, eventData], handler)

eventType (string)

Space-separated list of events to listen for e.g. mousedown mouseup mouseout or click.

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.

eventData (*)

If specified and non-null, will be made available in event.data.

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.

.off([eventType][, selector][, handler])

Calling off with no arguments will remove all registered listeners, effectively resetting the instance.

eventType (string)

Remove handlers for events matching these types, in a space-separated list, considering the other parameters.

selector (string)

Only remove listeners registered with the given selector, among the other arguments.

handler (function)

Only remove listeners registered with the given handler function, among the other arguments.

Credits and collaboration

The lead developer of Delegate is Matthew Caruana Galizia at FT Labs. The API is influenced by jQuery Live. All open source code released by FT Labs is licenced under the MIT licence. We welcome comments, feedback and suggestions. Please feel free to raise an issue or pull request. Enjoy.

Keywords

FAQs

Package last updated on 08 Jan 2013

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc