prototype: Event.fire/Element#fire now returns the newly-fired event instead of the event's target element.

This commit is contained in:
Sam Stephenson 2007-08-11 18:46:02 +00:00
parent d7da841c80
commit 14ea77ef39
3 changed files with 18 additions and 20 deletions

View File

@ -1,5 +1,7 @@
*SVN*
* 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]
* Fix a failing test in base.html in Safari 2. [Tobie Langel]

View File

@ -177,6 +177,8 @@ Object.extend(Event, (function() {
} else {
element.attachEvent("on" + name, wrapper);
}
return element;
},
stopObserving: function(element, eventName, handler) {
@ -204,6 +206,8 @@ Object.extend(Event, (function() {
}
destroyWrapper(id, eventName, handler);
return element;
},
fire: function(element, eventName, memo) {
@ -228,7 +232,7 @@ Object.extend(Event, (function() {
element.fireEvent(event.eventType, event);
}
return element;
return event;
}
};
})());
@ -236,20 +240,9 @@ Object.extend(Event, (function() {
Object.extend(Event, Event.Methods);
Element.addMethods({
fire: function() {
Event.fire.apply(Event, arguments);
return $A(arguments).first();
},
observe: function() {
Event.observe.apply(Event, arguments);
return $A(arguments).first();
},
stopObserving: function() {
Event.stopObserving.apply(Event, arguments);
return $A(arguments).first();
}
fire: Event.fire,
observe: Event.observe,
stopObserving: Event.stopObserving
});
Object.extend(document, {
@ -281,12 +274,14 @@ Object.extend(document, {
Event.observe(window, "load", fireContentLoadedEvent);
} else {
document.addEventListener("DOMContentLoaded", fireContentLoadedEvent, false);
document.addEventListener("DOMContentLoaded",
fireContentLoadedEvent, false);
}
} else {
var dummy = location.protocol == "https:" ? "https://javascript:void(0)" : "javascript:void(0)";
document.write("<script id=__onDOMContentLoaded defer src='" + dummy + "'><\/script>");
document.write("<script id=__onDOMContentLoaded defer " +
"src='://javascript:void(0)'><\/script>");
$("__onDOMContentLoaded").onreadystatechange = function() {
if (this.readyState == "complete") {
this.onreadystatechange = null;

View File

@ -105,9 +105,10 @@
}},
testEventObjectIsExtended: function() { with(this) {
var span = $("span"), event, observer = function(e) { event = e };
var span = $("span"), event, observedEvent, observer = function(e) { observedEvent = e };
span.observe("somethingHappened", observer);
span.fire("somethingHappened");
event = span.fire("somethingHappened");
assertEqual(event, observedEvent);
assertEqual(Event.Methods.stop.methodize(), event.stop);
span.stopObserving("somethingHappened", observer);
}},