Permalink
Browse files

adding object support for Class.removeEvents

  • Loading branch information...
kassens committed Oct 9, 2008
1 parent b9e824c commit f0b4c5f3985ef348f6a77d52a11425d48eb99a1a
Showing with 35 additions and 10 deletions.
  1. +1 −0 CHANGELOG
  2. +5 −2 Docs/Class/Class.Extras.md
  3. +1 −1 Docs/Element/Element.Event.md
  4. +10 −6 Source/Class/Class.Extras.js
  5. +18 −1 Specs/Class/Class.Extras.js
View
@@ -2,6 +2,7 @@
[ADD] Browser.Features.query to check if the Browser supports the new querySelector method on the document object
[ADD] Browser.Engine detection for WebKit version 525
[ADD] Element.removeEvents now also accepts an object
+[ADD] Class.removeEvents now also accepts an object
[CHG] Element.js has been refactored to make use of private variables wherever possible
[CHG] $unlink now returns an unlinked Hash instead of an object when a Hash is passed in
[CHG] Faster Element.hasChild
@@ -211,7 +211,7 @@ Adds an event to the Class instance's event stack.
Events Method: addEvents {#Events:addEvents}
------------------------------------------
-The same as [addEvent](#addEvent), but accepts an object to add multiple events at once.
+The same as [addEvent](#Events:addEvent), but accepts an object to add multiple events at once.
### Syntax:
@@ -303,6 +303,9 @@ Removes all events of the given type from the stack of events of a Class instanc
### 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.
+ - (*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).
### Returns:
@@ -393,4 +396,4 @@ Merges the default options of the Class with the options passed in.
[Fx.Tween]: /Fx/Fx.Tween
[Request]: /Request/Request
[Request.HTML]: /Request/Request.HTML
-[Events:removeEvent]: /Element/Element.Event/#Element:removeEvent
+[Events:removeEvent]: /Element/Element.Event/#Element:removeEvent
@@ -146,7 +146,7 @@ Removes all events of a certain type from an Element. If no argument is passed,
### Arguments:
1. what - (optional) if not passed removes all events from the element.
- - (*string*) The event name (e.g. 'click'). If undefined, removes all events.
+ - (*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.
### Returns:
@@ -60,12 +60,16 @@ var Events = new Class({
return this;
},
- removeEvents: function(type){
- if (type) type = Events.removeOn(type);
- for (var e in this.$events){
- if (type && type != e) continue;
- var fns = this.$events[e];
- for (var i = fns.length; i--; i) this.removeEvent(e, fns[i]);
+ removeEvents: function(what){
+ if ($type(what) == 'object'){
+ for (var type in what) this.removeEvent(type, what[type]);
+ return this;
+ }
+ if (what) what = Events.removeOn(what);
+ for (var type in this.$events){
+ if (what && what != type) continue;
+ var fns = this.$events[type];
+ for (var i = fns.length; i--; i) this.removeEvent(type, fns[i]);
}
return this;
}
@@ -135,8 +135,9 @@ describe("Events Class", {
},
"before each": function(){
+ Local.called = 0;
Local.fn = function(){
- return Local.EventsTest.called++;
+ return Local.called++;
};
},
@@ -212,6 +213,22 @@ describe("Events Class", {
var events = myTest.$events;
value_of(events["event1"].length).should_be(0);
value_of(events["event2"].length).should_be(0);
+ },
+
+ "should remove events with an object": function(){
+ var myTest = new Local.EventsTest();
+ var events = {
+ event1: Local.fn.create(),
+ event2: Local.fn.create()
+ };
+ myTest.addEvent('event1', Local.fn.create()).addEvents(events);
+ myTest.fireEvent('event1');
+ value_of(Local.called).should_be(2);
+ myTest.removeEvents(events);
+ myTest.fireEvent('event1');
+ value_of(Local.called).should_be(3);
+ myTest.fireEvent('event2');
+ value_of(Local.called).should_be(3);
}
});

0 comments on commit f0b4c5f

Please sign in to comment.