good-listener
Advanced tools
Comparing version 1.1.1 to 1.1.2
{ | ||
"name": "good-listener", | ||
"description": "A more versatile way of adding & removing event listeners", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "main": "dist/good-listener.js", |
@@ -58,3 +58,3 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.listen = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
/** | ||
* Delegates event `type` to `selector`. | ||
* Delegates event to a selector. | ||
* | ||
@@ -68,14 +68,9 @@ * @param {Element} element | ||
function delegate(element, selector, type, callback) { | ||
this.element = element; | ||
this.selector = selector; | ||
this.type = type; | ||
this.callback = callback; | ||
var listenerFn = listener.apply(this, arguments); | ||
var cachedListener = listener.bind(this); | ||
element.addEventListener(type, listenerFn); | ||
element.addEventListener(type, cachedListener); | ||
return { | ||
destroy: function() { | ||
element.removeEventListener(type, cachedListener); | ||
element.removeEventListener(type, listenerFn); | ||
} | ||
@@ -86,15 +81,21 @@ } | ||
/** | ||
* Finds closest match and invokes `callback(e)`. | ||
* Finds closest match and invokes callback. | ||
* | ||
* @param {Event} e | ||
* @param {Element} element | ||
* @param {String} selector | ||
* @param {String} type | ||
* @param {Function} callback | ||
* @return {Function} | ||
*/ | ||
function listener(e) { | ||
var delegateTarget = closest(e.target, selector, true); | ||
function listener(element, selector, type, callback) { | ||
return function(e) { | ||
var delegateTarget = closest(e.target, selector, true); | ||
if (delegateTarget) { | ||
Object.defineProperty(e, 'target', { | ||
value: delegateTarget | ||
}); | ||
if (delegateTarget) { | ||
Object.defineProperty(e, 'target', { | ||
value: delegateTarget | ||
}); | ||
callback.call(element, e); | ||
callback.call(element, e); | ||
} | ||
} | ||
@@ -101,0 +102,0 @@ } |
{ | ||
"name": "good-listener", | ||
"description": "A more versatile way of adding & removing event listeners", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"repository": "zenorocha/good-listener", | ||
@@ -12,3 +12,3 @@ "main": "src/listen.js", | ||
"dependencies": { | ||
"delegate": "^2.0.1" | ||
"delegate": "^2.0.2" | ||
}, | ||
@@ -15,0 +15,0 @@ "devDependencies": { |
26213
17
589
Updateddelegate@^2.0.2