Commit 4d8dc216 by Tomas Alabes

Modified our Eve so it works with amd and globally

parent 7fd4df74
......@@ -39,7 +39,7 @@ module.exports = function(grunt) {
dist: {
dest: "<%= pkg.name %>.js",
src: [
"node_modules/eve/eve.js",
"dev/eve.js",
"dev/raphael.core.js",
"dev/raphael.svg.js",
"dev/raphael.vml.js",
......
{
"name": "raphael",
"version": "2.1.2",
"version": "2.1.4",
"description": "JavaScript Vector Library",
"main": "./dev",
"main": "raphael",
"repository": "git://github.com/DmitryBaranovskiy/raphael.git",
"keywords": [
"vector",
......
......@@ -2,7 +2,8 @@
require.config({
paths: {
raphael: '../raphael'
raphael: '../raphael'/*,
eve: '../bower_components/eve/eve'*/
}
});
......
This diff is collapsed. Click to expand it.
......@@ -7,7 +7,7 @@
<!-- Global use -->
<!-- To work with full version -->
<!--<script type="text/javascript" src="../raphael.js"></script>-->
<script type="text/javascript" src="../raphael.js"></script>
<!-- To work with minified version -->
<!--<script type="text/javascript" src="../raphael-min.js"></script>-->
......@@ -18,21 +18,20 @@
<!--<script type="text/javascript" src="raphael.core.js"></script>-->
<!--<script type="text/javascript" src="raphael.svg.js"></script>-->
<!--<script type="text/javascript" src="raphael.vml.js"></script>-->
<!--<script type="text/javascript" src="raphael.amd.js"></script>-->
<!-- Comment this script tag if you are testing with AMD -->
<!--<script type="text/javascript">
<script type="text/javascript">
// Initialize container when document is loaded
window.onload = function () {
paper = Raphael(0, 0, 640, 720, "container");
paper.circle(100, 100, 100); //example
};
//Work here, in a separate script file or via command line
</script>-->
</script>
<!-- AMD use -->
<script data-main="amdDev" src="require.js"></script>
<!-- Use amdDev.js to work with AMD and Raphael -->
<!-- You need to do a 'bower install -D' first to get requirejs -->
<!--<script data-main="amdDev" src="../bower_components/requirejs/require.js"></script>-->
</head>
<body>
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -16,8 +16,17 @@
// ├────────────────────────────────────────────────────────────┤ \\
// │ Author Dmitry Baranovskiy (http://dmitry.baranovskiy.com/) │ \\
// └────────────────────────────────────────────────────────────┘ \\
(function (glob) {
(function (glob, factory) {
if (typeof define === "function" && define.amd) {
define("eve", function() {
return factory();
});
} else if (typeof exports === "object") {
module.exports = factory();
} else {
glob.eve = factory();
}
}(this, function(){
var version = "0.4.2",
has = "hasOwnProperty",
separator = /[\.\/]/,
......@@ -42,9 +51,9 @@
- varargs (...) the rest of arguments will be sent to event handlers
= (object) array of returned values from the listeners
\*/
\*/
eve = function (name, scope) {
name = String(name);
name = String(name);
var e = events,
oldstop = stop,
args = Array.prototype.slice.call(arguments, 2),
......@@ -104,8 +113,8 @@
current_event = ce;
return out.length ? out : null;
};
// Undocumented. Debug only.
eve._events = events;
// Undocumented. Debug only.
eve._events = events;
/*\
* eve.listeners
[ method ]
......@@ -117,7 +126,7 @@
- name (string) name of the event, dot (`.`) or slash (`/`) separated
= (array) array of event handlers
\*/
\*/
eve.listeners = function (name) {
var names = name.split(separator),
e = events,
......@@ -149,7 +158,7 @@
}
return out;
};
/*\
* eve.on
[ method ]
......@@ -164,21 +173,21 @@
- name (string) name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards
- 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.
= (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", eatIt)(2);
| eve.on("mouse", scream);
| 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”.
\*/
\*/
eve.on = function (name, f) {
name = String(name);
if (typeof f != "function") {
return function () {};
}
name = String(name);
if (typeof f != "function") {
return function () {};
}
var names = name.split(separator),
e = events;
for (var i = 0, ii = names.length; i < ii; i++) {
......@@ -201,29 +210,29 @@
[ method ]
**
* 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
\*/
eve.f = function (event) {
var attrs = [].slice.call(arguments, 1);
return function () {
eve.apply(null, [event, null].concat(attrs).concat([].slice.call(arguments, 0)));
};
};
- 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.stop
[ method ]
**
* Is used inside an event handler to stop the event, preventing any subsequent listeners from firing.
\*/
\*/
eve.stop = function () {
stop = 1;
};
......@@ -240,7 +249,7 @@
= (string) name of the event, if `subname` is not specified
* or
= (boolean) `true`, if current event’s name contains `subname`
\*/
\*/
eve.nt = function (subname) {
if (subname) {
return new RegExp("(?:\\.|\\/|^)" + subname + "(?:\\.|\\/|$)").test(current_event);
......@@ -255,7 +264,7 @@
**
**
= (array) names of the event
\*/
\*/
eve.nts = function () {
return current_event.split(separator);
};
......@@ -264,24 +273,24 @@
[ method ]
**
* 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.
**
> Arguments
**
- name (string) name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards
- f (function) event handler function
\*/
\*/
/*\
* eve.unbind
[ method ]
**
* See @eve.off
\*/
\*/
eve.off = eve.unbind = function (name, f) {
if (!name) {
eve._events = events = {n: {}};
return;
}
if (!name) {
eve._events = events = {n: {}};
return;
}
var names = name.split(separator),
e,
key,
......@@ -349,7 +358,7 @@
- f (function) event handler function
**
= (function) same return function as @eve.on
\*/
\*/
eve.once = function (name, f) {
var f2 = function () {
eve.unbind(name, f2);
......@@ -362,13 +371,14 @@
[ property (string) ]
**
* Current version of the library.
\*/
\*/
eve.version = version;
eve.toString = function () {
return "You are running Eve " + version;
};
(typeof module != "undefined" && module.exports) ? (module.exports = eve) : (typeof define != "undefined" ? (define("eve", [], function() { return eve; })) : (glob.eve = eve));
})(this);
return eve;
}));
// ┌────────────────────────────────────────────────────────────────────┐ \\
// │ Raphaël 2.1.4 - JavaScript Vector Library │ \\
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment