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:
parent
a26b4d2ffa
commit
0b6a6e2f2f
|
@ -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]
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
})());
|
||||
|
|
|
@ -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'));
|
||||
}}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue