Comparing version 0.4.1 to 0.4.2
@@ -5,3 +5,3 @@ { | ||
"description": "Custom Events", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"keywords": ["events"], | ||
@@ -8,0 +8,0 @@ "dependencies": {}, |
118
eve.js
@@ -24,2 +24,3 @@ // Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved. | ||
separator = /[\.\/]/, | ||
comaseparator = /\s*,\s*/, | ||
wildcard = "*", | ||
@@ -33,2 +34,17 @@ fun = function () {}, | ||
events = {n: {}}, | ||
firstDefined = function () { | ||
for (var i = 0, ii = this.length; i < ii; i++) { | ||
if (typeof this[i] != "undefined") { | ||
return this[i]; | ||
} | ||
} | ||
}, | ||
lastDefined = function () { | ||
var i = this.length; | ||
while (--i) { | ||
if (typeof this[i] != "undefined") { | ||
return this[i]; | ||
} | ||
} | ||
}, | ||
/*\ | ||
@@ -46,6 +62,6 @@ * eve | ||
= (object) array of returned values from the listeners | ||
= (object) array of returned values from the listeners. Array has two methods `.firstDefined()` and `.lastDefined()` to get first or last not `undefined` value. | ||
\*/ | ||
eve = function (name, scope) { | ||
name = String(name); | ||
name = String(name); | ||
var e = events, | ||
@@ -63,2 +79,4 @@ oldstop = stop, | ||
errors = []; | ||
out.firstDefined = firstDefined; | ||
out.lastDefined = lastDefined; | ||
current_event = name; | ||
@@ -109,6 +127,6 @@ stop = 0; | ||
current_event = ce; | ||
return out.length ? out : null; | ||
return out; | ||
}; | ||
// Undocumented. Debug only. | ||
eve._events = events; | ||
// Undocumented. Debug only. | ||
eve._events = events; | ||
/*\ | ||
@@ -177,4 +195,4 @@ * eve.listeners | ||
| eve.on("mouse", catchIt)(1); | ||
* This will ensure that `catchIt()` function will be called before `eatIt()`. | ||
* | ||
* This will ensure that `catchIt` function will be called before `eatIt`. | ||
* | ||
* If you want to put your handler before non-indexed handlers, specify a negative value. | ||
@@ -184,17 +202,24 @@ * Note: I assume most of the time you don’t need to worry about z-index, but it’s nice to have this feature “just in case”. | ||
eve.on = function (name, f) { | ||
name = String(name); | ||
if (typeof f != "function") { | ||
return function () {}; | ||
} | ||
var names = name.split(separator), | ||
e = events; | ||
name = String(name); | ||
if (typeof f != "function") { | ||
return function () {}; | ||
} | ||
var names = name.split(comaseparator); | ||
for (var i = 0, ii = names.length; i < ii; i++) { | ||
e = e.n; | ||
e = e.hasOwnProperty(names[i]) && e[names[i]] || (e[names[i]] = {n: {}}); | ||
(function (name) { | ||
var names = name.split(separator), | ||
e = events, | ||
exist; | ||
for (var i = 0, ii = names.length; i < ii; i++) { | ||
e = e.n; | ||
e = e.hasOwnProperty(names[i]) && e[names[i]] || (e[names[i]] = {n: {}}); | ||
} | ||
e.f = e.f || []; | ||
for (i = 0, ii = e.f.length; i < ii; i++) if (e.f[i] == f) { | ||
exist = true; | ||
break; | ||
} | ||
!exist && e.f.push(f); | ||
}(names[i])); | ||
} | ||
e.f = e.f || []; | ||
for (i = 0, ii = e.f.length; i < ii; i++) if (e.f[i] == f) { | ||
return fun; | ||
} | ||
e.f.push(f); | ||
return function (zIndex) { | ||
@@ -211,19 +236,19 @@ if (+zIndex == +zIndex) { | ||
* Returns function that will fire given event with optional arguments. | ||
* Arguments that will be passed to the result function will be also | ||
* concated to the list of final arguments. | ||
| el.onclick = eve.f("click", 1, 2); | ||
| eve.on("click", function (a, b, c) { | ||
| console.log(a, b, c); // 1, 2, [event object] | ||
| }); | ||
* Arguments that will be passed to the result function will be also | ||
* concated to the list of final arguments. | ||
| el.onclick = eve.f("click", 1, 2); | ||
| eve.on("click", function (a, b, c) { | ||
| console.log(a, b, c); // 1, 2, [event object] | ||
| }); | ||
> Arguments | ||
- event (string) event name | ||
- varargs (…) and any other arguments | ||
= (function) possible event handler function | ||
- event (string) event name | ||
- varargs (…) and any other arguments | ||
= (function) possible event handler function | ||
\*/ | ||
eve.f = function (event) { | ||
var attrs = [].slice.call(arguments, 1); | ||
return function () { | ||
eve.apply(null, [event, null].concat(attrs).concat([].slice.call(arguments, 0))); | ||
}; | ||
}; | ||
eve.f = function (event) { | ||
var attrs = [].slice.call(arguments, 1); | ||
return function () { | ||
eve.apply(null, [event, null].concat(attrs).concat([].slice.call(arguments, 0))); | ||
}; | ||
}; | ||
/*\ | ||
@@ -275,3 +300,3 @@ * eve.stop | ||
* Removes given function from the list of event listeners assigned to given name. | ||
* If no arguments specified all the events will be cleared. | ||
* If no arguments specified all the events will be cleared. | ||
** | ||
@@ -290,8 +315,15 @@ > Arguments | ||
eve.off = eve.unbind = function (name, f) { | ||
if (!name) { | ||
eve._events = events = {n: {}}; | ||
return; | ||
} | ||
var names = name.split(separator), | ||
e, | ||
if (!name) { | ||
eve._events = events = {n: {}}; | ||
return; | ||
} | ||
var names = name.split(comaseparator); | ||
if (names.length > 1) { | ||
for (var i = 0, ii = names.length; i < ii; i++) { | ||
eve.off(names[i], f); | ||
} | ||
return; | ||
} | ||
names = name.split(separator); | ||
var e, | ||
key, | ||
@@ -380,3 +412,3 @@ splice, | ||
}; | ||
(typeof module != "undefined" && module.exports) ? (module.exports = eve) : (typeof define != "undefined" ? (define("eve", [], function() { return eve; })) : (glob.eve = eve)); | ||
(typeof module != "undefined" && module.exports) ? (module.exports = eve) : (typeof define === "function" && define.amd ? (define("eve", [], function() { return eve; })) : (glob.eve = eve)); | ||
})(this); |
@@ -10,3 +10,3 @@ { | ||
"description" : "Simple custom events", | ||
"version" : "0.4.1", | ||
"version" : "0.4.2", | ||
@@ -13,0 +13,0 @@ "main" : "./eve.js", |
@@ -5,4 +5,2 @@ # Eve | ||
MIT Licence | ||
For use case look at e.html |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
27576
406
0
6