aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java30
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/SpecialEvent.java25
2 files changed, 21 insertions, 34 deletions
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 d2e4550c..d8b80e55 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
@@ -26,7 +26,7 @@ import com.google.gwt.query.client.js.JsMap;
import com.google.gwt.query.client.js.JsNamedArray;
import com.google.gwt.query.client.js.JsObjectArray;
import com.google.gwt.query.client.js.JsUtils;
-import com.google.gwt.query.client.plugins.events.SpecialEvent.AbstractSpecialEvent;
+import com.google.gwt.query.client.plugins.events.SpecialEvent.DefaultSpecialEvent;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.EventListener;
@@ -50,7 +50,7 @@ public class EventsListener implements EventListener {
/**
* Used for simulating mouseenter and mouseleave events
*/
- private static class MouseSpecialEvent extends AbstractSpecialEvent {
+ private static class MouseSpecialEvent extends DefaultSpecialEvent {
public MouseSpecialEvent(final String type, String delegateType) {
super(type, delegateType);
handler = new Function() {
@@ -71,22 +71,6 @@ public class EventsListener implements EventListener {
}
/**
- * Used for simulating mouseenter and mouseleave events
- */
- private static class FocusSpecialEvent extends AbstractSpecialEvent {
- public FocusSpecialEvent(final String type, String delegateType) {
- super(type, delegateType);
- handler = new Function() {
- public boolean f(Event e, Object... arg) {
- setEvent(e);
- getInstance(getElement()).dispatchEvent(e, type);
- return true;
- };
- };
- }
- }
-
- /**
* Utility class to split a list of events with or without namespaces
*/
private static class EvPart {
@@ -380,8 +364,8 @@ public class EventsListener implements EventListener {
special = new HashMap<String, SpecialEvent>();
special.put(MOUSEENTER, new MouseSpecialEvent(MOUSEENTER, "mouseover"));
special.put(MOUSELEAVE, new MouseSpecialEvent(MOUSELEAVE, "mouseout"));
- special.put(FOCUSIN, new FocusSpecialEvent(FOCUSIN, "focus"));
- special.put(FOCUSOUT, new FocusSpecialEvent(FOCUSOUT, "blur"));
+ special.put(FOCUSIN, new DefaultSpecialEvent(FOCUSIN, "focus"));
+ special.put(FOCUSOUT, new DefaultSpecialEvent(FOCUSOUT, "blur"));
}
public static void clean(Element e) {
@@ -766,10 +750,4 @@ public class EventsListener implements EventListener {
function.clean();
}
}
-
- public void list() {
- for (int i = 0, l = elementEvents.length(); i < l; i++) {
- GQuery.console.log(elementEvents.get(i).toString());
- }
- }
}
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 cda229c0..cc4020b9 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
@@ -25,14 +25,23 @@ import com.google.gwt.user.client.Event;
public interface SpecialEvent {
/**
- * Abstract implementation of SpecialEvents
+ * Default implementation of SpecialEvents for simple cases like
+ * creating event aliases. Extend this for creating more complex
+ * cases.
*/
- public static abstract class AbstractSpecialEvent implements SpecialEvent {
+ public static class DefaultSpecialEvent implements SpecialEvent {
protected final String delegateType;
protected final String type;
- protected Function handler = null;
- public AbstractSpecialEvent(String type, String delegateType) {
+ protected Function handler = new Function() {
+ public boolean f(Event e, Object... arg) {
+ setEvent(e);
+ EventsListener.getInstance(getElement()).dispatchEvent(e, type);
+ return true;
+ };
+ };
+
+ public DefaultSpecialEvent(String type, String delegateType) {
this.type = type;
this.delegateType = delegateType;
}
@@ -43,7 +52,7 @@ public interface SpecialEvent {
@Override
public void add(Element e, String eventType, String nameSpace, Object data, Function f) {
- // Nothing to do, let gQuery use default eentEvents mechanism
+ // Nothing to do, let gQuery use default events mechanism
}
@Override
@@ -53,13 +62,13 @@ public interface SpecialEvent {
@Override
public void remove(Element e, String eventType, String nameSpace, Function f) {
- // Nothing to do, let gQuery use default eentEvents mechanism
+ // Nothing to do, let gQuery use default events mechanism
}
@Override
public boolean setup(Element e) {
if (!hasHandlers(e)) {
- listener(e).bind(Event.getTypeInt(delegateType), null, delegateType, null, handler, -1);
+ listener(e).bind(delegateType, null, handler);
}
return false;
}
@@ -67,7 +76,7 @@ public interface SpecialEvent {
@Override
public boolean tearDown(Element e) {
if (!hasHandlers(e)) {
- listener(e).unbind(Event.getTypeInt(delegateType), null, delegateType, handler);
+ listener(e).unbind(delegateType, handler);
}
return false;
}