/** Add a {@link BindFunction} for a specific css selector. */ public void addBindFunctionForSelector(String cssSelector, BindFunction f) { JsObjectArray<BindFunction> bindFunctions = bindFunctionBySelector.get(cssSelector); if (bindFunctions == null) { bindFunctions = JsObjectArray.create(); bindFunctionBySelector.put(cssSelector, bindFunctions); } bindFunctions.add(f); }
public void bind( int eventbits, String namespace, String eventName, Object data, Function function, int times) { sink(eventbits, eventName); elementEvents.add(new BindFunction(eventbits, eventName, namespace, function, data, times)); }
private void liveBitlessEvent( String eventName, String nameSpace, String cssSelector, Object data, Function... funcs) { LiveBindFunction liveBindFunction = liveBindFunctionByEventName.get(eventName); if (liveBindFunction == null) { liveBindFunction = new LiveBindFunction(eventName, "live", data); sink(BITLESS, eventName); elementEvents.add(liveBindFunction); liveBindFunctionByEventName.put(eventName, liveBindFunction); } for (Function f : funcs) { liveBindFunction.addBindFunctionForSelector( cssSelector, new BindFunction(BITLESS, eventName, nameSpace, f, data, -1)); } }
public void unbind(int eventbits, String namespace, String eventName, Function f) { JsObjectArray<BindFunction> newList = JsObjectArray.createArray().cast(); for (int i = 0; i < elementEvents.length(); i++) { BindFunction listener = elementEvents.get(i); boolean matchNS = isNullOrEmpty(namespace) || listener.nameSpace.equals(namespace); boolean matchEV = eventbits <= 0 || listener.hasEventType(eventbits); boolean matchEVN = matchEV || listener.isTypeOf(eventName); boolean matchFC = f == null || listener.isEquals(f); if (matchNS && matchEV && matchEVN && matchFC) { int currentEventbits = listener.unsink(eventbits); if (currentEventbits == 0) { // the BindFunction doesn't listen anymore on any events continue; } } newList.add(listener); } elementEvents = newList; }
private void liveBitEvent( 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) { // is a LiveBindFunction already attached for this kind of event LiveBindFunction liveBindFunction = liveBindFunctionByEventType.get(event); if (liveBindFunction == null) { liveBindFunction = new LiveBindFunction(event, "live", data); sink(eventbits, null); elementEvents.add(liveBindFunction); liveBindFunctionByEventType.put(event, liveBindFunction); } for (Function f : funcs) { liveBindFunction.addBindFunctionForSelector( cssSelector, new BindFunction(event, null, nameSpace, f, data, -1)); } } } }
/** Remove the BindFunction associated to this cssSelector. */ public void removeBindFunctionForSelector(String cssSelector, String nameSpace) { if (nameSpace == null) { 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 != null && !nameSpace.equals(f.nameSpace)) { newFunctions.add(f); } } bindFunctionBySelector.delete(cssSelector); if (newFunctions.length() > 0) { bindFunctionBySelector.put(cssSelector, newFunctions); } } }