diff options
author | Manolo Carrasco <manolo@apache.org> | 2010-05-03 16:10:03 +0000 |
---|---|---|
committer | Manolo Carrasco <manolo@apache.org> | 2010-05-03 16:10:03 +0000 |
commit | b04a54192b8f70349fa421d9cc59588a1eaeeb13 (patch) | |
tree | 107608b94c4b92eeeb6c03c2f912ea1051d4e8af /gwtquery-core/src | |
parent | 11d181f5c451ce618b300f088d5a6b1294929be3 (diff) | |
download | gwtquery-b04a54192b8f70349fa421d9cc59588a1eaeeb13.tar.gz gwtquery-b04a54192b8f70349fa421d9cc59588a1eaeeb13.zip |
Fixes Issue_29
Diffstat (limited to 'gwtquery-core/src')
3 files changed, 14 insertions, 2 deletions
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<GQuery, LazyGQuery> { /**
* 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>.</p><p>.</p><p>.</p>", $("p", e)); + $("p", e).each(new Function() { + public String f(Element e, int i) { + $(e).text("" + i); + return ""; + } + }); + assertHtmlEquals("<p>0</p><p>1</p><p>2</p>", $("p", e)); } public void testEffectsPlugin() { |