From 67cf7509567b83c6a637651aa6596e3da73c61dc Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Fri, 26 Oct 2007 19:15:35 +0000 Subject: [PATCH] Add event.stopped, a boolean that is set to when Event#stop is called. --- src/event.js | 5 +++-- test/unit/event.html | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/event.js b/src/event.js index f5e8a99..63379cd 100644 --- a/src/event.js +++ b/src/event.js @@ -82,8 +82,9 @@ Event.Methods = (function() { stop: function(event) { Event.extend(event); - event.preventDefault(); - event.stopPropagation(); + event.preventDefault(); + event.stopPropagation(); + event.stopped = true; } }; })(); diff --git a/test/unit/event.html b/test/unit/event.html index 87e4647..036f203 100644 --- a/test/unit/event.html +++ b/test/unit/event.html @@ -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) {