From: jdramaix Date: Thu, 5 Dec 2013 23:26:55 +0000 (+0100) Subject: Merge branch 'master' of github.com:gwtquery/gwtquery into jd_fix_event_1 X-Git-Tag: release-1.4.0~19^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=459fcfcc8115dcd158d0d8c600d8852a51a16320;p=gwtquery.git Merge branch 'master' of github.com:gwtquery/gwtquery into jd_fix_event_1 Conflicts: gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java --- 459fcfcc8115dcd158d0d8c600d8852a51a16320 diff --cc gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java index 61e05ac9,e3ada526..b781d1d9 --- 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 @@@ -1596,90 -1596,11 +1596,98 @@@ public class GQueryEventsTestGwt extend assertEquals(1, handler.invokationCounter); } + public void testIssue226() { + $(e).html("
"); + GQuery target = $("#target", e); + + // this should not throw a NPE + target.undelegate("li", "click"); + } ++ + // issue 25 : https://github.com/gwtquery/gwtquery/issues/25 + public void testDelegateAfterUndelegateWithoutParameter() { + $(e).html( + "
Content 0blop
Content 0blop
"); + + CounterFunction clickFunction = new CounterFunction(); + CounterFunction mouseOverFunction = new CounterFunction(); + + $(".mainDiv", e).delegate(".subDiv", "click", clickFunction); + + $(".mainDiv", e).delegate(".subDiv", Event.ONMOUSEOVER, mouseOverFunction); + + for (Element mainDiv : $(".mainDiv", e).elements()) { + for (int i = 0; i < 3; i++) { + String html = "
Content " + i + "blop
"; + $(mainDiv).append(html); + } + } + + assertEquals(8, $(".subDiv", e).length()); + + $("span", e).click().trigger(Event.ONMOUSEOVER); + + assertEquals(8, clickFunction.invokationCounter); + assertEquals(8, mouseOverFunction.invokationCounter); + + clickFunction.invokationCounter = 0; + mouseOverFunction.invokationCounter = 0; + + $(".mainDiv", e).undelegate(); + + $("span", e).click().trigger(Event.ONMOUSEOVER); + assertEquals(0, clickFunction.invokationCounter); + assertEquals(0, mouseOverFunction.invokationCounter); + + //reattach the event + + $(".mainDiv", e).delegate(".subDiv", "click", clickFunction); + $(".mainDiv", e).delegate(".subDiv", Event.ONMOUSEOVER, mouseOverFunction); + + $("span", e).click().trigger(Event.ONMOUSEOVER); + + assertEquals(8, clickFunction.invokationCounter); + assertEquals(8, mouseOverFunction.invokationCounter); + + } + + public void testDelegateAfterUndelegateWithSelectorWithDifferentEvent() { + $(e).html( + "
Content 0blop
Content 0blop
"); + + CounterFunction clickFunction = new CounterFunction(); + CounterFunction mouseOverFunction = new CounterFunction(); + CounterFunction customEventFunction = new CounterFunction(); + + $(".mainDiv", e).delegate(".subDiv", "click", clickFunction) + .delegate(".subDiv", Event.ONMOUSEOVER, mouseOverFunction) + .delegate(".subDiv", "custom", customEventFunction); + + for (Element mainDiv : $(".mainDiv", e).elements()) { + for (int i = 0; i < 3; i++) { + String html = "
Content " + i + "blop
"; + $(mainDiv).append(html); + } + } + + assertEquals(8, $(".subDiv", e).length()); + + $("span", e).click().trigger(Event.ONMOUSEOVER).trigger("custom"); + + assertEquals(8, clickFunction.invokationCounter); + assertEquals(8, mouseOverFunction.invokationCounter); + assertEquals(8, customEventFunction.invokationCounter); + + $(".mainDiv", e).undelegate(".subDiv"); + + clickFunction.invokationCounter = 0; + mouseOverFunction.invokationCounter = 0; + customEventFunction.invokationCounter = 0; + + $("span", e).click().trigger(Event.ONMOUSEOVER).trigger("custom"); + + assertEquals(0, clickFunction.invokationCounter); + assertEquals(0, mouseOverFunction.invokationCounter); + assertEquals(0, customEventFunction.invokationCounter); + } }