From b04a54192b8f70349fa421d9cc59588a1eaeeb13 Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Mon, 3 May 2010 16:10:03 +0000 Subject: Fixes Issue_29 --- .../src/main/java/com/google/gwt/query/client/Function.java | 2 ++ .../src/main/java/com/google/gwt/query/client/GQuery.java | 7 +++++-- .../test/java/com/google/gwt/query/client/GwtQueryCoreTest.java | 7 +++++++ 3 files changed, 14 insertions(+), 2 deletions(-) (limited to 'gwtquery-core/src') diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Function.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Function.java index 77599c51..333e537b 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/Function.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/Function.java @@ -28,6 +28,7 @@ public abstract class Function { * invoke a callback on each element. */ public String f(Element e, int i) { + f(e); return ""; } @@ -36,6 +37,7 @@ public abstract class Function { * return value, apply to a single element only. */ public void f(Element e) { + throw new RuntimeException("You have to override the adequate method to handle this action."); } /** diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java index 46cfefee..d6899eb8 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java @@ -900,11 +900,14 @@ public class GQuery implements Lazy { /** * 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 f(Element e, int i) */ public GQuery each(Function... f) { for (Function f1 : f) { - for (Element e : elements()) { - f1.f(e); + for (int i = 0; i < elements.getLength(); i++) { + f1.f(elements.getItem(i), i); } } return this; diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GwtQueryCoreTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GwtQueryCoreTest.java index 74f5b783..2a55a7df 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GwtQueryCoreTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GwtQueryCoreTest.java @@ -147,6 +147,13 @@ public class GwtQueryCoreTest extends GWTTestCase { } }); assertHtmlEquals("

.

.

.

", $("p", e)); + $("p", e).each(new Function() { + public String f(Element e, int i) { + $(e).text("" + i); + return ""; + } + }); + assertHtmlEquals("

0

1

2

", $("p", e)); } public void testEffectsPlugin() { -- cgit v1.2.3