Add event.stopped, a boolean that is set to when Event#stop is called.

This commit is contained in:
Andrew Dupont 2007-10-26 19:15:35 +00:00
parent 18969c5159
commit 67cf750956
2 changed files with 18 additions and 2 deletions

View File

@ -82,8 +82,9 @@ Event.Methods = (function() {
stop: function(event) {
Event.extend(event);
event.preventDefault();
event.stopPropagation();
event.preventDefault();
event.stopPropagation();
event.stopped = true;
}
};
})();

View File

@ -208,8 +208,23 @@
assert(eventResults.windowLoad, "windowLoad");
assert(eventResults.windowLoad.endOfDocument, "windowLoad.endOfDocument");
assert(eventResults.windowLoad.contentLoaded, "windowLoad.contentLoaded");
}},
testEventStopped: function() { with(this) {
var span = $("span"), event;
span.observe("test:somethingHappened", function() { });
event = span.fire("test:somethingHappened");
assert(!event.stopped, "event.stopped should be false with an empty observer");
span.stopObserving("test:somethingHappened");
span.observe("test:somethingHappened", function(e) { e.stop() });
event = span.fire("test:somethingHappened");
assert(event.stopped, "event.stopped should be true for an observer that calls stop");
span.stopObserving("test:somethingHappened");
}}
}, 'testlog');
document.observe("dom:loaded", function(event) {