prototype: Make sure Element#stopObserving is always chainable.
This commit is contained in:
parent
14ea77ef39
commit
d2974cfca3
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Make sure Element#stopObserving is always chainable. [sam]
|
||||
|
||||
* Event.fire/Element#fire now returns the newly-fired event instead of the event's target element. [sam]
|
||||
|
||||
* Restrict Event.DOMEvents to include only events that can be supported in all browsers. [sam]
|
||||
|
|
12
src/event.js
12
src/event.js
|
@ -186,18 +186,20 @@ Object.extend(Event, (function() {
|
|||
var id = getEventID(element), name = getDOMEventName(eventName);
|
||||
|
||||
if (!handler && eventName) {
|
||||
return getWrappersForEventName(id, eventName).each(function(wrapper) {
|
||||
getWrappersForEventName(id, eventName).each(function(wrapper) {
|
||||
element.stopObserving(eventName, wrapper.handler);
|
||||
}) && false;
|
||||
});
|
||||
return element;
|
||||
|
||||
} else if (!eventName) {
|
||||
return Object.keys(getCacheForID(id)).each(function(eventName) {
|
||||
Object.keys(getCacheForID(id)).each(function(eventName) {
|
||||
element.stopObserving(eventName);
|
||||
}) && false;
|
||||
});
|
||||
return element;
|
||||
}
|
||||
|
||||
var wrapper = findWrapper(id, eventName, handler);
|
||||
if (!wrapper) return false;
|
||||
if (!wrapper) return element;
|
||||
|
||||
if (element.removeEventListener) {
|
||||
element.removeEventListener(name, wrapper, false);
|
||||
|
|
|
@ -183,6 +183,17 @@
|
|||
assertEqual(0, Event.cache[eventID].somethingHappened.length);
|
||||
}},
|
||||
|
||||
testStopObservingIsChainable: function() { with(this) {
|
||||
var span = $("span"), observer = function() { };
|
||||
span.observe("somethingHappened", observer);
|
||||
assertEqual(span, span.stopObserving("somethingHappened", observer));
|
||||
span.observe("somethingHappened", observer);
|
||||
assertEqual(span, span.stopObserving("somethingHappened"));
|
||||
span.observe("somethingHappened", observer);
|
||||
assertEqual(span, span.stopObserving());
|
||||
assertEqual(span, span.stopObserving()); // assert it again, after there are no observers
|
||||
}},
|
||||
|
||||
testDocumentContentLoadedEventFiresBeforeWindowLoad: function() { with(this) {
|
||||
assert(eventResults.contentLoaded, "contentLoaded");
|
||||
assert(eventResults.contentLoaded.endOfDocument, "contentLoaded.endOfDocument");
|
||||
|
|
Loading…
Reference in New Issue