return as(Events).bind(eventbits, data, funcs);\r
}\r
\r
+ /**\r
+ * Binds a set of handlers to a particular Event for each matched element.\r
+ * \r
+ * The event handlers are passed as Functions that you can use to prevent\r
+ * default behavior. To stop both default action and event bubbling, the\r
+ * function event handler has to return false.\r
+ * \r
+ * You can pass an additional Object data to your Function as the second\r
+ * parameter\r
+ * \r
+ */\r
+ public GQuery bind(String eventType, final Object data, final Function... funcs) {\r
+ return as(Events).bind(eventType, data, funcs);\r
+ }\r
+\r
/**\r
* Bind a set of functions to the blur event of each matched element. Or\r
* trigger the event if no functions are provided.\r
* initially used with {@link #live(String, Function)}\r
*/\r
public GQuery die() {\r
- return as(Events).die(null);\r
+ return die(0);\r
}\r
\r
/**\r
public GQuery die(String eventName) {\r
return as(Events).die(eventName);\r
}\r
+ \r
+ /**\r
+ * Remove an event handlers previously attached using\r
+ * {@link #live(int, Function)} In order for this method to function\r
+ * correctly, the selector used with it must match exactly the selector\r
+ * initially used with {@link #live(int, Function)}\r
+ */\r
+ public GQuery die(int eventbits) {\r
+ return as(Events).die(eventbits);\r
+ }\r
\r
/**\r
* Run one or more Functions over each element of the GQuery. You have to\r
* </ul>\r
* </p>\r
*/\r
- public GQuery live(String eventName, Function func) {\r
- return as(Events).live(eventName, null, func);\r
+ public GQuery live(String eventName, Function... funcs) {\r
+ return as(Events).live(eventName, null, funcs);\r
}\r
\r
+ /**\r
+ * Attach a handler for this event to all elements which match the current\r
+ * selector, now and in the future.\r
+ */\r
+ public GQuery live(int eventbits, Function...funcs){\r
+ return as(Events).live(eventbits, null, funcs);\r
+ }\r
+\r
+ /**\r
+ * Attach a handler for this event to all elements which match the current\r
+ * selector, now and in the future.\r
+ */\r
+ public GQuery live(int eventbits, Object data, Function...funcs){\r
+ return as(Events).live(eventbits, data, funcs);\r
+ }\r
\r
/**\r
* <p>\r
*/
LazyGQuery<T> die(String eventName);
+ /**
+ * Remove an event handlers previously attached using
+ * {@link #live(int, Function)} In order for this method to function
+ * correctly, the selector used with it must match exactly the selector
+ * initially used with {@link #live(int, Function)}
+ */
+ LazyGQuery<T> die(int eventbits);
+
/**
* Run one or more Functions over each element of the GQuery. You have to
* override one of these funcions: public void f(Element e) public String
* </ul>
* </p>
*/
- LazyGQuery<T> live(String eventName, Function func);
+ LazyGQuery<T> live(String eventName, Function... funcs);
+
+ /**
+ * Attach a handler for this event to all elements which match the current
+ * selector, now and in the future.
+ */
+ LazyGQuery<T> live(int eventbits, Function...funcs);
+
+ /**
+ * Attach a handler for this event to all elements which match the current
+ * selector, now and in the future.
+ */
+ LazyGQuery<T> live(int eventbits, Object data, Function...funcs);
/**
* <p>
public GQuery die(String eventName) {
EventsListener.getInstance(
Element.is(currentContext) ? (Element) currentContext : body).die(
- eventName, currentSelector);
+ eventName, currentSelector);
return this;
}
- public GQuery live(String eventName, final Object data, Function func) {
+ public GQuery die(int eventbits) {
+ EventsListener.getInstance(
+ Element.is(currentContext) ? (Element) currentContext : body).die(
+ eventbits, currentSelector);
+ return this;
+ }
- // bind live delegating event to the current context
+ public GQuery live(String eventName, final Object data, Function... funcs) {
EventsListener.getInstance(
Element.is(currentContext) ? (Element) currentContext : body).live(
- eventName, currentSelector, data, func);
-
+ eventName, currentSelector, data, funcs);
+ return this;
+ }
+
+ public GQuery live(int eventbits, final Object data, Function... funcs) {
+ EventsListener.getInstance(
+ Element.is(currentContext) ? (Element) currentContext : body).live(
+ eventbits, currentSelector, data, funcs);
return this;
}
+
/**
* Binds a handler to a particular Event (like Event.ONCLICK) for each matched
* element. The handler is executed only once for each element.
*/
GQuery die(String eventName);
- GQuery live(String eventName, Object data, Function func);
+ GQuery die(int eventbits);
+
+ GQuery live(String eventName, Object data, Function... funcs);
+
+ GQuery live(int eventbits, Object data, Function... funcs);
/**
* Binds a handler to a particular Event (like Event.ONCLICK) for each matched
private Element element;
private JsObjectArray<BindFunction> elementEvents = JsObjectArray.createArray().cast();
- private Map<String, LiveBindFunction> liveBindFunctionByEventType = new HashMap<String, LiveBindFunction>();
+ private Map<Integer, LiveBindFunction> liveBindFunctionByEventType = new HashMap<Integer, LiveBindFunction>();
private EventsListener(Element element) {
this.element = element;
bind(b, nameSpace, data, function, -1);
}
}
-
+
public void die(String eventName, String cssSelector) {
- if (eventName == null) {
+ int eventType = "submit".equals(eventName) ? eventType = ONSUBMIT
+ : Event.getTypeInt(eventName);
+ die(eventType, cssSelector);
+ }
+
+ public void die(int eventbits, String cssSelector) {
+ if (eventbits == 0) {
for (LiveBindFunction liveBindFunction : liveBindFunctionByEventType.values()) {
liveBindFunction.removeBindFunctionForSelector(cssSelector);
}
} else {
- LiveBindFunction liveBindFunction = liveBindFunctionByEventType.get(eventName);
+ LiveBindFunction liveBindFunction = liveBindFunctionByEventType.get(eventbits);
liveBindFunction.removeBindFunctionForSelector(cssSelector);
}
}
public void dispatchEvent(Event event) {
-
int etype = "submit".equalsIgnoreCase(event.getType()) ? ONSUBMIT
: DOM.eventGetType(event);
for (int i = 0; i < elementEvents.length(); i++) {
return getGwtEventListener(element);
}
- public void live(String eventName, String cssSelector, Object data, Function f) {
- int eventType = 0;
- if ("submit".equals(eventName)) {
- eventType = ONSUBMIT;
- } else {
- eventType = Event.getTypeInt(eventName);
- }
+ public void live(String eventName, String cssSelector, Object data, Function... f) {
+ int eventType = "submit".equals(eventName) ? eventType = ONSUBMIT
+ : Event.getTypeInt(eventName);
+ live(eventType, cssSelector, data, f);
+ }
+
+ public void live(int eventbits, String cssSelector, Object data, Function... funcs) {
// is a LiveBindFunction already attached for this kind of event
- LiveBindFunction liveBindFunction = liveBindFunctionByEventType.get(eventName);
+ LiveBindFunction liveBindFunction = liveBindFunctionByEventType.get(eventbits);
if (liveBindFunction == null) {
- liveBindFunction = new LiveBindFunction(eventType, "live");
- eventBits |= eventType;
+ liveBindFunction = new LiveBindFunction(eventbits, "live");
+ eventBits |= eventbits;
sink();
elementEvents.add(liveBindFunction);
- liveBindFunctionByEventType.put(eventName, liveBindFunction);
+ liveBindFunctionByEventType.put(eventbits, liveBindFunction);
}
- liveBindFunction.addBindFunctionForSelector(cssSelector, new BindFunction(
- eventType, "live", f, data));
+ for (Function f: funcs) {
+ liveBindFunction.addBindFunctionForSelector(cssSelector, new BindFunction(
+ eventbits, "live", f, data));
+ }
}
private void clean() {
cleanGQListeners(element);
elementEvents = JsObjectArray.createArray().cast();
- liveBindFunctionByEventType = new HashMap<String, LiveBindFunction>();
+ liveBindFunctionByEventType = new HashMap<Integer, LiveBindFunction>();
}
private void sink() {