prototype: Event handlers are now bound to the observed element, not the event's target element.
This commit is contained in:
parent
aa1a7f5bf0
commit
b2f884b4fa
@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Event handlers are now bound to the observed element, not the event's target element. [Dan Webb]
|
||||
|
||||
* Define Node constants conditionally after checking for Node.ELEMENT_NODE presence. Add unit test to check the values of all constants. Closes #7625. [Mislav Marohnić]
|
||||
|
||||
* Make sure Enumerable#include doesn't do type comparision. [Mislav Marohnić]
|
||||
|
@ -127,7 +127,8 @@ Object.extend(Event, (function() {
|
||||
return c[eventName] = c[eventName] || [];
|
||||
}
|
||||
|
||||
function createWrapper(id, eventName, handler) {
|
||||
function createWrapper(element, eventName, handler) {
|
||||
var id = getEventID(element);
|
||||
var c = getWrappersForEventName(id, eventName);
|
||||
if (c.pluck("handler").include(handler)) return false;
|
||||
|
||||
@ -136,7 +137,7 @@ Object.extend(Event, (function() {
|
||||
return false;
|
||||
|
||||
Event.extend(event);
|
||||
handler.call(event.target, event);
|
||||
handler.call(element, event)
|
||||
};
|
||||
|
||||
wrapper.handler = handler;
|
||||
@ -168,9 +169,9 @@ Object.extend(Event, (function() {
|
||||
return {
|
||||
observe: function(element, eventName, handler) {
|
||||
element = $(element);
|
||||
var id = getEventID(element), name = getDOMEventName(eventName);
|
||||
var name = getDOMEventName(eventName);
|
||||
|
||||
var wrapper = createWrapper(id, eventName, handler);
|
||||
var wrapper = createWrapper(element, eventName, handler);
|
||||
if (!wrapper) return element;
|
||||
|
||||
if (element.addEventListener) {
|
||||
|
@ -113,7 +113,7 @@
|
||||
span.stopObserving("somethingHappened", observer);
|
||||
}},
|
||||
|
||||
testEventObserversAreBoundToTheTargetElement: function() { with(this) {
|
||||
testEventObserversAreBoundToTheObservedElement: function() { with(this) {
|
||||
var span = $("span"), target, observer = function() { target = this };
|
||||
|
||||
span.observe("somethingHappened", observer);
|
||||
@ -126,7 +126,7 @@
|
||||
outer.observe("somethingHappened", observer);
|
||||
span.fire("somethingHappened");
|
||||
outer.stopObserving("somethingHappened", observer);
|
||||
assertEqual(span, target);
|
||||
assertEqual(outer, target);
|
||||
}},
|
||||
|
||||
testMultipleCustomEventObserversWithTheSameHandler: function() { with(this) {
|
||||
|
Loading…
Reference in New Issue
Block a user