From 37cff9a5acb515c13b299b842971bb1d128a4359 Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Tue, 30 Dec 2014 13:52:32 +0100 Subject: [PATCH] Change EvPart name, remove focusin/focusout aliases. --- .../gwt/query/client/plugins/Events.java | 4 +-- .../client/plugins/events/EventsListener.java | 25 ++++++++----------- .../client/plugins/events/SpecialEvent.java | 2 +- .../gwt/query/client/GQueryEventsTestGwt.java | 22 ---------------- 4 files changed, 14 insertions(+), 39 deletions(-) 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 d7f7e7df..55190938 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 @@ -21,7 +21,7 @@ import com.google.gwt.query.client.Function; import com.google.gwt.query.client.GQuery; import com.google.gwt.query.client.js.JsUtils; import com.google.gwt.query.client.plugins.events.EventsListener; -import com.google.gwt.query.client.plugins.events.EventsListener.EvPart; +import com.google.gwt.query.client.plugins.events.EventsListener.EventName; import com.google.gwt.user.client.Event; /** @@ -300,7 +300,7 @@ public class Events extends GQuery { * @param functions a set of function to run. */ public Events triggerHtmlEvent(String htmlEvent, Object[] datas, final Function... functions) { - for (EvPart part : EvPart.split(htmlEvent)) { + for (EventName part : EventName.split(htmlEvent)) { NativeEvent e = document.createHtmlEvent(part.eventName, true, true); JsUtils.prop(e, "namespace", part.nameSpace); if ("submit".equals(part.eventName)){ 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 a6e5912e..f6f2113a 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 @@ -34,6 +34,7 @@ import com.google.gwt.user.client.EventListener; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; /** * This class implements an event queue instance for one Element. The queue instance is configured @@ -73,22 +74,22 @@ public class EventsListener implements EventListener { /** * Utility class to split a list of events with or without namespaces */ - public static class EvPart { + public static class EventName { public final String nameSpace; public final String eventName; - public EvPart(String n, String e) { + public EventName(String n, String e) { nameSpace = n; eventName = e; } - public static List split(String events) { - List ret = new ArrayList(); + public static List split(String events) { + List ret = new ArrayList(); String[] parts = events.split("[\\s,]+"); for (String event : parts) { String[] tmp = event.split("\\.", 2); String eventName = tmp[0]; String nameSpace = tmp.length > 1 ? tmp[1] : null; - ret.add(new EvPart(nameSpace, eventName)); + ret.add(new EventName(nameSpace, eventName)); } return ret; } @@ -354,18 +355,14 @@ public class EventsListener implements EventListener { public static String MOUSEENTER = "mouseenter"; public static String MOUSELEAVE = "mouseleave"; - public static String FOCUSIN = "focusin"; - public static String FOCUSOUT = "focusout"; - public static HashMap special; + public static Map special; static { // Register some special events which already exist in jQuery special = new HashMap(); special.put(MOUSEENTER, new MouseSpecialEvent(MOUSEENTER, "mouseover")); special.put(MOUSELEAVE, new MouseSpecialEvent(MOUSELEAVE, "mouseout")); - special.put(FOCUSIN, new DefaultSpecialEvent(FOCUSIN, "focus")); - special.put(FOCUSOUT, new DefaultSpecialEvent(FOCUSOUT, "blur")); } public static void clean(Element e) { @@ -470,7 +467,7 @@ public class EventsListener implements EventListener { unbind(events, null); } - for (EvPart ev : EvPart.split(events)) { + for (EventName ev : EventName.split(events)) { SpecialEvent hook = special.get(ev.eventName); boolean bind = hook == null || hook.setup(element) == false; for (Function function : funcs) { @@ -491,7 +488,7 @@ public class EventsListener implements EventListener { } public void die(String events, String cssSelector) { - for (EvPart ev : EvPart.split(events)) { + for (EventName ev : EventName.split(events)) { SpecialEvent hook = special.get(ev.eventName); boolean unbind = hook == null || hook.tearDown(element) == false; if (unbind) { @@ -582,7 +579,7 @@ public class EventsListener implements EventListener { } public void live(String events, String cssSelector, Object data, Function... funcs) { - for (EvPart ev : EvPart.split(events)) { + for (EventName ev : EventName.split(events)) { SpecialEvent hook = special.get(ev.eventName); boolean bind = hook == null || hook.setup(element) == false; for (Function function : funcs) { @@ -708,7 +705,7 @@ public class EventsListener implements EventListener { } public void unbind(String events, Function f) { - for (EvPart ev : EvPart.split(events)) { + for (EventName ev : EventName.split(events)) { SpecialEvent hook = special.get(ev.eventName); boolean unbind = hook == null || hook.tearDown(element) == false; if (unbind) { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/SpecialEvent.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/SpecialEvent.java index cc4020b9..8083b098 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/SpecialEvent.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/SpecialEvent.java @@ -112,4 +112,4 @@ public interface SpecialEvent { * before calling remove. */ boolean tearDown(Element e); -} \ No newline at end of file +} 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 0ad8ae40..315999a1 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 @@ -455,28 +455,6 @@ public class GQueryEventsTestGwt extends GWTTestCase { assertEquals("", $("p", e).css("border", false)); } - @DoNotRunWith({Platform.HtmlUnitLayout}) - public void testSpecialFocusInOut() { - $(e).html("

Content

"); - $("p", e).on(EventsListener.FOCUSIN, new Function() { - public void f(Element elem) { - GQuery.console.log("focus"); - $(elem).css("background-color", "red"); - } - }); - $("p", e).focus(); - assertEquals("red", $("p", e).css("background-color", false)); - - // blur - $("p", e).on(EventsListener.FOCUSOUT, new Function() { - public void f(Element elem) { - $(elem).css("background-color", "white"); - } - }); - $("p", e).blur(); - assertEquals("white", $("p", e).css("background-color", false)); - } - public void testLazyMethods() { $(e).css(CSS.COLOR.with(RGBColor.WHITE)); assertEquals("white", $(e).css("color", false)); -- 2.39.5