Comparing version 0.2.4 to 0.3.5
141
eve.js
@@ -1,10 +0,10 @@ | ||
/* | ||
* Eve 0.2.4 - JavaScript Events Library | ||
* | ||
* Copyright (c) 2011 Dmitry Baranovskiy (http://dmitry.baranovskiy.com/) | ||
* Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license. | ||
*/ | ||
// ┌──────────────────────────────────────────────────────────────────────────────────────┐ \\ | ||
// │ Eve 0.3.5 - JavaScript Events Library │ \\ | ||
// ├──────────────────────────────────────────────────────────────────────────────────────┤ \\ | ||
// │ Copyright (c) 2008-2012 Dmitry Baranovskiy (http://dmitry.baranovskiy.com/) │ \\ | ||
// │ Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license. │ \\ | ||
// └──────────────────────────────────────────────────────────────────────────────────────┘ \\ | ||
(function (glob) { | ||
var version = "0.2.4", | ||
var version = "0.3.5", | ||
has = "hasOwnProperty", | ||
@@ -18,2 +18,3 @@ separator = /[\.\/]/, | ||
current_event, | ||
stop, | ||
events = {n: {}}, | ||
@@ -23,19 +24,16 @@ /*\ | ||
[ method ] | ||
** | ||
* Fires event with given `name`, given scope and other parameters. | ||
** | ||
> Arguments | ||
** | ||
- name (string) name of the event, dot (`.`) or slash (`/`) separated | ||
- name (string) name of the *event*, dot (`.`) or slash (`/`) separated | ||
- scope (object) context for the event handlers | ||
- varargs (...) the rest of arguments will be sent to event handlers | ||
** | ||
= (array) array of errors, if any. Each element of the array is in format: | ||
o { | ||
o error (string) error message | ||
o func (function) handler that caused error | ||
o } | ||
= (object) array of returned values from the listeners | ||
\*/ | ||
eve = function (name, scope) { | ||
var e = events, | ||
oldstop = stop, | ||
args = Array.prototype.slice.call(arguments, 2), | ||
@@ -48,4 +46,7 @@ listeners = eve.listeners(name), | ||
queue = {}, | ||
out = [], | ||
ce = current_event, | ||
errors = []; | ||
current_event = name; | ||
stop = 0; | ||
for (var i = 0, ii = listeners.length; i < ii; i++) if ("zIndex" in listeners[i]) { | ||
@@ -60,4 +61,6 @@ indexed.push(listeners[i].zIndex); | ||
l = queue[indexed[z++]]; | ||
if (l.apply(scope, args) === f) { | ||
return f; | ||
out.push(l.apply(scope, args)); | ||
if (stop) { | ||
stop = oldstop; | ||
return out; | ||
} | ||
@@ -69,4 +72,5 @@ } | ||
if (l.zIndex == indexed[z]) { | ||
if (l.apply(scope, args) === f) { | ||
return f; | ||
out.push(l.apply(scope, args)); | ||
if (stop) { | ||
break; | ||
} | ||
@@ -76,4 +80,5 @@ do { | ||
l = queue[indexed[z]]; | ||
if (l && l.apply(scope, args) === f) { | ||
return f; | ||
l && out.push(l.apply(scope, args)); | ||
if (stop) { | ||
break; | ||
} | ||
@@ -85,8 +90,14 @@ } while (l) | ||
} else { | ||
if (l.apply(scope, args) === f) { | ||
return f; | ||
out.push(l.apply(scope, args)); | ||
if (stop) { | ||
break; | ||
} | ||
} | ||
} | ||
stop = oldstop; | ||
current_event = ce; | ||
return out.length ? out : null; | ||
}; | ||
// Undocumented. Debug only. | ||
eve._events = events; | ||
/*\ | ||
@@ -150,9 +161,10 @@ * eve.listeners | ||
** | ||
= (function) returned function accept one number parameter that represents z-index of the handler. It is optional feature and only used when you need to ensure that some subset of handlers will be invoked in a given order, despite of the order of assignment. | ||
= (function) returned function accepts a single numeric parameter that represents z-index of the handler. It is an optional feature and only used when you need to ensure that some subset of handlers will be invoked in a given order, despite of the order of assignment. | ||
> Example: | ||
| eve.on("mouse", eat)(2); | ||
| eve.on("mouse", eatIt)(2); | ||
| eve.on("mouse", scream); | ||
| eve.on("mouse", catch)(1); | ||
* This will ensure that `catch` function will be called before `eat`. | ||
* If you want to put you hadler before not indexed handlers specify negative value. | ||
| eve.on("mouse", catchIt)(1); | ||
* 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. | ||
* 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”. | ||
@@ -165,4 +177,3 @@ \*/ | ||
e = e.n; | ||
!e[names[i]] && (e[names[i]] = {n: {}}); | ||
e = e[names[i]]; | ||
e = e[names[i]] || (e[names[i]] = {n: {}}); | ||
} | ||
@@ -181,2 +192,11 @@ e.f = e.f || []; | ||
/*\ | ||
* eve.stop | ||
[ method ] | ||
** | ||
* Is used inside an event handler to stop the event, preventing any subsequent listeners from firing. | ||
\*/ | ||
eve.stop = function () { | ||
stop = 1; | ||
}; | ||
/*\ | ||
* eve.nt | ||
@@ -202,6 +222,7 @@ [ method ] | ||
/*\ | ||
* eve.unbind | ||
* eve.off | ||
[ method ] | ||
** | ||
* Removes given function from the list of event listeners assigned to given name. | ||
* If no arguments specified all the events will be cleared. | ||
** | ||
@@ -213,3 +234,13 @@ > Arguments | ||
\*/ | ||
eve.unbind = function (name, f) { | ||
/*\ | ||
* eve.unbind | ||
[ method ] | ||
** | ||
* See @eve.off | ||
\*/ | ||
eve.off = eve.unbind = function (name, f) { | ||
if (!name) { | ||
eve._events = events = {n: {}}; | ||
return; | ||
} | ||
var names = name.split(separator), | ||
@@ -219,5 +250,6 @@ e, | ||
splice, | ||
i, ii, j, jj, | ||
cur = [events]; | ||
for (var i = 0, ii = names.length; i < ii; i++) { | ||
for (var j = 0; j < cur.length; j += splice.length - 2) { | ||
for (i = 0, ii = names.length; i < ii; i++) { | ||
for (j = 0; j < cur.length; j += splice.length - 2) { | ||
splice = [j, 1]; | ||
@@ -242,4 +274,4 @@ e = cur[j].n; | ||
if (e.f) { | ||
for (i = 0, ii = e.f.length; i < ii; i++) if (e.f[i] == f) { | ||
e.f.splice(i, 1); | ||
for (j = 0, jj = e.f.length; j < jj; j++) if (e.f[j] == f) { | ||
e.f.splice(j, 1); | ||
break; | ||
@@ -251,4 +283,4 @@ } | ||
var funcs = e.n[key].f; | ||
for (i = 0, ii = funcs.length; i < ii; i++) if (funcs[i] == f) { | ||
funcs.splice(i, 1); | ||
for (j = 0, jj = funcs.length; j < jj; j++) if (funcs[j] == f) { | ||
funcs.splice(j, 1); | ||
break; | ||
@@ -269,2 +301,27 @@ } | ||
/*\ | ||
* eve.once | ||
[ method ] | ||
** | ||
* Binds given event handler with a given name to only run once then unbind itself. | ||
| eve.once("login", f); | ||
| eve("login"); // triggers f | ||
| eve("login"); // no listeners | ||
* Use @eve to trigger the listener. | ||
** | ||
> Arguments | ||
** | ||
- name (string) name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards | ||
- f (function) event handler function | ||
** | ||
= (function) same return function as @eve.on | ||
\*/ | ||
eve.once = function (name, f) { | ||
var f2 = function () { | ||
var res = f.apply(this, arguments); | ||
eve.unbind(name, f2); | ||
return res; | ||
}; | ||
return eve.on(name, f2); | ||
}; | ||
/*\ | ||
* eve.version | ||
@@ -279,3 +336,3 @@ [ property (string) ] | ||
}; | ||
(typeof module != "undefined" && module.exports) ? (module.exports = eve) : (glob.eve = eve); | ||
})(this); | ||
(typeof module != "undefined" && module.exports) ? (module.exports = eve) : (typeof define != "undefined" ? (define("eve", [], function() { return eve; })) : (glob.eve = eve)); | ||
})(this); |
@@ -1,7 +0,7 @@ | ||
/* | ||
* Eve 0.2.3 - JavaScript Events Library | ||
* | ||
* Copyright (c) 2011 Dmitry Baranovskiy (http://dmitry.baranovskiy.com/) | ||
* Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license. | ||
*/ | ||
var eve=function(){var a="0.2.3",b="hasOwnProperty",c=/[\.\/]/,d="*",e=function(){},f=function(a,b){return a-b},g,h={n:{}},i=function(a,b){var c=h,d=Array.prototype.slice.call(arguments,2),e=i.listeners(a),j=0,k,l=[],m={},n=[];g=a;for(var o=0,p=e.length;o<p;o++)"zIndex"in e[o]&&(l.push(e[o].zIndex),e[o].zIndex<0&&(m[e[o].zIndex]=e[o]));l.sort(f);while(l[j]<0){k=m[l[j++]];if(k.apply(b,d)===!1)return}for(o=0;o<p;o++){k=e[o];if("zIndex"in k)if(k.zIndex==l[j]){if(k.apply(b,d)===!1)return;do{j++,k=m[l[j]];if(k&&k.apply(b,d)===!1)return}while(k)}else m[k.zIndex]=k;else if(k.apply(b,d)===!1)return}};i.listeners=function(a){var b=a.split(c),e=h,f,g,i,j,k,l,m,n,o=[e],p=[];for(j=0,k=b.length;j<k;j++){n=[];for(l=0,m=o.length;l<m;l++){e=o[l].n,g=[e[b[j]],e[d]],i=2;while(i--)f=g[i],f&&(n.push(f),p=p.concat(f.f||[]))}o=n}return p},i.on=function(a,b){var d=a.split(c),f=h;for(var g=0,i=d.length;g<i;g++)f=f.n,!f[d[g]]&&(f[d[g]]={n:{}}),f=f[d[g]];f.f=f.f||[];for(g=0,i=f.f.length;g<i;g++)if(f.f[g]==b)return e;f.f.push(b);return function(a){+a==+a&&(b.zIndex=+a)}},i.nt=function(a){if(a)return(new RegExp("(?:\\.|\\/|^)"+a+"(?:\\.|\\/|$)")).test(g);return g},i.unbind=function(a,e){var f=a.split(c),g,i,j,k=[h];for(var l=0,m=f.length;l<m;l++)for(var n=0;n<k.length;n+=j.length-2){j=[n,1],g=k[n].n;if(f[l]!=d)g[f[l]]&&j.push(g[f[l]]);else for(i in g)g[b](i)&&j.push(g[i]);k.splice.apply(k,j)}for(l=0,m=k.length;l<m;l++){g=k[l];while(g.n){if(e){if(g.f){for(l=0,m=g.f.length;l<m;l++)if(g.f[l]==e){g.f.splice(l,1);break}!g.f.length&&delete g.f}for(i in g.n)if(g.n[b](i)&&g.n[i].f){var o=g.n[i].f;for(l=0,m=o.length;l<m;l++)if(o[l]==e){o.splice(l,1);break}!o.length&&delete g.n[i].f}}else{delete g.f;for(i in g.n)g.n[b](i)&&g.n[i].f&&delete g.n[i].f}g=g.n}}},i.version=a,i.toString=function(){return"You are running Eve "+a};return i}();typeof exports!="undefined"&&exports!=null&&(exports.eve=eve) | ||
// ┌──────────────────────────────────────────────────────────────────────────────────────┐ \\ | ||
// │ Eve 0.3.2 - JavaScript Events Library │ \\ | ||
// ├──────────────────────────────────────────────────────────────────────────────────────┤ \\ | ||
// │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://dmitry.baranovskiy.com/) │ \\ | ||
// │ Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license. │ \\ | ||
// └──────────────────────────────────────────────────────────────────────────────────────┘ \\ | ||
(function(a){var b="0.3.2",c="hasOwnProperty",d=/[\.\/]/,e="*",f=function(){},g=function(a,b){return a-b},h,i,j={n:{}},k=function(a,b){var c=j,d=i,e=Array.prototype.slice.call(arguments,2),f=k.listeners(a),l=0,m=!1,n,o=[],p={},q=[],r=[];h=a,i=0;for(var s=0,t=f.length;s<t;s++)"zIndex"in f[s]&&(o.push(f[s].zIndex),f[s].zIndex<0&&(p[f[s].zIndex]=f[s]));o.sort(g);while(o[l]<0){n=p[o[l++]],q.push(n.apply(b,e));if(i){i=d;return q}}for(s=0;s<t;s++){n=f[s];if("zIndex"in n)if(n.zIndex==o[l]){q.push(n.apply(b,e));if(i){i=d;return q}do{l++,n=p[o[l]],n&&q.push(n.apply(b,e));if(i){i=d;return q}}while(n)}else p[n.zIndex]=n;else{q.push(n.apply(b,e));if(i){i=d;return q}}}i=d;return q.length?q:null};k.listeners=function(a){var b=a.split(d),c=j,f,g,h,i,k,l,m,n,o=[c],p=[];for(i=0,k=b.length;i<k;i++){n=[];for(l=0,m=o.length;l<m;l++){c=o[l].n,g=[c[b[i]],c[e]],h=2;while(h--)f=g[h],f&&(n.push(f),p=p.concat(f.f||[]))}o=n}return p},k.on=function(a,b){var c=a.split(d),e=j;for(var g=0,h=c.length;g<h;g++)e=e.n,!e[c[g]]&&(e[c[g]]={n:{}}),e=e[c[g]];e.f=e.f||[];for(g=0,h=e.f.length;g<h;g++)if(e.f[g]==b)return f;e.f.push(b);return function(a){+a==+a&&(b.zIndex=+a)}},k.stop=function(){i=1},k.nt=function(a){if(a)return(new RegExp("(?:\\.|\\/|^)"+a+"(?:\\.|\\/|$)")).test(h);return h},k.unbind=function(a,b){var f=a.split(d),g,h,i,k=[j];for(var l=0,m=f.length;l<m;l++)for(var n=0;n<k.length;n+=i.length-2){i=[n,1],g=k[n].n;if(f[l]!=e)g[f[l]]&&i.push(g[f[l]]);else for(h in g)g[c](h)&&i.push(g[h]);k.splice.apply(k,i)}for(l=0,m=k.length;l<m;l++){g=k[l];while(g.n){if(b){if(g.f){for(n=0,jj=g.f.length;n<jj;n++)if(g.f[n]==b){g.f.splice(n,1);break}!g.f.length&&delete g.f}for(h in g.n)if(g.n[c](h)&&g.n[h].f){var o=g.n[h].f;for(n=0,jj=o.length;n<jj;n++)if(o[n]==b){o.splice(n,1);break}!o.length&&delete g.n[h].f}}else{delete g.f;for(h in g.n)g.n[c](h)&&g.n[h].f&&delete g.n[h].f}g=g.n}}},k.version=b,k.toString=function(){return"You are running Eve "+b},typeof module!="undefined"&&module.exports?module.exports=k:a.eve=k})(this) |
@@ -9,5 +9,5 @@ { | ||
}, | ||
"description" : "Simple custom events", | ||
"version" : "0.3.5", | ||
"version" : "0.2.4", | ||
"main" : "./eve.js", | ||
@@ -14,0 +14,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
334018
20
6747
0
1