return as(Events).unbind(eventbits);\r
}\r
\r
+ /**\r
+ * Removes the function passed from the set of events which match \r
+ * the eventbits.\r
+ */\r
+ public GQuery unbind(int eventbits, Function f) {\r
+ return as(Events).unbind(eventbits, null, f);\r
+ }\r
+ \r
/**\r
* Removes all events that match the eventList.\r
*/\r
public GQuery unbind(String eventList) {\r
- return as(Events).unbind(eventList);\r
+ return unbind(eventList, null);\r
+ }\r
+ \r
+ /**\r
+ * Removes all events that match the eventList.\r
+ */\r
+ public GQuery unbind(String eventList, Function f) {\r
+ return as(Events).unbind(eventList, f);\r
}\r
\r
/**\r
*
* Example: unbind(Event.ONCLICK | Event.ONMOUSEOVER, "my.namespace")
*/
- public Events unbind(int eventbits, String name) {
+ public Events unbind(int eventbits, String name, Function f) {
for (Element e : elements()) {
if (isEventCapable(e)){
- EventsListener.getInstance(e).unbind(eventbits, name);
+ EventsListener.getInstance(e).unbind(eventbits, name, f);
}
}
return this;
}
/**
- * Removes all handlers, that matches event name passed. This name could
- * contain a namespace.
+ * Removes all handlers, that matches the event name passed.
+ *
+ * This name could contain a namespace.
*
* Example: unbind("click.my.namespace")
*/
public Events unbind(String name) {
+ return unbind(name, null);
+ }
+
+ /**
+ * Removes the function passed as parameter from the event list matching
+ * the event name passed.
+ * This name could contain a namespace.
+ *
+ * Example: unbind("click.my.namespace", myFunction)
+ */
+ public Events unbind(String name, Function f) {
for (Element e : elements()) {
if (isEventCapable(e)){
- EventsListener.getInstance(e).unbind(name);
+ EventsListener.getInstance(e).unbind(name, f);
}
}
return this;
\r
protected void destroyMouseHandler() {\r
as(Events)\r
- .unbind(Event.ONMOUSEDOWN | Event.ONCLICK, getPluginName());\r
+ .unbind(Event.ONMOUSEDOWN | Event.ONCLICK, getPluginName(), null);\r
}\r
\r
/**\r
\r
private void unbindOtherMouseEvent() {\r
$(document).as(Events).unbind((Event.ONMOUSEUP | Event.ONMOUSEMOVE),\r
- getPluginName());\r
+ getPluginName(), null);\r
}\r
\r
}\r
s.setData(data);
s.setSuccess(new Function() {
public void f() {
- // We clean up the returned string to smoothly append it to our document
- String s = getData()[0].toString().replaceAll("<![^>]+>\\s*", "")
- .replaceAll("(?si)</?html[^>]*>\\s*", "")
- .replaceFirst("(?si)<head[^>]*>.*</head>\\s*", "")
- .replaceFirst("(?si)<script[^>]*>.*</script>\\s*", "")
- .replaceAll("<?si></?body[^>]*>\\s*", "");
- // We wrap the results in a div
- s = "<div>" + s + "</div>";
-
- Ajax.this.empty().append(filter.isEmpty() ? $(s) : $(s).find(filter));
- if (onSuccess != null) {
- onSuccess.setElement(Ajax.this.get(0));
- onSuccess.f();
+ try {
+ // We clean up the returned string to smoothly append it to our document
+ String s = getData()[0].toString().replaceAll("<![^>]+>\\s*", "")
+ .replaceAll("(?si)</?html[^>]*>\\s*", "")
+ .replaceFirst("(?si)<head[^>]*>.*</head>\\s*", "")
+ .replaceFirst("(?si)<script[^>]*>.*</script>\\s*", "")
+ .replaceAll("<?si></?body[^>]*>\\s*", "");
+ // We wrap the results in a div
+ s = "<div>" + s + "</div>";
+
+ Ajax.this.empty().append(filter.isEmpty() ? $(s) : $(s).find(filter));
+ if (onSuccess != null) {
+ onSuccess.setElement(Ajax.this.get(0));
+ onSuccess.f();
+ }
+ } catch (Exception e) {
+ if (GWT.getUncaughtExceptionHandler() != null) {
+ GWT.getUncaughtExceptionHandler().onUncaughtException(e);
+ }
}
}
});
public String toString() {
return "bind function for event type " + type;
}
+
+ public boolean isEquals(Function f) {
+ return function.equals(f);
+ }
}
/**
public void bind(int eventbits, String namespace, final Object data,
final Function function, int times) {
if (function == null) {
- unbind(eventbits, namespace);
+ unbind(eventbits, namespace, null);
return;
}
eventBits |= eventbits;
}
public void unbind(int eventbits) {
- unbind(eventbits, null);
+ unbind(eventbits, null, null);
}
- public void unbind(int eventbits, String namespace) {
+ public void unbind(int eventbits, String namespace, Function f) {
JsObjectArray<BindFunction> newList = JsObjectArray.createArray().cast();
for (int i = 0; i < elementEvents.length(); i++) {
BindFunction listener = elementEvents.get(i);
boolean matchNS = namespace == null || namespace.isEmpty()
|| listener.nameSpace.equals(namespace);
boolean matchEV = eventbits <= 0 || listener.hasEventType(eventbits);
- if (matchNS && matchEV) {
+ boolean matchFC = f == null || listener.isEquals(f);
+ if (matchNS && matchEV && matchFC) {
continue;
}
newList.add(listener);
}
elementEvents = newList;
+
}
- public void unbind(String event) {
+ public void unbind(String event, Function f) {
// TODO: nameSpaces in event lists
String nameSpace = event.replaceFirst("^[^\\.]+\\.*(.*)$", "$1");
String eventName = event.replaceFirst("^([^\\.]+).*$", "$1");
int b = getEventBits(eventName);
- unbind(b, nameSpace);
+ unbind(b, nameSpace, f);
}
private void clean() {
function.clean();
}
}
+
}
$("p", e).unbind(Event.ONCLICK);
$("p", e).click();
assertEquals("white", $("p", e).css("color", false));
+
+ Function f1 = new Function() {
+ public void f(){
+ $(this).css(CSS.COLOR.with(RGBColor.RED));
+ }
+ };
+ Function f2 = new Function() {
+ public void f(){
+ $(this).css(CSS.COLOR.with(RGBColor.GREEN));
+ }
+ };
+ $("p", e).click(f1, f2);
+ $("p", e).css(CSS.COLOR.with(RGBColor.WHITE));
+ $("p", e, Events.Events).trigger(Event.ONCLICK);
+ assertEquals("green", $("p", e).css("color", false));
+ $("p", e).unbind(Event.ONCLICK, f2);
+ $("p", e, Events.Events).trigger(Event.ONCLICK);
+ assertEquals("red", $("p", e).css("color", false));
+
+
// toggle
$("p", e).unbind(Event.ONCLICK);
public boolean f(Event evnt) {
GQuery gq = $(evnt);
int c = evnt.getCharCode() > 0 ? evnt.getCharCode() : evnt.getKeyCode();
- System.out.println(evnt.getCharCode() + " " + evnt.getKeyCode());
gq.val(gq.val() + Character.toString((char)c));
return false;
}