From fbec240685774f56474b5df0f392217d02523147 Mon Sep 17 00:00:00 2001 From: Julien Dramaix Date: Fri, 18 May 2012 14:09:42 +0000 Subject: [PATCH] better management of binding/unbinding multiple events at once / fix the issue 134 --- .../client/plugins/events/EventsListener.java | 27 +- .../gwt/query/client/GQueryEventsTestGwt.java | 611 ++++++++++-------- 2 files changed, 370 insertions(+), 268 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 8cbad2cc..9f469618 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 @@ -77,9 +77,24 @@ public class EventsListener implements EventListener { } public boolean hasEventType(int etype) { - return (type & etype) == type; + return (type & etype) != 0; } + /** + * Remove a set of events. The bind function will not be fire anymore for those events + * @param eventBits the set of events to unsink + * + */ + public int unsink(int eventBits){ + if (eventBits <= 0){ + type = 0; + }else{ + type = type & ~eventBits; + } + + return type; + } + @Override public String toString() { return "bind function for event type " + type; @@ -446,13 +461,21 @@ public class EventsListener implements EventListener { JsObjectArray 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); boolean matchFC = f == null || listener.isEquals(f); + if (matchNS && matchEV && matchFC) { - continue; + int currentEventbits = listener.unsink(eventbits); + + if (currentEventbits == 0){ + //the BindFunction doesn't listen anymore on any events + continue; + } } + newList.add(listener); } elementEvents = newList; diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java index da077622..dcd6c2af 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java @@ -1,16 +1,14 @@ /* * Copyright 2011, The gwtquery team. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under * the License. */ package com.google.gwt.query.client; @@ -18,6 +16,7 @@ package com.google.gwt.query.client; import static com.google.gwt.query.client.GQuery.$; import static com.google.gwt.query.client.GQuery.document; import static com.google.gwt.query.client.GQuery.lazy; +import static com.google.gwt.user.client.Event.*; import com.google.gwt.dom.client.Element; import com.google.gwt.event.dom.client.ClickEvent; @@ -51,7 +50,7 @@ public class GQueryEventsTestGwt extends GWTTestCase { public String getModuleName() { return "com.google.gwt.query.Query"; } - + public void gwtTearDown() { $(e).remove(); e = null; @@ -67,85 +66,83 @@ public class GQueryEventsTestGwt extends GWTTestCase { EventsListener.clean(e); e.setInnerHTML(""); } - } - - - + } + public void testDie() { $(e).html("
content
"); - $(".clickMe", e).live("click", new Function(){ + $(".clickMe", e).live("click", new Function() { public void f(Element e) { $(e).css(CSS.COLOR.with(RGBColor.RED)); } }); - - $(".clickMe", e).live("dblclick", new Function(){ + + $(".clickMe", e).live("dblclick", new Function() { public void f(Element e) { $(e).css(CSS.COLOR.with(RGBColor.BLUE)); } }); - - $("#div1",e).addClass("clickMe"); - - $("#div1",e).click(); + + $("#div1", e).addClass("clickMe"); + + $("#div1", e).click(); assertEquals(RGBColor.RED.getCssName(), $("#div1", e).css(CSS.COLOR, false)); - - $("#div1",e).dblclick(); + + $("#div1", e).dblclick(); assertEquals(RGBColor.BLUE.getCssName(), $("#div1", e).css(CSS.COLOR, false)); - - //reset - $("#div1",e).css(CSS.COLOR.with(RGBColor.BLACK)); - + + // reset + $("#div1", e).css(CSS.COLOR.with(RGBColor.BLACK)); + $(".clickMe", e).die("click"); - $("#div1",e).click(); + $("#div1", e).click(); assertEquals(RGBColor.BLACK.getCssName(), $("#div1", e).css(CSS.COLOR, false)); - - $("#div1",e).dblclick(); + + $("#div1", e).dblclick(); assertEquals(RGBColor.BLUE.getCssName(), $("#div1", e).css(CSS.COLOR, false)); - - //reset - $("#div1",e).css(CSS.COLOR.with(RGBColor.BLACK)); - + + // reset + $("#div1", e).css(CSS.COLOR.with(RGBColor.BLACK)); + $(".clickMe", e).die("dblclick"); - - $("#div1",e).dblclick(); + + $("#div1", e).dblclick(); assertEquals(RGBColor.BLACK.getCssName(), $("#div1", e).css(CSS.COLOR, false)); - + } - + public void testDie2() { $(e).html("
content
"); - $(".clickMe", e).live("click", new Function(){ + $(".clickMe", e).live("click", new Function() { public void f(Element e) { $(e).css(CSS.COLOR.with(RGBColor.RED)); } }); - - $(".clickMe", e).live("dblclick", new Function(){ + + $(".clickMe", e).live("dblclick", new Function() { public void f(Element e) { $(e).css(CSS.COLOR.with(RGBColor.BLUE)); } }); - - $("#div1",e).addClass("clickMe"); - - $("#div1",e).click(); + + $("#div1", e).addClass("clickMe"); + + $("#div1", e).click(); assertEquals(RGBColor.RED.getCssName(), $("#div1", e).css(CSS.COLOR, false)); - - $("#div1",e).dblclick(); + + $("#div1", e).dblclick(); assertEquals(RGBColor.BLUE.getCssName(), $("#div1", e).css(CSS.COLOR, false)); - - //reset - $("#div1",e).css(CSS.COLOR.with(RGBColor.BLACK)); - + + // reset + $("#div1", e).css(CSS.COLOR.with(RGBColor.BLACK)); + $(".clickMe", e).die(); - $("#div1",e).click(); + $("#div1", e).click(); assertEquals(RGBColor.BLACK.getCssName(), $("#div1", e).css(CSS.COLOR, false)); - $("#div1",e).dblclick(); + $("#div1", e).dblclick(); assertEquals(RGBColor.BLACK.getCssName(), $("#div1", e).css(CSS.COLOR, false)); - + } /** @@ -163,7 +160,7 @@ public class GQueryEventsTestGwt extends GWTTestCase { $("p", e).dblclick(); assertEquals("yellow", $("p", e).css("color", false)); } - + /** * TODO: focus/blur doesn't work with HtmlUnit, investigate and report. */ @@ -192,7 +189,7 @@ public class GQueryEventsTestGwt extends GWTTestCase { $("p", e).blur(); assertEquals("", $("p", e).css("border", false)); } - + public void testEventsPlugin() { $(e).html("

Content

"); @@ -215,14 +212,14 @@ public class GQueryEventsTestGwt extends GWTTestCase { $("p", e).unbind(Event.ONCLICK); $("p", e).click(); assertEquals("white", $("p", e).css("color", false)); - + Function f1 = new Function() { - public void f(){ + public void f() { $(this).css(CSS.COLOR.with(RGBColor.RED)); } }; Function f2 = new Function() { - public void f(){ + public void f() { $(this).css(CSS.COLOR.with(RGBColor.GREEN)); } }; @@ -233,8 +230,6 @@ public class GQueryEventsTestGwt extends GWTTestCase { $("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); @@ -286,7 +281,7 @@ public class GQueryEventsTestGwt extends GWTTestCase { public boolean f(Event evnt) { GQuery gq = $(evnt); int c = evnt.getCharCode() > 0 ? evnt.getCharCode() : evnt.getKeyCode(); - gq.val(gq.val() + Character.toString((char)c)); + gq.val(gq.val() + Character.toString((char) c)); return false; } }; @@ -302,7 +297,7 @@ public class GQueryEventsTestGwt extends GWTTestCase { $("input", e).keyup('c'); assertEquals("ABCabc", $("input", e).val()); } - + public void testLazyMethods() { $(e).css(CSS.COLOR.with(RGBColor.WHITE)); assertEquals("white", $(e).css("color", false)); @@ -317,20 +312,22 @@ public class GQueryEventsTestGwt extends GWTTestCase { } public void testLive() { - $(e).html("
Content 1 blop
"); - $(".clickMe", e).live("click", new Function(){ + $(e).html( + "
Content 1 blop
"); + $(".clickMe", e).live("click", new Function() { public void f() { $(this).css("color", "red"); } }); - - $(e).append("
Content 2
blop
"); - + + $(e).append( + "
Content 2
blop
"); + $(".clickMe", e).click(); assertEquals("red", $("#div1", e).css("color", false)); assertEquals("red", $("#div3", e).css("color", false)); - - //reset + + // reset $("*", e).css(CSS.COLOR.with(RGBColor.BLACK)); assertEquals("black", $("div", e).css("color", false)); assertEquals("black", $("span", e).css("color", false)); @@ -338,28 +335,28 @@ public class GQueryEventsTestGwt extends GWTTestCase { $("#span1", e).click(); assertEquals("red", $("#div1", e).css("color", false)); assertEquals("black", $("#div3", e).css("color", false)); - - //reset + + // reset $("*", e).css(CSS.COLOR.with(RGBColor.BLACK)); - + $("#span2", e).click(); assertEquals("black", $("#div1", e).css("color", false)); assertEquals("red", $("#div3", e).css("color", false)); - - //reset + + // reset $("*", e).removeClass("clickMe").css(CSS.COLOR.with(RGBColor.BLACK)); - + $("#div2, #div4", e).addClass("clickMe"); - + $("#span1", e).click(); assertEquals("black", $("#div1", e).css("color", false)); assertEquals("red", $("#div2", e).css("color", false)); assertEquals("black", $("#div3", e).css("color", false)); assertEquals("black", $("#div4", e).css("color", false)); - //reset + // reset $("*", e).css(CSS.COLOR.with(RGBColor.BLACK)); - + $("#span2", e).click(); assertEquals("black", $("#div1", e).css("color", false)); assertEquals("black", $("#div2", e).css("color", false)); @@ -368,327 +365,324 @@ public class GQueryEventsTestGwt extends GWTTestCase { } public void testLive2() { - + $(e).html("
Content 1 blop
"); - - $(".clickable", e).live("click", new Function(){ + + $(".clickable", e).live("click", new Function() { public void f(Element e) { $(e).css(CSS.COLOR.with(RGBColor.RED)); } }); - - $(".clickable2", e).live("click", new Function(){ + + $(".clickable2", e).live("click", new Function() { public void f(Element e) { $(e).css(CSS.COLOR.with(RGBColor.BLUE)); } }); - - $(".hover", e).live("mouseover", new Function(){ + + $(".hover", e).live("mouseover", new Function() { public void f(Element e) { $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.YELLOW)); } }); - + $("#div1", e).addClass("clickable"); $("#div2", e).addClass("clickable2", "hover"); - + $("#span1", e).click(); - + assertEquals("red", $("#div1", e).css(CSS.COLOR, false)); assertEquals("blue", $("#div2", e).css(CSS.COLOR, false)); - //ensure taht handler related to mouseover event was not called + // ensure taht handler related to mouseover event was not called assertNotSame("yellow", $("#div2", e).css(CSS.BACKGROUND_COLOR, false)); - - + } - + public void testLiveWithEventBit() { $(e).html("
Content 1 blop
"); - - $(".clickable", e).live(Event.ONCLICK, new Function(){ + + $(".clickable", e).live(Event.ONCLICK, new Function() { public void f(Element e) { $(e).css(CSS.COLOR.with(RGBColor.RED)); } }); - + $("#div1", e).addClass("clickable"); $("#span1", e).click(); - + assertEquals("red", $("#div1", e).css(CSS.COLOR, false)); - + } - + public void testLiveWithMultipleFunction() { - + $(e).html("
Content 1 blop
"); - - $(".clickable", e).live("click", new Function(){ + + $(".clickable", e).live("click", new Function() { public void f(Element e) { $(e).css(CSS.COLOR.with(RGBColor.RED)); } - }, new Function(){ + }, new Function() { public void f(Element e) { $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.YELLOW)); } }); - + $("#div1", e).addClass("clickable"); - + $("#span1", e).click(); - + assertEquals("red", $("#div1", e).css(CSS.COLOR, false)); assertNotSame("yellow", $("#div1", e).css(CSS.BACKGROUND_COLOR, false)); - - + } - - public void testDelegate(){ - - $(e).html("
Content 0blop
Content 0blop
"); - - $(".mainDiv",e).delegate(".subDiv", "click", new Function(){ + + public void testDelegate() { + + $(e).html( + "
Content 0blop
Content 0blop
"); + + $(".mainDiv", e).delegate(".subDiv", "click", new Function() { @Override public void f(Element e) { $(e).css(CSS.COLOR.with(RGBColor.RED)); } }); - - $(".mainDiv",e).delegate(".subDiv", Event.ONMOUSEOVER, new Function(){ + + $(".mainDiv", e).delegate(".subDiv", Event.ONMOUSEOVER, new Function() { @Override public void f(Element e) { $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.YELLOW)); } }); - - for (Element mainDiv : $(".mainDiv",e).elements()){ - for (int i = 0; i < 3 ; i++){ - String html = "
Content "+i+"blop
"; + + for (Element mainDiv : $(".mainDiv", e).elements()) { + for (int i = 0; i < 3; i++) { + String html = "
Content " + i + "blop
"; $(mainDiv).append(html); } } - - assertEquals(8, $(".subDiv",e).length()); - - $("span",e).click().trigger(Event.ONMOUSEOVER); - - for (Element el : $(".subDiv",e).elements()){ + + assertEquals(8, $(".subDiv", e).length()); + + $("span", e).click().trigger(Event.ONMOUSEOVER); + + for (Element el : $(".subDiv", e).elements()) { assertEquals("red", $(el).css(CSS.COLOR, false)); assertEquals("yellow", $(el).css(CSS.BACKGROUND_COLOR, false)); } - - - + } - public void testUnDelegate(){ - - $(e).html("
Content 0blop
Content 0blop
"); - - $(".mainDiv",e).delegate(".subDiv", "click", new Function(){ + public void testUnDelegate() { + + $(e).html( + "
Content 0blop
Content 0blop
"); + + $(".mainDiv", e).delegate(".subDiv", "click", new Function() { @Override public void f(Element e) { $(e).css(CSS.COLOR.with(RGBColor.RED)); } }); - - $(".mainDiv",e).delegate(".subDiv", Event.ONMOUSEOVER, new Function(){ + + $(".mainDiv", e).delegate(".subDiv", Event.ONMOUSEOVER, new Function() { @Override public void f(Element e) { $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.YELLOW)); } }); - - for (Element mainDiv : $(".mainDiv",e).elements()){ - for (int i = 0; i < 3 ; i++){ - String html = "
Content "+i+"blop
"; + + for (Element mainDiv : $(".mainDiv", e).elements()) { + for (int i = 0; i < 3; i++) { + String html = "
Content " + i + "blop
"; $(mainDiv).append(html); } } - - assertEquals(8, $(".subDiv",e).length()); - - $("span",e).click().trigger(Event.ONMOUSEOVER); - - for (Element el : $(".subDiv",e).elements()){ + + assertEquals(8, $(".subDiv", e).length()); + + $("span", e).click().trigger(Event.ONMOUSEOVER); + + for (Element el : $(".subDiv", e).elements()) { assertEquals("red", $(el).css(CSS.COLOR, false)); assertEquals("yellow", $(el).css(CSS.BACKGROUND_COLOR, false)); - //reset + // reset $(el).css(CSS.COLOR.with(RGBColor.BLACK), CSS.BACKGROUND_COLOR.with(RGBColor.WHITE)); } - - $(".mainDiv", e).undelegate(".subDiv",Event.ONCLICK); - - $("span",e).click().trigger(Event.ONMOUSEOVER); - - for (Element el : $(".subDiv",e).elements()){ + + $(".mainDiv", e).undelegate(".subDiv", Event.ONCLICK); + + $("span", e).click().trigger(Event.ONMOUSEOVER); + + for (Element el : $(".subDiv", e).elements()) { assertEquals("black", $(el).css(CSS.COLOR, false)); assertEquals("yellow", $(el).css(CSS.BACKGROUND_COLOR, false)); - //reset + // reset $(el).css(CSS.COLOR.with(RGBColor.BLACK), CSS.BACKGROUND_COLOR.with(RGBColor.WHITE)); } - - $(".mainDiv", e).undelegate(".subDiv","mouseover"); - - $("span",e).click().trigger(Event.ONMOUSEOVER); - - for (Element el : $(".subDiv",e).elements()){ + + $(".mainDiv", e).undelegate(".subDiv", "mouseover"); + + $("span", e).click().trigger(Event.ONMOUSEOVER); + + for (Element el : $(".subDiv", e).elements()) { assertEquals("black", $(el).css(CSS.COLOR, false)); assertEquals("white", $(el).css(CSS.BACKGROUND_COLOR, false)); } } - - public void testUnDelegateAll(){ - - $(e).html("
Content 0blop
Content 0blop
"); - - $(".mainDiv",e).delegate(".subDiv", "click", new Function(){ + + public void testUnDelegateAll() { + + $(e).html( + "
Content 0blop
Content 0blop
"); + + $(".mainDiv", e).delegate(".subDiv", "click", new Function() { @Override public void f(Element e) { $(e).css(CSS.COLOR.with(RGBColor.RED)); } }); - - $(".mainDiv",e).delegate(".subDiv", Event.ONMOUSEOVER, new Function(){ + + $(".mainDiv", e).delegate(".subDiv", Event.ONMOUSEOVER, new Function() { @Override public void f(Element e) { $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.YELLOW)); } }); - - for (Element mainDiv : $(".mainDiv",e).elements()){ - for (int i = 0; i < 3 ; i++){ - String html = "
Content "+i+"blop
"; + + for (Element mainDiv : $(".mainDiv", e).elements()) { + for (int i = 0; i < 3; i++) { + String html = "
Content " + i + "blop
"; $(mainDiv).append(html); } } - - assertEquals(8, $(".subDiv",e).length()); - - $("span",e).click().trigger(Event.ONMOUSEOVER); - - for (Element el : $(".subDiv",e).elements()){ + + assertEquals(8, $(".subDiv", e).length()); + + $("span", e).click().trigger(Event.ONMOUSEOVER); + + for (Element el : $(".subDiv", e).elements()) { assertEquals("red", $(el).css(CSS.COLOR, false)); assertEquals("yellow", $(el).css(CSS.BACKGROUND_COLOR, false)); - //reset + // reset $(el).css(CSS.COLOR.with(RGBColor.BLACK), CSS.BACKGROUND_COLOR.with(RGBColor.WHITE)); } - + $(".mainDiv", e).undelegate(".subDiv"); - - $("span",e).click().trigger(Event.ONMOUSEOVER); - - for (Element el : $(".subDiv",e).elements()){ + + $("span", e).click().trigger(Event.ONMOUSEOVER); + + for (Element el : $(".subDiv", e).elements()) { assertEquals("black", $(el).css(CSS.COLOR, false)); assertEquals("white", $(el).css(CSS.BACKGROUND_COLOR, false)); } } -public void testUnDelegateAll2(){ - - $(e).html("
Content 0blop
Content 0blop
"); - - $(".mainDiv",e).delegate(".subDiv", "click", new Function(){ + public void testUnDelegateAll2() { + + $(e).html( + "
Content 0blop
Content 0blop
"); + + $(".mainDiv", e).delegate(".subDiv", "click", new Function() { @Override public void f(Element e) { $(e).css(CSS.COLOR.with(RGBColor.RED)); } }); - - $(".mainDiv",e).delegate(".subDiv", Event.ONMOUSEOVER, new Function(){ + + $(".mainDiv", e).delegate(".subDiv", Event.ONMOUSEOVER, new Function() { @Override public void f(Element e) { $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.YELLOW)); } }); - - for (Element mainDiv : $(".mainDiv",e).elements()){ - for (int i = 0; i < 3 ; i++){ - String html = "
Content "+i+"blop
"; + + for (Element mainDiv : $(".mainDiv", e).elements()) { + for (int i = 0; i < 3; i++) { + String html = "
Content " + i + "blop
"; $(mainDiv).append(html); } } - - assertEquals(8, $(".subDiv",e).length()); - - $("span",e).click().trigger(Event.ONMOUSEOVER); - - for (Element el : $(".subDiv",e).elements()){ + + assertEquals(8, $(".subDiv", e).length()); + + $("span", e).click().trigger(Event.ONMOUSEOVER); + + for (Element el : $(".subDiv", e).elements()) { assertEquals("red", $(el).css(CSS.COLOR, false)); assertEquals("yellow", $(el).css(CSS.BACKGROUND_COLOR, false)); - //reset + // reset $(el).css(CSS.COLOR.with(RGBColor.BLACK), CSS.BACKGROUND_COLOR.with(RGBColor.WHITE)); } - + $(".mainDiv", e).undelegate(); - - $("span",e).click().trigger(Event.ONMOUSEOVER); - - for (Element el : $(".subDiv",e).elements()){ + + $("span", e).click().trigger(Event.ONMOUSEOVER); + + for (Element el : $(".subDiv", e).elements()) { assertEquals("black", $(el).css(CSS.COLOR, false)); assertEquals("white", $(el).css(CSS.BACKGROUND_COLOR, false)); } } - - - public void testLiveWithMultipleEvent() { - + $(e).html("
Content 1 blop
"); - - $(".myClass", e).live("click mouseover", new Function(){ + + $(".myClass", e).live("click mouseover", new Function() { public void f(Element e) { $(e).css(CSS.COLOR.with(RGBColor.RED)); } }); - + $("#div1", e).addClass("myClass"); - + $("#div1", e).click(); - + assertEquals("red", $("#div1", e).css(CSS.COLOR, false)); - + $("#div1", e).css(CSS.COLOR.with(RGBColor.BLACK)); - + $("#div1", e).trigger(Event.ONMOUSEOVER); assertEquals("red", $("#div1", e).css(CSS.COLOR, false)); - - $(".myClass2", e).live(Event.ONCLICK|Event.ONMOUSEDOWN, new Function(){ + + $(".myClass2", e).live(Event.ONCLICK | Event.ONMOUSEDOWN, new Function() { public void f(Element e) { $(e).css(CSS.COLOR.with(RGBColor.YELLOW)); } }); - + $("#div2", e).addClass("myClass2"); - + $("#div2", e).click(); - + assertEquals("yellow", $("#div2", e).css(CSS.COLOR, false)); - + $("#div2", e).css(CSS.COLOR.with(RGBColor.BLACK)); - + $("#div2", e).trigger(Event.ONMOUSEDOWN); assertEquals("yellow", $("#div2", e).css(CSS.COLOR, false)); - - - - } + } public void testNamedBinding() { $(e).html("

Content

"); - $("p", e, Events.Events).bind("click.first.namespace", null, new Function() {; + $("p", e, Events.Events).bind("click.first.namespace", null, new Function() { + ; public void f(Element elem) { $(elem).css(CSS.COLOR.with(RGBColor.RED)); } }); - $("p", e, Events.Events).bind("click.second.namespace", null, new Function() {; + $("p", e, Events.Events).bind("click.second.namespace", null, new Function() { + ; public void f(Element elem) { $(elem).css(CSS.BACKGROUND_COLOR.with(RGBColor.GREEN)); } }); - $("p", e, Events.Events).bind("click", null, new Function() {; + $("p", e, Events.Events).bind("click", null, new Function() { + ; public void f(Element elem) { $(elem).css(CSS.FONT_SIZE.with(Length.px(24))); } @@ -697,8 +691,9 @@ public void testUnDelegateAll2(){ assertEquals("red", $("p", e).css("color", false)); assertEquals("green", $("p", e).css("background-color", false)); assertEquals(24.0d, $("p", e).cur("fontSize", true)); - - $("p", e).css(CSS.COLOR.with(null)).css(CSS.BACKGROUND_COLOR,"").css(CSS.FONT_SIZE.with(Length.px(12))); + + $("p", e).css(CSS.COLOR.with(null)).css(CSS.BACKGROUND_COLOR, "").css( + CSS.FONT_SIZE.with(Length.px(12))); assertFalse("red".equalsIgnoreCase($("p", e).css("color", false))); assertFalse("green".equalsIgnoreCase($("p", e).css("background-color", false))); assertEquals(12.0d, $("p", e).cur("fontSize", true)); @@ -708,9 +703,9 @@ public void testUnDelegateAll2(){ assertFalse("red".equalsIgnoreCase($("p", e).css("color", false))); assertEquals("green", $("p", e).css("background-color", false)); assertEquals(24.0d, $("p", e).cur("fontSize", true)); - - - $("p", e).css(CSS.COLOR.with(null)).css(CSS.BACKGROUND_COLOR,"").css(CSS.FONT_SIZE.with(Length.px(12))); + + $("p", e).css(CSS.COLOR.with(null)).css(CSS.BACKGROUND_COLOR, "").css( + CSS.FONT_SIZE.with(Length.px(12))); assertFalse("red".equalsIgnoreCase($("p", e).css("color", false))); assertFalse("green".equalsIgnoreCase($("p", e).css("background-color", false))); assertEquals(12.0d, $("p", e).cur("fontSize", true)); @@ -727,7 +722,7 @@ public void testUnDelegateAll2(){ assertEquals(1, b.size()); assertEquals(1, b.get().getLength()); b.click(new Function() { - public void f(Element e){ + public void f(Element e) { b.css(CSS.COLOR.with(RGBColor.RED)); } }); @@ -739,39 +734,40 @@ public void testUnDelegateAll2(){ b.click(); assertEquals("red", $(b).css("color", false)); } - + @DoNotRunWith({Platform.HtmlUnitLayout}) public void testResizeWindowEvent() { GQuery w = $(GQuery.window); - + delayTestFinish(100); w.bind("resize", null, new Function() { public void f(Element e) { finishTest(); } }); - + Window.resizeTo(w.width(), w.height() + 100); } - + public void testResizeEvent() { $(e).html("
"); GQuery g = $("#ra", e); - + delayTestFinish(100); g.bind("resize", null, new Function() { public void f(Element e) { finishTest(); } }); - + g.width(400); g.resize(); } public void testBindUnbindSubmitEvent() { // Add a form and an iframe to the dom. The form target is the iframe - $(e).html("