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

dom-delegate

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dom-delegate - npm Package Compare versions

Comparing version 0.3.0 to 0.3.2

10

build/dom-delegate.js

@@ -20,4 +20,2 @@ (function(e){if("function"==typeof bootstrap)bootstrap("delegate",e);else if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeDelegate=e}else"undefined"!=typeof window?window.Delegate=e():global.Delegate=e()})(function(){var define,ses,bootstrap,module,exports;

function Delegate(root) {
var self = this;
if (root) {

@@ -36,3 +34,3 @@ this.root(root);

/** @type function() */
this.handle = function(event) { Delegate.prototype.handle.call(self, event); };
this.handle = Delegate.prototype.handle.bind(this);
}

@@ -369,5 +367,7 @@

*/
Delegate.prototype.matches = (function(p) {
Delegate.prototype.matches = (function(el) {
if (!el) return;
var p = el.prototype;
return (p.matchesSelector || p.webkitMatchesSelector || p.mozMatchesSelector || p.msMatchesSelector || p.oMatchesSelector);
}(HTMLElement.prototype));
}(HTMLElement));

@@ -374,0 +374,0 @@ /**

@@ -1,1 +0,1 @@

(function(e){if("function"==typeof bootstrap)bootstrap("delegate",e);else if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeDelegate=e}else"undefined"!=typeof window?window.Delegate=e():global.Delegate=e()})(function(){return function(e,t,r){function n(r,i){if(!t[r]){if(!e[r]){var s="function"==typeof require&&require;if(!i&&s)return s(r,!0);if(o)return o(r,!0);throw Error("Cannot find module '"+r+"'")}var a=t[r]={exports:{}};e[r][0].call(a.exports,function(t){var o=e[r][1][t];return n(o?o:t)},a,a.exports)}return t[r].exports}for(var o="function"==typeof require&&require,i=0;r.length>i;i++)n(r[i]);return n}({1:[function(e,t){"use strict";function r(e){var t=this;e&&this.root(e),this.listenerMap={},this.handle=function(e){r.prototype.handle.call(t,e)}}t.exports=r,r.tagsCaseSensitive=null,r.prototype.root=function(e){var t,r=this.listenerMap;if("string"==typeof e&&(e=document.querySelector(e)),this.rootElement)for(t in r)r.hasOwnProperty(t)&&this.rootElement.removeEventListener(t,this.handle,this.captureForType(t));if(!e||!e.addEventListener)return this.rootElement&&delete this.rootElement,this;this.rootElement=e;for(t in r)r.hasOwnProperty(t)&&this.rootElement.addEventListener(t,this.handle,this.captureForType(t));return this},r.prototype.captureForType=function(e){return"error"===e},r.prototype.on=function(e,t,n,o){var i,s,a,l;if(!e)throw new TypeError("Invalid event type: "+e);if("function"==typeof t&&(n=t,t=null,o=n),void 0===o&&(o=null),"function"!=typeof n)throw new TypeError("Handler must be a type of Function");return i=this.rootElement,s=this.listenerMap,s[e]||(i&&i.addEventListener(e,this.handle,this.captureForType(e)),s[e]=[]),t?/^[a-z]+$/i.test(t)?(null===r.tagsCaseSensitive&&(r.tagsCaseSensitive="i"===document.createElement("i").tagName),l=r.tagsCaseSensitive?t:t.toUpperCase(),a=this.matchesTag):/^#[a-z0-9\-_]+$/i.test(t)?(l=t.slice(1),a=this.matchesId):(l=t,a=this.matches):(l=null,a=this.matchesRoot.bind(this)),s[e].push({selector:t,eventData:o,handler:n,matcher:a,matcherParam:l}),this},r.prototype.off=function(e,t,r){var n,o,i,s,a;if("function"==typeof t&&(r=t,t=null),i=this.listenerMap,!e){for(a in i)i.hasOwnProperty(a)&&this.off(a,t,r);return this}if(s=i[e],!s||!s.length)return this;for(n=s.length-1;n>=0;n--)o=s[n],t&&t!==o.selector||r&&r!==o.handler||s.splice(n,1);return s.length||(delete i[e],this.rootElement&&this.rootElement.removeEventListener(e,this.handle,this.captureForType(e))),this},r.prototype.handle=function(e){var t,r,n,o,i,s,a,l="ftLabsDelegateIgnore";if(e[l]!==!0)for(a=e.target,a.nodeType===Node.TEXT_NODE&&(a=a.parentNode),n=this.rootElement,s=this.listenerMap[e.type],r=s.length;a&&r;){for(t=0;r>t&&(o=s[t],o);t++)if(o.matcher.call(a,o.matcherParam,a)&&(i=this.fire(e,a,o)),i===!1)return e[l]=!0,void 0;if(a===n)break;r=s.length,a=a.parentElement}},r.prototype.fire=function(e,t,r){var n,o;return null!==r.eventData?(o=e.data,e.data=r.eventData,n=r.handler.call(t,e,t),e.data=o):n=r.handler.call(t,e,t),n},r.prototype.matches=function(e){return e.matchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector||e.msMatchesSelector||e.oMatchesSelector}(HTMLElement.prototype),r.prototype.matchesTag=function(e,t){return e===t.tagName},r.prototype.matchesRoot=function(e,t){return this.rootElement===t},r.prototype.matchesId=function(e,t){return e===t.id},r.prototype.destroy=function(){this.off(),this.root()}},{}]},{},[1])(1)});
(function(e){if("function"==typeof bootstrap)bootstrap("delegate",e);else if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeDelegate=e}else"undefined"!=typeof window?window.Delegate=e():global.Delegate=e()})(function(){return function(e,t,r){function n(r,i){if(!t[r]){if(!e[r]){var s="function"==typeof require&&require;if(!i&&s)return s(r,!0);if(o)return o(r,!0);throw Error("Cannot find module '"+r+"'")}var a=t[r]={exports:{}};e[r][0].call(a.exports,function(t){var o=e[r][1][t];return n(o?o:t)},a,a.exports)}return t[r].exports}for(var o="function"==typeof require&&require,i=0;r.length>i;i++)n(r[i]);return n}({1:[function(e,t){"use strict";function r(e){e&&this.root(e),this.listenerMap={},this.handle=r.prototype.handle.bind(this)}t.exports=r,r.tagsCaseSensitive=null,r.prototype.root=function(e){var t,r=this.listenerMap;if("string"==typeof e&&(e=document.querySelector(e)),this.rootElement)for(t in r)r.hasOwnProperty(t)&&this.rootElement.removeEventListener(t,this.handle,this.captureForType(t));if(!e||!e.addEventListener)return this.rootElement&&delete this.rootElement,this;this.rootElement=e;for(t in r)r.hasOwnProperty(t)&&this.rootElement.addEventListener(t,this.handle,this.captureForType(t));return this},r.prototype.captureForType=function(e){return"error"===e},r.prototype.on=function(e,t,n,o){var i,s,a,l;if(!e)throw new TypeError("Invalid event type: "+e);if("function"==typeof t&&(n=t,t=null,o=n),void 0===o&&(o=null),"function"!=typeof n)throw new TypeError("Handler must be a type of Function");return i=this.rootElement,s=this.listenerMap,s[e]||(i&&i.addEventListener(e,this.handle,this.captureForType(e)),s[e]=[]),t?/^[a-z]+$/i.test(t)?(null===r.tagsCaseSensitive&&(r.tagsCaseSensitive="i"===document.createElement("i").tagName),l=r.tagsCaseSensitive?t:t.toUpperCase(),a=this.matchesTag):/^#[a-z0-9\-_]+$/i.test(t)?(l=t.slice(1),a=this.matchesId):(l=t,a=this.matches):(l=null,a=this.matchesRoot.bind(this)),s[e].push({selector:t,eventData:o,handler:n,matcher:a,matcherParam:l}),this},r.prototype.off=function(e,t,r){var n,o,i,s,a;if("function"==typeof t&&(r=t,t=null),i=this.listenerMap,!e){for(a in i)i.hasOwnProperty(a)&&this.off(a,t,r);return this}if(s=i[e],!s||!s.length)return this;for(n=s.length-1;n>=0;n--)o=s[n],t&&t!==o.selector||r&&r!==o.handler||s.splice(n,1);return s.length||(delete i[e],this.rootElement&&this.rootElement.removeEventListener(e,this.handle,this.captureForType(e))),this},r.prototype.handle=function(e){var t,r,n,o,i,s,a,l="ftLabsDelegateIgnore";if(e[l]!==!0)for(a=e.target,a.nodeType===Node.TEXT_NODE&&(a=a.parentNode),n=this.rootElement,s=this.listenerMap[e.type],r=s.length;a&&r;){for(t=0;r>t&&(o=s[t],o);t++)if(o.matcher.call(a,o.matcherParam,a)&&(i=this.fire(e,a,o)),i===!1)return e[l]=!0,void 0;if(a===n)break;r=s.length,a=a.parentElement}},r.prototype.fire=function(e,t,r){var n,o;return null!==r.eventData?(o=e.data,e.data=r.eventData,n=r.handler.call(t,e,t),e.data=o):n=r.handler.call(t,e,t),n},r.prototype.matches=function(e){if(e){var t=e.prototype;return t.matchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector||t.oMatchesSelector}}(HTMLElement),r.prototype.matchesTag=function(e,t){return e===t.tagName},r.prototype.matchesRoot=function(e,t){return this.rootElement===t},r.prototype.matchesId=function(e,t){return e===t.id},r.prototype.destroy=function(){this.off(),this.root()}},{}]},{},[1])(1)});

@@ -18,4 +18,2 @@ /*jshint browser:true, node:true*/

function Delegate(root) {
var self = this;
if (root) {

@@ -34,3 +32,3 @@ this.root(root);

/** @type function() */
this.handle = function(event) { Delegate.prototype.handle.call(self, event); };
this.handle = Delegate.prototype.handle.bind(this);
}

@@ -37,0 +35,0 @@

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

@@ -14,3 +14,3 @@ "description": "Create and manage a DOM event delegator.",

"type": "git",
"url": "git://github.com/ftlabs/dom-delegate.git"
"url": "git://github.com/ftlabs/ftdomdelegate.git"
},

@@ -17,0 +17,0 @@ "engines": {

@@ -1,4 +0,4 @@

# dom-delegate [![Build Status](https://travis-ci.org/ftlabs/dom-delegate.png?branch=master)](https://travis-ci.org/ftlabs/dom-delegate)
# ftdomdelegate [![Build Status](https://travis-ci.org/ftlabs/ftdomdelegate.png?branch=master)](https://travis-ci.org/ftlabs/ftdomdelegate)
FT's dom-delegate is a simple, easy-to-use 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](http://www.sitepoint.com/javascript-event-delegation-is-easier-than-you-think/).
FT's dom delegate library is a simple, easy-to-use 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](http://www.sitepoint.com/javascript-event-delegation-is-easier-than-you-think/).

@@ -37,3 +37,3 @@ Delegate is developed by [FT Labs](http://labs.ft.com/), part of the Financial Times.

Download the [production version](http://github.com/ftlabs/dom-delegate/raw/master/build/dom-delegate.min.js) (<1k gzipped) or the [development version](http://github.com/ftlabs/dom-delegate/raw/master/build/dom-delegate.js).
Download the [production version](http://github.com/ftlabs/ftdomdelegate/raw/master/build/dom-delegate.min.js) (<1k gzipped) or the [development version](http://github.com/ftlabs/dom-delegate/raw/master/build/dom-delegate.js).

@@ -92,3 +92,3 @@ ## Usage ##

```
$ cd dom-delegate/
$ cd ftdomdelegate/
$ buster static -c test/buster.js

@@ -155,8 +155,6 @@ Starting server on http://localhost:8282/

#### `element (Node|string)` ####
#### `element (Node)` ####
Set the delegate's root node or a selector string matching the root 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.
If no element or string passed in the root node will be deleted and the event listeners will be removed.
### .destroy() ###

@@ -163,0 +161,0 @@

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