From 163b15aa0ef6361484c462a6f363dbbd6800885e Mon Sep 17 00:00:00 2001 From: jdramaix Date: Thu, 10 Apr 2014 15:10:55 +0200 Subject: [PATCH] Fix event bubbling for custom event for IE6-8. --- gwtquery-core/pom.xml | 2 +- .../gwt/query/client/plugins/Events.java | 22 +++++++++++++++++-- pom.xml | 2 +- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/gwtquery-core/pom.xml b/gwtquery-core/pom.xml index 31aede2d..1ef308f8 100644 --- a/gwtquery-core/pom.xml +++ b/gwtquery-core/pom.xml @@ -8,7 +8,7 @@ gwtquery jar - 1.4.1 + 1.4.2-SNAPSHOT Gwt Query Core API http://gquery.org 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 c89cf884..70928b02 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 @@ -17,7 +17,6 @@ import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.FormElement; import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.dom.client.Node; -import com.google.gwt.event.dom.client.HasNativeEvent; import com.google.gwt.query.client.Function; import com.google.gwt.query.client.GQuery; import com.google.gwt.query.client.js.JsUtils; @@ -401,7 +400,7 @@ public class Events extends GQuery { // Ie6-8 don't dispatch bitless event if ((browser.ie6 || browser.ie8) && Event.getTypeInt(evt.getType()) == -1) { - EventsListener.getInstance(e).dispatchEvent(evt.cast()); + bubbleEventForIE(e, evt.cast()); } else { e.dispatchEvent(evt); } @@ -414,6 +413,25 @@ public class Events extends GQuery { } } + private void bubbleEventForIE(Element e, Event event) { + if (e == null || "html".equalsIgnoreCase(e.getTagName()) || isEventPropagationStopped(event)) { + return; + } + + EventsListener.getInstance(e).dispatchEvent(event); + + bubbleEventForIE(e.getParentElement(), event); + } + + /** + * Only valid for IE6-8 + * @param event + * @return + */ + private native boolean isEventPropagationStopped(Event event)/*-{ + return !!event.cancelBubble; + }-*/; + private void callHandlers(Element e, NativeEvent evt, Function... functions){ for (Function f : functions) { f.setEvent(Event.as(evt)); diff --git a/pom.xml b/pom.xml index ccf7fc60..c1b358dd 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.googlecode.gwtquery gwtquery-project pom - 1.4.1 + 1.4.2-SNAPSHOT Gwt Query Project http://gwtquery.com GwtQuery is a jQuery clone written in GWT. -- 2.39.5