Comparing version 0.4.2 to 0.5.0
@@ -5,3 +5,3 @@ { | ||
"description": "Custom Events", | ||
"version": "0.4.2", | ||
"version": "0.5.0", | ||
"keywords": ["events"], | ||
@@ -8,0 +8,0 @@ "dependencies": {}, |
55
eve.js
@@ -15,3 +15,3 @@ // Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved. | ||
// ┌────────────────────────────────────────────────────────────┐ \\ | ||
// │ Eve 0.4.2 - JavaScript Events Library │ \\ | ||
// │ Eve 0.5.0 - JavaScript Events Library │ \\ | ||
// ├────────────────────────────────────────────────────────────┤ \\ | ||
@@ -22,3 +22,3 @@ // │ Author Dmitry Baranovskiy (http://dmitry.baranovskiy.com/) │ \\ | ||
(function (glob) { | ||
var version = "0.4.2", | ||
var version = "0.5.0", | ||
has = "hasOwnProperty", | ||
@@ -50,2 +50,7 @@ separator = /[\.\/]/, | ||
}, | ||
objtos = Object.prototype.toString, | ||
Str = String, | ||
isArray = Array.isArray || function (ar) { | ||
return ar instanceof Array || objtos.call(ar) == "[object Array]"; | ||
}; | ||
/*\ | ||
@@ -66,3 +71,2 @@ * eve | ||
eve = function (name, scope) { | ||
name = String(name); | ||
var e = events, | ||
@@ -144,3 +148,3 @@ oldstop = stop, | ||
eve.listeners = function (name) { | ||
var names = name.split(separator), | ||
var names = isArray(name) ? name : name.split(separator), | ||
e = events, | ||
@@ -175,4 +179,22 @@ item, | ||
}; | ||
/*\ | ||
* eve.separator | ||
[ method ] | ||
* If for some reasons you don’t like default separators (`.` or `/`) you can specify yours | ||
* here. Be aware that if you pass a string longer than one character it will be treated as | ||
* a list of characters. | ||
- separator (string) new separator. Empty string resets to default: `.` or `/`. | ||
\*/ | ||
eve.separator = function (sep) { | ||
if (sep) { | ||
sep = Str(sep).replace(/(?=[\.\^\]\[\-])/g, "\\"); | ||
sep = "[" + sep + "]"; | ||
separator = new RegExp(sep); | ||
} else { | ||
separator = /[\.\/]/; | ||
} | ||
}; | ||
/*\ | ||
* eve.on | ||
@@ -186,7 +208,8 @@ [ method ] | ||
** | ||
> Arguments | ||
** | ||
- name (string) name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards | ||
- f (function) event handler function | ||
** | ||
- name (array) if you don’t want to use separators, you can use array of strings | ||
- f (function) event handler function | ||
** | ||
= (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. | ||
@@ -203,10 +226,9 @@ > Example: | ||
eve.on = function (name, f) { | ||
name = String(name); | ||
if (typeof f != "function") { | ||
return function () {}; | ||
} | ||
var names = name.split(comaseparator); | ||
var names = isArray(name) ? (isArray(name[0]) ? name : [name]) : Str(name).split(comaseparator); | ||
for (var i = 0, ii = names.length; i < ii; i++) { | ||
(function (name) { | ||
var names = name.split(separator), | ||
var names = isArray(name) ? name : Str(name).split(separator), | ||
e = events, | ||
@@ -278,6 +300,7 @@ exist; | ||
eve.nt = function (subname) { | ||
var cur = isArray(current_event) ? current_event.join(".") : current_event; | ||
if (subname) { | ||
return new RegExp("(?:\\.|\\/|^)" + subname + "(?:\\.|\\/|$)").test(current_event); | ||
return new RegExp("(?:\\.|\\/|^)" + subname + "(?:\\.|\\/|$)").test(cur); | ||
} | ||
return current_event; | ||
return cur; | ||
}; | ||
@@ -294,3 +317,3 @@ /*\ | ||
eve.nts = function () { | ||
return current_event.split(separator); | ||
return isArray(current_event) ? current_event : current_event.split(separator); | ||
}; | ||
@@ -320,3 +343,3 @@ /*\ | ||
} | ||
var names = name.split(comaseparator); | ||
var names = isArray(name) ? (isArray(name[0]) ? name : [name]) : Str(name).split(comaseparator); | ||
if (names.length > 1) { | ||
@@ -328,3 +351,3 @@ for (var i = 0, ii = names.length; i < ii; i++) { | ||
} | ||
names = name.split(separator); | ||
names = isArray(name) ? name : Str(name).split(separator); | ||
var e, | ||
@@ -399,3 +422,3 @@ key, | ||
var f2 = function () { | ||
eve.unbind(name, f2); | ||
eve.off(name, f2); | ||
return f.apply(this, arguments); | ||
@@ -402,0 +425,0 @@ }; |
@@ -10,3 +10,3 @@ { | ||
"description" : "Simple custom events", | ||
"version" : "0.4.2", | ||
"version" : "0.5.0", | ||
@@ -13,0 +13,0 @@ "main" : "./eve.js", |
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
28753
428