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;
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) {
}
+ private boolean isNullOrEmpty(String s) {
+ return s == null || s.isEmpty();
+ }
+
public void unbind(String events, Function f) {
String[] parts = events.split("[\\s,]+");
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);
+ }
+
}