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;
/**
* @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)){
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
/**
* 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<EvPart> split(String events) {
- List<EvPart> ret = new ArrayList<EvPart>();
+ public static List<EventName> split(String events) {
+ List<EventName> ret = new ArrayList<EventName>();
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;
}
public static String MOUSEENTER = "mouseenter";
public static String MOUSELEAVE = "mouseleave";
- public static String FOCUSIN = "focusin";
- public static String FOCUSOUT = "focusout";
- public static HashMap<String, SpecialEvent> special;
+ public static Map<String, SpecialEvent> special;
static {
// Register some special events which already exist in jQuery
special = new HashMap<String, SpecialEvent>();
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) {
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) {
}
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) {
}
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) {
}
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) {
assertEquals("", $("p", e).css("border", false));
}
- @DoNotRunWith({Platform.HtmlUnitLayout})
- public void testSpecialFocusInOut() {
- $(e).html("<p>Content</p>");
- $("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));