Skip to content

Commit

Permalink
improved Events class, renamed 'what' to 'events'
Browse files Browse the repository at this point in the history
  • Loading branch information
kassens committed Oct 14, 2008
1 parent 4cfd9cb commit f75ea8d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
5 changes: 2 additions & 3 deletions Docs/Class/Class.Extras.md
Expand Up @@ -298,12 +298,11 @@ Removes all events of the given type from the stack of events of a Class instanc

### Syntax:

myClass.removeEvents([type]);
myClass.removeEvents([events]);

### Arguments:

1. type - (*string*, optional) The type of event to remove (e.g. 'complete'). If no type is specified, removes all events of all types.
1. what - (optional) If not passed removes all events of all types.
1. events - (optional) If not passed removes all events of all types.
- (*string*) The event name (e.g. 'success'). Removes all events of that type.
- (*object*) An object of type function pairs. Like the one passed to [addEvents](#Events:addEvents).

Expand Down
6 changes: 3 additions & 3 deletions Docs/Element/Element.Event.md
Expand Up @@ -141,13 +141,13 @@ Removes all events of a certain type from an Element. If no argument is passed,

### Syntax:

myElements.removeEvents([what]);
myElements.removeEvents([events]);

### Arguments:

1. what - (optional) if not passed removes all events from the element.
1. events - (optional) if not passed removes all events from the element.
- (*string*) The event name (e.g. 'click'). Removes all events of that type.
- (*object*) An object of type function pairs. Like the one passed to addEvents.
- (*object*) An object of type function pairs. Like the one passed to [Element:addEvent](#Element:addEvent).

### Returns:

Expand Down
15 changes: 8 additions & 7 deletions Source/Class/Class.Extras.js
Expand Up @@ -28,10 +28,11 @@ var Chain = new Class({

var Events = new Class({

$events: {},

addEvent: function(type, fn, internal){
type = Events.removeOn(type);
if (fn != $empty){
this.$events = this.$events || {};
this.$events[type] = this.$events[type] || [];
this.$events[type].include(fn);
if (internal) fn.internal = true;
Expand All @@ -55,19 +56,19 @@ var Events = new Class({

removeEvent: function(type, fn){
type = Events.removeOn(type);
if (!this.$events || !this.$events[type]) return this;
if (!this.$events[type]) return this;
if (!fn.internal) this.$events[type].erase(fn);
return this;
},

removeEvents: function(what){
if ($type(what) == 'object'){
for (var type in what) this.removeEvent(type, what[type]);
removeEvents: function(events){
if ($type(events) == 'object'){
for (var type in events) this.removeEvent(type, events[type]);
return this;
}
if (what) what = Events.removeOn(what);
if (events) events = Events.removeOn(events);
for (var type in this.$events){
if (what && what != type) continue;
if (events && events != type) continue;
var fns = this.$events[type];
for (var i = fns.length; i--; i) this.removeEvent(type, fns[i]);
}
Expand Down
20 changes: 10 additions & 10 deletions Source/Element/Element.Event.js
Expand Up @@ -65,19 +65,19 @@ Native.implement([Element, Window, Document], {
return this;
},

removeEvents: function(what){
if ($type(what) == 'object'){
for (var type in what) this.removeEvent(type, what[type]);
removeEvents: function(events){
if ($type(events) == 'object'){
for (var type in events) this.removeEvent(type, events[type]);
return this;
}
var events = this.retrieve('events');
if (!events) return this;
if (!what){
for (var type in events) this.removeEvents(type);
var attached = this.retrieve('events');
if (!attached) return this;
if (!events){
for (var type in attached) this.removeEvents(type);
this.eliminate('events');
} else if (events[what]){
while (events[what].keys[0]) this.removeEvent(what, events[what].keys[0]);
events[what] = null;
} else if (attached[events]){
while (attached[events].keys[0]) this.removeEvent(events, attached[events].keys[0]);
attached[events] = null;
}
return this;
},
Expand Down

0 comments on commit f75ea8d

Please sign in to comment.