From: jdramaix Date: Mon, 7 Jan 2013 20:55:03 +0000 (+0100) Subject: handle special event mouseenter or mouseleave in live and die method X-Git-Tag: release-1.3.2~22^2^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8b041045a51dd7cc9612268fc227e27c564bf420;p=gwtquery.git handle special event mouseenter or mouseleave in live and die method --- diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java index ce9d0272..f9ee5519 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java @@ -109,7 +109,7 @@ public class Events extends GQuery { public GQuery die(int eventbits, String nameSpace) { EventsListener.getInstance(Element.is(currentContext) ? (Element) currentContext : body).die( - eventbits, nameSpace, currentSelector); + eventbits, nameSpace, null, currentSelector); return this; } @@ -136,7 +136,7 @@ public class Events extends GQuery { public GQuery live(int eventbits, String nameSpace, final Object data, Function... funcs) { EventsListener.getInstance(Element.is(currentContext) ? (Element) currentContext : body).live( - eventbits, nameSpace, currentSelector, data, funcs); + eventbits, nameSpace, null, currentSelector, data, funcs); return this; } 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 7064ae35..6ba03bae 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 @@ -280,8 +280,8 @@ public class EventsListener implements EventListener { /** * Remove the BindFunction associated to this cssSelector */ - public void removeBindFunctionForSelector(String cssSelector, String nameSpace) { - if (nameSpace == null || nameSpace.length() == 0) { + public void removeBindFunctionForSelector(String cssSelector, String nameSpace, String originalEventName) { + if (nameSpace == null && originalEventName == null) { bindFunctionBySelector.delete(cssSelector); } else { JsObjectArray functions = bindFunctionBySelector.get(cssSelector); @@ -293,7 +293,10 @@ public class EventsListener implements EventListener { for (int i = 0; i < functions.length(); i++) { BindFunction f = functions.get(i); - if (!nameSpace.equals(f.nameSpace)) { + boolean matchNamespace = nameSpace == null || nameSpace.equals(f.nameSpace); + boolean matchOriginalEventName = originalEventName == null || originalEventName.equals(f.originalEventType); + + if (!matchNamespace || !matchOriginalEventName) { newFunctions.add(f); } } @@ -509,24 +512,30 @@ public class EventsListener implements EventListener { eventName = subparts[0]; } + + //handle special event like mouseenter or mouseleave + SpecialEvent hook = special.get(eventName); + eventName = hook != null ? hook.getDelegateType() : eventName; + String originalEventName = hook != null ? hook.getOriginalType() : null; + int b = getTypeInt(eventName); - die(b, nameSpace, cssSelector); + die(b, nameSpace, originalEventName, cssSelector); } } - public void die(int eventbits, String nameSpace, String cssSelector) { + public void die(int eventbits, String nameSpace, String originalEventName,String cssSelector) { if (eventbits <= 0) { for (String k : liveBindFunctionByEventType.keys()) { LiveBindFunction liveBindFunction = liveBindFunctionByEventType. cast().get(k); - liveBindFunction.removeBindFunctionForSelector(cssSelector, nameSpace); + liveBindFunction.removeBindFunctionForSelector(cssSelector, nameSpace, null); } } else { LiveBindFunction liveBindFunction = liveBindFunctionByEventType.get(eventbits); if (liveBindFunction != null) { - liveBindFunction.removeBindFunctionForSelector(cssSelector, nameSpace); + liveBindFunction.removeBindFunctionForSelector(cssSelector, nameSpace, originalEventName); } } } @@ -573,15 +582,20 @@ public class EventsListener implements EventListener { eventName = subparts[0]; } + //handle special event like mouseenter or mouseleave + SpecialEvent hook = special.get(eventName); + eventName = hook != null ? hook.getDelegateType() : eventName; + String originalEventName = hook != null ? hook.getOriginalType() : null; + int b = getTypeInt(eventName); for (Function function : funcs) { - //Function handler = hook != null ? hook.createDelegateHandler(function) : function; - live(b, nameSpace, cssSelector, data, function); + Function handler = hook != null ? hook.createDelegateHandler(function) : function; + live(b, nameSpace, originalEventName, cssSelector, data, handler); } } } - public void live(int eventbits, String nameSpace, String cssSelector, Object data, Function... funcs) { + public void live(int eventbits, String nameSpace, String originalEventName, String cssSelector, Object data, Function... funcs) { for (int i = 0; i < 28; i++) { int event = (int) Math.pow(2, i); if ((eventbits & event) == event) { @@ -597,9 +611,8 @@ public class EventsListener implements EventListener { } for (Function f : funcs) { - // TODO handle special event by passing original event name liveBindFunction.addBindFunctionForSelector(cssSelector, new BindFunction(event, nameSpace, - null, f, data)); + originalEventName, f, data)); } } }