prototype: Make sure Element#observe is always chainable.

This commit is contained in:
Sam Stephenson 2007-08-11 19:53:39 +00:00
parent d2974cfca3
commit 11f25aa995
3 changed files with 11 additions and 4 deletions

View File

@ -1,6 +1,6 @@
*SVN*
* Make sure Element#stopObserving is always chainable. [sam]
* Make sure Element#observe and Element#stopObserving are always chainable. [sam]
* Event.fire/Element#fire now returns the newly-fired event instead of the event's target element. [sam]

View File

@ -170,7 +170,7 @@ Object.extend(Event, (function() {
var id = getEventID(element), name = getDOMEventName(eventName);
var wrapper = createWrapper(id, eventName, handler);
if (!wrapper) return false;
if (!wrapper) return element;
if (element.addEventListener) {
element.addEventListener(name, wrapper, false);

View File

@ -183,15 +183,22 @@
assertEqual(0, Event.cache[eventID].somethingHappened.length);
}},
testStopObservingIsChainable: function() { with(this) {
testObserveAndStopObservingAreChainable: function() { with(this) {
var span = $("span"), observer = function() { };
span.observe("somethingHappened", observer);
assertEqual(span, 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
span.observe("somethingHappened", observer);
assertEqual(span, span.observe("somethingHappened", observer)); // try to reuse the same observer
span.stopObserving();
}},
testDocumentContentLoadedEventFiresBeforeWindowLoad: function() { with(this) {