return this;
}
- public GQuery die(int eventbits) {
+
+ public GQuery die(int eventbits, String nameSpace) {
EventsListener.getInstance(Element.is(currentContext) ? (Element) currentContext : body).die(
- eventbits, currentSelector);
+ eventbits, nameSpace, currentSelector);
return this;
}
+
+ public GQuery die(int eventbits) {
+ return die(eventbits, null);
+ }
+
/**
* Remove an event handlers previously attached using live() The selector used with it must match
* exactly the selector initially used with live(). if <code>eventName</code> is null, all event
}
public GQuery live(int eventbits, final Object data, Function... funcs) {
+ return live(eventbits, null, data, funcs);
+
+ }
+
+ public GQuery live(int eventbits, String nameSpace, final Object data, Function... funcs) {
EventsListener.getInstance(Element.is(currentContext) ? (Element) currentContext : body).live(
- eventbits, currentSelector, data, funcs);
+ eventbits, nameSpace, currentSelector, data, funcs);
return this;
}
/**
* Remove the BindFunction associated to this cssSelector
*/
- public void removeBindFunctionForSelector(String cssSelector) {
- bindFunctionBySelector.delete(cssSelector);
+ public void removeBindFunctionForSelector(String cssSelector, String nameSpace) {
+ if (nameSpace == null || nameSpace.length() == 0) {
+ bindFunctionBySelector.delete(cssSelector);
+ } else {
+ JsObjectArray<BindFunction> functions = bindFunctionBySelector.get(cssSelector);
+
+ if (functions == null || functions.length() == 0) {
+ return;
+ }
+ JsObjectArray<BindFunction> newFunctions = JsObjectArray.create();
+
+ for (int i = 0; i < functions.length(); i++) {
+ BindFunction f = functions.get(i);
+ if (!nameSpace.equals(f.nameSpace)) {
+ newFunctions.add(f);
+ }
+ }
+
+ bindFunctionBySelector.delete(cssSelector);
+ if (newFunctions.length() > 0) {
+ bindFunctionBySelector.put(cssSelector, newFunctions);
+ }
+
+ }
}
/**
}
public void die(String eventNames, String cssSelector) {
- die(getEventBits(eventNames), cssSelector);
+ String[] parts = eventNames.split("[\\s,]+");
+
+ for (String event : parts) {
+ String nameSpace = null;
+ String eventName = event;
+
+ //seperate possible namespace
+ //jDramaix: I removed old regex ^([^.]*)\.?(.*$) because it didn't work on IE8...
+ String[] subparts = event.split("\\.", 2);
+
+ if (subparts.length == 2) {
+ nameSpace = subparts[1];
+ eventName = subparts[0];
+ }
+
+ int b = getTypeInt(eventName);
+
+ die(b, nameSpace, cssSelector);
+ }
+
+
}
- public void die(int eventbits, String cssSelector) {
- if (eventbits == 0) {
+ public void die(int eventbits, String nameSpace, String cssSelector) {
+ if (eventbits <= 0) {
for (String k : liveBindFunctionByEventType.keys()) {
LiveBindFunction liveBindFunction = liveBindFunctionByEventType.<JsCache> cast().get(k);
- liveBindFunction.removeBindFunctionForSelector(cssSelector);
+ liveBindFunction.removeBindFunctionForSelector(cssSelector, nameSpace);
}
} else {
LiveBindFunction liveBindFunction = liveBindFunctionByEventType.get(eventbits);
if (liveBindFunction != null) {
- liveBindFunction.removeBindFunctionForSelector(cssSelector);
+ liveBindFunction.removeBindFunctionForSelector(cssSelector, nameSpace);
}
}
}
return getGwtEventListener(element);
}
- public void live(String eventNames, String cssSelector, Object data, Function... f) {
- live(getEventBits(eventNames), cssSelector, data, f);
+ public void live(String events, String cssSelector, Object data, Function... funcs) {
+
+ String[] parts = events.split("[\\s,]+");
+
+ for (String event : parts) {
+
+ String nameSpace = null;
+ String eventName = event;
+
+
+ String[] subparts = event.split("\\.", 2);
+
+ if (subparts.length == 2) {
+ nameSpace = subparts[1];
+ eventName = subparts[0];
+ }
+
+ int b = getTypeInt(eventName);
+ for (Function function : funcs) {
+ //Function handler = hook != null ? hook.createDelegateHandler(function) : function;
+ live(b, nameSpace, cssSelector, data, function);
+ }
+ }
}
- public void live(int eventbits, String cssSelector, Object data, Function... funcs) {
+ public void live(int eventbits, String nameSpace, String cssSelector, Object data, Function... funcs) {
for (int i = 0; i < 28; i++) {
int event = (int) Math.pow(2, i);
if ((eventbits & event) == event) {
for (Function f : funcs) {
// TODO handle special event by passing original event name
- liveBindFunction.addBindFunctionForSelector(cssSelector, new BindFunction(event, "live",
+ liveBindFunction.addBindFunctionForSelector(cssSelector, new BindFunction(event, nameSpace,
null, f, data));
}
}
assertEquals("yellow", $("#div1", e).css(CSS.BACKGROUND_COLOR, false));
}
+ public void testLiveWithNameSpace() {
+ String content = "<input type='text' id='test'></div>";
+ $(e).html(content);
+
+ $(".live", e)
+ .live(
+ "keydown.keyevents keypress.keyevents keyup.keyevents "
+ + "mousedown.mouseevents mouseup.mouseevents mousemove.mouseevents mouseover.mouseevents "
+ + "mouseout.mouseevents", new Function() {
+ @Override
+ public void f() {
+ $("#test", e).val("event fired");
+ }
+ });
+
+ $("#test", e).addClass("live");
+
+
+ int allEventbits[] =
+ new int[]{
+ ONKEYDOWN, ONKEYPRESS, ONKEYUP, ONMOUSEDOWN, ONMOUSEUP, ONMOUSEMOVE,
+ ONMOUSEOVER, ONMOUSEOUT};
+
+ for (int eventbits : allEventbits) {
+ $("#test", e).trigger(eventbits, 'c');
+
+ assertEquals("event fired", $("#test", e).val());
+ $("#test", e).val("");
+
+
+ }
+
+ // test die without namespace
+ $(".live", e).die("keydown");
+
+ for (int eventbits : allEventbits) {
+ $("#test", e).trigger(eventbits, 'c');
+
+ if (eventbits != ONKEYDOWN) {
+ assertEquals("event fired", $("#test", e).val());
+ $("#test", e).val("");
+ } else {
+ assertEquals("", $("#test", e).val());
+ }
+
+ }
+
+ // test die event name + namespace
+ $(".live", e).die("keypress.keyevents keyup.keyevents");
+
+ for (int eventbits : allEventbits) {
+ $("#test", e).trigger(eventbits, 'c');
+ if ((eventbits & MOUSEEVENTS) == eventbits) {
+ assertEquals("event fired", $("#test", e).val());
+ $("#test", e).val("");
+ } else {
+ assertEquals("", $("#test", e).val());
+ }
+ }
+
+ // test die only on namespace
+ $(".live", e).die(".mouseevents");
+
+ for (int eventbits : allEventbits) {
+ $("#test", e).trigger(eventbits, 'c');
+
+ assertEquals("", $("#test", e).val());
+
+ }
+
+ }
+
public void testMouseenterEvent() {
String content = "<div id='test'>blop</div>";
$(e).html(content);