From: Manuel Carrasco MoƱino Date: Mon, 10 Dec 2012 09:24:01 +0000 (+0100) Subject: Dont dispatch new added events when running the events dispatch loop. Fixes issue 152 X-Git-Tag: release-1.3.2~29 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b915257904c9e782918841c39fe2762fd82ef06c;p=gwtquery.git Dont dispatch new added events when running the events dispatch loop. Fixes issue 152 --- 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 38366b60..77abf267 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 @@ -495,7 +495,7 @@ public class EventsListener implements EventListener { int etype = getTypeInt(event.getType()); String originalEventType = GqEvent.getOriginalEventType(event); - for (int i = 0; i < elementEvents.length(); i++) { + for (int i = 0, l = elementEvents.length(); i < l; i++) { BindFunction listener = elementEvents.get(i); if (listener.hasEventType(etype) && (originalEventType == null || originalEventType diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java index fbc4c3e8..c5bdc5ac 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java @@ -1223,5 +1223,23 @@ public class GQueryEventsTestGwt extends GWTTestCase { assertEquals("red", $("button").css("color", false)); assertEquals("black", $("button").css("background-color", false)); } + + public void testIssue152() { + $(e).html("
"); + final GQuery div = $(".mdiv", e); + final int[] count = { 0 }; + div.one(Event.ONCLICK, null, new Function() { + public void f() { + count[0]++; + div.one(Event.ONCLICK, null, new Function() { + public void f() { + fail(); + } + }); + }; + }); + div.click(); + assertEquals(1, count[0]); + } }