import static com.google.gwt.query.client.plugins.Events.Events;\r
import static com.google.gwt.query.client.plugins.SimpleNamedQueue.SimpleNamedQueue;\r
\r
+import java.util.ArrayList;\r
+import java.util.Arrays;\r
+import java.util.List;\r
+\r
import com.google.gwt.core.client.GWT;\r
import com.google.gwt.core.client.JavaScriptObject;\r
import com.google.gwt.core.client.JsArray;\r
import com.google.gwt.dom.client.NodeList;\r
import com.google.gwt.dom.client.OptionElement;\r
import com.google.gwt.dom.client.SelectElement;\r
-import com.google.gwt.dom.client.TextAreaElement;\r
import com.google.gwt.dom.client.Style.Display;\r
import com.google.gwt.dom.client.Style.HasCssName;\r
+import com.google.gwt.dom.client.TextAreaElement;\r
import com.google.gwt.query.client.css.CSS;\r
import com.google.gwt.query.client.css.HasCssValue;\r
import com.google.gwt.query.client.css.TakesCssValue;\r
import com.google.gwt.query.client.impl.SelectorEngine;\r
import com.google.gwt.query.client.js.JsCache;\r
import com.google.gwt.query.client.js.JsMap;\r
+import com.google.gwt.query.client.js.JsNamedArray;\r
import com.google.gwt.query.client.js.JsNodeArray;\r
import com.google.gwt.query.client.js.JsUtils;\r
import com.google.gwt.query.client.plugins.Effects;\r
import com.google.gwt.user.client.ui.GqUi;\r
import com.google.gwt.user.client.ui.Widget;\r
\r
-import java.util.ArrayList;\r
-import java.util.Arrays;\r
-import java.util.HashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
/**\r
* GwtQuery is a GWT clone of the popular jQuery library.\r
*/\r
* @param selector\r
* @return\r
*/\r
- public Map<String, List<Element>> closest(String[] selectors) {\r
+ public JsNamedArray<NodeList<Element>> closest(String[] selectors) {\r
return closest(selectors, null);\r
}\r
\r
* @param selector\r
* @return\r
*/\r
- public Map<String, List<Element>> closest(String[] selectors, Node context) {\r
- Map<String, List<Element>> results = new HashMap<String, List<Element>>();\r
+ public JsNamedArray<NodeList<Element>> closest(String[] selectors, Node context) {\r
+ JsNamedArray<NodeList<Element>> results = JsNamedArray.create();\r
\r
if (context == null) {\r
context = currentContext;\r
}\r
\r
Element first = get(0);\r
-\r
if (first != null && selectors != null && selectors.length > 0) {\r
-\r
- Map<String, GQuery> matches = new HashMap<String, GQuery>();\r
-\r
+ JsNamedArray<GQuery> matches = JsNamedArray.create();\r
for (String selector : selectors) {\r
- if (!matches.containsKey(selector)) {\r
+ if (!matches.exists(selector)) {\r
matches.put(selector, selector.matches(POS_REGEX) ? $(selector,\r
context) : null);\r
}\r
}\r
\r
Element current = first;\r
-\r
while (current != null && current.getOwnerDocument() != null\r
&& current != context) {\r
// for each selector, check if the current element match it.\r
- for (String selector : matches.keySet()) {\r
+ for (String selector : matches.keys()) {\r
\r
GQuery pos = matches.get(selector);\r
-\r
boolean match = pos != null ? pos.index(current) > -1\r
: $(current).is(selector);\r
\r
if (match) {\r
-\r
- List<Element> elementsMatchingSelector = results.get(selector);\r
-\r
+ JsNodeArray elementsMatchingSelector = results.get(selector).cast();\r
if (elementsMatchingSelector == null) {\r
- elementsMatchingSelector = new ArrayList<Element>();\r
+ elementsMatchingSelector = JsNodeArray.create();\r
results.put(selector, elementsMatchingSelector);\r
}\r
-\r
- elementsMatchingSelector.add(current);\r
+ elementsMatchingSelector.addNode(current);\r
}\r
}\r
\r
current = current.getParentElement();\r
}\r
-\r
}\r
-\r
return results;\r
}\r
\r
*/\r
@SuppressWarnings("unchecked")\r
public <W> List<W> map(Function f) {\r
+ @SuppressWarnings("rawtypes")\r
ArrayList ret = new ArrayList();\r
for (int i = 0; i < elements().length; i++) {\r
Object o = f.f(elements()[i], i);\r
}\r
\r
private GQuery domManip(String htmlString, int func) {\r
- HashMap<Document, GQuery> cache = new HashMap<Document, GQuery>();\r
+ JsMap<Document, GQuery> cache = JsMap.createObject().cast();\r
for (Element e : elements()) {\r
Document d = e.getNodeType() == Node.DOCUMENT_NODE ? e.<Document> cast()\r
: e.getOwnerDocument();\r
}\r
domManip(g.clone(), func, e);\r
}\r
-\r
return this;\r
}\r
\r
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.SimpleNamedQueue.SimpleNamedQueue;
+import java.util.ArrayList;
+import java.util.Arrays;
+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;
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.Style.HasCssName;
+import com.google.gwt.dom.client.TextAreaElement;
import com.google.gwt.query.client.css.CSS;
import com.google.gwt.query.client.css.HasCssValue;
import com.google.gwt.query.client.css.TakesCssValue;
import com.google.gwt.query.client.impl.SelectorEngine;
import com.google.gwt.query.client.js.JsCache;
import com.google.gwt.query.client.js.JsMap;
+import com.google.gwt.query.client.js.JsNamedArray;
import com.google.gwt.query.client.js.JsNodeArray;
import com.google.gwt.query.client.js.JsUtils;
import com.google.gwt.query.client.plugins.Effects;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.GqUi;
import com.google.gwt.user.client.ui.Widget;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
import com.google.gwt.query.client.LazyBase;
public interface LazyGQuery<T> extends LazyBase<T>{
* @param selector
* @return
*/
- Map<String, List<Element>> closest(String[] selectors);
+ JsNamedArray<NodeList<Element>> closest(String[] selectors);
/**
* Returns a {@link Map} object as key a selector and as value the list of
* @param selector
* @return
*/
- Map<String, List<Element>> closest(String[] selectors, Node context);
+ JsNamedArray<NodeList<Element>> closest(String[] selectors, Node context);
/**
* Get the first ancestor element that matches the selector (for each matched
import com.google.gwt.core.client.Duration;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.EventTarget;
+import com.google.gwt.dom.client.NodeList;
import com.google.gwt.query.client.Function;
+import com.google.gwt.query.client.js.JsNamedArray;
import com.google.gwt.query.client.js.JsObjectArray;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
@Override
public boolean fire(Event event) {
-
if (isEmpty()) {
return true;
}
return true;
}
- Map<String, List<Element>> realCurrentTargetBySelector = $(eventTarget).closest(
+ JsNamedArray<NodeList<Element>> realCurrentTargetBySelector = $(eventTarget).closest(
selectors, liveContextElement);
// nothing match the selectors
- if (realCurrentTargetBySelector.isEmpty()) {
+ if (realCurrentTargetBySelector.length() == 0) {
return true;
}
com.google.gwt.query.client.plugins.events.Event gqEvent = com.google.gwt.query.client.plugins.events.Event.create(event);
- for (String cssSelector : realCurrentTargetBySelector.keySet()) {
+ for (String cssSelector : realCurrentTargetBySelector.keys()) {
List<BindFunction> bindFunctions = bindFunctionBySelector.get(cssSelector);
-
if (bindFunctions == null){
continue;
}
for (BindFunction f : bindFunctions) {
- for (Element element : realCurrentTargetBySelector.get(cssSelector)) {
+ NodeList<Element> n = realCurrentTargetBySelector.get(cssSelector);
+ if (n != null ) for (int i = 0; i < n.getLength(); i++) {
+ Element element = n.getItem(i);
gqEvent.setCurrentElementTarget(element);
boolean subResult = f.fire(gqEvent);
result &= subResult;
// trick to reset the right currentTarget on the original event on ie
gqEvent.setCurrentElementTarget(liveContextElement);
-
return result;
-
}
/**
import static com.google.gwt.query.client.GQuery.$$;
import static com.google.gwt.query.client.GQuery.document;
+import java.util.List;
+
+import junit.framework.Assert;
+
import com.google.gwt.dom.client.Document;
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.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.junit.client.GWTTestCase;
import com.google.gwt.query.client.css.RGBColor;
import com.google.gwt.query.client.impl.SelectorEngineImpl;
import com.google.gwt.query.client.impl.SelectorEngineSizzle;
+import com.google.gwt.query.client.js.JsNamedArray;
import com.google.gwt.query.client.js.JsNodeArray;
import com.google.gwt.query.client.js.JsUtils;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextArea;
-import junit.framework.Assert;
-
-import java.util.List;
-import java.util.Map;
-
/**
* Test class for testing gwtquery-core api.
*/
String html = "<div id='mainDiv'><div id='subDiv' class='test'><div id='subSubDiv'><p id='mainP'><span id='testSpan' class='test'><input id='firstInput' type='text'></input></span></p></div></div></div>";
$(e).html(html);
- Map<String, List<Element>> close = $("input", e).closest(new String[]{"p","div", ".test", "#unknown"});
+ JsNamedArray<NodeList<Element>> close = $("input", e).closest(new String[]{"p","div", ".test", "#unknown"});
- assertEquals(3, close.size());
+ assertEquals(3, close.length());
assertNotNull(close.get("p"));
- assertEquals(1,close.get("p").size());
- assertEquals("mainP", close.get("p").get(0).getId());
+ assertEquals(1,close.get("p").getLength());
+ assertEquals("mainP", close.get("p").getItem(0).getId());
assertNotNull(close.get("div"));
- assertEquals(3,close.get("div").size());
- assertEquals("subSubDiv", close.get("div").get(0).getId());
- assertEquals("subDiv", close.get("div").get(1).getId());
- assertEquals("mainDiv", close.get("div").get(2).getId());
+ assertEquals(3,close.get("div").getLength());
+ assertEquals("subSubDiv", close.get("div").getItem(0).getId());
+ assertEquals("subDiv", close.get("div").getItem(1).getId());
+ assertEquals("mainDiv", close.get("div").getItem(2).getId());
assertNotNull(close.get(".test"));
- assertEquals(2,close.get(".test").size());
- assertEquals("testSpan", close.get(".test").get(0).getId());
- assertEquals("subDiv", close.get(".test").get(1).getId());
+ assertEquals(2,close.get(".test").getLength());
+ assertEquals("testSpan", close.get(".test").getItem(0).getId());
+ assertEquals("subDiv", close.get(".test").getItem(1).getId());
assertNull(close.get("#unknown"));