diff options
author | jdramaix <julien.dramaix@gmail.com> | 2014-03-04 17:53:43 +0100 |
---|---|---|
committer | jdramaix <julien.dramaix@gmail.com> | 2014-03-04 17:53:43 +0100 |
commit | 1e134ef6425467662cc0ed0fda89f26991e48618 (patch) | |
tree | 57b8fd21910b302af0688836a9ad2b34ffa20a98 | |
parent | fc152330bd09f8d88b2668a60932d176ca18e007 (diff) | |
download | gwtquery-1e134ef6425467662cc0ed0fda89f26991e48618.tar.gz gwtquery-1e134ef6425467662cc0ed0fda89f26991e48618.zip |
fix issue when unbind special events only with namespace
-rw-r--r-- | gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java | 14 | ||||
-rw-r--r-- | gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java | 23 |
2 files changed, 32 insertions, 5 deletions
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 0fbf8742..cf10dcbe 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 @@ -14,6 +14,7 @@ package com.google.gwt.query.client.plugins.events; import com.google.gwt.core.client.Duration; +import com.google.gwt.dev.util.Strings; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.EventTarget; import com.google.gwt.dom.client.NodeList; @@ -737,13 +738,12 @@ public class EventsListener implements EventListener { for (int i = 0; i < elementEvents.length(); i++) { BindFunction listener = elementEvents.get(i); - boolean matchNS = - namespace == null || namespace.isEmpty() || listener.nameSpace.equals(namespace); + boolean matchNS = isNullOrEmpty(namespace) || listener.nameSpace.equals(namespace); boolean matchEV = eventbits <= 0 || listener.hasEventType(eventbits); boolean matchEVN = matchEV || listener.isTypeOf(eventName); - boolean matchOEVT = (originalEventType == null && listener.getOriginalEventType() == null) - || (originalEventType != null && originalEventType.equals(listener - .getOriginalEventType())); + boolean matchOEVT = (isNullOrEmpty(eventName) && !isNullOrEmpty(namespace) && matchNS) + || (originalEventType == null && listener.getOriginalEventType() == null) + || (originalEventType != null && originalEventType.equals(listener.getOriginalEventType())); boolean matchFC = f == null || listener.isEquals(f); if (matchNS && matchEV && matchEVN && matchFC && matchOEVT) { @@ -761,6 +761,10 @@ public class EventsListener implements EventListener { } + private boolean isNullOrEmpty(String s) { + return s == null || s.isEmpty(); + } + public void unbind(String events, Function f) { String[] parts = events.split("[\\s,]+"); 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 681faa78..31ff1695 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 @@ -1687,4 +1687,27 @@ public class GQueryEventsTestGwt extends GWTTestCase { assertEquals(0, mouseOverFunction.invokationCounter); assertEquals(0, customEventFunction.invokationCounter); } + + public void testUnbindSpecialEventWithNameSpace() { + $(e).html("<div id='mainDiv'>blop</div>"); + + CounterFunction mouseEnterFunction = new CounterFunction(); + + $("#mainDiv", e).on("mouseenter.mynamespace", mouseEnterFunction); + $("#mainDiv", e).mouseenter(); + assertEquals(1, mouseEnterFunction.invokationCounter); + + $("#mainDiv", e).off(".mynamespace"); + $("#mainDiv", e).mouseenter(); + assertEquals(1, mouseEnterFunction.invokationCounter); + + $("#mainDiv", e).on("mouseenter.mynamespace", mouseEnterFunction); + $("#mainDiv", e).mouseenter(); + assertEquals(2, mouseEnterFunction.invokationCounter); + + $("#mainDiv", e).off("mouseenter.mynamespace"); + $("#mainDiv", e).mouseenter(); + assertEquals(2, mouseEnterFunction.invokationCounter); + } + } |