Permalink
Browse files

* events.js: add event.js

  • Loading branch information...
1 parent 2dde5fe commit b1e4cf1594ba37571547fee6bb394ec121d42778 David Nolen committed May 19, 2010
Showing with 36 additions and 0 deletions.
  1. +36 −0 events.js
View
@@ -0,0 +1,36 @@
+(function() {
+ var root = this;
+ root.Events = _.Module({
+ name: "Events",
+
+ addEvent: function (type, fn) {
+ if(!this._events) this._events = {};
+ var events = this._events;
+ if(!events[type]) events[type] = [];
+ events[type].push(fn);
+ },
+
+ fireEvent: function(type, x) {
+ var events = this._events[type];
+ if(events) {
+ _(events).each(function(fn) {
+ fn(x);
+ });
+ }
+ },
+
+ removeEvent: function(type, fn) {
+ var events = this._events;
+ if(events && events[type]) {
+ events[type] = _(events[type]).without(fn);
+ }
+ },
+
+ removeEvents: function(type) {
+ var events = this._events;
+ if(events[type]) {
+ events[type] = [];
+ }
+ }
+ });
+})();

0 comments on commit b1e4cf1

Please sign in to comment.