prototype: Ensure Event#fire always returns an extended event. Make Event#findElement's expression argument optional. Perf optimizations for Event#findElement.

This commit is contained in:
Tobie Langel 2007-11-13 21:48:09 +00:00
parent a26b4d2ffa
commit 0b6a6e2f2f
3 changed files with 19 additions and 2 deletions

View File

@ -1,3 +1,7 @@
* Performance optimizations for Event#findElement. Make Event#findElement's expression argument optional, in which case the extended target element is returned (same as Event#element). [Tobie Langel]
* Ensure Event#fire always returns an extended event. [Tobie Langel]
*1.6.0* (November 6, 2007)
* Fix Class#addMethods for "toString" and "valueOf" methods in Internet Explorer. Closes #9901. [sam]

View File

@ -65,7 +65,9 @@ Event.Methods = (function() {
findElement: function(event, expression) {
var element = Event.element(event);
return element.match(expression) ? element : element.up(expression);
if (!expression) return element;
var elements = [element].concat(element.ancestors());
return Selector.findElement(elements, expression, 0);
},
pointer: function(event) {
@ -257,7 +259,7 @@ Object.extend(Event, (function() {
element.fireEvent(event.eventType, event);
}
return event;
return Event.extend(event);
}
};
})());

View File

@ -111,6 +111,9 @@
assertEqual(event, observedEvent);
assertEqual(Event.Methods.stop.methodize(), event.stop);
span.stopObserving("test:somethingHappened", observer);
event = span.fire("test:somethingHappenedButNoOneIsListening");
assertEqual(Event.Methods.stop.methodize(), event.stop);
}},
testEventObserversAreBoundToTheObservedElement: function() { with(this) {
@ -222,6 +225,14 @@
event = span.fire("test:somethingHappened");
assert(event.stopped, "event.stopped should be true for an observer that calls stop");
span.stopObserving("test:somethingHappened");
}},
testEventFindElement: function() { with(this) {
var span = $("span"), event;
event = span.fire("test:somethingHappened");
assertEqual(span, event.findElement());
assertEqual(span, event.findElement('span'));
assertEqual(null, event.findElement('div.does_not_exist'));
}}