From: Manolo Carrasco Date: Thu, 21 Jun 2012 12:18:46 +0000 (+0000) Subject: fixe live() so as it behaves the same than jquery X-Git-Tag: release-1.3.2~78 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9144d84ba56a120dba475205873e9d33e796bf95;p=gwtquery.git fixe live() so as it behaves the same than jquery --- diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java index 5221b634..5d56359e 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java @@ -173,9 +173,8 @@ public class EventsListener implements EventListener { return true; } - boolean result = true; + Element stopElement = null; GqEvent gqEvent = GqEvent.create(event); - outerLoop: for (String cssSelector : realCurrentTargetBySelector.keys()) { JsObjectArray bindFunctions = bindFunctionBySelector.get(cssSelector); for (int i = 0; bindFunctions != null && i < bindFunctions.length(); i++) { @@ -184,11 +183,12 @@ public class EventsListener implements EventListener { NodeList n = realCurrentTargetBySelector.get(cssSelector); for (int j = 0; n != null && j < n.getLength(); j++) { Element element = n.getItem(i); - gqEvent.setCurrentElementTarget(element); - result = f.fire(gqEvent); - if (!result) { - // Event should not continue because returning false, means to run it once - break outerLoop; + // When an event fired in an element stops bubbling we have to fire also all other + // handlers for this element bound to this element + if (stopElement == null || element.equals(stopElement)) { + if (!f.fire(gqEvent)) { + stopElement = element; + } } } } @@ -197,7 +197,7 @@ public class EventsListener implements EventListener { // trick to reset the right currentTarget on the original event on ie gqEvent.setCurrentElementTarget(liveContextElement); - return result; + return stopElement == null; } /**