Socket
Socket
Sign inDemoInstall

dom-delegate

Package Overview
Dependencies
0
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 0.1.1

.travis.yml

6

_tests/buster.js

@@ -8,5 +8,5 @@ var config = module.exports;

"buster-coverage": {
outputDirectory: "build/logs/jscoverage", //Write to this directory instead of coverage
format: "lcov", //At the moment cobertura and lcov are the only ones available
combinedResultsOnly: true //Write one combined file instead of one for each browser
outputDirectory: "build/logs/jscoverage",
format: "lcov",
combinedResultsOnly: true
},

@@ -13,0 +13,0 @@ sources: [

@@ -282,18 +282,18 @@ /*global buster, assert, refute, Delegate*/

delegate.on('click', '#delegate-test-clickable', dataA, function(event) {
delegate.on('click', '#delegate-test-clickable', function(event) {
assert.equals(dataA, event.data);
spyA();
});
}, dataA);
delegate.on('click', '#delegate-test-clickable', undefined, function(event) {
delegate.on('click', '#delegate-test-clickable', function(event) {
refute.equals(dataA, event.data);
refute.equals(dataB, event.data);
spyB();
});
}, undefined);
delegate.on('click', '#delegate-test-clickable', null, function(event) {
delegate.on('click', '#delegate-test-clickable', function(event) {
refute.equals(dataA, event.data);
refute.equals(dataB, event.data);
spyC();
});
}, null);

@@ -306,6 +306,6 @@ delegate.on('click', '#delegate-test-clickable', function(event) {

delegate.on('click', '#delegate-test-clickable', dataB, function(event) {
delegate.on('click', '#delegate-test-clickable', function(event) {
assert.equals(dataB, event.data);
spyE();
});
}, dataB);

@@ -312,0 +312,0 @@ var element = document.getElementById('delegate-test-clickable');

{
"name": "delegate",
"description": "Create and manage a DOM event delegator.",
"version": "0.1.0",
"version": "0.1.1",
"main": "lib/delegate.js",

@@ -6,0 +6,0 @@ "scripts": [

/**
* @preserve Create and manage a DOM event delegator.
*
* @version 0.1.0
* @version 0.1.1
* @codingstandard ftlabs-jsv2

@@ -20,3 +20,3 @@ * @copyright The Financial Times Limited [All Rights Reserved]

* @constructor
* @param {Node|DOMWindow|string} root The root node, a window object or a selector string
* @param {Node|string} root The root node or a selector string matching the root node
*/

@@ -27,3 +27,3 @@ function Delegate(root) {

if (root && typeof root === 'string') {
if (typeof root === 'string') {
root = document.querySelector(root);

@@ -38,5 +38,5 @@ }

/**
* The root node or window object at which listeners are attached.
* The root node at which listeners are attached.
*
* @type Node|DOMWindow
* @type Node
*/

@@ -61,3 +61,3 @@ this.root = root;

* @protected
* @type boolean
* @type ?boolean
*/

@@ -86,7 +86,7 @@ Delegate.tagsCaseSensitive = null;

* @param {string} selector Only handle events on elements matching this selector
* @param {Object} [eventData] If this parameter is not specified, the third parameter must be the handler
* @param {function()} handler Handler function - event data passed here will be in event.data
* @param {Object} [eventData] Data to pass in event.data
* @returns {Delegate} This method is chainable
*/
Delegate.prototype.on = function(eventType, selector, eventData, handler) {
Delegate.prototype.on = function(eventType, selector, handler, eventData) {
'use strict';

@@ -106,3 +106,3 @@ var root, listenerMap, matcher, matcherParam, self = this, /** @const */ SEPARATOR = ' ';

eventType.split(SEPARATOR).forEach(function(singleEventType) {
self.on(singleEventType, selector, eventData, handler);
self.on(singleEventType, selector, handler, eventData);
});

@@ -113,8 +113,4 @@

if (handler === undefined) {
handler = eventData;
eventData = null;
// Normalise undefined eventData to null
} else if (eventData === undefined) {
if (eventData === undefined) {
eventData = null;

@@ -317,3 +313,2 @@ }

* @param {string} selector A CSS selector
* @returns boolean
*/

@@ -320,0 +315,0 @@ Delegate.prototype.matches = (function(p) {

{
"name": "dom-delegate",
"version": "0.1.0",
"version": "0.1.1",
"author": "FT Labs <enquiries@labs.ft.com> (http://labs.ft.com/)",

@@ -15,2 +15,5 @@ "description": "Create and manage a DOM event delegator.",

},
"scripts" : {
"test" : "node_modules/.bin/buster-test -c _tests/buster.js"
},
"keywords": [

@@ -21,4 +24,8 @@ "delegate",

],
"devDependencies": {
"buster": "~0.6.2",
"buster-coverage": "*"
},
"license": "MIT",
"homepage": "https://github.com/ftlabs/delegate"
}
# Delegate #
[![Build Status](https://travis-ci.org/ftlabs/delegate.png?branch=master)](https://travis-ci.org/ftlabs/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](http://www.sitepoint.com/javascript-event-delegation-is-easier-than-you-think/).

@@ -28,3 +30,3 @@

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

@@ -56,3 +58,3 @@

Installation via the [Node Package Manager](https://npmjs.org/package/fastclick) 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`.
Installation via the [Node Package Manager](https://npmjs.org/package/dom-delegate) 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`](https://npmjs.org/package/dom-delegate).

@@ -69,7 +71,20 @@ ## Tests ##

...then point your browser to http://localhost:8282/.
...then point your browser to http://localhost:8282/. To generate code coverage reports, for which [buster-coverage](https://github.com/ebi/buster-coverage) is required:
```
$ buster server
buster-server running on http://localhost:1111
```
Point your browser to http://localhost:1111 and capture it, then in another terminal tab:
```
$ buster test -c _tests/buster.js
```
The report in `build/logs/jscoverage/` can be processed using `genhtml`, which is installed with `lcov`.
## API ##
### .on(eventType, selector[, eventData], handler) ###
### .on(eventType, selector, handler[, eventData]) ###

@@ -84,6 +99,2 @@ #### `eventType (string)` ####

#### `eventData (*)` ####
If specified and non-null, will be made available in `event.data`.
#### `handler (function)` ####

@@ -93,2 +104,6 @@

#### `eventData (*)` ####
If defined and non-null, will be made available in `event.data`.
### .off([eventType][, selector][, handler]) ###

@@ -112,2 +127,2 @@

The lead developer of Delegate is [Matthew Caruana Galizia](http://twitter.com/mcaruanagalizia) at FT Labs. The API is influenced by [jQuery Live](http://api.jquery.com/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.
The lead developer of Delegate is [Matthew Caruana Galizia](http://twitter.com/mcaruanagalizia) at FT Labs. Test engineering by [Sam Giles](https://twitter.com/SamuelGiles_). The API is influenced by [jQuery Live](http://api.jquery.com/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.
SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc