From e4ba7e79c6d782e92de9e03e09d191c24188dc2a Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Mon, 17 Jan 2011 09:06:04 +0000 Subject: [PATCH] - Added QueryMin module thought to produce small javascript code although it increases number of permutations. - Removed plugins module since it is a new project. - Added some missing methods in GQuery: first, last, map. - Updated gwt version to 2.1.1 - Adding lazy interface to Widgets plugin. --- devtest/pom.xml | 2 +- gwtquery-core/pom.xml | 13 --- .../com/google/gwt/query/QueryMin.gwt.xml | 44 +++++++ .../com/google/gwt/query/client/Function.java | 10 +- .../com/google/gwt/query/client/GQuery.java | 70 +++++++++--- .../google/gwt/query/client/LazyGQuery.java | 28 ++++- .../query/client/impl/SelectorEngineImpl.java | 95 ---------------- .../client/impl/SelectorEngineNativeIE8.java | 8 +- .../client/impl/SelectorEngineNativeMin.java | 42 +++++++ .../impl/SelectorEngineNativeMinIE8.java | 42 +++++++ .../impl/{ => research}/SelectorEngineJS.java | 103 ++++++++++++++++- .../{ => research}/SelectorEngineJSIE.java | 2 +- .../SelectorEngineSizzleGwt.java | 61 +++++----- .../{ => research}/SelectorEngineXPath.java | 13 ++- .../gwt/query/client/plugins/LazyWidgets.java | 2 +- .../gwt/query/client/plugins/Widgets.java | 6 +- .../gwt/query/client/GQueryCoreTest.java | 37 ++++++ .../gwt/query/client/GQuerySelectorsTest.java | 6 +- plugins/pom.xml | 31 ----- .../src/main/java/gwtquery/Plugins.gwt.xml | 6 - .../gwtquery/plugins/collapser/Collapser.java | 73 ------------ .../gwtquery/plugins/widgets/Widgets.java | 107 ------------------ pom.xml | 6 +- samples/pom.xml | 48 ++++++-- .../gwtquery/samples/GwtQueryBench.gwt.xml | 1 - .../gwtquery/samples/GwtQueryDemo.gwt.xml | 1 - .../gwtquery/samples/GwtQueryEffects.gwt.xml | 1 - .../samples/GwtQueryEffectsMin.gwt.xml | 5 + .../samples/GwtQueryImageZoom.gwt.xml | 1 - .../gwtquery/samples/GwtQuerySample.gwt.xml | 2 - .../gwtquery/samples/GwtQueryWidgets.gwt.xml | 1 - .../samples/client/GwtQueryBenchModule.java | 6 +- .../samples/client/GwtQueryWidgetModule.java | 31 +++-- .../samples/public/GwtQueryEffectsMin.html | 65 +++++++++++ .../samples/public/GwtQueryWidgets.html | 2 - samples/src/main/webapp/index.html | 1 + 36 files changed, 543 insertions(+), 429 deletions(-) create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/QueryMin.gwt.xml create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMin.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMinIE8.java rename gwtquery-core/src/main/java/com/google/gwt/query/client/impl/{ => research}/SelectorEngineJS.java (87%) rename gwtquery-core/src/main/java/com/google/gwt/query/client/impl/{ => research}/SelectorEngineJSIE.java (86%) rename gwtquery-core/src/main/java/com/google/gwt/query/client/impl/{ => research}/SelectorEngineSizzleGwt.java (81%) rename gwtquery-core/src/main/java/com/google/gwt/query/client/impl/{ => research}/SelectorEngineXPath.java (90%) delete mode 100644 plugins/pom.xml delete mode 100644 plugins/src/main/java/gwtquery/Plugins.gwt.xml delete mode 100644 plugins/src/main/java/gwtquery/plugins/collapser/Collapser.java delete mode 100644 plugins/src/main/java/gwtquery/plugins/widgets/Widgets.java create mode 100644 samples/src/main/java/gwtquery/samples/GwtQueryEffectsMin.gwt.xml create mode 100644 samples/src/main/java/gwtquery/samples/public/GwtQueryEffectsMin.html diff --git a/devtest/pom.xml b/devtest/pom.xml index cd6ec0de..7c4e5e9c 100644 --- a/devtest/pom.xml +++ b/devtest/pom.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 - com.google.gwt + com.googlecode.gwtquery gwtquery-project 1.0.0-SNAPSHOT diff --git a/gwtquery-core/pom.xml b/gwtquery-core/pom.xml index c8852bcb..6fc760c0 100644 --- a/gwtquery-core/pom.xml +++ b/gwtquery-core/pom.xml @@ -51,19 +51,6 @@ - - org.apache.maven.plugins - maven-javadoc-plugin - - - attach-javadocs - verify - - jar - - - - org.apache.maven.plugins maven-surefire-plugin diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/QueryMin.gwt.xml b/gwtquery-core/src/main/java/com/google/gwt/query/QueryMin.gwt.xml new file mode 100644 index 00000000..a1381bd8 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/QueryMin.gwt.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 00df5dda..ff201feb 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 @@ -47,7 +47,7 @@ public abstract class Function { if (w != null){ return f(w, i); } else { - f(e); + f((com.google.gwt.user.client.Element)e); return ""; } } @@ -73,7 +73,7 @@ public abstract class Function { * Override this method for bound event handlers. */ public boolean f(Event e) { - f((Element)e.getCurrentEventTarget().cast()); + f((com.google.gwt.user.client.Element)e.getCurrentEventTarget().cast()); return true; } @@ -90,6 +90,11 @@ public abstract class Function { } } + + public void f(com.google.gwt.user.client.Element e) { + f((Element)e); + } + /** * Override this for GQuery methods which take a callback, but do not expect a * return value, apply to a single widget. @@ -102,4 +107,5 @@ public abstract class Function { public void f(Widget w){ f(); } + } 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 8a88cd81..b9f04f3f 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 @@ -19,6 +19,11 @@ import static com.google.gwt.query.client.plugins.Effects.Effects; import static com.google.gwt.query.client.plugins.Events.Events; import static com.google.gwt.query.client.plugins.Widgets.Widgets; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; + import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.JsArray; @@ -33,8 +38,8 @@ import com.google.gwt.dom.client.Node; import com.google.gwt.dom.client.NodeList; import com.google.gwt.dom.client.OptionElement; import com.google.gwt.dom.client.SelectElement; -import com.google.gwt.dom.client.TextAreaElement; import com.google.gwt.dom.client.Style.Display; +import com.google.gwt.dom.client.TextAreaElement; import com.google.gwt.query.client.css.CssProperty; import com.google.gwt.query.client.css.Length; import com.google.gwt.query.client.css.Percentage; @@ -48,11 +53,6 @@ import com.google.gwt.user.client.EventListener; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.Widget; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; - /** * Gwt Query is a GWT clone of the popular jQuery library. */ @@ -224,6 +224,22 @@ public class GQuery implements Lazy { public static GQuery $(NodeList elements) { return new GQuery(elements); } + + /** + * Create a new GQuery given a list of objects. + * Only node objects will be added; + */ + public static GQuery $(@SuppressWarnings("rawtypes") ArrayList a) { + JSArray elements = JSArray.create(); + for (Object o : a ) { + if (o instanceof Node) { + elements.addNode((Node)o); + } else if (o instanceof Widget) { + elements.addNode(((Widget)o).getElement()); + } + } + return new GQuery(elements); + } /** * This function accepts a string containing a CSS selector which is then used @@ -1168,6 +1184,13 @@ public class GQuery implements Lazy { } return pushStack(unique(array), "find", filters[0]); } + + /** + * Reduce the set of matched elements to the first in the set. + */ + public GQuery first() { + return eq(0); + } /** * Bind a set of functions to the focus event of each matched element. @@ -1431,6 +1454,13 @@ public class GQuery implements Lazy { public GQuery keyup(int key) { return trigger(Event.ONKEYUP, key); } + + /** + * Reduce the set of matched elements to the final one in the set. + */ + public GQuery last() { + return eq(size() - 1); + } /** * Returns the computed left position of the first element matched. @@ -1463,6 +1493,23 @@ public class GQuery implements Lazy { return $(slice(0, pos)); } + /** + * Pass each element in the current matched set through a function, + * producing a new array containing the return values. + */ + @SuppressWarnings("unchecked") + public ArrayList map(Function f) { + @SuppressWarnings("rawtypes") + ArrayList ret = new ArrayList(); + for (int i = 0; i < elements().length; i++) { + Object o = f.f(elements()[i], i); + if (o != null) { + ret.add(o); + } + } + return ret; + } + /** * Bind a set of functions to the mousedown event of each matched element. * Or trigger the event if no functions are provided. @@ -2440,9 +2487,10 @@ public class GQuery implements Lazy { * Return the first non null attached widget from the matched elements * or null if there isn't any. */ - public Widget widget(){ + public W widget(){ for (Element e : elements()){ - Widget w = getAssociatedWidget(e); + @SuppressWarnings("unchecked") + W w = (W) getAssociatedWidget(e); if (w != null){ return w; } @@ -2631,7 +2679,6 @@ public class GQuery implements Lazy { g.setSelector(selector); return g; } - private void allNextSiblingElements(Element firstChildElement, JSArray result, Element elem) { @@ -2713,7 +2760,6 @@ public class GQuery implements Lazy { return this; } - private native Element getPreviousSiblingElement(Element elem) /*-{ var sib = elem.previousSibling; while (sib && sib.nodeType != 1) @@ -2729,10 +2775,6 @@ public class GQuery implements Lazy { return res; } - - - - private void removeData(Element item, String name) { if (dataCache == null) { windowData = JavaScriptObject.createObject().cast(); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java index 4ce4ae90..39b49a71 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java @@ -17,6 +17,10 @@ package com.google.gwt.query.client; import static com.google.gwt.query.client.plugins.Effects.Effects; import static com.google.gwt.query.client.plugins.Events.Events; import static com.google.gwt.query.client.plugins.Widgets.Widgets; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.JsArray; @@ -31,8 +35,8 @@ import com.google.gwt.dom.client.Node; import com.google.gwt.dom.client.NodeList; import com.google.gwt.dom.client.OptionElement; import com.google.gwt.dom.client.SelectElement; -import com.google.gwt.dom.client.TextAreaElement; import com.google.gwt.dom.client.Style.Display; +import com.google.gwt.dom.client.TextAreaElement; import com.google.gwt.query.client.css.CssProperty; import com.google.gwt.query.client.css.Length; import com.google.gwt.query.client.css.Percentage; @@ -45,10 +49,6 @@ import com.google.gwt.user.client.Event; import com.google.gwt.user.client.EventListener; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.Widget; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; import com.google.gwt.query.client.LazyBase; public interface LazyGQuery extends LazyBase{ @@ -440,6 +440,11 @@ public interface LazyGQuery extends LazyBase{ */ LazyGQuery find(String... filters); + /** + * Reduce the set of matched elements to the first in the set. + */ + LazyGQuery first(); + /** * Bind a set of functions to the focus event of each matched element. * Or trigger the event if no functions are provided. @@ -613,6 +618,11 @@ public interface LazyGQuery extends LazyBase{ */ LazyGQuery keyup(int key); + /** + * Reduce the set of matched elements to the final one in the set. + */ + LazyGQuery last(); + /** * Returns the computed left position of the first element matched. */ @@ -636,6 +646,12 @@ public interface LazyGQuery extends LazyBase{ */ LazyGQuery lt(int pos); + /** + * Pass each element in the current matched set through a function, + * producing a new array containing the return values. + */ + ArrayList map(Function f); + /** * Bind a set of functions to the mousedown event of each matched element. * Or trigger the event if no functions are provided. @@ -1129,7 +1145,7 @@ public interface LazyGQuery extends LazyBase{ * Return the first non null attached widget from the matched elements * or null if there isn't any. */ - Widget widget(); + W widget(); /** * return the list of attached widgets matching the query diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineImpl.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineImpl.java index 7e1f8ad8..6d6c64f1 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineImpl.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineImpl.java @@ -26,100 +26,5 @@ import com.google.gwt.query.client.Regexp; */ public abstract class SelectorEngineImpl implements HasSelector { - /** - * Internal class. - */ - protected static class Sequence { - - public int start; - - public int max; - - public int add; - - public int modVal; - } - - /** - * Internal class. - */ - protected static class SplitRule { - - public String tag; - - public String id; - - public String allClasses; - - public String allAttr; - - public String allPseudos; - - public String tagRelation; - - public SplitRule(String tag, String id, String allClasses, String allAttr, - String allPseudos) { - this.tag = tag; - this.id = id; - this.allClasses = allClasses; - this.allAttr = allAttr; - this.allPseudos = allPseudos; - } - - public SplitRule(String tag, String id, String allClasses, String allAttr, - String allPseudos, String tagRelation) { - this.tag = tag; - this.id = id; - this.allClasses = allClasses; - this.allAttr = allAttr; - this.allPseudos = allPseudos; - this.tagRelation = tagRelation; - } - } - - protected static Sequence getSequence(String expression) { - int start = 0, add = 2, max = -1, modVal = -1; - Regexp expressionRegExp = new Regexp( - "^((odd|even)|([1-9]\\d*)|((([1-9]\\d*)?)n((\\+|\\-)(\\d+))?)|(\\-(([1-9]\\d*)?)n\\+(\\d+)))$"); - JSArray pseudoValue = expressionRegExp.exec(expression); - if (!truth(pseudoValue)) { - return null; - } else { - if (truth(pseudoValue.getStr(2))) { // odd or even - start = (eq(pseudoValue.getStr(2), "odd")) ? 1 : 2; - modVal = (start == 1) ? 1 : 0; - } else if (GQUtils - .truth(pseudoValue.getStr(3))) { // single digit - start = Integer.parseInt(pseudoValue.getStr(3), 10); - add = 0; - max = start; - } else if (truth(pseudoValue.getStr(4))) { // an+b - add = truth(pseudoValue.getStr(6)) ? Integer - .parseInt(pseudoValue.getStr(6), 10) : 1; - start = truth(pseudoValue.getStr(7)) ? Integer.parseInt( - (pseudoValue.getStr(8).charAt(0) == '+' ? "" - : pseudoValue.getStr(8)) + pseudoValue.getStr(9), 10) : 0; - while (start < 1) { - start += add; - } - modVal = (start > add) ? (start - add) % add - : ((start == add) ? 0 : start); - } else if (truth(pseudoValue.getStr(10))) { // -an+b - add = truth(pseudoValue.getStr(12)) ? Integer - .parseInt(pseudoValue.getStr(12), 10) : 1; - start = max = Integer.parseInt(pseudoValue.getStr(13), 10); - while (start > add) { - start -= add; - } - modVal = (max > add) ? (max - add) % add : ((max == add) ? 0 : max); - } - } - Sequence s = new Sequence(); - s.start = start; - s.add = add; - s.max = max; - s.modVal = modVal; - return s; - } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeIE8.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeIE8.java index c880a3ec..1383f8de 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeIE8.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeIE8.java @@ -21,8 +21,12 @@ import com.google.gwt.dom.client.NodeList; import com.google.gwt.query.client.SelectorEngine; /** - * Runtime selector engine implementation for browsers with native - * querySelectorAll support. + * Runtime selector engine implementation for IE with native + * querySelectorAll support (IE8 standards mode). + * + * It will fall back to Sizzle engine when QuerySelector were unavailable + * or in the case of selectors unsupported by the IE8 native QuerySelector. + * */ public class SelectorEngineNativeIE8 extends SelectorEngineSizzleIE { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMin.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMin.java new file mode 100644 index 00000000..98fc77ed --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMin.java @@ -0,0 +1,42 @@ +/* + * Copyright 2009 Google Inc. + * + * 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 + * the License. + */ +package com.google.gwt.query.client.impl; + +import com.google.gwt.dom.client.Element; +import com.google.gwt.dom.client.Node; +import com.google.gwt.dom.client.NodeList; +import com.google.gwt.query.client.SelectorEngine; +import com.google.gwt.user.client.Window; + +/** + * Runtime selector engine implementation for browsers with native + * querySelectorAll support. + * + * In the case of unsupported selectors, it will display an error message + * instead of falling back to a pure js implementation. + */ +public class SelectorEngineNativeMin extends SelectorEngineImpl { + + public NodeList select(String selector, Node ctx) { + try { + return SelectorEngine.querySelectorAllImpl(selector, ctx); + } catch (Exception e) { + Window.alert("Selector '" + selector + "' is unsupported in this Native engine, do not use this syntax or configure your module to use JS fallback"); + return null; + } + } + +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMinIE8.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMinIE8.java new file mode 100644 index 00000000..4d98d912 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMinIE8.java @@ -0,0 +1,42 @@ +/* + * Copyright 2009 Google Inc. + * + * 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 + * the License. + */ +package com.google.gwt.query.client.impl; + +import com.google.gwt.dom.client.Element; +import com.google.gwt.dom.client.Node; +import com.google.gwt.dom.client.NodeList; +import com.google.gwt.query.client.SelectorEngine; +import com.google.gwt.user.client.Window; + +/** + * Runtime selector engine implementation for IE with native querySelectorAll + * support (IE8 standards mode). + * + * In the case of QuerySelector were unavailable or unsupported selectors, it + * will display an error message instead of falling back to js. + */ +public class SelectorEngineNativeMinIE8 extends SelectorEngineImpl { + + public NodeList select(String selector, Node ctx) { + try { + return SelectorEngine.querySelectorAllImpl(selector, ctx); + } catch (Exception e) { + Window.alert("Selector '" + selector + "' is unsupported in this IE8 engine, check that you are in 'standards mode' or configure your module to use JS fallback"); + return null; + } + } + +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineJS.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJS.java similarity index 87% rename from gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineJS.java rename to gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJS.java index 5f7446b8..ad722e55 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineJS.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJS.java @@ -13,7 +13,10 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.google.gwt.query.client.impl; +package com.google.gwt.query.client.impl.research; + +import static com.google.gwt.query.client.GQUtils.eq; +import static com.google.gwt.query.client.GQUtils.truth; import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.JsArray; @@ -25,12 +28,110 @@ import com.google.gwt.query.client.GQUtils; import com.google.gwt.query.client.JSArray; import com.google.gwt.query.client.Regexp; import com.google.gwt.query.client.SelectorEngine; +import com.google.gwt.query.client.impl.SelectorEngineImpl; /** * Runtime selector engine implementation with no-XPath/native support based on * DOMAssistant. */ public class SelectorEngineJS extends SelectorEngineImpl { + + + /** + * Internal class. + */ + protected static class Sequence { + + public int start; + + public int max; + + public int add; + + public int modVal; + } + + /** + * Internal class. + */ + protected static class SplitRule { + + public String tag; + + public String id; + + public String allClasses; + + public String allAttr; + + public String allPseudos; + + public String tagRelation; + + public SplitRule(String tag, String id, String allClasses, String allAttr, + String allPseudos) { + this.tag = tag; + this.id = id; + this.allClasses = allClasses; + this.allAttr = allAttr; + this.allPseudos = allPseudos; + } + + public SplitRule(String tag, String id, String allClasses, String allAttr, + String allPseudos, String tagRelation) { + this.tag = tag; + this.id = id; + this.allClasses = allClasses; + this.allAttr = allAttr; + this.allPseudos = allPseudos; + this.tagRelation = tagRelation; + } + } + + protected static Sequence getSequence(String expression) { + int start = 0, add = 2, max = -1, modVal = -1; + Regexp expressionRegExp = new Regexp( + "^((odd|even)|([1-9]\\d*)|((([1-9]\\d*)?)n((\\+|\\-)(\\d+))?)|(\\-(([1-9]\\d*)?)n\\+(\\d+)))$"); + JSArray pseudoValue = expressionRegExp.exec(expression); + if (!truth(pseudoValue)) { + return null; + } else { + if (truth(pseudoValue.getStr(2))) { // odd or even + start = (eq(pseudoValue.getStr(2), "odd")) ? 1 : 2; + modVal = (start == 1) ? 1 : 0; + } else if (GQUtils + .truth(pseudoValue.getStr(3))) { // single digit + start = Integer.parseInt(pseudoValue.getStr(3), 10); + add = 0; + max = start; + } else if (truth(pseudoValue.getStr(4))) { // an+b + add = truth(pseudoValue.getStr(6)) ? Integer + .parseInt(pseudoValue.getStr(6), 10) : 1; + start = truth(pseudoValue.getStr(7)) ? Integer.parseInt( + (pseudoValue.getStr(8).charAt(0) == '+' ? "" + : pseudoValue.getStr(8)) + pseudoValue.getStr(9), 10) : 0; + while (start < 1) { + start += add; + } + modVal = (start > add) ? (start - add) % add + : ((start == add) ? 0 : start); + } else if (truth(pseudoValue.getStr(10))) { // -an+b + add = truth(pseudoValue.getStr(12)) ? Integer + .parseInt(pseudoValue.getStr(12), 10) : 1; + start = max = Integer.parseInt(pseudoValue.getStr(13), 10); + while (start > add) { + start -= add; + } + modVal = (max > add) ? (max - add) % add : ((max == add) ? 0 : max); + } + } + Sequence s = new Sequence(); + s.start = start; + s.add = add; + s.max = max; + s.modVal = modVal; + return s; + } public static void clearAdded(JSArray a) { for (int i = 0, len = a.size(); i < len; i++) { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineJSIE.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJSIE.java similarity index 86% rename from gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineJSIE.java rename to gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJSIE.java index be93619b..7d34a908 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineJSIE.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJSIE.java @@ -1,4 +1,4 @@ -package com.google.gwt.query.client.impl; +package com.google.gwt.query.client.impl.research; import com.google.gwt.dom.client.Element; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineSizzleGwt.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineSizzleGwt.java similarity index 81% rename from gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineSizzleGwt.java rename to gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineSizzleGwt.java index 44780ea9..7a6e58b0 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineSizzleGwt.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineSizzleGwt.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.google.gwt.query.client.impl; +package com.google.gwt.query.client.impl.research; import com.google.gwt.core.client.JavaScriptObject; @@ -22,6 +22,7 @@ import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Node; import com.google.gwt.dom.client.NodeList; import com.google.gwt.query.client.GQUtils; +import com.google.gwt.query.client.impl.SelectorEngineImpl; /** * Pure Javascript Selector Engine Gwt Implementation based on @@ -84,7 +85,7 @@ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { } } if ( isPartStrNotTag ) { - @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::filter(Ljava/lang/String;Lcom/google/gwt/core/client/JsArray;ZLjava/lang/Object;)( part, checkSet, true ); + @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::filter(Ljava/lang/String;Lcom/google/gwt/core/client/JsArray;ZLjava/lang/Object;)( part, checkSet, true ); } }, ">": function(checkSet, part){ @@ -109,7 +110,7 @@ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { } } if ( isPartStr ) { - @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::filter(Ljava/lang/String;Lcom/google/gwt/core/client/JsArray;ZLjava/lang/Object;)( part, checkSet, true ); + @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::filter(Ljava/lang/String;Lcom/google/gwt/core/client/JsArray;ZLjava/lang/Object;)( part, checkSet, true ); } } }, @@ -117,17 +118,17 @@ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { var doneName = done++; if ( typeof part === "string" && !/\W/.test(part) ) { checkFn = $wnd.dirNodeCheck; - @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::dirNodeCheck(Ljava/lang/String;Ljava/lang/Object;ILjava/lang/Object;)("parentNode", part, doneName, checkSet); + @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::dirNodeCheck(Ljava/lang/String;Ljava/lang/Object;ILjava/lang/Object;)("parentNode", part, doneName, checkSet); } else { - @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::dirCheck(Ljava/lang/String;Ljava/lang/Object;ILjava/lang/Object;)("parentNode", part, doneName, checkSet); + @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::dirCheck(Ljava/lang/String;Ljava/lang/Object;ILjava/lang/Object;)("parentNode", part, doneName, checkSet); } }, "~": function(checkSet, part){ var doneName = done++; if ( typeof part === "string" && !/\W/.test(part) ) { - @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::dirNodeCheck(Ljava/lang/String;Ljava/lang/Object;ILjava/lang/Object;)("previousSibling", part, doneName, checkSet); + @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::dirNodeCheck(Ljava/lang/String;Ljava/lang/Object;ILjava/lang/Object;)("previousSibling", part, doneName, checkSet); } else { - @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::dirCheck(Ljava/lang/String;Ljava/lang/Object;ILjava/lang/Object;)("previousSibling", part, doneName, checkSet); + @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::dirCheck(Ljava/lang/String;Ljava/lang/Object;ILjava/lang/Object;)("previousSibling", part, doneName, checkSet); } } }, @@ -204,9 +205,9 @@ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { if ( match[1] === "not" ) { // If we're dealing with a complex expression, or a simple one if ( ( $wnd.Expr.match.CHUNKER.exec(match[3]) || "" ).length > 1 || /^\w/.test(match[3]) ) { - match[3] = @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::select(Ljava/lang/String;Lcom/google/gwt/dom/client/Node;Lcom/google/gwt/core/client/JsArray;Lcom/google/gwt/core/client/JsArray;)(match[3], null, null, curLoop); + match[3] = @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::select(Ljava/lang/String;Lcom/google/gwt/dom/client/Node;Lcom/google/gwt/core/client/JsArray;Lcom/google/gwt/core/client/JsArray;)(match[3], null, null, curLoop); } else { - var ret = @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::filter(Ljava/lang/String;Lcom/google/gwt/core/client/JsArray;ZLjava/lang/Object;)(match[3], curLoop, inplace, true ^ not); + var ret = @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::filter(Ljava/lang/String;Lcom/google/gwt/core/client/JsArray;ZLjava/lang/Object;)(match[3], curLoop, inplace, true ^ not); if ( !inplace ) { result.push.apply( result, ret ); } @@ -245,7 +246,7 @@ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { return !elem.firstChild; }, has: function(elem, i, match){ - return !!@com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::select(Ljava/lang/String;Lcom/google/gwt/dom/client/Node;Lcom/google/gwt/core/client/JsArray;Lcom/google/gwt/core/client/JsArray;)(match[3], elem, null, null).length; + return !!@com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::select(Ljava/lang/String;Lcom/google/gwt/dom/client/Node;Lcom/google/gwt/core/client/JsArray;Lcom/google/gwt/core/client/JsArray;)(match[3], elem, null, null).length; }, header: function(elem){ return /h\d/i.test( elem.nodeName ); @@ -313,7 +314,7 @@ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { if ( filter ) { return filter( elem, i, match, array ); } else if ( name === "contains" ) { - return (elem.textContent || elem.innerText || @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::getText(Ljava/lang/Object;)([ elem ]) || "").indexOf(match[3]) >= 0; + return (elem.textContent || elem.innerText || @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::getText(Ljava/lang/Object;)([ elem ]) || "").indexOf(match[3]) >= 0; } else if ( name === "not" ) { var not = match[3]; @@ -324,7 +325,7 @@ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { } return true; } else { - @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::error(Ljava/lang/String;)("Syntax error, unrecognized expression: " + name); + @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::error(Ljava/lang/String;)("Syntax error, unrecognized expression: " + name); } }, CHILD: function(elem, match){ @@ -450,7 +451,7 @@ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { match = true; break; } - } else if ( @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::filter(Ljava/lang/String;Lcom/google/gwt/core/client/JsArray;ZLjava/lang/Object;)( cur, [elem], false ).length > 0 ) { + } else if ( @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::filter(Ljava/lang/String;Lcom/google/gwt/core/client/JsArray;ZLjava/lang/Object;)( cur, [elem], false ).length > 0 ) { match = elem; break; } @@ -548,7 +549,7 @@ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { // Improper expression if ( expr === old ) { if ( anyFound == null ) { - @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::error(Ljava/lang/String;)(expr); + @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::error(Ljava/lang/String;)(expr); } else { break; } @@ -595,7 +596,7 @@ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { ret += elem.nodeValue; // Traverse everything else, except comment nodes } else if ( elem.nodeType !== 8 ) { - ret += @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::getText(Ljava/lang/Object;)(elem.childNodes); + ret += @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::getText(Ljava/lang/Object;)(elem.childNodes); } } return ret; @@ -629,9 +630,9 @@ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { } selector = $wnd.Expr.relative[selector] ? selector + "*" : selector; for ( var i = 0, l = root.length; i < l; i++ ) { - @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::select(Ljava/lang/String;Lcom/google/gwt/dom/client/Node;Lcom/google/gwt/core/client/JsArray;Lcom/google/gwt/core/client/JsArray;)(selector, root[i], tmpSet, null); + @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::select(Ljava/lang/String;Lcom/google/gwt/dom/client/Node;Lcom/google/gwt/core/client/JsArray;Lcom/google/gwt/core/client/JsArray;)(selector, root[i], tmpSet, null); } - return @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::filter(Ljava/lang/String;Lcom/google/gwt/core/client/JsArray;ZLjava/lang/Object;)( later, tmpSet, false ); + return @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::filter(Ljava/lang/String;Lcom/google/gwt/core/client/JsArray;ZLjava/lang/Object;)( later, tmpSet, false ); }-*/; private static native JsArray select(String selector, Node context, JsArray results, JsArray seed) /*-{ @@ -649,17 +650,17 @@ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { } if ( parts.length > 1 && $wnd.Expr.match.POS.exec( selector ) ) { if ( parts.length === 2 && $wnd.Expr.relative[ parts[0] ] ) { - set = @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::posProcess(Ljava/lang/String;Lcom/google/gwt/dom/client/Node;)(parts[0] + parts[1], context); + set = @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::posProcess(Ljava/lang/String;Lcom/google/gwt/dom/client/Node;)(parts[0] + parts[1], context); } else { set = $wnd.Expr.relative[ parts[0] ] ? [ context ] : - @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::select(Ljava/lang/String;Lcom/google/gwt/dom/client/Node;Lcom/google/gwt/core/client/JsArray;Lcom/google/gwt/core/client/JsArray;)(parts.shift(), context, null, null); + @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::select(Ljava/lang/String;Lcom/google/gwt/dom/client/Node;Lcom/google/gwt/core/client/JsArray;Lcom/google/gwt/core/client/JsArray;)(parts.shift(), context, null, null); while ( parts.length ) { selector = parts.shift(); if ( $wnd.Expr.relative[ selector ] ) { selector += parts.shift(); } - set = @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::posProcess(Ljava/lang/String;Lcom/google/gwt/dom/client/Node;)(selector, set); + set = @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::posProcess(Ljava/lang/String;Lcom/google/gwt/dom/client/Node;)(selector, set); } } } else { @@ -667,16 +668,16 @@ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { // (but not if it'll be faster if the inner selector is an ID) if ( !seed && parts.length > 1 && context.nodeType === 9 && $wnd.Expr.match.ID.test(parts[0]) && !$wnd.Expr.match.ID.test(parts[parts.length - 1]) ) { - var ret = @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::find(Ljava/lang/String;Lcom/google/gwt/dom/client/Node;)( parts.shift(), context); - context = ret.expr ? @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::filter(Ljava/lang/String;Lcom/google/gwt/core/client/JsArray;ZLjava/lang/Object;)( ret.expr, ret.set, false )[0] : ret.set[0]; + var ret = @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::find(Ljava/lang/String;Lcom/google/gwt/dom/client/Node;)( parts.shift(), context); + context = ret.expr ? @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::filter(Ljava/lang/String;Lcom/google/gwt/core/client/JsArray;ZLjava/lang/Object;)( ret.expr, ret.set, false )[0] : ret.set[0]; } if ( context ) { var ret = seed ? - { expr: parts.pop(), set: @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::makeArray(Lcom/google/gwt/dom/client/NodeList;Lcom/google/gwt/core/client/JsArray;)(seed, null) } : - @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::find(Ljava/lang/String;Lcom/google/gwt/dom/client/Node;)( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context); - set = ret.expr ? @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::filter(Ljava/lang/String;Lcom/google/gwt/core/client/JsArray;ZLjava/lang/Object;)( ret.expr, ret.set, false ) : ret.set; + { expr: parts.pop(), set: @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::makeArray(Lcom/google/gwt/dom/client/NodeList;Lcom/google/gwt/core/client/JsArray;)(seed, null) } : + @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::find(Ljava/lang/String;Lcom/google/gwt/dom/client/Node;)( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context); + set = ret.expr ? @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::filter(Ljava/lang/String;Lcom/google/gwt/core/client/JsArray;ZLjava/lang/Object;)( ret.expr, ret.set, false ) : ret.set; if ( parts.length > 0 ) { - checkSet = @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::makeArray(Lcom/google/gwt/dom/client/NodeList;Lcom/google/gwt/core/client/JsArray;)(set, null); + checkSet = @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::makeArray(Lcom/google/gwt/dom/client/NodeList;Lcom/google/gwt/core/client/JsArray;)(set, null); } else { prune = false; } @@ -700,14 +701,14 @@ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { checkSet = set; } if ( !checkSet ) { - @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::error(Ljava/lang/String;)(cur || selector); + @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::error(Ljava/lang/String;)(cur || selector); } if ( Object.prototype.toString.call(checkSet) === "[object Array]" ) { if ( !prune ) { results.push.apply( results, checkSet ); } else if ( context && context.nodeType === 1 ) { for ( var i = 0; checkSet[i] != null; i++ ) { - if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::contains(Ljava/lang/Object;Ljava/lang/Object;)(context, checkSet[i])) ) { + if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::contains(Ljava/lang/Object;Ljava/lang/Object;)(context, checkSet[i])) ) { results.push( set[i] ); } } @@ -719,10 +720,10 @@ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { } } } else { - @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::makeArray(Lcom/google/gwt/dom/client/NodeList;Lcom/google/gwt/core/client/JsArray;)(checkSet, results); + @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::makeArray(Lcom/google/gwt/dom/client/NodeList;Lcom/google/gwt/core/client/JsArray;)(checkSet, results); } if ( extra ) { - @com.google.gwt.query.client.impl.SelectorEngineSizzleGwt::select(Ljava/lang/String;Lcom/google/gwt/dom/client/Node;Lcom/google/gwt/core/client/JsArray;Lcom/google/gwt/core/client/JsArray;)(extra, origContext, results, seed); + @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::select(Ljava/lang/String;Lcom/google/gwt/dom/client/Node;Lcom/google/gwt/core/client/JsArray;Lcom/google/gwt/core/client/JsArray;)(extra, origContext, results, seed); } return results; }-*/; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineXPath.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineXPath.java similarity index 90% rename from gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineXPath.java rename to gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineXPath.java index 6cc48dec..b2ba41f7 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineXPath.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineXPath.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.google.gwt.query.client.impl; +package com.google.gwt.query.client.impl.research; import static com.google.gwt.query.client.GQUtils.eq; import static com.google.gwt.query.client.GQUtils.truth; @@ -26,6 +26,9 @@ import com.google.gwt.query.client.GQUtils; import com.google.gwt.query.client.JSArray; import com.google.gwt.query.client.Regexp; import com.google.gwt.query.client.SelectorEngine; +import com.google.gwt.query.client.impl.SelectorEngineImpl; +import com.google.gwt.query.client.impl.research.SelectorEngineJS.Sequence; +import com.google.gwt.query.client.impl.research.SelectorEngineJS.SplitRule; /** @@ -173,7 +176,7 @@ public class SelectorEngineXPath extends SelectorEngineImpl { + ")"; } else if (eq("nth-child", pseudoClass)) { if (!eq("n", pseudoClass)) { - Sequence sequence = getSequence(pseudoValue); + Sequence sequence = SelectorEngineJS.getSequence(pseudoValue); if (sequence != null) { if (sequence.start == sequence.max) { xpath = "count(preceding-sibling::*) = " + (sequence.start - 1); @@ -189,7 +192,7 @@ public class SelectorEngineXPath extends SelectorEngineImpl { } } else if (eq("nth-of-type", pseudoClass)) { if (!pseudoValue.startsWith("n")) { - Sequence sequence = getSequence(pseudoValue); + Sequence sequence = SelectorEngineJS.getSequence(pseudoValue); if (sequence != null) { if (sequence.start == sequence.max) { xpath = pseudoValue; @@ -235,13 +238,13 @@ public class SelectorEngineXPath extends SelectorEngineImpl { if(!allAttr) return ""; return allAttr.replace(/["']+/g,'').replace(/(\w+)(\^|\$|\*|\||~)?=?([\w\u00C0-\uFFFF\s\-_\.]+)?/g, function(a,b,c,d) { - return @com.google.gwt.query.client.impl.SelectorEngineXPath::attrToXPath(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)(a,b || "",c || "",d || ""); + return @com.google.gwt.query.client.impl.research.SelectorEngineXPath::attrToXPath(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)(a,b || "",c || "",d || ""); }); }-*/; private native String replaceAttr2(String allAttr) /*-{ if(!allAttr) return ""; - return allAttr.replace(/\[(\w+)(\^|\$|\*|\||~)?=?([\w\u00C0-\uFFFF\s\-_\.]+)?\]/g, @com.google.gwt.query.client.impl.SelectorEngineXPath::attrToXPath(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)); + return allAttr.replace(/\[(\w+)(\^|\$|\*|\||~)?=?([\w\u00C0-\uFFFF\s\-_\.]+)?\]/g, @com.google.gwt.query.client.impl.research.SelectorEngineXPath::attrToXPath(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)); }-*/; } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyWidgets.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyWidgets.java index 27ec1ee3..881e9d7f 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyWidgets.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyWidgets.java @@ -27,6 +27,6 @@ import com.google.gwt.query.client.LazyBase; public interface LazyWidgets extends LazyBase{ - Widget widget(); + W widget(); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java index 745a830b..713a73a3 100755 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java @@ -56,8 +56,10 @@ public class Widgets extends GQueryQueue { super(list); } + @SuppressWarnings("unchecked") @Override - public Widget widget() { + // TODO: consider more widgets + public W widget() { Widget w = super.widget(); if (w == null) { Element e = elements.getItem(0); @@ -71,7 +73,7 @@ public class Widgets extends GQueryQueue { w = new HTML($(e).toString()); } } - return w; + return (W)w; } } diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java index 061f8277..f7c54c50 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java @@ -19,6 +19,8 @@ import static com.google.gwt.query.client.GQuery.$; import static com.google.gwt.query.client.GQuery.$$; import static com.google.gwt.query.client.GQuery.document; +import java.util.ArrayList; + import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Element; import com.google.gwt.event.dom.client.ClickEvent; @@ -790,5 +792,40 @@ public class GQueryCoreTest extends GWTTestCase { (b2).click(); assertEquals("red", $(b1).css("color")); } + + public void testGQueryMap() { + String content = "

"; + $(e).html(content); + + ArrayList s = $("p", e).map(new Function() { + public Object f(Element e, int i) { + return null; + } + }); + assertNotNull(s); + assertEquals(0, s.size()); + + s = $("p", e).map(new Function() { + public Object f(Element e, int i) { + String id = $(e).attr("id"); + return id.isEmpty() ? null: id; + } + }); + assertEquals(3, s.size()); + assertEquals("1", s.get(0)); + assertEquals("2", s.get(1)); + assertEquals("4", s.get(2)); + + + ArrayList a = $("p", e).map(new Function() { + public Object f(Element e, int i) { + String id = $(e).attr("id"); + return id.isEmpty() ? null: e; + } + }); + assertEquals(3, a.size()); + assertEquals(3, $(a).size()); + + } } diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQuerySelectorsTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQuerySelectorsTest.java index 79aca34b..4efe789b 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQuerySelectorsTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQuerySelectorsTest.java @@ -27,11 +27,11 @@ import com.google.gwt.dom.client.NodeList; import com.google.gwt.junit.client.GWTTestCase; import com.google.gwt.query.client.impl.SelectorEngineCssToXPath; import com.google.gwt.query.client.impl.SelectorEngineImpl; -import com.google.gwt.query.client.impl.SelectorEngineJS; import com.google.gwt.query.client.impl.SelectorEngineNative; import com.google.gwt.query.client.impl.SelectorEngineSizzle; -import com.google.gwt.query.client.impl.SelectorEngineSizzleGwt; -import com.google.gwt.query.client.impl.SelectorEngineXPath; +import com.google.gwt.query.client.impl.research.SelectorEngineJS; +import com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt; +import com.google.gwt.query.client.impl.research.SelectorEngineXPath; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.RootPanel; diff --git a/plugins/pom.xml b/plugins/pom.xml deleted file mode 100644 index 24fe56f3..00000000 --- a/plugins/pom.xml +++ /dev/null @@ -1,31 +0,0 @@ - - 4.0.0 - - com.google.gwt - gwtquery-project - 1.0.0-SNAPSHOT - - - GwtQuery Plugins - gwtquery-plugins - jar - - - ${groupId} - gwtquery - ${version} - - - - - - ${basedir}/src/main/java - - - ${basedir}/src/main/resources - - - - diff --git a/plugins/src/main/java/gwtquery/Plugins.gwt.xml b/plugins/src/main/java/gwtquery/Plugins.gwt.xml deleted file mode 100644 index 6dba0da2..00000000 --- a/plugins/src/main/java/gwtquery/Plugins.gwt.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/plugins/src/main/java/gwtquery/plugins/collapser/Collapser.java b/plugins/src/main/java/gwtquery/plugins/collapser/Collapser.java deleted file mode 100644 index 8cdc995b..00000000 --- a/plugins/src/main/java/gwtquery/plugins/collapser/Collapser.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2009 Google Inc. - * - * 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 - * the License. - */ -package gwtquery.plugins.collapser; - -import com.google.gwt.dom.client.Element; -import com.google.gwt.dom.client.NodeList; -import com.google.gwt.query.client.Function; -import com.google.gwt.query.client.GQuery; -import com.google.gwt.query.client.Plugin; -import com.google.gwt.query.client.plugins.Effects; -import com.google.gwt.user.client.Event; - -/** - * Collapser sample plugin. For all matched elements, adds a clickable [X] next - * to the element which toggles its visibility. - */ -public class Collapser extends GQuery { - - /** - * Used to register the plugin. - */ - private static class CollapserPlugin implements Plugin { - - public Collapser init(GQuery gq) { - return new Collapser(gq.get()); - } - } - - /** - * Plugin key for Collapser. - */ - public static final Class Collapser = Collapser.class; - - static { - GQuery.registerPlugin(Collapser.class, new CollapserPlugin()); - } - - public Collapser(NodeList list) { - super(list); - } - - /** - * Adds a [X] link button before each matched element with a bound click - * handler that toggles visibility of the element. - */ - public Collapser apply() { - for (final Element e : elements()) { - GQuery button = $("[X]"); - $(e).before(button); - button.click(new Function() { - public boolean f(Event evt) { - $(e).as(Effects.Effects).toggle(); - return true; - } - }); - } - - return this; - } -} \ No newline at end of file diff --git a/plugins/src/main/java/gwtquery/plugins/widgets/Widgets.java b/plugins/src/main/java/gwtquery/plugins/widgets/Widgets.java deleted file mode 100644 index b1103ed3..00000000 --- a/plugins/src/main/java/gwtquery/plugins/widgets/Widgets.java +++ /dev/null @@ -1,107 +0,0 @@ -package gwtquery.plugins.widgets; - -import com.google.gwt.dom.client.Element; -import com.google.gwt.dom.client.NodeList; -import com.google.gwt.event.dom.client.ClickHandler; -import com.google.gwt.query.client.GQuery; -import com.google.gwt.query.client.JSArray; -import com.google.gwt.query.client.Plugin; -import com.google.gwt.user.client.ui.Button; - -import java.util.ArrayList; -import java.util.Collection; - -/** - * Experimental Gwt Query plugin for integrating Gwt Widgets. - */ -public class Widgets extends GQuery { - - /** - * Used to register the plugin. - */ - private static class WidgetsPlugin implements Plugin { - - public Widgets init(GQuery gq) { - return new Widgets(gq.get()); - } - } - - public static final Class Widgets = Widgets.class; - - static { - GQuery.registerPlugin(Widgets.class, new WidgetsPlugin()); - } - - public Widgets(Element element) { - super(element); - } - - public Widgets(JSArray elements) { - super(elements); - } - - public Widgets(NodeList list) { - super(list); - } - - /** - * Create a builder capable of instantiating a GWT Button object over every - * matched element. Call end() to execute builder and return to the current - * query object. - * - * @return a ButtonBuilder - */ - public ButtonBuilder button() { - return new ButtonBuilder("*"); - } - - public class ButtonBuilder { - - private String selector; - - private String label = null; - - private String labelSelector = null; - - private Collection handlers = new ArrayList(); - - public ButtonBuilder(String selector) { - this.selector = selector; - } - - public ButtonBuilder labelQuery(String label) { - this.labelSelector = label; - return this; - } - - public ButtonBuilder label(String label) { - this.label = label; - return this; - } - - public ButtonBuilder addClickHandler(ClickHandler handler) { - handlers.add(handler); - return this; - } - - public Widgets end() { - for (Element e : elements()) { - Button b = null; - if ("button".equalsIgnoreCase(e.getTagName())) { - b = Button.wrap(e); - } else { - Element bElt = $(""); - $("#enhance").one(Event.ONCLICK, null, new Function() { - @Override + $("").appendTo(".outer").one(Event.ONCLICK, null, new Function() { public boolean f(Event e) { - $(".btn:nth-child(odd)").as(Widgets).button().label("Foo") - .addClickHandler(new ClickHandler() { + $(".btn:nth-child(odd)").each(new Function(){ + public void f(Element el) { + // Replace odd labels by a button + GQuery g = $("
+ + +
+
+

+Span 1 +Span 2 +Span 3 +
+
+
+
Div 1
+
Div 2
+
Div 3
+
Div 4
+
+ + + + + + + + \ No newline at end of file diff --git a/samples/src/main/java/gwtquery/samples/public/GwtQueryWidgets.html b/samples/src/main/java/gwtquery/samples/public/GwtQueryWidgets.html index d47bca9e..a414cf94 100644 --- a/samples/src/main/java/gwtquery/samples/public/GwtQueryWidgets.html +++ b/samples/src/main/java/gwtquery/samples/public/GwtQueryWidgets.html @@ -3,8 +3,6 @@ GQuery Demo - -