/*\r
* Copyright 2011, The gwtquery team.\r
* \r
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not\r
- * use this file except in compliance with the License. You may obtain a copy of\r
- * the License at\r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
+ * in compliance with the License. You may obtain a copy of the License at\r
* \r
* http://www.apache.org/licenses/LICENSE-2.0\r
* \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT\r
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\r
- * License for the specific language governing permissions and limitations under\r
+ * Unless required by applicable law or agreed to in writing, software distributed under the License\r
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
+ * or implied. See the License for the specific language governing permissions and limitations under\r
* the License.\r
*/\r
package com.google.gwt.query.client;\r
private enum DomMan {\r
AFTER, APPEND, BEFORE, PREPEND;\r
}\r
- \r
+\r
/**\r
* A POJO used to store the top/left CSS positioning values of an element.\r
*/\r
}\r
\r
/**\r
- * Class used internally to create DOM element from html snippet\r
+ * Class used internally to create DOM element from html snippet\r
*/\r
private static class TagWrapper {\r
public static final TagWrapper DEFAULT = new TagWrapper(0, "", "");\r
- private String postWrap; \r
+ private String postWrap;\r
private String preWrap;\r
private int wrapDepth;\r
- \r
+\r
public TagWrapper(int wrapDepth, String preWrap, String postWrap) {\r
- this.wrapDepth=wrapDepth;\r
+ this.wrapDepth = wrapDepth;\r
this.postWrap = postWrap;\r
this.preWrap = preWrap;\r
}\r
* The body element in the current page.\r
*/\r
public static final BodyElement body = Document.get().getBody();\r
- \r
+\r
/**\r
* Object to store element data.\r
*/\r
protected static JsCache dataCache = null;\r
- \r
+\r
/**\r
* The document element in the current page.\r
*/\r
public static final Document document = Document.get();\r
- \r
+\r
/**\r
* Static reference Effects plugin\r
*/\r
* A static reference to the GQuery class.\r
*/\r
public static Class<GQuery> GQUERY = GQuery.class;\r
- \r
+\r
private static final String OLD_DATA_PREFIX = "old-";\r
\r
private static JsMap<Class<? extends GQuery>, Plugin<? extends GQuery>> plugins;\r
\r
// Sizzle POS regex : usefull in some methods\r
// TODO: Share this static with SelectorEngineSizzle\r
- private static final String POS_REGEX = ":(nth|eq|gt|lt|first|last|even|odd)(?:\\((\\d*)\\))?(?=[^\\-]|$)";\r
+ private static final String POS_REGEX =\r
+ ":(nth|eq|gt|lt|first|last|even|odd)(?:\\((\\d*)\\))?(?=[^\\-]|$)";\r
\r
/**\r
* Implementation class used for style manipulations.\r
* Static reference to the Widgets plugin\r
*/\r
public static Class<Widgets> Widgets = com.google.gwt.query.client.plugins.Widgets.Widgets;\r
- \r
+\r
/**\r
* The window object.\r
*/\r
public static final Element window = window();\r
- \r
+\r
private static Element windowData = null;\r
- \r
+\r
private static JsNamedArray<TagWrapper> wrapperMap;\r
- \r
+\r
/**\r
* Create an empty GQuery object.\r
*/\r
public static GQuery $() {\r
return new GQuery(JsNodeArray.create());\r
}\r
- \r
+\r
/**\r
* Wrap a GQuery around an existing element.\r
*/\r
* Wrap a GQuery around an event's target element.\r
*/\r
public static GQuery $(Event event) {\r
- return event == null ? $()\r
- : $((Element) event.getCurrentEventTarget().cast());\r
+ return event == null ? $() : $((Element) event.getCurrentEventTarget().cast());\r
}\r
\r
/**\r
public static GQuery $(Function f) {\r
return $(f.getElement());\r
}\r
- \r
+\r
/**\r
* Wrap a GQuery around an existing element, event, node or nodelist.\r
*/\r
public static GQuery $(JavaScriptObject e) {\r
- return \r
- JsUtils.isWindow(e) ? GQuery.$(e.<Element>cast()) :\r
- JsUtils.isElement(e) ? GQuery.$(e.<Element>cast()) :\r
- JsUtils.isEvent(e) ? GQuery.$(e.<Event>cast()) :\r
- JsUtils.isNodeList(e) ? GQuery.$(e.<NodeList<Element>>cast()) :\r
- $();\r
+ return JsUtils.isWindow(e) ? GQuery.$(e.<Element> cast()) : JsUtils.isElement(e) ? GQuery.$(e\r
+ .<Element> cast()) : JsUtils.isEvent(e) ? GQuery.$(e.<Event> cast()) : JsUtils\r
+ .isNodeList(e) ? GQuery.$(e.<NodeList<Element>> cast()) : $();\r
}\r
- \r
+\r
/**\r
* Create a new GQuery given a list of nodes, elements or widgets\r
*/\r
* Wrap a GQuery around an existing node.\r
*/\r
public static GQuery $(Node n) {\r
- return $((Element)n);\r
+ return $((Element) n);\r
}\r
\r
/**\r
}\r
\r
/**\r
- * This function accepts a string containing a CSS selector which is then used\r
- * to match a set of elements, or it accepts raw HTML creating a GQuery\r
- * element containing those elements.\r
- * Xpath selector is supported in browsers with native xpath engine.\r
+ * This function accepts a string containing a CSS selector which is then used to match a set of\r
+ * elements, or it accepts raw HTML creating a GQuery element containing those elements. Xpath\r
+ * selector is supported in browsers with native xpath engine.\r
*/\r
public static GQuery $(String selectorOrHtml) {\r
return $(selectorOrHtml, document);\r
}\r
\r
/**\r
- * This function accepts a string containing a CSS selector which is then used\r
- * to match a set of elements, or it accepts raw HTML creating a GQuery\r
- * element containing those elements. The second parameter is is a class\r
- * reference to a plugin to be used.\r
+ * This function accepts a string containing a CSS selector which is then used to match a set of\r
+ * elements, or it accepts raw HTML creating a GQuery element containing those elements. The\r
+ * second parameter is is a class reference to a plugin to be used.\r
* \r
* Xpath selector is supported in browsers with native xpath engine.\r
*/\r
}\r
\r
/**\r
- * This function accepts a string containing a CSS selector which is then used\r
- * to match a set of elements, or it accepts raw HTML creating a GQuery\r
- * element containing those elements. The second parameter is the context to\r
- * use for the selector, or the document where the new elements will be\r
- * created.\r
+ * This function accepts a string containing a CSS selector which is then used to match a set of\r
+ * elements, or it accepts raw HTML creating a GQuery element containing those elements. The\r
+ * second parameter is the context to use for the selector, or the document where the new elements\r
+ * will be created.\r
* \r
* Xpath selector is supported in browsers with native xpath engine.\r
*/\r
return new GQuery().select(selectorOrHtml, ctx);\r
}\r
\r
- /**\r
- * This function accepts a string containing a CSS selector which is then used\r
- * to match a set of elements, or it accepts raw HTML creating a GQuery\r
- * element containing those elements. The second parameter is the context to\r
- * use for the selector. The third parameter is the class plugin to use.\r
+ /**\r
+ * This function accepts a string containing a CSS selector which is then used to match a set of\r
+ * elements, or it accepts raw HTML creating a GQuery element containing those elements. The\r
+ * second parameter is the context to use for the selector. The third parameter is the class\r
+ * plugin to use.\r
* \r
* Xpath selector is supported in browsers with native xpath engine.\r
*/\r
@SuppressWarnings("unchecked")\r
- public static <T extends GQuery> T $(String selector, Node context,\r
- Class<T> plugin) {\r
+ public static <T extends GQuery> T $(String selector, Node context, Class<T> plugin) {\r
try {\r
if (plugins != null) {\r
- T gquery = (T) plugins.get(plugin).init(\r
- new GQuery().select(selector, context));\r
+ T gquery = (T) plugins.get(plugin).init(new GQuery().select(selector, context));\r
return gquery;\r
}\r
throw new RuntimeException("No plugin for class " + plugin);\r
}\r
}\r
\r
- /**\r
- * This function accepts a string containing a CSS selector which is then used\r
- * to match a set of elements, or it accepts raw HTML creating a GQuery\r
- * element containing those elements. The second parameter is the context to\r
- * use for the selector, or the document where the new elements will be\r
- * created.\r
+ /**\r
+ * This function accepts a string containing a CSS selector which is then used to match a set of\r
+ * elements, or it accepts raw HTML creating a GQuery element containing those elements. The\r
+ * second parameter is the context to use for the selector, or the document where the new elements\r
+ * will be created.\r
* \r
* Xpath selector is supported in browsers with native xpath engine.\r
*/\r
}\r
\r
/**\r
- * This function accepts a string containing a CSS selector which is then used\r
- * to match a set of elements, or it accepts raw HTML creating a GQuery\r
- * element containing those elements. The second parameter is the context to\r
- * use for the selector. The third parameter is the class plugin to use.\r
- *\r
+ * This function accepts a string containing a CSS selector which is then used to match a set of\r
+ * elements, or it accepts raw HTML creating a GQuery element containing those elements. The\r
+ * second parameter is the context to use for the selector. The third parameter is the class\r
+ * plugin to use.\r
+ * \r
* Xpath selector is supported in browsers with native xpath engine.\r
*/\r
- public static <T extends GQuery> T $(String selector, Widget context,\r
- Class<T> plugin) {\r
+ public static <T extends GQuery> T $(String selector, Widget context, Class<T> plugin) {\r
return $(selector, context.getElement(), plugin);\r
}\r
\r
- /**\r
+ /**\r
* wraps a GQuery or a plugin object\r
*/\r
public static <T extends GQuery> T $(T gq) {\r
/**\r
* Perform an ajax request to the server.\r
*/\r
- public static void ajax(Properties p) {\r
- ajax(p);\r
- }\r
+ public static void ajax(Properties p) {\r
+ ajax(p);\r
+ }\r
\r
/**\r
* Perform an ajax request to the server.\r
*/\r
- public static void ajax(Settings settings) {\r
- Ajax.ajax(settings);\r
- }\r
+ public static void ajax(Settings settings) {\r
+ Ajax.ajax(settings);\r
+ }\r
\r
/**\r
* Perform an ajax request to the server.\r
*/\r
- public static void ajax(String url, Settings settings) {\r
- Ajax.ajax(url, settings);\r
- }\r
+ public static void ajax(String url, Settings settings) {\r
+ Ajax.ajax(url, settings);\r
+ }\r
\r
@SuppressWarnings("unchecked")\r
protected static GQuery cleanHtmlString(String elem, Document doc) {\r
- \r
+\r
String tag = tagNameRegex.exec(elem).get(1);\r
- \r
- if (tag == null){\r
- throw new RuntimeException("HTML snippet doesn't contain any tag");\r
+\r
+ if (tag == null) {\r
+ throw new RuntimeException("HTML snippet doesn't contain any tag");\r
}\r
- \r
- if (wrapperMap == null){\r
+\r
+ if (wrapperMap == null) {\r
initWrapperMap();\r
}\r
- \r
+\r
TagWrapper wrapper = wrapperMap.get(tag.toLowerCase());\r
- \r
- if (wrapper == null){\r
+\r
+ if (wrapper == null) {\r
wrapper = TagWrapper.DEFAULT;\r
}\r
- \r
+\r
// TODO: fix IE link tag serialization\r
// TODO: fix IE <script> tag\r
Element div = doc.createDivElement();\r
}\r
\r
/**\r
- * Return true if the element b is contained in a. \r
- */\r
- public static boolean contains(Element a, Element b) {\r
- return engine.contains(a, b);\r
- }\r
+ * Return true if the element b is contained in a.\r
+ */\r
+ public static boolean contains(Element a, Element b) {\r
+ return engine.contains(a, b);\r
+ }\r
\r
/**\r
- * Get the element data matching the key. \r
- */\r
- public static Object data(Element e, String key) {\r
- return GQuery.data(e, key, null);\r
- }\r
+ * Get the element data matching the key.\r
+ */\r
+ public static Object data(Element e, String key) {\r
+ return GQuery.data(e, key, null);\r
+ }\r
\r
protected static <S> Object data(Element item, String name, S value) {\r
if (dataCache == null) {\r
}\r
return name != null ? d.get(name) : id;\r
}\r
- \r
+\r
/**\r
* Execute a function around each object\r
*/\r
- public static void each(JsArrayMixed objects, Function f) {\r
- for (int i = 0, l = objects.length(); i < l; i++) {\r
- f.f(i, objects.getObject(i));\r
- }\r
- }\r
+ public static void each(JsArrayMixed objects, Function f) {\r
+ for (int i = 0, l = objects.length(); i < l; i++) {\r
+ f.f(i, objects.getObject(i));\r
+ }\r
+ }\r
\r
/**\r
- * Execute a function around each object\r
- */\r
- public static <T> void each(List<T> objects, Function f) {\r
- for (int i = 0, l = objects.size(); i < l; i++) {\r
- f.f(i, objects.get(i));\r
- }\r
- }\r
+ * Execute a function around each object\r
+ */\r
+ public static <T> void each(List<T> objects, Function f) {\r
+ for (int i = 0, l = objects.size(); i < l; i++) {\r
+ f.f(i, objects.get(i));\r
+ }\r
+ }\r
\r
/**\r
* Execute a function around each object\r
*/\r
- public static <T> void each(T[] objects, Function f) {\r
- for (int i = 0, l = objects.length; i < l; i++) {\r
- f.f(i, objects[i]);\r
- }\r
- }\r
+ public static <T> void each(T[] objects, Function f) {\r
+ for (int i = 0, l = objects.length; i < l; i++) {\r
+ f.f(i, objects[i]);\r
+ }\r
+ }\r
\r
/**\r
* Perform an ajax request to the server using GET.\r
*/\r
- public static void get(String url, Properties data, final Function onSuccess) {\r
- Ajax.get(url, data, onSuccess);\r
- }\r
+ public static void get(String url, Properties data, final Function onSuccess) {\r
+ Ajax.get(url, data, onSuccess);\r
+ }\r
\r
/**\r
- * We will use the fact as GWT use the widget itself as EventListener ! If no\r
- * Widget associated with the element, this method returns null.\r
+ * We will use the fact as GWT use the widget itself as EventListener ! If no Widget associated\r
+ * with the element, this method returns null.\r
*/\r
protected static Widget getAssociatedWidget(Element e) {\r
try {\r
}\r
}\r
} catch (Exception e2) {\r
- // Some times this code could raise an exception. \r
+ // Some times this code could raise an exception.\r
// We do not want GQuery to fail, but in dev-move we log the error.\r
e2.printStackTrace();\r
}\r
return null;\r
}\r
\r
- private static AttributeImpl getAttributeImpl(){\r
- if (attributeImpl == null){\r
+ private static AttributeImpl getAttributeImpl() {\r
+ if (attributeImpl == null) {\r
attributeImpl = GWT.create(AttributeImpl.class);\r
}\r
return attributeImpl;\r
}\r
- \r
+\r
/**\r
- * Perform an ajax request to the server using POST and\r
- * parsing the json response.\r
- */ \r
- public static void getJSON(String url, Properties data,\r
- final Function onSuccess) {\r
- Ajax.getJSON(url, data, onSuccess);\r
- }\r
- \r
+ * Perform an ajax request to the server using POST and parsing the json response.\r
+ */\r
+ public static void getJSON(String url, Properties data, final Function onSuccess) {\r
+ Ajax.getJSON(url, data, onSuccess);\r
+ }\r
+\r
/**\r
- * Perform an ajax request to the server using scripts tags and\r
- * parsing the json response. The request is not subject to the \r
- * same origin policy restrictions.\r
+ * Perform an ajax request to the server using scripts tags and parsing the json response. The\r
+ * request is not subject to the same origin policy restrictions.\r
* \r
- * Server side should accept a parameter to specify the callback\r
- * funcion name, and it must return a valid json object wrapped\r
- * this callback function.\r
+ * Server side should accept a parameter to specify the callback funcion name, and it must return\r
+ * a valid json object wrapped this callback function.\r
* \r
* Example:\r
- <pre>\r
+ * \r
+ * <pre>\r
Client code:\r
getJSONP("http://server.exampe.com/getData.php",$$("myCallback:'?', otherParameter='whatever'"), \r
new Function(){ public void f() {\r
myCallback({"k1":"v1", "k2":"v2"});\r
</pre>\r
* \r
- */ \r
- public static void getJSONP(String url, Properties data,\r
- final Function onSuccess) {\r
+ */\r
+ public static void getJSONP(String url, Properties data, final Function onSuccess) {\r
Ajax.getJSONP(url, data, onSuccess);\r
}\r
- \r
- protected static DocumentStyleImpl getStyleImpl(){\r
- if (styleImpl == null){\r
+\r
+ protected static DocumentStyleImpl getStyleImpl() {\r
+ if (styleImpl == null) {\r
styleImpl = GWT.create(DocumentStyleImpl.class);\r
}\r
return styleImpl;\r
/**\r
* Return only the set of objects with match the predicate.\r
*/\r
- @SuppressWarnings("unchecked")\r
- public static <T> T[] grep(T[] objects, Predicate f) {\r
- ArrayList<Object> ret = new ArrayList<Object>();\r
- for (int i = 0, l = objects.length; i < l; i++) {\r
- if (f.f(objects[i], i)) {\r
- ret.add(objects[i]);\r
- }\r
- }\r
- return (T[]) ret.toArray(new Object[0]);\r
- }\r
+ @SuppressWarnings("unchecked")\r
+ public static <T> T[] grep(T[] objects, Predicate f) {\r
+ ArrayList<Object> ret = new ArrayList<Object>();\r
+ for (int i = 0, l = objects.length; i < l; i++) {\r
+ if (f.f(objects[i], i)) {\r
+ ret.add(objects[i]);\r
+ }\r
+ }\r
+ return (T[]) ret.toArray(new Object[0]);\r
+ }\r
\r
private static boolean hasClass(Element e, String clz) {\r
return e.getClassName().matches("(^|.*\\s)" + clz + "(\\s.*|$)");\r
}\r
\r
- private static void initWrapperMap(){\r
- \r
+ private static void initWrapperMap() {\r
+\r
TagWrapper tableWrapper = new TagWrapper(1, "<table>", "</table>");\r
- TagWrapper selectWrapper = new TagWrapper(1, "<select multiple=\"multiple\">", "</select>");\r
+ TagWrapper selectWrapper = new TagWrapper(1, "<select multiple=\"multiple\">", "</select>");\r
TagWrapper trWrapper = new TagWrapper(3, "<table><tbody><tr>", "</tr></tbody></table>");\r
- \r
+\r
wrapperMap = JsNamedArray.create();\r
wrapperMap.put("option", selectWrapper);\r
wrapperMap.put("optgroup", selectWrapper);\r
- wrapperMap.put("legend", new TagWrapper(1, "<fieldset>", "</fieldset>") );\r
+ wrapperMap.put("legend", new TagWrapper(1, "<fieldset>", "</fieldset>"));\r
wrapperMap.put("thead", tableWrapper);\r
wrapperMap.put("tbody", tableWrapper);\r
wrapperMap.put("tfoot", tableWrapper);\r
wrapperMap.put("colgroup", tableWrapper);\r
wrapperMap.put("caption", tableWrapper);\r
- wrapperMap.put("tr", new TagWrapper(2, "<table><tbody>", "</tbody></table>"));\r
+ wrapperMap.put("tr", new TagWrapper(2, "<table><tbody>", "</tbody></table>"));\r
wrapperMap.put("td", trWrapper);\r
- wrapperMap.put("th", trWrapper); \r
- wrapperMap.put("col", new TagWrapper(2, "<table><tbody></tbody><colgroup>", "</colgroup></table>"));\r
- wrapperMap.put("area", new TagWrapper(1, "<map>", "</map>"));\r
- \r
+ wrapperMap.put("th", trWrapper);\r
+ wrapperMap.put("col", new TagWrapper(2, "<table><tbody></tbody><colgroup>",\r
+ "</colgroup></table>"));\r
+ wrapperMap.put("area", new TagWrapper(1, "<map>", "</map>"));\r
+\r
}\r
\r
private static GQuery innerHtml(String html, Document doc) {\r
return $(cleanHtmlString(html, doc));\r
}\r
- \r
+\r
protected static String[] jsArrayToString(JsArrayString array) {\r
if (GWT.isScript()) {\r
return jsArrayToString0(array);\r
return result;\r
}\r
}\r
- \r
+\r
private static native String[] jsArrayToString0(JsArrayString array) /*-{\r
return array;\r
}-*/;\r
\r
/**\r
- * Return a lazy version of the GQuery interface. Lazy function calls are\r
- * simply queued up and not executed immediately.\r
+ * Return a lazy version of the GQuery interface. Lazy function calls are simply queued up and not\r
+ * executed immediately.\r
*/\r
public static LazyGQuery<?> lazy() {\r
return $().createLazy();\r
\r
/**\r
* Perform an ajax request to the server using POST.\r
- */ \r
- public static void post(String url, Properties data,\r
- final Function onSuccess) {\r
- Ajax.post(url, data, onSuccess);\r
- }\r
-\r
- public static <T extends GQuery> Class<T> registerPlugin(Class<T> plugin,\r
- Plugin<T> pluginFactory) {\r
+ */\r
+ public static void post(String url, Properties data, final Function onSuccess) {\r
+ Ajax.post(url, data, onSuccess);\r
+ }\r
+\r
+ public static <T extends GQuery> Class<T> registerPlugin(Class<T> plugin, Plugin<T> pluginFactory) {\r
if (plugins == null) {\r
plugins = JsMap.createObject().cast();\r
}\r
if (n)\r
n.scrollIntoView()\r
}-*/;\r
- \r
+\r
private static native void setElementValue(Element e, String value) /*-{\r
- e.value = value;\r
+ e.value = value;\r
}-*/;\r
\r
private static native Element window() /*-{\r
*/\r
// TODO: remove this and use elements, change return type of get()\r
private NodeList<Element> nodeList = JavaScriptObject.createArray().cast();\r
- \r
+\r
private GQuery previousObject;\r
\r
private GQuery() {\r
}\r
\r
private GQuery(JsNodeArray nodes) {\r
- this(nodes.<NodeList<Element>>cast());\r
+ this(nodes.<NodeList<Element>> cast());\r
}\r
\r
private GQuery(NodeList<Element> list) {\r
* It also update the selector appending the new one.\r
*/\r
public GQuery add(GQuery elementsToAdd) {\r
- return pushStack(JsUtils.copyNodeList(nodeList, elementsToAdd.nodeList, true).<JsNodeArray>cast(), "add",\r
- getSelector() + "," + elementsToAdd.getSelector());\r
+ return pushStack(JsUtils.copyNodeList(nodeList, elementsToAdd.nodeList, true)\r
+ .<JsNodeArray> cast(), "add", getSelector() + "," + elementsToAdd.getSelector());\r
}\r
- \r
+\r
/**\r
* Add elements to the set of matched elements if they are not included yet.\r
*/\r
*/\r
public GQuery addClass(String... classes) {\r
for (Element e : elements) {\r
- //issue 81 : ensure that the element is an Element node.\r
- if (Element.is(e)){\r
+ // issue 81 : ensure that the element is an Element node.\r
+ if (Element.is(e)) {\r
for (String clz : classes) {\r
e.addClassName(clz);\r
}\r
}\r
\r
/**\r
- * Insert content after each of the matched elements. The elements must\r
- * already be inserted into the document (you can't insert an element after\r
- * another if it's not in the page).\r
+ * Insert content after each of the matched elements. The elements must already be inserted into\r
+ * the document (you can't insert an element after another if it's not in the page).\r
*/\r
public GQuery after(GQuery query) {\r
return domManip(query, DomMan.AFTER);\r
}\r
\r
/**\r
- * Insert content after each of the matched elements. The elements must\r
- * already be inserted into the document (you can't insert an element after\r
- * another if it's not in the page).\r
+ * Insert content after each of the matched elements. The elements must already be inserted into\r
+ * the document (you can't insert an element after another if it's not in the page).\r
*/\r
public GQuery after(Node n) {\r
return domManip($(n), DomMan.AFTER);\r
}\r
\r
/**\r
- * Insert content after each of the matched elements. The elements must\r
- * already be inserted into the document (you can't insert an element after\r
- * another if it's not in the page).\r
+ * Insert content after each of the matched elements. The elements must already be inserted into\r
+ * the document (you can't insert an element after another if it's not in the page).\r
*/\r
public GQuery after(String html) {\r
return domManip(html, DomMan.AFTER);\r
}\r
\r
- private void allNextSiblingElements(Element firstChildElement,\r
- JsNodeArray result, Element elem, GQuery until, String filterSelector) {\r
- \r
- while (firstChildElement != null) {\r
- \r
- if (until != null && until.index(firstChildElement) != -1){\r
+ private void allNextSiblingElements(Element firstChildElement, JsNodeArray result, Element elem,\r
+ GQuery until, String filterSelector) {\r
+\r
+ while (firstChildElement != null) {\r
+\r
+ if (until != null && until.index(firstChildElement) != -1) {\r
return;\r
}\r
- \r
- if (firstChildElement != elem\r
- && (filterSelector == null || $(firstChildElement).is(filterSelector))) {\r
- result.addNode(firstChildElement);\r
+\r
+ if (firstChildElement != elem\r
+ && (filterSelector == null || $(firstChildElement).is(filterSelector))) {\r
+ result.addNode(firstChildElement);\r
}\r
firstChildElement = firstChildElement.getNextSiblingElement();\r
}\r
}\r
\r
- private void allPreviousSiblingElements(Element firstChildElement,\r
- JsNodeArray result, GQuery until, String filterSelector) {\r
+ private void allPreviousSiblingElements(Element firstChildElement, JsNodeArray result,\r
+ GQuery until, String filterSelector) {\r
while (firstChildElement != null) {\r
- if (until != null && until.index(firstChildElement) != -1){\r
+ if (until != null && until.index(firstChildElement) != -1) {\r
return;\r
}\r
- \r
- if(filterSelector == null || $(firstChildElement).is(filterSelector)){\r
- result.addNode(firstChildElement);\r
+\r
+ if (filterSelector == null || $(firstChildElement).is(filterSelector)) {\r
+ result.addNode(firstChildElement);\r
}\r
\r
firstChildElement = getPreviousSiblingElement(firstChildElement);\r
}\r
\r
/**\r
- * Add the previous selection to the current selection. Useful for traversing\r
- * elements, and then adding something that was matched before the last\r
- * traversal.\r
+ * Add the previous selection to the current selection. Useful for traversing elements, and then\r
+ * adding something that was matched before the last traversal.\r
*/\r
public GQuery andSelf() {\r
return add(previousObject);\r
\r
/**\r
* \r
- * The animate() method allows you to create animation effects on any numeric\r
- * Attribute, CSS property, or color CSS property.\r
+ * The animate() method allows you to create animation effects on any numeric Attribute, CSS\r
+ * property, or color CSS property.\r
* \r
- * Concerning to numeric properties, values are treated as a number of pixels\r
- * unless otherwise specified. The units em and % can be specified where\r
- * applicable.\r
+ * Concerning to numeric properties, values are treated as a number of pixels unless otherwise\r
+ * specified. The units em and % can be specified where applicable.\r
* \r
- * By default animate considers css properties, if you wanted to animate element\r
- * attributes you should to prepend the symbol dollar to the attribute name.\r
+ * By default animate considers css properties, if you wanted to animate element attributes you\r
+ * should to prepend the symbol dollar to the attribute name.\r
* \r
* Example:\r
* \r
* $("table").animate("$width:'500'"), 400, Easing.LINEAR);\r
* </pre>\r
* \r
- * In addition to numeric values, each property can take the strings 'show',\r
- * 'hide', and 'toggle'. These shortcuts allow for custom hiding and showing\r
- * animations that take into account the display type of the element. Animated\r
- * properties can also be relative. If a value is supplied with a leading +=\r
- * or -= sequence of characters, then the target value is computed by adding\r
- * or subtracting the given number from the current value of the property.\r
+ * In addition to numeric values, each property can take the strings 'show', 'hide', and 'toggle'.\r
+ * These shortcuts allow for custom hiding and showing animations that take into account the\r
+ * display type of the element. Animated properties can also be relative. If a value is supplied\r
+ * with a leading += or -= sequence of characters, then the target value is computed by adding or\r
+ * subtracting the given number from the current value of the property.\r
* \r
* Example:\r
* \r
* \r
* The duration of the animation is 500ms.\r
* \r
- * For color css properties, values can be specified via hexadecimal or rgb or\r
- * literal values.\r
+ * For color css properties, values can be specified via hexadecimal or rgb or literal values.\r
* \r
* Example:\r
* \r
* </pre>\r
* \r
* @param prop the property to animate : "cssName:'value'"\r
- * @param funcs an array of {@link Function} called once the animation is\r
- * complete\r
+ * @param funcs an array of {@link Function} called once the animation is complete\r
*/\r
public GQuery animate(Object stringOrProperties, Function... funcs) {\r
return as(Effects).animate(stringOrProperties, funcs);\r
}\r
\r
/**\r
- * The animate() method allows you to create animation effects on any numeric\r
- * Attribute, CSS property, or color CSS property.\r
+ * The animate() method allows you to create animation effects on any numeric Attribute, CSS\r
+ * property, or color CSS property.\r
* \r
- * Concerning to numeric properties, values are treated as a number of pixels\r
- * unless otherwise specified. The units em and % can be specified where\r
- * applicable.\r
+ * Concerning to numeric properties, values are treated as a number of pixels unless otherwise\r
+ * specified. The units em and % can be specified where applicable.\r
* \r
- * By default animate considers css properties, if you wanted to animate element\r
- * attributes you should to prepend the symbol dollar to the attribute name.\r
+ * By default animate considers css properties, if you wanted to animate element attributes you\r
+ * should to prepend the symbol dollar to the attribute name.\r
* \r
* Example:\r
* \r
* $("table").animate(Properties.create("{$width: '500', $border: '10'}"), 400, Easing.LINEAR);\r
* </pre>\r
* \r
- * In addition to numeric values, each property can take the strings 'show',\r
- * 'hide', and 'toggle'. These shortcuts allow for custom hiding and showing\r
- * animations that take into account the display type of the element. Animated\r
- * properties can also be relative. If a value is supplied with a leading +=\r
- * or -= sequence of characters, then the target value is computed by adding\r
- * or subtracting the given number from the current value of the property.\r
+ * In addition to numeric values, each property can take the strings 'show', 'hide', and 'toggle'.\r
+ * These shortcuts allow for custom hiding and showing animations that take into account the\r
+ * display type of the element. Animated properties can also be relative. If a value is supplied\r
+ * with a leading += or -= sequence of characters, then the target value is computed by adding or\r
+ * subtracting the given number from the current value of the property.\r
* \r
* Example:\r
* \r
* $("#foo").animate(Properties.create("{top:'+=500px',left:'+=500px'}"), 400, Easing.SWING);\r
* </pre>\r
* \r
- * For color css properties, values can be specified via hexadecimal or rgb or\r
- * literal values.\r
+ * For color css properties, values can be specified via hexadecimal or rgb or literal values.\r
* \r
* Example:\r
* \r
* $("#foo").animate("backgroundColor:'red', color:'#ffffff', borderColor:'rgb(129, 0, 70)'"), 400, Easing.SWING);\r
* </pre>\r
* \r
- * @param stringOrProperties a String or a {@link Properties} object containing css properties to animate.\r
- * @param funcs an array of {@link Function} called once the animation is\r
- * complete\r
+ * @param stringOrProperties a String or a {@link Properties} object containing css properties to\r
+ * animate.\r
+ * @param funcs an array of {@link Function} called once the animation is complete\r
* @param duration the duration in milliseconds of the animation\r
* @param easing the easing function to use for the transition\r
*/\r
}\r
\r
/**\r
- * The animate() method allows you to create animation effects on any numeric\r
- * Attribute, CSS properties, or color CSS property.\r
+ * The animate() method allows you to create animation effects on any numeric Attribute, CSS\r
+ * properties, or color CSS property.\r
* \r
- * Concerning to numeric property, values are treated as a number of pixels\r
- * unless otherwise specified. The units em and % can be specified where\r
- * applicable.\r
+ * Concerning to numeric property, values are treated as a number of pixels unless otherwise\r
+ * specified. The units em and % can be specified where applicable.\r
* \r
- * By default animate considers css properties, if you wanted to animate element\r
- * attributes you should to prepend the symbol dollar to the attribute name.\r
+ * By default animate considers css properties, if you wanted to animate element attributes you\r
+ * should to prepend the symbol dollar to the attribute name.\r
* \r
* Example:\r
* \r
* $("table").animate("$width:'500'"), 400);\r
* </pre>\r
* \r
- * In addition to numeric values, each property can take the strings 'show',\r
- * 'hide', and 'toggle'. These shortcuts allow for custom hiding and showing\r
- * animations that take into account the display type of the element. Animated\r
- * properties can also be relative. If a value is supplied with a leading +=\r
- * or -= sequence of characters, then the target value is computed by adding\r
- * or subtracting the given number from the current value of the property.\r
+ * In addition to numeric values, each property can take the strings 'show', 'hide', and 'toggle'.\r
+ * These shortcuts allow for custom hiding and showing animations that take into account the\r
+ * display type of the element. Animated properties can also be relative. If a value is supplied\r
+ * with a leading += or -= sequence of characters, then the target value is computed by adding or\r
+ * subtracting the given number from the current value of the property.\r
* \r
* Example:\r
* \r
* </pre>\r
* \r
* \r
- * For color css properties, values can be specified via hexadecimal or rgb or\r
- * literal values.\r
+ * For color css properties, values can be specified via hexadecimal or rgb or literal values.\r
* \r
* Example:\r
* \r
* \r
* \r
* @param prop the property to animate : "cssName:'value'"\r
- * @param funcs an array of {@link Function} called once the animation is\r
- * complete\r
+ * @param funcs an array of {@link Function} called once the animation is complete\r
* @param duration the duration in milliseconds of the animation\r
*/\r
public GQuery animate(Object stringOrProperties, int duration, Function... funcs) {\r
}\r
\r
/**\r
- * Append content to the inside of every matched element. This operation is\r
- * similar to doing an appendChild to all the specified elements, adding them\r
- * into the document.\r
+ * Append content to the inside of every matched element. This operation is similar to doing an\r
+ * appendChild to all the specified elements, adding them into the document.\r
*/\r
public GQuery append(GQuery query) {\r
return domManip(query, DomMan.APPEND);\r
}\r
\r
/**\r
- * Append content to the inside of every matched element. This operation is\r
- * similar to doing an appendChild to all the specified elements, adding them\r
- * into the document.\r
+ * Append content to the inside of every matched element. This operation is similar to doing an\r
+ * appendChild to all the specified elements, adding them into the document.\r
*/\r
public GQuery append(Node n) {\r
return domManip($(n), DomMan.APPEND);\r
}\r
\r
/**\r
- * Append content to the inside of every matched element. This operation is\r
- * similar to doing an appendChild to all the specified elements, adding them\r
- * into the document.\r
+ * Append content to the inside of every matched element. This operation is similar to doing an\r
+ * appendChild to all the specified elements, adding them into the document.\r
*/\r
public GQuery append(String html) {\r
return domManip(html, DomMan.APPEND);\r
}\r
\r
/**\r
- * All of the matched set of elements will be inserted at the end of the\r
- * element(s) specified by the parameter other.\r
+ * All of the matched set of elements will be inserted at the end of the element(s) specified by\r
+ * the parameter other.\r
* \r
- * The operation $(A).appendTo(B) is, essentially, the reverse of doing a\r
- * regular $(A).append(B), instead of appending B to A, you're appending A to\r
- * B.\r
+ * The operation $(A).appendTo(B) is, essentially, the reverse of doing a regular $(A).append(B),\r
+ * instead of appending B to A, you're appending A to B.\r
*/\r
public GQuery appendTo(GQuery other) {\r
other.append(this);\r
}\r
\r
/**\r
- * All of the matched set of elements will be inserted at the end of the\r
- * element(s) specified by the parameter other.\r
+ * All of the matched set of elements will be inserted at the end of the element(s) specified by\r
+ * the parameter other.\r
* \r
- * The operation $(A).appendTo(B) is, essentially, the reverse of doing a\r
- * regular $(A).append(B), instead of appending B to A, you're appending A to\r
- * B.\r
+ * The operation $(A).appendTo(B) is, essentially, the reverse of doing a regular $(A).append(B),\r
+ * instead of appending B to A, you're appending A to B.\r
*/\r
public GQuery appendTo(Node n) {\r
GQuery a = $(n);\r
}\r
\r
/**\r
- * All of the matched set of elements will be inserted at the end of the\r
- * element(s) specified by the parameter other.\r
+ * All of the matched set of elements will be inserted at the end of the element(s) specified by\r
+ * the parameter other.\r
* \r
- * The operation $(A).appendTo(B) is, essentially, the reverse of doing a\r
- * regular $(A).append(B), instead of appending B to A, you're appending A to\r
- * B.\r
+ * The operation $(A).appendTo(B) is, essentially, the reverse of doing a regular $(A).append(B),\r
+ * instead of appending B to A, you're appending A to B.\r
*/\r
public GQuery appendTo(String html) {\r
$(html).append(this);\r
return (T) p.init(this);\r
}\r
}\r
- throw new RuntimeException("No plugin registered for class "\r
- + plugin.getName());\r
+ throw new RuntimeException("No plugin registered for class " + plugin.getName());\r
}\r
\r
/**\r
* Set a key/value object as properties to all matched elements.\r
* \r
- * Example: $("img").attr(new\r
- * Properties("src: 'test.jpg', alt: 'Test Image'"))\r
+ * Example: $("img").attr(new Properties("src: 'test.jpg', alt: 'Test Image'"))\r
*/\r
public GQuery attr(Properties properties) {\r
for (String name : properties.keys()) {\r
}\r
return this;\r
}\r
- \r
+\r
/**\r
- * Access a property on the first matched element. This method makes it easy\r
- * to retrieve a property value from the first matched element. If the element\r
- * does not have an attribute with such a name, empty string is returned.\r
- * Attributes include title, alt, src, href, width, style, etc.\r
+ * Access a property on the first matched element. This method makes it easy to retrieve a\r
+ * property value from the first matched element. If the element does not have an attribute with\r
+ * such a name, empty string is returned. Attributes include title, alt, src, href, width, style,\r
+ * etc.\r
*/\r
public String attr(String name) {\r
return isEmpty() ? "" : get(0).getAttribute(name);\r
- } \r
-
+ }\r
+\r
/**\r
* Set a single property to a computed value, on all matched elements.\r
*/\r
public GQuery attr(String key, Function closure) {\r
int i = 0;\r
for (Element e : elements) {\r
- Object val = closure.f(e.<com.google.gwt.dom.client.Element>cast(), i++);\r
+ Object val = closure.f(e.<com.google.gwt.dom.client.Element> cast(), i++);\r
$(e).attr(key, val);\r
}\r
return this;\r
}\r
- \r
- \r
\r
/**\r
* Set a single property to a value, on all matched elements.\r
public GQuery attr(String key, Object value) {\r
assert key != null : "key cannot be null";\r
assert !"$H".equalsIgnoreCase(key) : "$H is a GWT reserved attribute. Changing its value will break your application.";\r
- \r
+\r
getAttributeImpl().setAttribute(this, key, value);\r
- \r
+\r
return this;\r
}\r
\r
/**\r
- * Insert content before each of the matched elements. The elements must\r
- * already be inserted into the document (you can't insert an element before\r
- * another if it's not in the page).\r
+ * Insert content before each of the matched elements. The elements must already be inserted into\r
+ * the document (you can't insert an element before another if it's not in the page).\r
*/\r
public GQuery before(GQuery query) {\r
return domManip(query, DomMan.BEFORE);\r
}\r
\r
/**\r
- * Insert content before each of the matched elements. The elements must\r
- * already be inserted into the document (you can't insert an element before\r
- * another if it's not in the page).\r
+ * Insert content before each of the matched elements. The elements must already be inserted into\r
+ * the document (you can't insert an element before another if it's not in the page).\r
*/\r
public GQuery before(Node n) {\r
return domManip($(n), DomMan.BEFORE);\r
}\r
\r
/**\r
- * Insert content before each of the matched elements. The elements must\r
- * already be inserted into the document (you can't insert an element before\r
- * another if it's not in the page).\r
+ * Insert content before each of the matched elements. The elements must already be inserted into\r
+ * the document (you can't insert an element before another if it's not in the page).\r
*/\r
public GQuery before(String html) {\r
return domManip(html, DomMan.BEFORE);\r
/**\r
* Binds a set of handlers to a particular Event for each matched element.\r
* \r
- * The event handlers are passed as Functions that you can use to prevent\r
- * default behavior. To stop both default action and event bubbling, the\r
- * function event handler has to return false.\r
+ * The event handlers are passed as Functions that you can use to prevent default behavior. To\r
+ * stop both default action and event bubbling, the function event handler has to return false.\r
* \r
- * You can pass an additional Object data to your Function as the second\r
- * parameter\r
+ * You can pass an additional Object data to your Function as the second parameter\r
* \r
*/\r
public GQuery bind(int eventbits, final Object data, final Function... funcs) {\r
return as(Events).bind(eventbits, data, funcs);\r
}\r
+ \r
+ /**\r
+ * Binds a set of handlers to a particular Event for each matched element.\r
+ * \r
+ * The event handlers are passed as Functions that you can use to prevent default behavior. To\r
+ * stop both default action and event bubbling, the function event handler has to return false.\r
+ * \r
+ * \r
+ */\r
+ public GQuery bind(int eventbits, final Function... funcs) {\r
+ return as(Events).bind(eventbits, null, funcs);\r
+ }\r
\r
/**\r
* Binds a set of handlers to a particular Event for each matched element.\r
* \r
- * The event handlers are passed as Functions that you can use to prevent\r
- * default behavior. To stop both default action and event bubbling, the\r
- * function event handler has to return false.\r
+ * The event handlers are passed as Functions that you can use to prevent default behavior. To\r
+ * stop both default action and event bubbling, the function event handler has to return false.\r
* \r
- * You can pass an additional Object data to your Function as the second\r
- * parameter\r
+ * You can pass an additional Object data to your Function as the second parameter\r
* \r
*/\r
- public GQuery bind(String eventType, final Object data,\r
- final Function... funcs) {\r
+ public GQuery bind(String eventType, final Object data, final Function... funcs) {\r
return as(Events).bind(eventType, data, funcs);\r
}\r
\r
+ /**\r
+ * Binds a set of handlers to a particular Event for each matched element.\r
+ * \r
+ * The event handlers are passed as Functions that you can use to prevent default behavior. To\r
+ * stop both default action and event bubbling, the function event handler has to return false.\r
+ * \r
+ * \r
+ */\r
+ public GQuery bind(String eventType, final Function... funcs) {\r
+ return as(Events).bind(eventType, null, funcs);\r
+ }\r
+\r
/**\r
* Bind Handlers or fire Events for each matched element.\r
*/\r
- private GQuery bindOrFire(int eventbits, final Object data,\r
- final Function... funcs) {\r
+ private GQuery bindOrFire(int eventbits, final Object data, final Function... funcs) {\r
if (funcs.length == 0) {\r
return trigger(eventbits);\r
} else {\r
}\r
\r
/**\r
- * Bind a set of functions to the blur event of each matched element. \r
- * Or trigger the blur event if no functions are provided.\r
+ * Bind a set of functions to the blur event of each matched element. Or trigger the blur event if\r
+ * no functions are provided.\r
*/\r
public GQuery blur(Function... f) {\r
bindOrFire(Event.ONBLUR, null, f);\r
}\r
\r
/**\r
- * Bind a set of functions to the change event of each matched element. Or\r
- * trigger the event if no functions are provided.\r
+ * Bind a set of functions to the change event of each matched element. Or trigger the event if no\r
+ * functions are provided.\r
*/\r
public GQuery change(Function... f) {\r
return bindOrFire(Event.ONCHANGE, null, f);\r
}\r
\r
/**\r
- * Get a set of elements containing all of the unique immediate children of\r
- * each of the matched set of elements. Also note: while parents() will look\r
- * at all ancestors, children() will only consider immediate child elements.\r
+ * Get a set of elements containing all of the unique immediate children of each of the matched\r
+ * set of elements. Also note: while parents() will look at all ancestors, children() will only\r
+ * consider immediate child elements.\r
*/\r
public GQuery children() {\r
JsNodeArray result = JsNodeArray.create();\r
}\r
\r
/**\r
- * Get a set of elements containing all of the unique children of each of the\r
- * matched set of elements. This set is filtered with the expressions that\r
- * will cause only elements matching any of the selectors to be collected.\r
+ * Get a set of elements containing all of the unique children of each of the matched set of\r
+ * elements. This set is filtered with the expressions that will cause only elements matching any\r
+ * of the selectors to be collected.\r
*/\r
public GQuery children(String... filters) {\r
return children().filter(filters);\r
}\r
}\r
\r
- \r
/**\r
- * Remove from the Effects queue all {@link Function} that have not yet been\r
- * run.\r
+ * Remove from the Effects queue all {@link Function} that have not yet been run.\r
*/\r
public GQuery clearQueue() {\r
return as(Queue).clearQueue();\r
}\r
\r
/**\r
- * Bind a set of functions to the click event of each matched element. Or\r
- * trigger the event if no functions are provided.\r
+ * Bind a set of functions to the click event of each matched element. Or trigger the event if no\r
+ * functions are provided.\r
*/\r
public GQuery click(Function... f) {\r
return bindOrFire(Event.ONCLICK, null, f);\r
}\r
\r
/**\r
- * Clone matched DOM Elements and select the clones. This is useful for moving\r
- * copies of the elements to another location in the DOM.\r
+ * Clone matched DOM Elements and select the clones. This is useful for moving copies of the\r
+ * elements to another location in the DOM.\r
*/\r
public GQuery clone() {\r
JsNodeArray result = JsNodeArray.create();\r
}\r
\r
/**\r
- * Get the first ancestor element that matches the selector (for each matched\r
- * element), beginning at the current element and progressing up through the\r
- * DOM tree.\r
+ * Get the first ancestor element that matches the selector (for each matched element), beginning\r
+ * at the current element and progressing up through the DOM tree.\r
* \r
* @param selector\r
* @return\r
}\r
\r
/**\r
- * Get the first ancestor element that matches the selector (for each matched\r
- * element), beginning at the current element and progressing up through the\r
- * DOM tree until reach the <code>context</code> node.\r
+ * Get the first ancestor element that matches the selector (for each matched element), beginning\r
+ * at the current element and progressing up through the DOM tree until reach the\r
+ * <code>context</code> node.\r
* \r
- * If no context is passed in then the context of the gQuery object will be\r
- * used instead.\r
+ * If no context is passed in then the context of the gQuery object will be used instead.\r
* \r
*/\r
public GQuery closest(String selector, Node context) {\r
\r
for (Element e : elements) {\r
Element current = e;\r
- while (current != null && current.getOwnerDocument() != null\r
- && current != context) {\r
- boolean match = pos != null ? pos.index(current) > -1 : $(current).is(\r
- selector);\r
+ while (current != null && current.getOwnerDocument() != null && current != context) {\r
+ boolean match = pos != null ? pos.index(current) > -1 : $(current).is(selector);\r
if (match) {\r
result.addNode(current);\r
break;\r
}\r
\r
/**\r
- * Returns a {@link Map} object as key a selector and as value the list of\r
- * ancestor elements matching this selectors, beginning at the first matched\r
- * element and progressing up through the DOM. This method allows retrieving\r
- * the list of ancestors matching many selectors by traversing the DOM only\r
- * one time.\r
+ * Returns a {@link Map} object as key a selector and as value the list of ancestor elements\r
+ * matching this selectors, beginning at the first matched element and progressing up through the\r
+ * DOM. This method allows retrieving the list of ancestors matching many selectors by traversing\r
+ * the DOM only one time.\r
* \r
* @param selector\r
* @return\r
}\r
\r
/**\r
- * Returns a {@link Map} object as key a selector and as value the list of\r
- * ancestor elements matching this selectors, beginning at the first matched\r
- * element and progressing up through the DOM until reach the\r
- * <code>context</code> node.. This method allows retrieving the list of\r
+ * Returns a {@link Map} object as key a selector and as value the list of ancestor elements\r
+ * matching this selectors, beginning at the first matched element and progressing up through the\r
+ * DOM until reach the <code>context</code> node.. This method allows retrieving the list of\r
* ancestors matching many selectors by traversing the DOM only one time.\r
* \r
* @param selector\r
JsNamedArray<GQuery> matches = JsNamedArray.create();\r
for (String selector : selectors) {\r
if (!matches.exists(selector)) {\r
- matches.put(selector, selector.matches(POS_REGEX) ? $(selector,\r
- context) : null);\r
+ matches.put(selector, selector.matches(POS_REGEX) ? $(selector, context) : null);\r
}\r
}\r
\r
Element current = first;\r
- while (current != null && current.getOwnerDocument() != null\r
- && current != context) {\r
+ while (current != null && current.getOwnerDocument() != null && current != context) {\r
// for each selector, check if the current element match it.\r
for (String selector : matches.keys()) {\r
\r
GQuery pos = matches.get(selector);\r
- boolean match = pos != null ? pos.index(current) > -1\r
- : $(current).is(selector);\r
+ boolean match = pos != null ? pos.index(current) > -1 : $(current).is(selector);\r
\r
if (match) {\r
JsNodeArray elementsMatchingSelector = results.get(selector).cast();\r
}\r
\r
/**\r
- * Find all the child nodes inside the matched elements (including text\r
- * nodes), or the content document, if the element is an iframe.\r
+ * Find all the child nodes inside the matched elements (including text nodes), or the content\r
+ * document, if the element is an iframe.\r
*/\r
public GQuery contents() {\r
JsNodeArray result = JsNodeArray.create();\r
}\r
\r
/**\r
- * Set CSS a single style property on every matched element using type-safe\r
- * enumerations.\r
+ * Set CSS a single style property on every matched element using type-safe enumerations.\r
* \r
- * The best way to use this method (i.e. to generate a CssSetter) is to take\r
- * the desired css property defined in {@link CSS} class and call the\r
- * {@link TakesCssValue#with(HasCssName)} method on it.\r
+ * The best way to use this method (i.e. to generate a CssSetter) is to take the desired css\r
+ * property defined in {@link CSS} class and call the {@link TakesCssValue#with(HasCssName)}\r
+ * method on it.\r
* \r
* \r
* ex :\r
}\r
\r
/**\r
- * Return a style property on the first matched element using type-safe\r
- * enumerations.\r
+ * Return a style property on the first matched element using type-safe enumerations.\r
* \r
* Ex : $("#myId").css(CSS.BACKGROUND_COLOR);\r
*/\r
}\r
\r
/**\r
- * Return a style property on the first matched element using type-safe\r
- * enumerations.\r
+ * Return a style property on the first matched element using type-safe enumerations.\r
* \r
- * The parameter force has a special meaning here: - When force is false,\r
- * returns the value of the css property defined in the style attribute of the\r
- * element. - Otherwise it returns the real computed value.\r
+ * The parameter force has a special meaning here: - When force is false, returns the value of the\r
+ * css property defined in the style attribute of the element. - Otherwise it returns the real\r
+ * computed value.\r
* \r
- * For instance if you define 'display=none' not in the element style but in\r
- * the css stylesheet, it returns an empty string unless you pass the\r
- * parameter force=true.\r
+ * For instance if you define 'display=none' not in the element style but in the css stylesheet,\r
+ * it returns an empty string unless you pass the parameter force=true.\r
* \r
* Ex : $("#myId").css(CSS.WIDTH, true);\r
*/\r
}\r
\r
/**\r
- * Set a key/value object as style properties to all matched elements. This\r
- * serves as the best way to set a large number of style properties on all\r
- * matched elements. You can use either js maps or pure css syntax.\r
+ * Set a key/value object as style properties to all matched elements. This serves as the best way\r
+ * to set a large number of style properties on all matched elements. You can use either js maps\r
+ * or pure css syntax.\r
* \r
* Example:\r
* \r
return this;\r
}\r
\r
-\r
/**\r
* Return a style property on the first matched element.\r
*/\r
/**\r
* Return a style property on the first matched element.\r
* \r
- * The parameter force has a special meaning here: \r
+ * The parameter force has a special meaning here:\r
* <ul>\r
- * <li>When force is false, returns the value of the css property \r
- * defined in the style attribute of the element. \r
+ * <li>When force is false, returns the value of the css property defined in the style attribute\r
+ * of the element.\r
* <li>Otherwise it returns the real computed value.\r
* </ul>\r
* \r
- * For instance if you don't define 'display=none'in the element style but in\r
- * the css stylesheet, it returns an empty string unless you pass the\r
- * parameter force=true.\r
+ * For instance if you don't define 'display=none'in the element style but in the css stylesheet,\r
+ * it returns an empty string unless you pass the parameter force=true.\r
*/\r
public String css(String name, boolean force) {\r
return isEmpty() ? "" : getStyleImpl().curCSS(get(0), name, force);\r
}\r
\r
/**\r
- * Set CSS a single style property on every matched element using type-safe\r
- * enumerations. This method allows you to set manually the value or set\r
- * <i>inherit</i> value\r
+ * Set CSS a single style property on every matched element using type-safe enumerations. This\r
+ * method allows you to set manually the value or set <i>inherit</i> value\r
* \r
* ex :\r
* \r
/**\r
* Returns the numeric value of a css property.\r
* \r
- * The parameter force has a special meaning: - When force is false, returns\r
- * the value of the css property defined in the set of style attributes. -\r
- * When true returns the real computed value.\r
+ * The parameter force has a special meaning: - When force is false, returns the value of the css\r
+ * property defined in the set of style attributes. - When true returns the real computed value.\r
*/\r
public double cur(String prop, boolean force) {\r
return isEmpty() ? 0 : getStyleImpl().cur(get(0), prop, force);\r
}\r
\r
/**\r
- * Returns value at named data store for the element, as set by data(name,\r
- * value).\r
+ * Returns value at named data store for the element, as set by data(name, value).\r
*/\r
public Object data(String name) {\r
return isEmpty() ? null : data(get(0), name, null);\r
}\r
\r
/**\r
- * Returns value at named data store for the element, as set by data(name,\r
- * value) with desired return type.\r
+ * Returns value at named data store for the element, as set by data(name, value) with desired\r
+ * return type.\r
* \r
* @param clz return type class literal\r
*/\r
}\r
\r
/**\r
- * Bind a set of functions to the dblclick event of each matched element. Or\r
- * trigger the event if no functions are provided.\r
+ * Bind a set of functions to the dblclick event of each matched element. Or trigger the event if\r
+ * no functions are provided.\r
*/\r
public GQuery dblclick(Function... f) {\r
return bindOrFire(Event.ONDBLCLICK, null, f);\r
}\r
\r
/**\r
- * Insert a delay (in ms) in the GQuery queue, and optionally execute one o\r
- * more functions if provided when the delay finishes.\r
- * It uses the effects queue namespace, so you can stack any of the methods in the effects\r
- * plugin.\r
+ * Insert a delay (in ms) in the GQuery queue, and optionally execute one o more functions if\r
+ * provided when the delay finishes. It uses the effects queue namespace, so you can stack any of\r
+ * the methods in the effects plugin.\r
* \r
* Example:\r
* \r
* .fadeIn(400); \r
* </pre>\r
* \r
- * When this statement is executed, the element slides up for 300 milliseconds\r
- * and then pauses for 800 milliseconds before fading in for 400 milliseconds.\r
- * Aditionally after those 800 milliseconds the element color is set to red.\r
+ * When this statement is executed, the element slides up for 300 milliseconds and then pauses for\r
+ * 800 milliseconds before fading in for 400 milliseconds. Aditionally after those 800\r
+ * milliseconds the element color is set to red.\r
* \r
- * NOTE that this methods affects only methods which uses the queue like effects.\r
- * So the following example is wrong:\r
+ * NOTE that this methods affects only methods which uses the queue like effects. So the following\r
+ * example is wrong:\r
* \r
* <pre>\r
* $("#foo").css(CSS.COLOR.with(RGBColor.RED)).delay(800).css(CSS.COLOR.with(RGBColor.BLACK)); \r
* </pre>\r
* \r
- * The code above will not insert a delay of 800 ms between the css() calls !\r
- * For this kind of behavior, you should execute these methods puting them in inline \r
- * functions passed as argument to the delay() method, or adding them to the queue.\r
+ * The code above will not insert a delay of 800 ms between the css() calls ! For this kind of\r
+ * behavior, you should execute these methods puting them in inline functions passed as argument\r
+ * to the delay() method, or adding them to the queue.\r
* \r
* <pre>\r
* $("#foo").css(CSS.COLOR.with(RGBColor.RED)).delay(800, lazy().css(CSS.COLOR.with(RGBColor.BLACK)).done()); \r
}\r
\r
/**\r
- * Insert a delay (in ms) in the queue identified by the\r
- * <code>queueName</code> parameter, and optionally execute one o\r
- * more functions if provided when the delay finishes.\r
+ * Insert a delay (in ms) in the queue identified by the <code>queueName</code> parameter, and\r
+ * optionally execute one o more functions if provided when the delay finishes.\r
* \r
- * If <code>queueName</code> is null or\r
- * equats to 'fx', the delay will be inserted to the Effects queue.\r
+ * If <code>queueName</code> is null or equats to 'fx', the delay will be inserted to the Effects\r
+ * queue.\r
* \r
* Example :\r
* \r
* .queue("colorQueue", lazy().css(CSS.COLOR.with(RGBColor.BLACK)).dequeue("colorQueue").done()); \r
* </pre>\r
* \r
- * When this statement is executed, the text color of the element changes to\r
- * red and then wait for 800 milliseconds before changes the text color to\r
- * black.\r
+ * When this statement is executed, the text color of the element changes to red and then wait for\r
+ * 800 milliseconds before changes the text color to black.\r
* \r
*/\r
public GQuery delay(int milliseconds, String queueName, Function... f) {\r
}\r
\r
/**\r
- * Attach <code>handlers</code> to one or more events for all elements that\r
- * match the <code>selector</code>, now or in the future, based on a specific\r
- * set of root elements. \r
+ * Attach <code>handlers</code> to one or more events for all elements that match the\r
+ * <code>selector</code>, now or in the future, based on a specific set of root elements.\r
* \r
* Example:\r
* \r
* });\r
* </pre>\r
* \r
- * This code above add an handler on click event on all cell (the existing\r
- * oneand the future cell) of all table. This code is equivalent to :\r
+ * This code above add an handler on click event on all cell (the existing oneand the future cell)\r
+ * of all table. This code is equivalent to :\r
* \r
* <pre>\r
* $("table").each(new Function(){\r
*\r
* </pre>\r
* \r
- * You can attach the handlers to many events by using the '|' operator\r
- * ex:\r
+ * You can attach the handlers to many events by using the '|' operator ex:\r
+ * \r
* <pre>\r
* $("div.main").delegate(".subMain", Event.ONCLICK | Event.ONDBLCLICK, new Function(){...});\r
* </pre>\r
}\r
\r
/**\r
- * Attach <code>handlers</code> to one or more events for all elements that match the <code>selector</code>, \r
- * now or in the future, based on a specific set of root elements.\r
- * The <code>data</code> parameter allows us\r
- * to pass data to the handler.\r
- *\r
+ * Attach <code>handlers</code> to one or more events for all elements that match the\r
+ * <code>selector</code>, now or in the future, based on a specific set of root elements. The\r
+ * <code>data</code> parameter allows us to pass data to the handler.\r
+ * \r
* Example:\r
+ * \r
* <pre>\r
* $("table").delegate("td", "click", new Function(){\r
* public void f(Element e){\r
* }\r
* });\r
* </pre>\r
- * This code above add an handler on click event on all cell (the existing oneand the future cell) of all table.\r
- * This code is equivalent to :\r
+ * \r
+ * This code above add an handler on click event on all cell (the existing oneand the future cell)\r
+ * of all table. This code is equivalent to :\r
+ * \r
* <pre>\r
* $("table").each(new Function(){\r
* public void f(Element table){\r
*\r
* </pre>\r
* \r
- * You can pass attach the handlers to many events by using the '|' operator\r
- * ex:\r
+ * You can pass attach the handlers to many events by using the '|' operator ex:\r
+ * \r
* <pre>\r
* $("div.main").delegate(".subMain", Event.ONCLICK | Event.ONDBLCLICK, new Function(){...});\r
* </pre>\r
*/\r
- public GQuery delegate(String selector, int eventbits, Object data,\r
- Function... handlers) {\r
+ public GQuery delegate(String selector, int eventbits, Object data, Function... handlers) {\r
\r
for (Element e : elements) {\r
$(selector, e).live(eventbits, data, handlers);\r
}\r
\r
/**\r
- * Attach <code>handlers</code> to one or more events for all elements that\r
- * match the <code>selector</code>, now or in the future, based on a specific\r
- * set of root elements.\r
+ * Attach <code>handlers</code> to one or more events for all elements that match the\r
+ * <code>selector</code>, now or in the future, based on a specific set of root elements.\r
* \r
* Example:\r
* \r
* });\r
* </pre>\r
* \r
- * This code above add an handler on click event on all cell (the existing\r
- * oneand the future cell) of all table. This code is equivalent to :\r
+ * This code above add an handler on click event on all cell (the existing oneand the future cell)\r
+ * of all table. This code is equivalent to :\r
* \r
* <pre>\r
* $("table").each(new Function(){\r
* \r
* You can pass attach the handlers to many events by specifying a String with espaced event type.\r
* ex:\r
+ * \r
* <pre>\r
* $("div.main").delegate(".subMain", "click dblclick", new Function(){...});\r
* </pre>\r
+ * \r
* </pre>\r
*/\r
- public GQuery delegate(String selector, String eventType,\r
- Function... handlers) {\r
+ public GQuery delegate(String selector, String eventType, Function... handlers) {\r
return delegate(selector, eventType, null, handlers);\r
}\r
\r
/**\r
- * Attach <code>handlers</code> to one or more events for all elements that\r
- * match the <code>selector</code>, now or in the future, based on a specific\r
- * set of root elements.\r
+ * Attach <code>handlers</code> to one or more events for all elements that match the\r
+ * <code>selector</code>, now or in the future, based on a specific set of root elements.\r
* \r
* Example:\r
* \r
* });\r
* </pre>\r
* \r
- * This code above add an handler on click event on all cell (the existing\r
- * oneand the future cell) of all table. This code is equivalent to :\r
+ * This code above add an handler on click event on all cell (the existing oneand the future cell)\r
+ * of all table. This code is equivalent to :\r
* \r
* <pre>\r
* $("table").each(new Function(){\r
*\r
* You can pass attach the handlers to many events by specifying a String with espaced event type.\r
* ex:\r
+ * \r
* <pre>\r
* $("div.main").delegate(".subMain", "click dblclick", new Function(){...});\r
* </pre>\r
+ * \r
* </pre>\r
*/\r
- public GQuery delegate(String selector, String eventType, Object data,\r
- Function... handlers) {\r
+ public GQuery delegate(String selector, String eventType, Object data, Function... handlers) {\r
for (Element e : elements) {\r
$(selector, e).live(eventType, data, handlers);\r
}\r
}\r
\r
/**\r
- * Execute the next function on the Effects queue for the matched elements.\r
- * This method is usefull to tell when a function you add in the Effects queue\r
- * is ended and so the next function in the queue can start.\r
+ * Execute the next function on the Effects queue for the matched elements. This method is usefull\r
+ * to tell when a function you add in the Effects queue is ended and so the next function in the\r
+ * queue can start.\r
* \r
- * Note: you should be sure to call dequeue() in all functions of a queue chain,\r
- * otherwise the queue execution will be stopped.\r
+ * Note: you should be sure to call dequeue() in all functions of a queue chain, otherwise the\r
+ * queue execution will be stopped.\r
*/\r
public GQuery dequeue() {\r
return as(Queue).dequeue();\r
}\r
\r
/**\r
- * Execute the next function on the queue named as queueName for the matched elements. \r
- * This method is usefull to tell when a function you add in the Effects queue is\r
- * ended and so the next function in the queue can start.\r
+ * Execute the next function on the queue named as queueName for the matched elements. This method\r
+ * is usefull to tell when a function you add in the Effects queue is ended and so the next\r
+ * function in the queue can start.\r
*/\r
public GQuery dequeue(String queueName) {\r
return as(Queue).dequeue(queueName);\r
}\r
\r
/**\r
- * Detach all matched elements from the DOM. This method is the same than\r
- * {@link #remove()} method except all data and event handlers are not remove\r
- * from the element. This method is useful when removed elements are to be\r
- * reinserted into the DOM at a later time.\r
+ * Detach all matched elements from the DOM. This method is the same than {@link #remove()} method\r
+ * except all data and event handlers are not remove from the element. This method is useful when\r
+ * removed elements are to be reinserted into the DOM at a later time.\r
*/\r
public GQuery detach() {\r
return remove(null, false);\r
}\r
\r
/**\r
- * Detach from the DOM all matched elements filtered by the\r
- * <code>filter</code>.. This method is the same than {@link #remove(String)}\r
- * method except all data and event handlers are not remove from the element.\r
- * This method is useful when removed elements are to be reinserted into the\r
- * DOM at a later time.\r
+ * Detach from the DOM all matched elements filtered by the <code>filter</code>.. This method is\r
+ * the same than {@link #remove(String)} method except all data and event handlers are not remove\r
+ * from the element. This method is useful when removed elements are to be reinserted into the DOM\r
+ * at a later time.\r
*/\r
public GQuery detach(String filter) {\r
return remove(filter, false);\r
}\r
\r
/**\r
- * Remove all event handlers previously attached using\r
- * {@link #live(String, Function)}. In order for this method to function\r
- * correctly, the selector used with it must match exactly the selector\r
- * initially used with {@link #live(String, Function)}\r
+ * Remove all event handlers previously attached using {@link #live(String, Function)}. In order\r
+ * for this method to function correctly, the selector used with it must match exactly the\r
+ * selector initially used with {@link #live(String, Function)}\r
*/\r
public GQuery die() {\r
return die(0);\r
}\r
\r
/**\r
- * Remove an event handlers previously attached using\r
- * {@link #live(int, Function)} In order for this method to function\r
- * correctly, the selector used with it must match exactly the selector\r
+ * Remove an event handlers previously attached using {@link #live(int, Function)} In order for\r
+ * this method to function correctly, the selector used with it must match exactly the selector\r
* initially used with {@link #live(int, Function)}\r
*/\r
public GQuery die(int eventbits) {\r
}\r
\r
/**\r
- * Remove an event handlers previously attached using\r
- * {@link #live(String, Function)} In order for this method to function\r
- * correctly, the selector used with it must match exactly the selector\r
+ * Remove an event handlers previously attached using {@link #live(String, Function)} In order for\r
+ * this method to function correctly, the selector used with it must match exactly the selector\r
* initially used with {@link #live(String, Function)}\r
*/\r
public GQuery die(String eventName) {\r
if (elms.length == 0) {\r
elms = elements;\r
}\r
- for (int i = 0, l = elms.length; i < l;i ++) {\r
+ for (int i = 0, l = elms.length; i < l; i++) {\r
Element e = elms[i];\r
if (e.getNodeType() == Node.DOCUMENT_NODE) {\r
- e = e.<Document>cast().getBody();\r
+ e = e.<Document> cast().getBody();\r
}\r
for (int j = 0, size = g.size(); j < size; j++) {\r
// Widget w = getAssociatedWidget(g.get(j));\r
// GqUi.detachWidget(w);\r
- \r
+\r
Node n = g.get(j);\r
- // If an element selected is inserted elsewhere, it will be moved into the target (not cloned).\r
- // If there is more than one target element, however, cloned copies of the inserted element will be created for each target after the first\r
+ // If an element selected is inserted elsewhere, it will be moved into the target (not\r
+ // cloned).\r
+ // If there is more than one target element, however, cloned copies of the inserted element\r
+ // will be created for each target after the first\r
if (i > 0) {\r
n = n.cloneNode(true);\r
}\r
newNodes.addNode(e.appendChild(n));\r
break;\r
case AFTER:\r
- newNodes.addNode(e.getParentNode().insertBefore(n,\r
- e.getNextSibling()));\r
+ newNodes.addNode(e.getParentNode().insertBefore(n, e.getNextSibling()));\r
break;\r
case BEFORE:\r
newNodes.addNode(e.getParentNode().insertBefore(n, e));\r
}\r
\r
/**\r
- * Run one or more Functions over each element of the GQuery. You have to\r
- * override one of these funcions: public void f(Element e) public String\r
- * f(Element e, int i)\r
+ * Run one or more Functions over each element of the GQuery. You have to override one of these\r
+ * funcions: public void f(Element e) public String f(Element e, int i)\r
*/\r
public GQuery each(Function... f) {\r
if (f != null) {\r
for (Function f1 : f) {\r
int i = 0;\r
for (Element e : elements) {\r
- f1.f(e.<com.google.gwt.dom.client.Element>cast(), i++);\r
+ f1.f(e.<com.google.gwt.dom.client.Element> cast(), i++);\r
}\r
}\r
}\r
}\r
\r
/**\r
- * Returns the working set of nodes as a Java array. <b>Do NOT</b> attempt to\r
- * modify this array, e.g. assign to its elements, or call Arrays.sort()\r
+ * Returns the working set of nodes as a Java array. <b>Do NOT</b> attempt to modify this array,\r
+ * e.g. assign to its elements, or call Arrays.sort()\r
*/\r
public Element[] elements() {\r
return elements;\r
}\r
\r
/**\r
- * Remove all child nodes from the set of matched elements. In the case of a\r
- * document element, it removes all the content You should call this method\r
- * whenever you create a new iframe and you want to add dynamic content to it.\r
+ * Remove all child nodes from the set of matched elements. In the case of a document element, it\r
+ * removes all the content You should call this method whenever you create a new iframe and you\r
+ * want to add dynamic content to it.\r
*/\r
public GQuery empty() {\r
for (Element e : elements) {\r
}\r
\r
/**\r
- * Revert the most recent 'destructive' operation, changing the set of matched\r
- * elements to its previous state (right before the destructive operation).\r
+ * Revert the most recent 'destructive' operation, changing the set of matched elements to its\r
+ * previous state (right before the destructive operation).\r
*/\r
public GQuery end() {\r
return previousObject != null ? previousObject : new GQuery();\r
}\r
\r
/**\r
- * Reduce GQuery to element in the specified position. This method accept\r
- * negative index. A negative index is counted from the end of the matched\r
- * set:\r
+ * Reduce GQuery to element in the specified position. This method accept negative index. A\r
+ * negative index is counted from the end of the matched set:\r
* \r
* Example:\r
* \r
}\r
\r
/**\r
- * Bind a set of functions to the error event of each matched element. Or\r
- * trigger the event if no functions are provided.\r
+ * Bind a set of functions to the error event of each matched element. Or trigger the event if no\r
+ * functions are provided.\r
*/\r
public GQuery error(Function... f) {\r
return bindOrFire(Event.ONERROR, null, f);\r
}\r
- \r
- \r
+\r
/**\r
- * Fade in all matched elements by adjusting their opacity. The effect will\r
- * take 1000 milliseconds to complete\r
+ * Fade in all matched elements by adjusting their opacity. The effect will take 1000 milliseconds\r
+ * to complete\r
*/\r
public GQuery fadeIn(Function... f) {\r
return $(as(Effects).fadeIn(f));\r
public GQuery fadeIn(int millisecs, Function... f) {\r
return $(as(Effects).fadeIn(millisecs, f));\r
}\r
- \r
+\r
/**\r
- * Fade out all matched elements by adjusting their opacity. The effect will\r
- * take 1000 milliseconds to complete\r
+ * Fade out all matched elements by adjusting their opacity. The effect will take 1000\r
+ * milliseconds to complete\r
*/\r
public GQuery fadeOut(Function... f) {\r
return $(as(Effects).fadeOut(f));\r
}\r
\r
/**\r
- * Toggle the visibility of all matched elements by adjusting their opacity and\r
- * firing an optional callback after completion. Only the opacity is adjusted for\r
- * this animation, meaning that all of the matched elements should already\r
- * have some form of height and width associated with them.\r
+ * Toggle the visibility of all matched elements by adjusting their opacity and firing an optional\r
+ * callback after completion. Only the opacity is adjusted for this animation, meaning that all of\r
+ * the matched elements should already have some form of height and width associated with them.\r
*/\r
public Effects fadeToggle(int millisecs, Function... f) {\r
return as(Effects).fadeToggle(millisecs, f);\r
}\r
\r
/**\r
- * Removes all elements from the set of matched elements that do not match the\r
- * specified function. The function is called with a context equal to the\r
- * current element. If the function returns false, then the element is removed\r
- * - anything else and the element is kept.\r
+ * Removes all elements from the set of matched elements that do not match the specified function.\r
+ * The function is called with a context equal to the current element. If the function returns\r
+ * false, then the element is removed - anything else and the element is kept.\r
*/\r
public GQuery filter(Predicate filterFn) {\r
JsNodeArray result = JsNodeArray.create();\r
}\r
\r
/**\r
- * Removes all elements from the set of matched elements that do not pass the\r
- * specified css expression. This method is used to narrow down the results of\r
- * a search. \r
+ * Removes all elements from the set of matched elements that do not pass the specified css\r
+ * expression. This method is used to narrow down the results of a search.\r
*/\r
- //TODO performance bad...\r
+ // TODO performance bad...\r
public GQuery filter(String... filters) {\r
JsNodeArray array = JsNodeArray.create();\r
- /*StringBuilder filterBuilder = new StringBuilder();\r
- for (int i = 0; i < filters.length ; i++){\r
- filterBuilder.append(filters[i]);\r
- if (i < filters.length - 1){\r
- filterBuilder.append(",");\r
- }\r
- }\r
- \r
- String filter = filterBuilder.toString();*/\r
+ /*\r
+ * StringBuilder filterBuilder = new StringBuilder(); for (int i = 0; i < filters.length ; i++){\r
+ * filterBuilder.append(filters[i]); if (i < filters.length - 1){ filterBuilder.append(","); } }\r
+ * \r
+ * String filter = filterBuilder.toString();\r
+ */\r
\r
for (String f : filters) {\r
for (Element e : elements) {\r
}\r
}\r
}\r
- \r
+\r
return pushStack(unique(array), "filter", filters[0]);\r
}\r
\r
/**\r
- * Searches for all elements that match the specified css expression. This\r
- * method is a good way to find additional descendant elements with which to\r
- * process.\r
+ * Searches for all elements that match the specified css expression. This method is a good way to\r
+ * find additional descendant elements with which to process.\r
* \r
- * Provide a comma-separated list of expressions to apply multiple filters at\r
- * once.\r
+ * Provide a comma-separated list of expressions to apply multiple filters at once.\r
*/\r
public GQuery find(String... filters) {\r
JsNodeArray array = JsNodeArray.create();\r
}\r
\r
/**\r
- * Bind a set of functions to the focus event of each matched element. Or\r
- * trigger the event and move the input focus to the first element \r
- * if no functions are provided.\r
+ * Bind a set of functions to the focus event of each matched element. Or trigger the event and\r
+ * move the input focus to the first element if no functions are provided.\r
*/\r
public GQuery focus(Function... f) {\r
bindOrFire(Event.ONFOCUS, null, f);\r
}\r
\r
/**\r
- * Return all elements matched in the GQuery as a NodeList. @see #elements()\r
- * for a method which returns them as an immutable Java array.\r
+ * Return all elements matched in the GQuery as a NodeList. @see #elements() for a method which\r
+ * returns them as an immutable Java array.\r
*/\r
public NodeList<Element> get() {\r
return nodeList;\r
}\r
- \r
\r
/**\r
- * Return the ith element matched. This method accept negative index. A\r
- * negative index is counted from the end of the matched set.\r
+ * Return the ith element matched. This method accept negative index. A negative index is counted\r
+ * from the end of the matched set.\r
* \r
* Example:\r
* \r
}\r
\r
/**\r
- * Return the previous set of matched elements prior to the last destructive\r
- * operation (e.g. query)\r
+ * Return the previous set of matched elements prior to the last destructive operation (e.g.\r
+ * query)\r
*/\r
public GQuery getPreviousObject() {\r
return previousObject;\r
}\r
\r
/**\r
- * Returns true any of the specified classes are present on any of the matched\r
- * Reduce the set of matched elements to all elements after a given position.\r
- * The position of the element in the set of matched elements starts at 0 and\r
- * goes to length - 1.\r
+ * Returns true any of the specified classes are present on any of the matched Reduce the set of\r
+ * matched elements to all elements after a given position. The position of the element in the set\r
+ * of matched elements starts at 0 and goes to length - 1.\r
*/\r
public GQuery gt(int pos) {\r
return $(slice(pos + 1, -1));\r
}\r
\r
/**\r
- * Reduce the set of matched elements to those that have a descendant \r
- * that matches the Element.\r
+ * Reduce the set of matched elements to those that have a descendant that matches the Element.\r
*/\r
public GQuery has(final Element elem) {\r
- return filter(new Predicate(){\r
+ return filter(new Predicate() {\r
public boolean f(Element e, int index) {\r
return engine.contains(e, elem);\r
}\r
}\r
\r
/**\r
- * Reduce the set of matched elements to those that have a descendant \r
- * that matches the selector.\r
+ * Reduce the set of matched elements to those that have a descendant that matches the selector.\r
*/\r
public GQuery has(final String selector) {\r
- return filter(new Predicate(){\r
+ return filter(new Predicate() {\r
public boolean f(Element e, int index) {\r
return !$(selector, e).isEmpty();\r
}\r
}\r
\r
/**\r
- * Returns true any of the specified classes are present on any of the matched\r
- * elements.\r
+ * Returns true any of the specified classes are present on any of the matched elements.\r
*/\r
public boolean hasClass(String... classes) {\r
for (Element e : elements) {\r
}\r
\r
/**\r
- * Get the current computed, pixel, height of the first matched element. It\r
- * does not include margin, padding nor border.\r
+ * Get the current computed, pixel, height of the first matched element. It does not include\r
+ * margin, padding nor border.\r
*/\r
public int height() {\r
return (int) cur("height", true);\r
}\r
\r
/**\r
- * Set the height style property of every matched element. It's useful for\r
- * using 'percent' or 'em' units Example: $(".a").width("100%")\r
+ * Set the height style property of every matched element. It's useful for using 'percent' or 'em'\r
+ * units Example: $(".a").width("100%")\r
*/\r
public GQuery height(String height) {\r
return css("height", height);\r
data(e, "oldDisplay", getStyleImpl().curCSS(e, "display", false));\r
}\r
}\r
- \r
+\r
// Set the display value in a separate for loop to avoid constant reflow\r
// Reflows is very bad in performance point of view\r
- for (Element e : elements){\r
+ for (Element e : elements) {\r
e.getStyle().setDisplay(Display.NONE);\r
}\r
- \r
+\r
return this;\r
}\r
\r
/**\r
- * Bind a function to the mouseover event of each matched element. A method\r
- * for simulating hovering (moving the mouse on, and off, an object). This is\r
- * a custom method which provides an 'in' to a frequent task. Whenever the\r
- * mouse cursor is moved over a matched element, the first specified function\r
- * is fired. Whenever the mouse moves off of the element, the second specified\r
+ * Bind a function to the mouseover event of each matched element. A method for simulating\r
+ * hovering (moving the mouse on, and off, an object). This is a custom method which provides an\r
+ * 'in' to a frequent task. Whenever the mouse cursor is moved over a matched element, the first\r
+ * specified function is fired. Whenever the mouse moves off of the element, the second specified\r
* function fires.\r
*/\r
public GQuery hover(Function fover, Function fout) {\r
- return bind(Event.ONMOUSEOVER, null, fover).bind(Event.ONMOUSEOUT, null,\r
- fout);\r
+ return bind(Event.ONMOUSEOVER, null, fover).bind(Event.ONMOUSEOUT, null, fout);\r
}\r
\r
/**\r
}\r
\r
/**\r
- * Returns the inner height of the first matched element, including padding\r
- * but not the vertical scrollbar height, border, or margin.\r
+ * Returns the inner height of the first matched element, including padding but not the vertical\r
+ * scrollbar height, border, or margin.\r
*/\r
public int innerHeight() {\r
return isEmpty() ? 0 : get(0).getClientHeight();\r
}\r
\r
/**\r
- * Returns the inner width of the first matched element, including padding but\r
- * not the vertical scrollbar width, border, or margin.\r
+ * Returns the inner width of the first matched element, including padding but not the vertical\r
+ * scrollbar width, border, or margin.\r
*/\r
public int innerWidth() {\r
return isEmpty() ? 0 : get(0).getClientWidth();\r
}\r
\r
/**\r
- * Insert all of the matched elements after another, specified, set of\r
- * elements.\r
+ * Insert all of the matched elements after another, specified, set of elements.\r
*/\r
public GQuery insertAfter(Element elem) {\r
return insertAfter($(elem));\r
}\r
- \r
+\r
/**\r
- * Insert all of the matched elements after another, specified, set of\r
- * elements.\r
+ * Insert all of the matched elements after another, specified, set of elements.\r
*/\r
public GQuery insertAfter(GQuery query) {\r
for (Element e : elements) {\r
}\r
\r
/**\r
- * Insert all of the matched elements after another, specified, set of\r
- * elements.\r
+ * Insert all of the matched elements after another, specified, set of elements.\r
*/\r
public GQuery insertAfter(String selector) {\r
return insertAfter($(selector));\r
}\r
\r
/**\r
- * Insert all of the matched elements before another, specified, set of\r
- * elements.\r
+ * Insert all of the matched elements before another, specified, set of elements.\r
* \r
- * The elements must already be inserted into the document (you can't insert\r
- * an element after another if it's not in the page).\r
+ * The elements must already be inserted into the document (you can't insert an element after\r
+ * another if it's not in the page).\r
*/\r
public GQuery insertBefore(Element item) {\r
return insertBefore($(item));\r
}\r
\r
/**\r
- * Insert all of the matched elements before another, specified, set of\r
- * elements.\r
+ * Insert all of the matched elements before another, specified, set of elements.\r
* \r
- * The elements must already be inserted into the document (you can't insert\r
- * an element after another if it's not in the page).\r
+ * The elements must already be inserted into the document (you can't insert an element after\r
+ * another if it's not in the page).\r
*/\r
public GQuery insertBefore(GQuery query) {\r
for (Element e : elements) {\r
}\r
\r
/**\r
- * Insert all of the matched elements before another, specified, set of\r
- * elements.\r
+ * Insert all of the matched elements before another, specified, set of elements.\r
* \r
- * The elements must already be inserted into the document (you can't insert\r
- * an element after another if it's not in the page).\r
+ * The elements must already be inserted into the document (you can't insert an element after\r
+ * another if it's not in the page).\r
*/\r
public GQuery insertBefore(String selector) {\r
return insertBefore($(selector));\r
}\r
\r
/**\r
- * Checks the current selection against an expression and returns true, if at\r
- * least one element of the selection fits the given expression. Does return\r
- * false, if no element fits or the expression is not valid.\r
+ * Checks the current selection against an expression and returns true, if at least one element of\r
+ * the selection fits the given expression. Does return false, if no element fits or the\r
+ * expression is not valid.\r
*/\r
public boolean is(String... filters) {\r
return !filter(filters).isEmpty();\r
}\r
\r
/**\r
- * Returns true if the number of matched elements is 0. \r
+ * Returns true if the number of matched elements is 0.\r
*/\r
public boolean isEmpty() {\r
return size() == 0;\r
}\r
\r
/**\r
- * Bind a set of functions to the keydown event of each matched element. Or\r
- * trigger the event if no functions are provided.\r
+ * Bind a set of functions to the keydown event of each matched element. Or trigger the event if\r
+ * no functions are provided.\r
*/\r
public GQuery keydown(Function... f) {\r
return bindOrFire(Event.ONKEYDOWN, null, f);\r
}\r
\r
/**\r
- * Bind a set of functions to the keypress event of each matched element. Or\r
- * trigger the event if no functions are provided.\r
+ * Bind a set of functions to the keypress event of each matched element. Or trigger the event if\r
+ * no functions are provided.\r
*/\r
public GQuery keypress(Function... f) {\r
return bindOrFire(Event.ONKEYPRESS, null, f);\r
}\r
\r
/**\r
- * Bind a set of functions to the keyup event of each matched element. Or\r
- * trigger the event if no functions are provided.\r
+ * Bind a set of functions to the keyup event of each matched element. Or trigger the event if no\r
+ * functions are provided.\r
*/\r
public GQuery keyup(Function... f) {\r
return bindOrFire(Event.ONKEYUP, null, f);\r
}\r
\r
/**\r
- * Returns the number of elements currently matched. The size function will\r
- * return the same value.\r
+ * Returns the number of elements currently matched. The size function will return the same value.\r
*/\r
public int length() {\r
return size();\r
}\r
\r
/**\r
- * Attach a handler for this event to all elements which match the current\r
- * selector, now and in the future.\r
+ * Attach a handler for this event to all elements which match the current selector, now and in\r
+ * the future.\r
*/\r
public GQuery live(int eventbits, Function... funcs) {\r
return as(Events).live(eventbits, null, funcs);\r
}\r
\r
/**\r
- * Attach a handler for this event to all elements which match the current\r
- * selector, now and in the future.\r
+ * Attach a handler for this event to all elements which match the current selector, now and in\r
+ * the future.\r
*/\r
public GQuery live(int eventbits, Object data, Function... funcs) {\r
return as(Events).live(eventbits, data, funcs);\r
\r
/**\r
* <p>\r
- * Attach a handler for this event to all elements which match the current\r
- * selector, now and in the future.\r
+ * Attach a handler for this event to all elements which match the current selector, now and in\r
+ * the future.\r
* <p>\r
* <p>\r
* Ex :\r
* });\r
* </pre>\r
* \r
- * With this code, all elements with class "clickable" present in the DOM or\r
- * added to the DOM in the future will be clickable. The text color will be\r
- * changed to red when they will be clicked. So if after in the code, you add\r
- * another element :\r
+ * With this code, all elements with class "clickable" present in the DOM or added to the DOM in\r
+ * the future will be clickable. The text color will be changed to red when they will be clicked.\r
+ * So if after in the code, you add another element :\r
* \r
* <pre>\r
* $("body").append("<div class='clickable'>Click me and I will be red</div>");\r
* The click on this new element will also trigger the handler.\r
* </p>\r
* <p>\r
- * In the same way, if you add "clickable" class on some existing element,\r
- * these elements will be clickable also.\r
+ * In the same way, if you add "clickable" class on some existing element, these elements will be\r
+ * clickable also.\r
* </p>\r
* <p>\r
* <h3>important remarks</h3>\r
* }\r
* });\r
* </pre>\r
- * The {@link Function} will be called only on elements having the class\r
- * "clickable" and being descendant of myElement.</li>\r
+ * The {@link Function} will be called only on elements having the class "clickable" and being\r
+ * descendant of myElement.</li>\r
* </ul>\r
* </p>\r
*/\r
\r
/**\r
* <p>\r
- * Attach a handler for this event to all elements which match the current\r
- * selector, now and in the future. The <code>data</code> parameter allows us\r
- * to pass data to the handler.\r
+ * Attach a handler for this event to all elements which match the current selector, now and in\r
+ * the future. The <code>data</code> parameter allows us to pass data to the handler.\r
* <p>\r
* <p>\r
* Ex :\r
* });\r
* </pre>\r
* \r
- * With this code, all elements with class "clickable" present in the DOM or\r
- * added to the DOM in the future will be clickable. The text color will be\r
- * changed to red when they will be clicked. So if after in the code, you add\r
- * another element :\r
+ * With this code, all elements with class "clickable" present in the DOM or added to the DOM in\r
+ * the future will be clickable. The text color will be changed to red when they will be clicked.\r
+ * So if after in the code, you add another element :\r
* \r
* <pre>\r
* $("body").append("<div class='clickable'>Click me and I will be red</div>");\r
* The click on this new element will also trigger the handler.\r
* </p>\r
* <p>\r
- * In the same way, if you add "clickable" class on some existing element,\r
- * these elements will be clickable also.\r
+ * In the same way, if you add "clickable" class on some existing element, these elements will be\r
+ * clickable also.\r
* </p>\r
* <p>\r
* <h3>important remarks</h3>\r
* }\r
* });\r
* </pre>\r
- * The {@link Function} will be called only on elements having the class\r
- * "clickable" and being descendant of myElement.</li>\r
+ * The {@link Function} will be called only on elements having the class "clickable" and being\r
+ * descendant of myElement.</li>\r
* </ul>\r
* </p>\r
*/\r
public GQuery load(Function f) {\r
return bind(Event.ONLOAD, null, f);\r
}\r
- \r
+\r
/**\r
* Load data from the server and place the returned HTML into the matched element.\r
* \r
- * The url allows us to specify a portion of the remote document to be inserted. \r
- * This is achieved with a special syntax for the url parameter. \r
- * If one or more space characters are included in the string, the portion of \r
- * the string following the first space is assumed to be a GQuery selector that \r
- * determines the content to be loaded.\r
+ * The url allows us to specify a portion of the remote document to be inserted. This is achieved\r
+ * with a special syntax for the url parameter. If one or more space characters are included in\r
+ * the string, the portion of the string following the first space is assumed to be a GQuery\r
+ * selector that determines the content to be loaded.\r
* \r
*/\r
public GQuery load(String url) {\r
return load(url, null, null);\r
}\r
- \r
+\r
/**\r
* Load data from the server and place the returned HTML into the matched element.\r
* \r
- * The url allows us to specify a portion of the remote document to be inserted. \r
- * This is achieved with a special syntax for the url parameter. \r
- * If one or more space characters are included in the string, the portion of \r
- * the string following the first space is assumed to be a GQuery selector that \r
- * determines the content to be loaded.\r
+ * The url allows us to specify a portion of the remote document to be inserted. This is achieved\r
+ * with a special syntax for the url parameter. If one or more space characters are included in\r
+ * the string, the portion of the string following the first space is assumed to be a GQuery\r
+ * selector that determines the content to be loaded.\r
* \r
*/\r
public GQuery load(String url, Properties data, final Function onSuccess) {\r
}\r
\r
/**\r
- * Reduce the set of matched elements to all elements before a given position.\r
- * The position of the element in the set of matched elements starts at 0 and\r
- * goes to length - 1.\r
+ * Reduce the set of matched elements to all elements before a given position. The position of the\r
+ * element in the set of matched elements starts at 0 and goes to length - 1.\r
*/\r
public GQuery lt(int pos) {\r
return $(slice(0, pos));\r
}\r
\r
/**\r
- * Pass each element in the current matched set through a function, producing\r
- * a new array containing the return values.\r
- * When the call to the function returns a null it is not added to the array.\r
+ * Pass each element in the current matched set through a function, producing a new array\r
+ * containing the return values. When the call to the function returns a null it is not added to\r
+ * the array.\r
*/\r
public <W> List<W> map(Function f) {\r
ArrayList<W> ret = new ArrayList<W>();\r
int i = 0;\r
for (Element e : elements) {\r
@SuppressWarnings("unchecked")\r
- W o = (W)f.f(e.<com.google.gwt.dom.client.Element>cast(), i++);\r
+ W o = (W) f.f(e.<com.google.gwt.dom.client.Element> cast(), i++);\r
if (o != null) {\r
ret.add(o);\r
}\r
return ret;\r
}\r
\r
- \r
/**\r
- * Bind a set of functions to the mousedown event of each matched element. Or\r
- * trigger the event if no functions are provided.\r
+ * Bind a set of functions to the mousedown event of each matched element. Or trigger the event if\r
+ * no functions are provided.\r
*/\r
public GQuery mousedown(Function... f) {\r
return bindOrFire(Event.ONMOUSEDOWN, null, f);\r
}\r
- \r
+\r
+ /**\r
+ * Bind an event handler to be fired when the mouse enter an element, or trigger that handler on\r
+ * an element if no functions are provided.\r
+ * \r
+ * The mouseenter event differs from mouseover in the way it handles event bubbling. When\r
+ * mouseover is used on an element having inner element(s), then when the mouse pointer moves hover\r
+ * of the Inner element, the handler would be triggered. This is usually undesirable behavior. The\r
+ * mouseenter event, on the other hand, only triggers its handler when the mouse enters the\r
+ * element it is bound to, not a descendant.\r
+ */\r
+ public GQuery mouseenter(Function... f) {\r
+ return as(Events).mouseenter(f);\r
+ }\r
+\r
/**\r
- * Bind a set of functions to the mousemove event of each matched element. Or\r
- * trigger the event if no functions are provided.\r
+ * Bind an event handler to be fired when the mouse leaves an element, or trigger that handler on\r
+ * an element if no functions are provided.\r
+ * \r
+ * The mouseleave event differs from mouseout in the way it handles event bubbling. When\r
+ * mouseout is used on an element having inner element(s), then when the mouse pointer moves out\r
+ * of the Inner element, the handler would be triggered. This is usually undesirable behavior. The\r
+ * mouseleave event, on the other hand, only triggers its handler when the mouse leaves the\r
+ * element it is bound to, not a descendant.\r
+ */\r
+ public GQuery mouseleave(Function... f) {\r
+ return as(Events).mouseleave(f);\r
+ }\r
+\r
+ /**\r
+ * Bind a set of functions to the mousemove event of each matched element. Or trigger the event if\r
+ * no functions are provided.\r
*/\r
public GQuery mousemove(Function... f) {\r
return bindOrFire(Event.ONMOUSEMOVE, null, f);\r
}\r
\r
/**\r
- * Bind a set of functions to the mouseout event of each matched element. Or\r
- * trigger the event if no functions are provided.\r
+ * Bind a set of functions to the mouseout event of each matched element. Or trigger the event if\r
+ * no functions are provided.\r
*/\r
public GQuery mouseout(Function... f) {\r
return bindOrFire(Event.ONMOUSEOUT, null, f);\r
}\r
\r
/**\r
- * Bind a set of functions to the mouseover event of each matched element. Or\r
- * trigger the event if no functions are provided.\r
+ * Bind a set of functions to the mouseover event of each matched element. Or trigger the event if\r
+ * no functions are provided.\r
*/\r
public GQuery mouseover(Function... f) {\r
return bindOrFire(Event.ONMOUSEOVER, null, f);\r
}\r
\r
/**\r
- * Bind a set of functions to the mouseup event of each matched element. Or\r
- * trigger the event if no functions are provided.\r
+ * Bind a set of functions to the mouseup event of each matched element. Or trigger the event if\r
+ * no functions are provided.\r
*/\r
public GQuery mouseup(Function... f) {\r
return bindOrFire(Event.ONMOUSEUP, null, f);\r
}\r
\r
/**\r
- * Get a set of elements containing the unique next siblings of each of the\r
- * given set of elements. next only returns the very next sibling for each\r
- * element, not all next siblings see {#nextAll}.\r
+ * Get a set of elements containing the unique next siblings of each of the given set of elements.\r
+ * next only returns the very next sibling for each element, not all next siblings see {#nextAll}.\r
*/\r
public GQuery next() {\r
JsNodeArray result = JsNodeArray.create();\r
}\r
\r
/**\r
- * Get a set of elements containing the unique next siblings of each of the\r
- * given set of elements filtered by 1 or more selectors. next only returns\r
- * the very next sibling for each element, not all next siblings see\r
- * {#nextAll}.\r
+ * Get a set of elements containing the unique next siblings of each of the given set of elements\r
+ * filtered by 1 or more selectors. next only returns the very next sibling for each element, not\r
+ * all next siblings see {#nextAll}.\r
*/\r
public GQuery next(String... selectors) {\r
JsNodeArray result = JsNodeArray.create();\r
}\r
\r
/**\r
- * Get all following siblings of each element in the set of matched\r
- * elements.\r
+ * Get all following siblings of each element in the set of matched elements.\r
*/\r
public GQuery nextAll() {\r
return nextAll(null);\r
}\r
- \r
+\r
/**\r
- * Get all following siblings of each element in the set of matched\r
- * elements, filtered by a selector.\r
+ * Get all following siblings of each element in the set of matched elements, filtered by a\r
+ * selector.\r
*/\r
public GQuery nextAll(String filter) {\r
JsNodeArray result = JsNodeArray.create();\r
for (Element e : elements) {\r
allNextSiblingElements(e.getNextSiblingElement(), result, null, null, filter);\r
}\r
- \r
+\r
return pushStack(unique(result), "nextAll", getSelector());\r
}\r
\r
/**\r
- * Get all following siblings of each element up to but not including the\r
- * element matched by the selector.\r
+ * Get all following siblings of each element up to but not including the element matched by the\r
+ * selector.\r
* \r
* @param selector\r
* @return\r
*/\r
public GQuery nextUntil(String selector) {\r
- return nextUntil($(selector), null);\r
+ return nextUntil($(selector), null);\r
}\r
- \r
+\r
/**\r
- * Get all following siblings of each element up to but not including the\r
- * element matched by the selector, filtered by a selector.\r
+ * Get all following siblings of each element up to but not including the element matched by the\r
+ * selector, filtered by a selector.\r
* \r
* @param selector\r
* @return\r
*/\r
public GQuery nextUntil(String selector, String filter) {\r
- return nextUntil($(selector), filter);\r
+ return nextUntil($(selector), filter);\r
}\r
\r
/**\r
- * Get all following siblings of each element up to but not including the\r
- * element matched by the DOM node.\r
+ * Get all following siblings of each element up to but not including the element matched by the\r
+ * DOM node.\r
* \r
* @param selector\r
* @return\r
*/\r
public GQuery nextUntil(Element until) {\r
- return nextUntil($(until), null);\r
+ return nextUntil($(until), null);\r
}\r
\r
- \r
/**\r
- * Get all following siblings of each element up to but not including the\r
- * element matched by the DOM node, filtered by a selector.\r
+ * Get all following siblings of each element up to but not including the element matched by the\r
+ * DOM node, filtered by a selector.\r
* \r
* @param selector\r
* @return\r
*/\r
public GQuery nextUntil(Element until, String filter) {\r
- return nextUntil($(until), filter);\r
+ return nextUntil($(until), filter);\r
}\r
- \r
- \r
+\r
/**\r
- * Get all following siblings of each element up to but not including the\r
- * element matched by the GQuery object.\r
+ * Get all following siblings of each element up to but not including the element matched by the\r
+ * GQuery object.\r
* \r
* @param selector\r
* @return\r
return nextUntil(until, null);\r
}\r
\r
- \r
/**\r
- * Get all following siblings of each element up to but not including the\r
- * element matched by the GQuery object, filtered by a selector\r
+ * Get all following siblings of each element up to but not including the element matched by the\r
+ * GQuery object, filtered by a selector\r
* \r
* @param selector\r
* @return\r
return pushStack(unique(result), "nextUntil", getSelector());\r
}\r
\r
- \r
/**\r
- * Removes the specified Element from the set of matched elements. This method\r
- * is used to remove a single Element from a jQuery object.\r
+ * Removes the specified Element from the set of matched elements. This method is used to remove a\r
+ * single Element from a jQuery object.\r
*/\r
public GQuery not(Element elem) {\r
JsNodeArray array = JsNodeArray.create();\r
}\r
\r
/**\r
- * Removes any elements inside the passed set of elements from the set of\r
- * matched elements.\r
+ * Removes any elements inside the passed set of elements from the set of matched elements.\r
*/\r
public GQuery not(GQuery gq) {\r
GQuery ret = this;\r
}\r
\r
/**\r
- * Removes elements matching the specified expression from the set of matched\r
- * elements.\r
+ * Removes elements matching the specified expression from the set of matched elements.\r
*/\r
public GQuery not(String... filters) {\r
GQuery ret = this;\r
}\r
\r
/**\r
- * Get the current offset of the first matched element, in pixels, relative to\r
- * the document. The returned object contains two integer properties, top and\r
- * left. The method works only with visible elements.\r
+ * Get the current offset of the first matched element, in pixels, relative to the document. The\r
+ * returned object contains two integer properties, top and left. The method works only with\r
+ * visible elements.\r
*/\r
public com.google.gwt.query.client.GQuery.Offset offset() {\r
Element e = get(0);\r
- return e == null ? new Offset(0, 0) : new Offset(e.getAbsoluteLeft(),\r
- e.getAbsoluteTop());\r
+ return e == null ? new Offset(0, 0) : new Offset(e.getAbsoluteLeft(), e.getAbsoluteTop());\r
}\r
\r
/**\r
- * Returns a GQuery collection with the positioned parent of the first matched\r
- * element. This is the first parent of the element that has position (as in\r
- * relative or absolute). This method only works with visible elements.\r
+ * Returns a GQuery collection with the positioned parent of the first matched element. This is\r
+ * the first parent of the element that has position (as in relative or absolute). This method\r
+ * only works with visible elements.\r
*/\r
public GQuery offsetParent() {\r
if (isEmpty()) {\r
return $();\r
}\r
Element offParent = JsUtils.or(get(0).getOffsetParent(), body);\r
- while (offParent != null\r
- && !"body".equalsIgnoreCase(offParent.getTagName())\r
+ while (offParent != null && !"body".equalsIgnoreCase(offParent.getTagName())\r
&& !"html".equalsIgnoreCase(offParent.getTagName())\r
&& "static".equals(getStyleImpl().curCSS(offParent, "position", true))) {\r
offParent = offParent.getOffsetParent();\r
}\r
\r
/**\r
- * Binds a handler to a particular Event (like Event.ONCLICK) for each matched\r
- * element. The handler is executed only once for each element.\r
+ * Binds a handler to a particular Event (like Event.ONCLICK) for each matched element. The\r
+ * handler is executed only once for each element.\r
* \r
- * The event handler is passed as a Function that you can use to prevent\r
- * default behavior. To stop both default action and event bubbling, the\r
- * function event handler has to return false.\r
+ * The event handler is passed as a Function that you can use to prevent default behavior. To stop\r
+ * both default action and event bubbling, the function event handler has to return false.\r
* \r
- * You can pass an additional Object data to your Function as the second\r
- * parameter\r
+ * You can pass an additional Object data to your Function as the second parameter\r
*/\r
public GQuery one(int eventbits, final Object data, final Function f) {\r
return as(Events).one(eventbits, data, f);\r
}\r
\r
/**\r
- * Get the current computed height for the first element in the set of matched\r
- * elements, including padding, border, but not the margin.\r
+ * Get the current computed height for the first element in the set of matched elements, including\r
+ * padding, border, but not the margin.\r
*/\r
public int outerHeight() {\r
return outerHeight(false);\r
}\r
- \r
+\r
/**\r
- * Get the current computed height for the first element in the set of matched\r
- * elements, including padding, border, and optionally margin.\r
+ * Get the current computed height for the first element in the set of matched elements, including\r
+ * padding, border, and optionally margin.\r
*/\r
public int outerHeight(boolean includeMargin) {\r
if (isEmpty()) {\r
}\r
return outerHeight;\r
}\r
- \r
\r
/**\r
- * Get the current computed width for the first element in the set of matched\r
- * elements, including padding, border, but not the margin.\r
+ * Get the current computed width for the first element in the set of matched elements, including\r
+ * padding, border, but not the margin.\r
*/\r
public int outerWidth() {\r
return outerWidth(false);\r
}\r
\r
/**\r
- * Get the current computed width for the first element in the set of matched\r
- * elements, including padding and border and optionally margin.\r
+ * Get the current computed width for the first element in the set of matched elements, including\r
+ * padding and border and optionally margin.\r
*/\r
public int outerWidth(boolean includeMargin) {\r
if (isEmpty()) {\r
}\r
\r
/**\r
- * Get a set of elements containing the unique parents of the matched set of\r
- * elements.\r
+ * Get a set of elements containing the unique parents of the matched set of elements.\r
*/\r
public GQuery parent() {\r
JsNodeArray result = JsNodeArray.create();\r
}\r
\r
/**\r
- * Get a set of elements containing the unique parents of the matched set of\r
- * elements. You may use an optional expressions to filter the set of parent\r
- * elements that will match one of them.\r
+ * Get a set of elements containing the unique parents of the matched set of elements. You may use\r
+ * an optional expressions to filter the set of parent elements that will match one of them.\r
*/\r
public GQuery parent(String... filters) {\r
return parent().filter(filters);\r
}\r
\r
/**\r
- * Get a set of elements containing the unique ancestors of the matched set of\r
- * elements (except for the root element).\r
+ * Get a set of elements containing the unique ancestors of the matched set of elements (except\r
+ * for the root element).\r
*/\r
public GQuery parents() {\r
return parentsUntil(null);\r
}\r
\r
/**\r
- * Get a set of elements containing the unique ancestors of the matched set of\r
- * elements (except for the root element). The matched elements are filtered,\r
- * returning those that match any of the filters.\r
+ * Get a set of elements containing the unique ancestors of the matched set of elements (except\r
+ * for the root element). The matched elements are filtered, returning those that match any of the\r
+ * filters.\r
*/\r
public GQuery parents(String... filters) {\r
return parents().filter(filters);\r
}\r
\r
/**\r
- * Get the ancestors of each element in the current set of matched elements,\r
- * up to but not including the element matched by the selector.\r
- *\r
+ * Get the ancestors of each element in the current set of matched elements, up to but not\r
+ * including the element matched by the selector.\r
+ * \r
*/\r
public GQuery parentsUntil(String selector) {\r
JsNodeArray result = JsNodeArray.create();\r
}\r
\r
/**\r
- * Gets the top and left position of an element relative to its offset parent.\r
- * The returned object contains two Integer properties, top and left. For\r
- * accurate calculations make sure to use pixel values for margins, borders\r
- * and padding. This method only works with visible elements.\r
+ * Gets the top and left position of an element relative to its offset parent. The returned object\r
+ * contains two Integer properties, top and left. For accurate calculations make sure to use pixel\r
+ * values for margins, borders and padding. This method only works with visible elements.\r
*/\r
public com.google.gwt.query.client.GQuery.Offset position() {\r
if (isEmpty()) {\r
offset = offset.add(-leftMargin, -topMargin);\r
\r
// Add offsetParent borders\r
- int parentOffsetBorderTop = (int) getStyleImpl().cur(offsetParent,\r
- "borderTopWidth", true);\r
- int parentOffsetBorderLeft = (int) getStyleImpl().cur(offsetParent,\r
- "borderLeftWidth", true);\r
- parentOffset = parentOffset.add(parentOffsetBorderLeft,\r
- parentOffsetBorderTop);\r
+ int parentOffsetBorderTop = (int) getStyleImpl().cur(offsetParent, "borderTopWidth", true);\r
+ int parentOffsetBorderLeft = (int) getStyleImpl().cur(offsetParent, "borderLeftWidth", true);\r
+ parentOffset = parentOffset.add(parentOffsetBorderLeft, parentOffsetBorderTop);\r
\r
// Subtract the two offsets\r
return offset.add(-parentOffset.left, -parentOffset.top);\r
}\r
\r
/**\r
- * Prepend content to the inside of every matched element. This operation is\r
- * the best way to insert elements inside, at the beginning, of all matched\r
- * elements.\r
+ * Prepend content to the inside of every matched element. This operation is the best way to\r
+ * insert elements inside, at the beginning, of all matched elements.\r
*/\r
public GQuery prepend(GQuery query) {\r
return domManip(query, DomMan.PREPEND);\r
}\r
\r
/**\r
- * Prepend content to the inside of every matched element. This operation is\r
- * the best way to insert elements inside, at the beginning, of all matched\r
- * elements.\r
+ * Prepend content to the inside of every matched element. This operation is the best way to\r
+ * insert elements inside, at the beginning, of all matched elements.\r
*/\r
public GQuery prepend(Node n) {\r
return domManip($(n), DomMan.PREPEND);\r
}\r
- \r
+\r
/**\r
- * Prepend content to the inside of every matched element. This operation is\r
- * the best way to insert elements inside, at the beginning, of all matched\r
- * elements.\r
+ * Prepend content to the inside of every matched element. This operation is the best way to\r
+ * insert elements inside, at the beginning, of all matched elements.\r
*/\r
public GQuery prepend(String html) {\r
return domManip(html, DomMan.PREPEND);\r
}\r
- \r
+\r
/**\r
- * All of the matched set of elements will be inserted at the beginning of the\r
- * element(s) specified by the parameter other.\r
+ * All of the matched set of elements will be inserted at the beginning of the element(s)\r
+ * specified by the parameter other.\r
* \r
- * The operation $(A).prependTo(B) is, essentially, the reverse of doing a\r
- * regular $(A).prepend(B), instead of prepending B to A, you're prepending A\r
- * to B.\r
+ * The operation $(A).prependTo(B) is, essentially, the reverse of doing a regular\r
+ * $(A).prepend(B), instead of prepending B to A, you're prepending A to B.\r
*/\r
public GQuery prependTo(GQuery other) {\r
other.prepend(this);\r
}\r
\r
/**\r
- * All of the matched set of elements will be inserted at the beginning of the\r
- * element(s) specified by the parameter other.\r
+ * All of the matched set of elements will be inserted at the beginning of the element(s)\r
+ * specified by the parameter other.\r
* \r
- * The operation $(A).prependTo(B) is, essentially, the reverse of doing a\r
- * regular $(A).prepend(B), instead of prepending B to A, you're prepending A\r
- * to B.\r
+ * The operation $(A).prependTo(B) is, essentially, the reverse of doing a regular\r
+ * $(A).prepend(B), instead of prepending B to A, you're prepending A to B.\r
*/\r
public GQuery prependTo(Node n) {\r
$(n).prepend(this);\r
}\r
\r
/**\r
- * All of the matched set of elements will be inserted at the beginning of the\r
- * element(s) specified by the parameter other.\r
+ * All of the matched set of elements will be inserted at the beginning of the element(s)\r
+ * specified by the parameter other.\r
* \r
- * The operation $(A).prependTo(B) is, essentially, the reverse of doing a\r
- * regular $(A).prepend(B), instead of prepending B to A, you're prepending A\r
- * to B.\r
+ * The operation $(A).prependTo(B) is, essentially, the reverse of doing a regular\r
+ * $(A).prepend(B), instead of prepending B to A, you're prepending A to B.\r
*/\r
public GQuery prependTo(String html) {\r
$(html).prepend(this);\r
return this;\r
}\r
- \r
+\r
/**\r
- * Get a set of elements containing the unique previous siblings of each of\r
- * the matched set of elements. Only the immediately previous sibling is\r
- * returned, not all previous siblings.\r
+ * Get a set of elements containing the unique previous siblings of each of the matched set of\r
+ * elements. Only the immediately previous sibling is returned, not all previous siblings.\r
*/\r
public GQuery prev() {\r
JsNodeArray result = JsNodeArray.create();\r
}\r
return new GQuery(unique(result));\r
}\r
- \r
+\r
/**\r
- * Get a set of elements containing the unique previous siblings of each of\r
- * the matched set of elements filtered by selector. Only the immediately\r
- * previous sibling is returned, not all previous siblings.\r
+ * Get a set of elements containing the unique previous siblings of each of the matched set of\r
+ * elements filtered by selector. Only the immediately previous sibling is returned, not all\r
+ * previous siblings.\r
*/\r
public GQuery prev(String... selectors) {\r
JsNodeArray result = JsNodeArray.create();\r
}\r
return new GQuery(unique(result)).filter(selectors);\r
}\r
- \r
- /**\r
- * Get all preceding siblings of each element in the set of matched\r
- * elements.\r
- */\r
- public GQuery prevAll() {\r
- return prevAll(null);\r
- }\r
-\r
- /**\r
- * Get all preceding siblings of each element in the set of matched elements\r
- * filtered by a selector.\r
- */\r
- public GQuery prevAll(String selector) {\r
- JsNodeArray result = JsNodeArray.create();\r
- for (Element e : elements) {\r
- allPreviousSiblingElements(getPreviousSiblingElement(e), result,\r
- null, selector);\r
- }\r
- return pushStack(unique(result), "prevAll", getSelector());\r
- }\r
-\r
- /**\r
- * Get all preceding siblings of each element up to but not including the\r
- * element matched by the <code>selector</code>.\r
- * \r
- * The elements are returned in order from the closest sibling to the\r
- * farthest.\r
- */\r
- public GQuery prevUntil(String selector) {\r
- return prevUntil($(selector), null);\r
- }\r
-\r
- /**\r
- * Get all preceding siblings of each element up to but not including the\r
- * <code>until</code> element.\r
- * \r
- * The elements are returned in order from the closest sibling to the\r
- * farthest.\r
- */\r
- public GQuery prevUntil(Element until) {\r
- return prevUntil($(until), null);\r
- }\r
-\r
- /**\r
- * Get all preceding siblings of each element up to but not including the\r
- * <code>until</code> element.\r
- * \r
- * The elements are returned in order from the closest sibling to the\r
- * farthest.\r
- */\r
- public GQuery prevUntil(GQuery until) {\r
- return prevUntil(until, null);\r
- }\r
-\r
- /**\r
- * Get all preceding siblings of each element matching the\r
- * <code>filter</code> up to but not including the element matched by the\r
- * <code>selector</code>.\r
- * \r
- * The elements are returned in order from the closest sibling to the\r
- * farthest.\r
- */\r
- public GQuery prevUntil(String selector, String filter) {\r
- return prevUntil($(selector), filter);\r
- }\r
-\r
- /**\r
- * Get all preceding siblings of each element matching the\r
- * <code>filter</code> up to but not including the <code>until</code>\r
- * element.\r
- * \r
- */\r
- public GQuery prevUntil(Element until, String filter) {\r
- return prevUntil($(until), filter);\r
- }\r
-\r
- /**\r
- * Get all preceding siblings of each element matching the\r
- * <code>filter</code> up to but not including the element matched by the\r
- * <code>until</code> element.\r
- * \r
- */\r
- public GQuery prevUntil(GQuery until, String filter) {\r
- JsNodeArray result = JsNodeArray.create();\r
- for (Element e : elements) {\r
- allPreviousSiblingElements(getPreviousSiblingElement(e), result,\r
- until, filter);\r
- }\r
- return pushStack(unique(result), "prevUntil", getSelector());\r
- }\r
+\r
+ /**\r
+ * Get all preceding siblings of each element in the set of matched elements.\r
+ */\r
+ public GQuery prevAll() {\r
+ return prevAll(null);\r
+ }\r
+\r
+ /**\r
+ * Get all preceding siblings of each element in the set of matched elements filtered by a\r
+ * selector.\r
+ */\r
+ public GQuery prevAll(String selector) {\r
+ JsNodeArray result = JsNodeArray.create();\r
+ for (Element e : elements) {\r
+ allPreviousSiblingElements(getPreviousSiblingElement(e), result, null, selector);\r
+ }\r
+ return pushStack(unique(result), "prevAll", getSelector());\r
+ }\r
+\r
+ /**\r
+ * Get all preceding siblings of each element up to but not including the element matched by the\r
+ * <code>selector</code>.\r
+ * \r
+ * The elements are returned in order from the closest sibling to the farthest.\r
+ */\r
+ public GQuery prevUntil(String selector) {\r
+ return prevUntil($(selector), null);\r
+ }\r
+\r
+ /**\r
+ * Get all preceding siblings of each element up to but not including the <code>until</code>\r
+ * element.\r
+ * \r
+ * The elements are returned in order from the closest sibling to the farthest.\r
+ */\r
+ public GQuery prevUntil(Element until) {\r
+ return prevUntil($(until), null);\r
+ }\r
+\r
+ /**\r
+ * Get all preceding siblings of each element up to but not including the <code>until</code>\r
+ * element.\r
+ * \r
+ * The elements are returned in order from the closest sibling to the farthest.\r
+ */\r
+ public GQuery prevUntil(GQuery until) {\r
+ return prevUntil(until, null);\r
+ }\r
+\r
+ /**\r
+ * Get all preceding siblings of each element matching the <code>filter</code> up to but not\r
+ * including the element matched by the <code>selector</code>.\r
+ * \r
+ * The elements are returned in order from the closest sibling to the farthest.\r
+ */\r
+ public GQuery prevUntil(String selector, String filter) {\r
+ return prevUntil($(selector), filter);\r
+ }\r
+\r
+ /**\r
+ * Get all preceding siblings of each element matching the <code>filter</code> up to but not\r
+ * including the <code>until</code> element.\r
+ * \r
+ */\r
+ public GQuery prevUntil(Element until, String filter) {\r
+ return prevUntil($(until), filter);\r
+ }\r
+\r
+ /**\r
+ * Get all preceding siblings of each element matching the <code>filter</code> up to but not\r
+ * including the element matched by the <code>until</code> element.\r
+ * \r
+ */\r
+ public GQuery prevUntil(GQuery until, String filter) {\r
+ JsNodeArray result = JsNodeArray.create();\r
+ for (Element e : elements) {\r
+ allPreviousSiblingElements(getPreviousSiblingElement(e), result, until, filter);\r
+ }\r
+ return pushStack(unique(result), "prevUntil", getSelector());\r
+ }\r
\r
/**\r
* Accesses a boolean property on the first matched element.\r
* \r
* @param key the name of the boolean property to be accessed\r
* \r
- * @return <code>true</code> if at least one element is matched and the\r
- * specified boolean property is set to <code>true</code> on the first\r
- * matched element; <code>false</code> otherwise\r
+ * @return <code>true</code> if at least one element is matched and the specified boolean property\r
+ * is set to <code>true</code> on the first matched element; <code>false</code> otherwise\r
* \r
*/\r
public boolean prop(String key) {\r
* Sets a boolean property to a computed value on all matched elements.\r
* \r
* @param key the name of the boolean property to be set\r
- * @param closure the closure to be used to compute the value the specified\r
- * boolean property should be set to; the <code>closure</code> is\r
- * {@linkplain Function#f(com.google.gwt.dom.client.Element, int)\r
- * passed} the target element and its index as arguments and is\r
- * expected to return either a <code>Boolean</code> value or an\r
- * object whose textual representation is converted to a\r
- * <code>Boolean</code> value; <code>null</code> return values are\r
- * ignored\r
+ * @param closure the closure to be used to compute the value the specified boolean property\r
+ * should be set to; the <code>closure</code> is\r
+ * {@linkplain Function#f(com.google.gwt.dom.client.Element, int) passed} the target\r
+ * element and its index as arguments and is expected to return either a\r
+ * <code>Boolean</code> value or an object whose textual representation is converted to a\r
+ * <code>Boolean</code> value; <code>null</code> return values are ignored\r
* \r
* @return this <code>GQuery</code> object\r
* \r
public GQuery prop(String key, Function closure) {\r
assert key != null : "Key is null";\r
assert closure != null : "Closure is null";\r
- \r
+\r
int i = 0;\r
for (Element e : elements) {\r
Object value = closure.f(e, i++);\r
if (value != null) {\r
- e.setPropertyBoolean(key, value instanceof Boolean ? (Boolean) value\r
- : Boolean.valueOf(value.toString()));\r
+ e.setPropertyBoolean(key, value instanceof Boolean ? (Boolean) value : Boolean\r
+ .valueOf(value.toString()));\r
}\r
}\r
\r
}\r
\r
/**\r
- * Show the number of functions in the efects queue to be executed on the\r
- * first matched element.\r
+ * Show the number of functions in the efects queue to be executed on the first matched element.\r
*/\r
public int queue() {\r
return as(Queue).queue();\r
* \r
* </pre>\r
* \r
- * When this statement is executed, the element move to 500 px to left for 400\r
- * ms, then its background color is changed to red and then move to 500px to\r
- * right for 400ms, and finally its color is set to yellow.\r
+ * When this statement is executed, the element move to 500 px to left for 400 ms, then its\r
+ * background color is changed to red and then move to 500px to right for 400ms, and finally its\r
+ * color is set to yellow.\r
* \r
- * Please note that {@link #dequeue()} function is needed at the end of your\r
- * function to start the next function in the queue. In lazy() methods you should\r
- * call dequeue() just before the done() call.\r
- * {@see #dequeue()}\r
+ * Please note that {@link #dequeue()} function is needed at the end of your function to start the\r
+ * next function in the queue. In lazy() methods you should call dequeue() just before the done()\r
+ * call. {@see #dequeue()}\r
*/\r
public GQuery queue(Function... f) {\r
return as(Queue).queue(f);\r
}\r
\r
/**\r
- * Show the number of functions in the queued named as queueName to be\r
- * executed on the first matched element.\r
+ * Show the number of functions in the queued named as queueName to be executed on the first\r
+ * matched element.\r
*/\r
public int queue(String queueName) {\r
return as(Queue).queue();\r
* .queue("myQueue", lazy().css(CSS.COLOR.with(RGBColor.YELLOW)).dequeue("myQueue").done());\r
* </pre>\r
* \r
- * When this statement is executed, the background color of the element is set\r
- * to red, then wait 500ms before to set the text color of the element to\r
- * yellow. right for 400ms.\r
+ * When this statement is executed, the background color of the element is set to red, then wait\r
+ * 500ms before to set the text color of the element to yellow. right for 400ms.\r
* \r
- * Please note that {@link #dequeue()} function is needed at the end of your\r
- * function to start the next function in the queue. In lazy() methods you should\r
- * call dequeue() just before the done() call.\r
- * {@see #dequeue()}\r
+ * Please note that {@link #dequeue()} function is needed at the end of your function to start the\r
+ * next function in the queue. In lazy() methods you should call dequeue() just before the done()\r
+ * call. {@see #dequeue()}\r
*/\r
public GQuery queue(String queueName, Function... f) {\r
return as(Queue).queue(queueName, f);\r
}\r
\r
/**\r
- * Removes from the DOM all matched elements filtered by the\r
- * <code>filter</code>.\r
+ * Removes from the DOM all matched elements filtered by the <code>filter</code>.\r
*/\r
public GQuery remove(String filter) {\r
return remove(filter, true);\r
}\r
\r
/**\r
- * Removes all matched elements from the DOM and cleans their data and bound\r
- * events if the value of <code>clean</code> parameter is set to true. The\r
- * <code> filter</code> parameter allows to filter the matched set to remove.\r
+ * Removes all matched elements from the DOM and cleans their data and bound events if the value\r
+ * of <code>clean</code> parameter is set to true. The <code> filter</code> parameter allows to\r
+ * filter the matched set to remove.\r
*/\r
protected GQuery remove(String filter, boolean clean) {\r
for (Element e : elements) {\r
}\r
return this;\r
}\r
- \r
+\r
/**\r
* Remove the named attribute from every element in the matched set.\r
*/\r
*/\r
public GQuery removeClass(String... classes) {\r
for (Element e : elements) {\r
- if (Element.is(e)){\r
+ if (Element.is(e)) {\r
for (String clz : classes) {\r
e.removeClassName(clz);\r
}\r
}\r
return this;\r
}\r
- \r
+\r
private void removeData(Element item, String name) {\r
if (dataCache == null) {\r
windowData = JavaScriptObject.createObject().cast();\r
}\r
\r
/**\r
- * Replaces the element <code>elem</code> by the specified selector with the\r
- * matched elements. This function is the complement to replaceWith() which\r
- * does the same task with the parameters reversed.\r
+ * Replaces the element <code>elem</code> by the specified selector with the matched elements.\r
+ * This function is the complement to replaceWith() which does the same task with the parameters\r
+ * reversed.\r
* \r
* @return a {@link GQuery} object containing the new elements.\r
*/\r
}\r
\r
/**\r
- * Replaces the elements matched by the target with the selected elements.\r
- * This function is the complement to replaceWith() which does the same task\r
- * with the parameters reversed.\r
+ * Replaces the elements matched by the target with the selected elements. This function is the\r
+ * complement to replaceWith() which does the same task with the parameters reversed.\r
* \r
* @return a {@link GQuery} object containing the new elements.\r
*/\r
// if there is only one element and it is not attached to the dom, we have\r
// to clone it to be reused on each element of target (if target contains\r
// more than one element)\r
- boolean mustBeCloned = length() == 1\r
- && parents().filter("body").length() == 0;\r
+ boolean mustBeCloned = length() == 1 && parents().filter("body").length() == 0;\r
\r
List<Element> newElements = new ArrayList<Element>();\r
for (int i = 0, l = target.size(); i < l; i++) {\r
}\r
\r
/**\r
- * Replaces the elements matched by the specified selector with the matched\r
- * elements. This function is the complement to replaceWith() which does the\r
- * same task with the parameters reversed.\r
+ * Replaces the elements matched by the specified selector with the matched elements. This\r
+ * function is the complement to replaceWith() which does the same task with the parameters\r
+ * reversed.\r
* \r
* @return a {@link GQuery} object containing the new elements.\r
*/\r
/**\r
* Replaces all matched elements with the specified element.\r
* \r
- * @return the GQuery element that was just replaced, which has been removed\r
- * from the DOM and not the new element that has replaced it.\r
+ * @return the GQuery element that was just replaced, which has been removed from the DOM and not\r
+ * the new element that has replaced it.\r
*/\r
public GQuery replaceWith(Element elem) {\r
return replaceWith($(elem));\r
}\r
\r
/**\r
- * Replaces all matched elements with elements selected by <code>target</code>\r
- * .\r
+ * Replaces all matched elements with elements selected by <code>target</code> .\r
* \r
- * @return the GQuery element that was just replaced, which has been removed\r
- * from the DOM and not the new element that has replaced it.\r
+ * @return the GQuery element that was just replaced, which has been removed from the DOM and not\r
+ * the new element that has replaced it.\r
*/\r
public GQuery replaceWith(GQuery target) {\r
for (Element el : elements) {\r
/**\r
* Replaces all matched elements with the specified HTML.\r
* \r
- * @return the GQuery element that was just replaced, which has been removed\r
- * from the DOM and not the new element that has replaced it.\r
+ * @return the GQuery element that was just replaced, which has been removed from the DOM and not\r
+ * the new element that has replaced it.\r
*/\r
public GQuery replaceWith(String html) {\r
for (Element el : elements) {\r
}\r
\r
/**\r
- * Bind a set of functions to the resize event of each matched element, or\r
- * tigger the resize event if no functions are provided.\r
+ * Bind a set of functions to the resize event of each matched element, or tigger the resize event\r
+ * if no functions are provided.\r
* \r
- * Note that although all elements can be configured to handle resize\r
- * events, by default only window will trigger it when it is resized, \r
- * for an arbitrary element you have to trigger the event after resizing \r
- * the object. \r
+ * Note that although all elements can be configured to handle resize events, by default only\r
+ * window will trigger it when it is resized, for an arbitrary element you have to trigger the\r
+ * event after resizing the object.\r
* \r
*/\r
public GQuery resize(Function... f) {\r
}\r
\r
/**\r
- * Bind an event handler to the "resize" JavaScript event, or trigger that event on an element. \r
+ * Bind an event handler to the "resize" JavaScript event, or trigger that event on an element.\r
*/\r
public GQuery resize(final Function f) {\r
return bindOrFire(EventsListener.ONRESIZE, null, f);\r
public void restoreCssAttrs(String... cssProps) {\r
for (Element e : elements) {\r
for (String a : cssProps) {\r
- getStyleImpl().setStyleProperty(e, a, (String) data(e, OLD_DATA_PREFIX + a,\r
- null));\r
+ getStyleImpl().setStyleProperty(e, a, (String) data(e, OLD_DATA_PREFIX + a, null));\r
}\r
}\r
}\r
}\r
\r
/**\r
- * Bind a set of functions to the scroll event of each matched element. Or\r
- * trigger the event if no functions are provided.\r
+ * Bind a set of functions to the scroll event of each matched element. Or trigger the event if no\r
+ * functions are provided.\r
*/\r
public GQuery scroll(Function... f) {\r
return bindOrFire(Event.ONSCROLL, null, f);\r
/**\r
* Scrolls the first matched element into view.\r
* \r
- * If ensure == true, it crawls up the DOM hierarchy, adjusting the scrollLeft\r
- * and scrollTop properties of each scroll-able element to ensure that the\r
- * specified element is completely in view. It adjusts each scroll position by\r
- * the minimum amount necessary.\r
+ * If ensure == true, it crawls up the DOM hierarchy, adjusting the scrollLeft and scrollTop\r
+ * properties of each scroll-able element to ensure that the specified element is completely in\r
+ * view. It adjusts each scroll position by the minimum amount necessary.\r
*/\r
public GQuery scrollIntoView(boolean ensure) {\r
if (!isEmpty() && ensure) {\r
}\r
\r
/**\r
- * Gets the scroll left offset of the first matched element. This method works\r
- * for both visible and hidden elements.\r
+ * Gets the scroll left offset of the first matched element. This method works for both visible\r
+ * and hidden elements.\r
*/\r
public int scrollLeft() {\r
Element e = get(0);\r
}\r
\r
/**\r
- * The scroll left offset is set to the passed value on all matched elements.\r
- * This method works for both visible and hidden elements.\r
+ * The scroll left offset is set to the passed value on all matched elements. This method works\r
+ * for both visible and hidden elements.\r
*/\r
public GQuery scrollLeft(int left) {\r
for (Element e : elements) {\r
\r
/**\r
* \r
- * Scrolls the contents of all matched elements to the specified co-ordinate\r
- * becoming the top left corner of the viewable area.\r
+ * Scrolls the contents of all matched elements to the specified co-ordinate becoming the top left\r
+ * corner of the viewable area.\r
* \r
- * This method is only useful where there are areas of the document not\r
- * viewable within the current viewable area of the window and the visible\r
- * property of the window's scrollbar must be set to true.\r
+ * This method is only useful where there are areas of the document not viewable within the\r
+ * current viewable area of the window and the visible property of the window's scrollbar must be\r
+ * set to true.\r
* \r
*/\r
public GQuery scrollTo(int left, int top) {\r
}\r
\r
/**\r
- * Gets the scroll top offset of the first matched element. This method works\r
- * for both visible and hidden elements.\r
+ * Gets the scroll top offset of the first matched element. This method works for both visible and\r
+ * hidden elements.\r
*/\r
public int scrollTop() {\r
Element e = get(0);\r
}\r
\r
/**\r
- * The scroll top offset is set to the passed value on all matched elements.\r
- * This method works for both visible and hidden elements.\r
+ * The scroll top offset is set to the passed value on all matched elements. This method works for\r
+ * both visible and hidden elements.\r
*/\r
public GQuery scrollTop(int top) {\r
for (Element e : elements) {\r
}\r
\r
/**\r
- * Force the current matched set of elements to become the specified array of\r
- * elements.\r
+ * Force the current matched set of elements to become the specified array of elements.\r
*/\r
public GQuery setArray(NodeList<Element> list) {\r
if (list != null) {\r
- nodeList.<JsCache>cast().clear();\r
+ nodeList.<JsCache> cast().clear();\r
int l = list.getLength();\r
elements = new Element[l];\r
for (int i = 0; i < l; i++) {\r
elements[i] = list.getItem(i);\r
- nodeList.<JsObjectArray<Element>>cast().add(list.getItem(i));\r
+ nodeList.<JsObjectArray<Element>> cast().add(list.getItem(i));\r
}\r
}\r
return this;\r
public GQuery show() {\r
for (Element e : elements) {\r
String currentDisplay = e.getStyle().getDisplay();\r
- String oldDisplay = (String) data(e,"oldDisplay", null);\r
- \r
- //reset the display\r
- if (oldDisplay == null && "none".equals(currentDisplay)){\r
+ String oldDisplay = (String) data(e, "oldDisplay", null);\r
+\r
+ // reset the display\r
+ if (oldDisplay == null && "none".equals(currentDisplay)) {\r
getStyleImpl().setStyleProperty(e, "display", "");\r
currentDisplay = "";\r
}\r
- \r
- //check if the stylesheet impose display: none. If it is the case, determine \r
- //the default display for the tag and store it at the element level\r
- if ("".equals(currentDisplay) && !getStyleImpl().isVisible(e)){\r
+\r
+ // check if the stylesheet impose display: none. If it is the case, determine\r
+ // the default display for the tag and store it at the element level\r
+ if ("".equals(currentDisplay) && !getStyleImpl().isVisible(e)) {\r
data(e, "oldDisplay", getStyleImpl().defaultDisplay(e.getNodeName()));\r
}\r
}\r
- \r
+\r
// set the display value in a separate for loop to avoid constant reflow\r
- // because broswer reflow is triggered each time we gonna set and after get (in isVisibleProperty() method)\r
+ // because broswer reflow is triggered each time we gonna set and after get (in\r
+ // isVisibleProperty() method)\r
// the diplay property. Reflows is very bad in performance point of view\r
for (Element e : elements) {\r
String currentDisplay = e.getStyle().getDisplay();\r
- if ("".equals(currentDisplay) || "none".equals(currentDisplay)){\r
- getStyleImpl().setStyleProperty(e, "display", JsUtils.or((String) data(e,\r
- "oldDisplay", null), ""));\r
+ if ("".equals(currentDisplay) || "none".equals(currentDisplay)) {\r
+ getStyleImpl().setStyleProperty(e, "display",\r
+ JsUtils.or((String) data(e, "oldDisplay", null), ""));\r
}\r
}\r
return this;\r
}\r
- \r
+\r
/**\r
- * Get a set of elements containing all of the unique siblings of each of the\r
- * matched set of elements.\r
+ * Get a set of elements containing all of the unique siblings of each of the matched set of\r
+ * elements.\r
*/\r
public GQuery siblings() {\r
JsNodeArray result = JsNodeArray.create();\r
for (Element e : elements) {\r
- allNextSiblingElements(e.getParentElement().getFirstChildElement(),\r
- result, e, null, null);\r
+ allNextSiblingElements(e.getParentElement().getFirstChildElement(), result, e, null, null);\r
}\r
return new GQuery(unique(result));\r
}\r
\r
/**\r
- * Get a set of elements containing all of the unique siblings of each of the\r
- * matched set of elements filtered by the provided set of selectors.\r
+ * Get a set of elements containing all of the unique siblings of each of the matched set of\r
+ * elements filtered by the provided set of selectors.\r
*/\r
public GQuery siblings(String... selectors) {\r
return siblings().filter(selectors);\r
}\r
\r
/**\r
- * Reveal all matched elements by adjusting their height and firing an\r
- * optional callback after completion.\r
+ * Reveal all matched elements by adjusting their height and firing an optional callback after\r
+ * completion.\r
*/\r
public Effects slideDown(Function... f) {\r
return as(Effects).slideDown(f);\r
}\r
\r
/**\r
- * Reveal all matched elements by adjusting their height and firing an\r
- * optional callback after completion.\r
+ * Reveal all matched elements by adjusting their height and firing an optional callback after\r
+ * completion.\r
*/\r
public Effects slideDown(int millisecs, Function... f) {\r
return as(Effects).slideDown(millisecs, f);\r
}\r
\r
/**\r
- * Toggle the visibility of all matched elements by adjusting their height and\r
- * firing an optional callback after completion. Only the height is adjusted\r
- * for this animation, causing all matched elements to be hidden or shown in a\r
- * "sliding" manner\r
+ * Toggle the visibility of all matched elements by adjusting their height and firing an optional\r
+ * callback after completion. Only the height is adjusted for this animation, causing all matched\r
+ * elements to be hidden or shown in a "sliding" manner\r
*/\r
public Effects slideToggle(int millisecs, Function... f) {\r
return as(Effects).slideToggle(millisecs, f);\r
}\r
\r
/**\r
- * Hide all matched elements by adjusting their height and firing an optional\r
- * callback after completion.\r
+ * Hide all matched elements by adjusting their height and firing an optional callback after\r
+ * completion.\r
*/\r
public Effects slideUp(Function... f) {\r
return as(Effects).slideUp(f);\r
}\r
\r
/**\r
- * Hide all matched elements by adjusting their height and firing an optional\r
- * callback after completion.\r
+ * Hide all matched elements by adjusting their height and firing an optional callback after\r
+ * completion.\r
*/\r
public Effects slideUp(int millisecs, Function... f) {\r
return as(Effects).slideUp(millisecs, f);\r
}\r
\r
/**\r
- * When .stop() is called on an element, the currently-running animation (if any) \r
- * is immediately stopped. If, for instance, an element is being hidden with .slideUp() \r
- * when .stop() is called, the element will now still be displayed, but will be \r
- * a fraction of its previous height. Callback functions are not called but\r
- * the next animation in the queue begins immediately. \r
+ * When .stop() is called on an element, the currently-running animation (if any) is immediately\r
+ * stopped. If, for instance, an element is being hidden with .slideUp() when .stop() is called,\r
+ * the element will now still be displayed, but will be a fraction of its previous height.\r
+ * Callback functions are not called but the next animation in the queue begins immediately.\r
*/\r
public GQuery stop() {\r
return stop(false);\r
}\r
\r
/**\r
- * When .stop() is called on an element, the currently-running animation (if any) \r
- * is immediately stopped. If, for instance, an element is being hidden with .slideUp() \r
- * when .stop() is called, the element will now still be displayed, but will be \r
- * a fraction of its previous height. Callback functions are not called but\r
- * the next animation in the queue begins immediately. \r
+ * When .stop() is called on an element, the currently-running animation (if any) is immediately\r
+ * stopped. If, for instance, an element is being hidden with .slideUp() when .stop() is called,\r
+ * the element will now still be displayed, but will be a fraction of its previous height.\r
+ * Callback functions are not called but the next animation in the queue begins immediately.\r
* \r
- * If the clearQueue parameter is provided with a value of true, then the rest of the \r
- * animations in the queue are removed and never run.\r
+ * If the clearQueue parameter is provided with a value of true, then the rest of the animations\r
+ * in the queue are removed and never run.\r
*/\r
public GQuery stop(boolean clearQueue) {\r
return stop(clearQueue, false);\r
}\r
\r
/**\r
- * When .stop() is called on an element, the currently-running animation (if any) \r
- * is immediately stopped. If, for instance, an element is being hidden with .slideUp() \r
- * when .stop() is called, the element will now still be displayed, but will be \r
- * a fraction of its previous height. Callback functions are not called but\r
- * the next animation in the queue begins immediately. \r
+ * When .stop() is called on an element, the currently-running animation (if any) is immediately\r
+ * stopped. If, for instance, an element is being hidden with .slideUp() when .stop() is called,\r
+ * the element will now still be displayed, but will be a fraction of its previous height.\r
+ * Callback functions are not called but the next animation in the queue begins immediately.\r
* \r
- * If the clearQueue parameter is provided with a value of true, then the rest of the \r
- * animations in the queue are removed and never run.\r
+ * If the clearQueue parameter is provided with a value of true, then the rest of the animations\r
+ * in the queue are removed and never run.\r
* \r
- * If the jumpToEnd property is provided with a value of true, the current animation stops, \r
- * but the element is immediately given its target values for each CSS property.\r
- * The callback functions are then immediately called, if provided.\r
+ * If the jumpToEnd property is provided with a value of true, the current animation stops, but\r
+ * the element is immediately given its target values for each CSS property. The callback\r
+ * functions are then immediately called, if provided.\r
*/\r
public GQuery stop(boolean clearQueue, boolean jumpToEnd) {\r
return as(Queue).stop(clearQueue, jumpToEnd);\r
}\r
\r
/**\r
- * Bind a set of functions to the submit event of each matched element. \r
- * Or submit a form if no functions are provided.\r
+ * Bind a set of functions to the submit event of each matched element. Or submit a form if no\r
+ * functions are provided.\r
*/\r
public GQuery submit(Function... funcs) {\r
return bindOrFire(EventsListener.ONSUBMIT, null, funcs);\r
}\r
- \r
+\r
/**\r
* Return the concatened text contained in the matched elements.\r
*/\r
}\r
return result;\r
}\r
- \r
+\r
/**\r
* Set the innerText of every matched element.\r
*/\r
}\r
return this;\r
}\r
- \r
+\r
/**\r
* Toggle among two or more function calls every other click.\r
*/\r
}\r
\r
/**\r
- * Adds or removes the specified classes to each matched element depending on\r
- * the class's presence.\r
+ * Adds or removes the specified classes to each matched element depending on the class's\r
+ * presence.\r
*/\r
public GQuery toggleClass(String... classes) {\r
for (Element e : elements) {\r
}\r
\r
/**\r
- * Adds or removes the specified classes to each matched element depending on\r
- * the value of the switch argument.\r
+ * Adds or removes the specified classes to each matched element depending on the value of the\r
+ * switch argument.\r
* \r
- * if addOrRemove is true, the class is added and in the case of false it is\r
- * removed.\r
+ * if addOrRemove is true, the class is added and in the case of false it is removed.\r
*/\r
public GQuery toggleClass(String clz, boolean addOrRemove) {\r
if (addOrRemove) {\r
public int top() {\r
return (int) cur("top", true);\r
}\r
- \r
+\r
/**\r
* Produces a string representation of the matched elements.\r
*/\r
public String toString() {\r
return toString(false);\r
}\r
- \r
+\r
/**\r
* Produces a string representation of the matched elements.\r
*/\r
try {\r
elStr = JsUtils.isXML(e) ? JsUtils.XML2String(e) : e.getString();\r
} catch (Exception e2) {\r
- elStr = "< " + (e == null ? "null" : e.getNodeName()) + "(gquery, error getting the element string representation: " + e2.getMessage() + ")/>";\r
+ elStr =\r
+ "< " + (e == null ? "null" : e.getNodeName())\r
+ + "(gquery, error getting the element string representation: " + e2.getMessage()\r
+ + ")/>";\r
}\r
r += (pretty && r.length() > 0 ? "\n " : "") + elStr;\r
}\r
return r;\r
}\r
- \r
+\r
/**\r
* Trigger a set of events on each matched element.\r
* \r
- * For keyboard events you can pass a second parameter which represents the\r
- * key-code of the pushed key.\r
+ * For keyboard events you can pass a second parameter which represents the key-code of the pushed\r
+ * key.\r
* \r
- * Example: fire(Event.ONCLICK | Event.ONFOCUS) Example: fire(Event.ONKEYDOWN.\r
- * 'a');\r
+ * Example: fire(Event.ONCLICK | Event.ONFOCUS) Example: fire(Event.ONKEYDOWN. 'a');\r
*/\r
public GQuery trigger(int eventbits, int... keys) {\r
return as(Events).trigger(eventbits, keys);\r
public GQuery unbind(int eventbits) {\r
return as(Events).unbind(eventbits);\r
}\r
- \r
+\r
/**\r
- * Removes the function passed from the set of events which match \r
- * the eventbits.\r
+ * Removes the function passed from the set of events which match the eventbits.\r
*/\r
public GQuery unbind(int eventbits, Function f) {\r
return as(Events).unbind(eventbits, null, f);\r
}\r
- \r
+\r
/**\r
* Removes all events that match the eventList.\r
*/\r
public GQuery unbind(String eventList) {\r
return unbind(eventList, null);\r
}\r
- \r
+\r
/**\r
* Removes all events that match the eventList.\r
*/\r
public GQuery undelegate() {\r
return as(Events).undelegate();\r
}\r
- \r
+\r
/**\r
* Undelegate is a way of removing event handlers that have been bound using\r
* {@link #delegate(String, int, Function...)} method\r
*/\r
public GQuery undelegate(String selector) {\r
- for (Element e : elements){\r
- $(selector, e).die();\r
- }\r
- \r
- return this;\r
+ for (Element e : elements) {\r
+ $(selector, e).die();\r
+ }\r
+\r
+ return this;\r
}\r
\r
/**\r
* {@link #delegate(String, int, Function...)} method\r
*/\r
public GQuery undelegate(String selector, int eventBit) {\r
- for (Element e : elements){\r
- $(selector, e).die(eventBit);\r
- }\r
- \r
- return this;\r
+ for (Element e : elements) {\r
+ $(selector, e).die(eventBit);\r
+ }\r
+\r
+ return this;\r
}\r
\r
/**\r
* {@link #delegate(String, int, Function...)} method\r
*/\r
public GQuery undelegate(String selector, String eventName) {\r
- for (Element e : elements){\r
- $(selector, e).die(eventName);\r
- }\r
- \r
- return this;\r
+ for (Element e : elements) {\r
+ $(selector, e).die(eventName);\r
+ }\r
+\r
+ return this;\r
}\r
\r
/**\r
- * Remove all duplicate elements from an array of elements. Note that this\r
- * only works on arrays of DOM elements, not strings or numbers.\r
+ * Remove all duplicate elements from an array of elements. Note that this only works on arrays of\r
+ * DOM elements, not strings or numbers.\r
*/\r
public JsNodeArray unique(NodeList<Element> result) {\r
return JsUtils.unique(result.<JsArray<Element>> cast()).cast();\r
}\r
\r
/**\r
- * This method removes the element's parent. The matched elements replaces\r
- * their parents within the DOM structure. It is the inverse of\r
- * {@link GQuery#wrap(GQuery)} method\r
+ * This method removes the element's parent. The matched elements replaces their parents within\r
+ * the DOM structure. It is the inverse of {@link GQuery#wrap(GQuery)} method\r
* \r
* @return\r
*/\r
}\r
\r
/**\r
- * Gets the content of the value attribute of the first matched element,\r
- * returns only the first value even if it is a multivalued element. To get an\r
- * array of all values in multivalues elements use vals()\r
+ * Gets the content of the value attribute of the first matched element, returns only the first\r
+ * value even if it is a multivalued element. To get an array of all values in multivalues\r
+ * elements use vals()\r
* \r
- * When the first element is a radio-button and is not checked, then it looks\r
- * for the first checked radio-button that has the same name in the list of\r
- * matched elements.\r
+ * When the first element is a radio-button and is not checked, then it looks for the first\r
+ * checked radio-button that has the same name in the list of matched elements.\r
* \r
* When there are not matched elements it returns null.\r
*/\r
}\r
\r
/**\r
- * Sets the value attribute of every matched element based in the return\r
- * value of the function evaluated for this element.\r
+ * Sets the value attribute of every matched element based in the return value of the function\r
+ * evaluated for this element.\r
* \r
- * NOTE: in jquery the function receives the arguments in different\r
- * way, first index and them the actual value, but we use the normal way\r
- * in gquery Function, first the element and second the index.\r
+ * NOTE: in jquery the function receives the arguments in different way, first index and them the\r
+ * actual value, but we use the normal way in gquery Function, first the element and second the\r
+ * index.\r
*/\r
public GQuery val(Function f) {\r
- for (int i = 0; i < size(); i++){\r
+ for (int i = 0; i < size(); i++) {\r
eq(i).val(f.f(get(i), i).toString());\r
}\r
return this;\r
}\r
\r
/**\r
- * Sets the 'value' attribute of every matched element, but\r
- * does not set the checked flag to checkboxes or radiobuttons.\r
+ * Sets the 'value' attribute of every matched element, but does not set the checked flag to\r
+ * checkboxes or radiobuttons.\r
* \r
- * If you wanted to set values in collections of checkboxes o radiobuttons \r
- * use val(String[]) instead\r
+ * If you wanted to set values in collections of checkboxes o radiobuttons use val(String[])\r
+ * instead\r
*/\r
public GQuery val(String value) {\r
for (Element e : elements) {\r
* \r
* There is a different behaviour depending on the element type:\r
* <ul>\r
- * <li>select multiple: options whose value match any of the passed values will be set.\r
- * <li>select single: the last option whose value matches any of the passed values will be set.\r
- * <li>input radio: the last input whose value matches any of the passed values will be set.\r
- * <li>input checkbox: inputs whose value match any of the passed values will be set.\r
- * <li>textarea, button, and other input: value will set to a string result of joining with coma, all passed values \r
+ * <li>select multiple: options whose value match any of the passed values will be set.\r
+ * <li>select single: the last option whose value matches any of the passed values will be set.\r
+ * <li>input radio: the last input whose value matches any of the passed values will be set.\r
+ * <li>input checkbox: inputs whose value match any of the passed values will be set.\r
+ * <li>textarea, button, and other input: value will set to a string result of joining with coma,\r
+ * all passed values\r
* </ul>\r
* \r
- * NOTE: if you wanted call this function with just one parameter, you have to\r
- * pass an array signature to avoid call the overloaded val(String) method:\r
+ * NOTE: if you wanted call this function with just one parameter, you have to pass an array\r
+ * signature to avoid call the overloaded val(String) method:\r
* \r
* $(...).val(new String[]{"value"});\r
*/\r
} else if ("input".equalsIgnoreCase(name)) {\r
InputElement ie = InputElement.as(e);\r
String type = ie.getType();\r
- if ("radio".equalsIgnoreCase((type))\r
- || "checkbox".equalsIgnoreCase(type)){\r
+ if ("radio".equalsIgnoreCase((type)) || "checkbox".equalsIgnoreCase(type)) {\r
ie.setChecked(false);\r
for (String v : values) {\r
if (ie.getValue().equals(v)) {\r
}\r
\r
/**\r
- * Gets the content of the value attribute of the first matched element,\r
- * returns more than one value if it is a multiple select.\r
+ * Gets the content of the value attribute of the first matched element, returns more than one\r
+ * value if it is a multiple select.\r
* \r
- * When the first element is a radio-button and is not checked, then it looks\r
- * for a the first checked radio-button that has the same name in the list of\r
- * matched elements.\r
+ * When the first element is a radio-button and is not checked, then it looks for a the first\r
+ * checked radio-button that has the same name in the list of matched elements.\r
* \r
- * This method always returns an array. If no valid value can be determined\r
- * the array will be empty, otherwise it will contain one or more values.\r
+ * This method always returns an array. If no valid value can be determined the array will be\r
+ * empty, otherwise it will contain one or more values.\r
*/\r
public String[] vals() {\r
if (!isEmpty()) {\r
SelectElement se = SelectElement.as(e);\r
if (se.isMultiple()) {\r
JsArrayString result = JsArrayString.createArray().cast();\r
- for (int i = 0, l = se.getOptions().getLength(); i < l; i++){\r
+ for (int i = 0, l = se.getOptions().getLength(); i < l; i++) {\r
OptionElement oe = se.getOptions().getItem(i);\r
if (oe.isSelected()) {\r
result.set(result.length(), oe.getValue());\r
}\r
return result.length() > 0 ? jsArrayToString(result) : null;\r
} else if (se.getSelectedIndex() >= 0) {\r
- return new String[]{se.getOptions().getItem(se.getSelectedIndex()).getValue()};\r
+ return new String[] {se.getOptions().getItem(se.getSelectedIndex()).getValue()};\r
}\r
} else if (e.getNodeName().equalsIgnoreCase("input")) {\r
InputElement ie = InputElement.as(e);\r
- return new String[]{ie.getValue()};\r
+ return new String[] {ie.getValue()};\r
} else if (e.getNodeName().equalsIgnoreCase("textarea")) {\r
- return new String[]{TextAreaElement.as(e).getValue()};\r
+ return new String[] {TextAreaElement.as(e).getValue()};\r
} else if (e.getNodeName().equalsIgnoreCase("button")) {\r
- return new String[]{ButtonElement.as(e).getValue()};\r
+ return new String[] {ButtonElement.as(e).getValue()};\r
}\r
}\r
return new String[0];\r
}\r
\r
/**\r
- * Return the first non null attached widget from the matched elements or null\r
- * if there isn't any.\r
+ * Return the first non null attached widget from the matched elements or null if there isn't any.\r
*/\r
@SuppressWarnings("unchecked")\r
public <W extends Widget> W widget() {\r
}\r
\r
/**\r
- * Return the nth non null attached widget from the matched elements or null\r
- * if there isn't any.\r
+ * Return the nth non null attached widget from the matched elements or null if there isn't any.\r
*/\r
public <W extends Widget> W widget(int n) {\r
for (Element e : elements) {\r
}\r
\r
/**\r
- * Return the list of attached widgets instance of the provided class matching\r
- * the query.\r
+ * Return the list of attached widgets instance of the provided class matching the query.\r
* \r
- * This method is very useful for decoupled views, so as we can access widgets\r
- * from other views without maintaining methods which export them.\r
+ * This method is very useful for decoupled views, so as we can access widgets from other views\r
+ * without maintaining methods which export them.\r
* \r
*/\r
@SuppressWarnings("unchecked")\r
}\r
\r
/**\r
- * Get the current computed, pixel, width of the first matched element. It\r
- * does not include margin, padding nor border.\r
+ * Get the current computed, pixel, width of the first matched element. It does not include\r
+ * margin, padding nor border.\r
*/\r
public int width() {\r
return (int) cur("width", true);\r
}\r
\r
/**\r
- * Wrap each matched element with the specified HTML content. This wrapping\r
- * process is most useful for injecting additional structure into a document,\r
- * without ruining the original semantic qualities of a document. This works\r
- * by going through the first element provided (which is generated, on the\r
- * fly, from the provided HTML) and finds the deepest descendant element\r
- * within its structure -- it is that element that will enwrap everything\r
- * else.\r
+ * Wrap each matched element with the specified HTML content. This wrapping process is most useful\r
+ * for injecting additional structure into a document, without ruining the original semantic\r
+ * qualities of a document. This works by going through the first element provided (which is\r
+ * generated, on the fly, from the provided HTML) and finds the deepest descendant element within\r
+ * its structure -- it is that element that will enwrap everything else.\r
*/\r
public GQuery wrap(Element elem) {\r
return wrap($(elem));\r
}\r
\r
/**\r
- * Wrap each matched element with the specified HTML content. This wrapping\r
- * process is most useful for injecting additional structure into a document,\r
- * without ruining the original semantic qualities of a document. This works\r
- * by going through the first element provided (which is generated, on the\r
- * fly, from the provided HTML) and finds the deepest descendant element\r
- * within its structure -- it is that element that will enwrap everything\r
- * else.\r
+ * Wrap each matched element with the specified HTML content. This wrapping process is most useful\r
+ * for injecting additional structure into a document, without ruining the original semantic\r
+ * qualities of a document. This works by going through the first element provided (which is\r
+ * generated, on the fly, from the provided HTML) and finds the deepest descendant element within\r
+ * its structure -- it is that element that will enwrap everything else.\r
*/\r
public GQuery wrap(GQuery query) {\r
for (Element e : elements) {\r
}\r
\r
/**\r
- * Wrap each matched element with the specified HTML content. This wrapping\r
- * process is most useful for injecting additional structure into a document,\r
- * without ruining the original semantic qualities of a document. This works\r
- * by going through the first element provided (which is generated, on the\r
- * fly, from the provided HTML) and finds the deepest descendant element\r
- * within its structure -- it is that element that will enwrap everything\r
- * else.\r
+ * Wrap each matched element with the specified HTML content. This wrapping process is most useful\r
+ * for injecting additional structure into a document, without ruining the original semantic\r
+ * qualities of a document. This works by going through the first element provided (which is\r
+ * generated, on the fly, from the provided HTML) and finds the deepest descendant element within\r
+ * its structure -- it is that element that will enwrap everything else.\r
*/\r
public GQuery wrap(String html) {\r
return wrap($(html));\r
}\r
\r
/**\r
- * Wrap all the elements in the matched set into a single wrapper element.\r
- * This is different from .wrap() where each element in the matched set would\r
- * get wrapped with an element. This wrapping process is most useful for\r
- * injecting additional structure into a document, without ruining the\r
+ * Wrap all the elements in the matched set into a single wrapper element. This is different from\r
+ * .wrap() where each element in the matched set would get wrapped with an element. This wrapping\r
+ * process is most useful for injecting additional structure into a document, without ruining the\r
* original semantic qualities of a document.\r
* \r
- * This works by going through the first element provided (which is generated,\r
- * on the fly, from the provided HTML) and finds the deepest descendant\r
- * element within its structure -- it is that element that will enwrap\r
- * everything else.\r
+ * This works by going through the first element provided (which is generated, on the fly, from\r
+ * the provided HTML) and finds the deepest descendant element within its structure -- it is that\r
+ * element that will enwrap everything else.\r
*/\r
public GQuery wrapAll(Element elem) {\r
return wrapAll($(elem));\r
}\r
\r
/**\r
- * Wrap all the elements in the matched set into a single wrapper element.\r
- * This is different from .wrap() where each element in the matched set would\r
- * get wrapped with an element. This wrapping process is most useful for\r
- * injecting additional structure into a document, without ruining the\r
+ * Wrap all the elements in the matched set into a single wrapper element. This is different from\r
+ * .wrap() where each element in the matched set would get wrapped with an element. This wrapping\r
+ * process is most useful for injecting additional structure into a document, without ruining the\r
* original semantic qualities of a document.\r
* \r
- * This works by going through the first element provided (which is generated,\r
- * on the fly, from the provided HTML) and finds the deepest descendant\r
- * element within its structure -- it is that element that will enwrap\r
- * everything else.\r
+ * This works by going through the first element provided (which is generated, on the fly, from\r
+ * the provided HTML) and finds the deepest descendant element within its structure -- it is that\r
+ * element that will enwrap everything else.\r
*/\r
public GQuery wrapAll(GQuery query) {\r
if (!isEmpty()) {\r
}\r
for (Element e : wrap.elements) {\r
Node n = e;\r
- while (n.getFirstChild() != null\r
- && n.getFirstChild().getNodeType() == Node.ELEMENT_NODE) {\r
+ while (n.getFirstChild() != null && n.getFirstChild().getNodeType() == Node.ELEMENT_NODE) {\r
n = n.getFirstChild();\r
}\r
$((Element) n).append(this);\r
}\r
\r
/**\r
- * Wrap all the elements in the matched set into a single wrapper element.\r
- * This is different from .wrap() where each element in the matched set would\r
- * get wrapped with an element. This wrapping process is most useful for\r
- * injecting additional structure into a document, without ruining the\r
+ * Wrap all the elements in the matched set into a single wrapper element. This is different from\r
+ * .wrap() where each element in the matched set would get wrapped with an element. This wrapping\r
+ * process is most useful for injecting additional structure into a document, without ruining the\r
* original semantic qualities of a document.\r
* \r
- * This works by going through the first element provided (which is generated,\r
- * on the fly, from the provided HTML) and finds the deepest descendant\r
- * element within its structure -- it is that element that will enwrap\r
- * everything else.\r
+ * This works by going through the first element provided (which is generated, on the fly, from\r
+ * the provided HTML) and finds the deepest descendant element within its structure -- it is that\r
+ * element that will enwrap everything else.\r
*/\r
public GQuery wrapAll(String html) {\r
return wrapAll($(html));\r
}\r
\r
/**\r
- * Wrap the inner child contents of each matched element (including text\r
- * nodes) with an HTML structure. This wrapping process is most useful for\r
- * injecting additional structure into a document, without ruining the\r
- * original semantic qualities of a document. This works by going through the\r
- * first element provided (which is generated, on the fly, from the provided\r
- * HTML) and finds the deepest ancestor element within its structure -- it is\r
- * that element that will enwrap everything else.\r
+ * Wrap the inner child contents of each matched element (including text nodes) with an HTML\r
+ * structure. This wrapping process is most useful for injecting additional structure into a\r
+ * document, without ruining the original semantic qualities of a document. This works by going\r
+ * through the first element provided (which is generated, on the fly, from the provided HTML) and\r
+ * finds the deepest ancestor element within its structure -- it is that element that will enwrap\r
+ * everything else.\r
*/\r
public GQuery wrapInner(Element elem) {\r
return wrapInner($(elem));\r
}\r
\r
/**\r
- * Wrap the inner child contents of each matched element (including text\r
- * nodes) with an HTML structure. This wrapping process is most useful for\r
- * injecting additional structure into a document, without ruining the\r
- * original semantic qualities of a document. This works by going through the\r
- * first element provided (which is generated, on the fly, from the provided\r
- * HTML) and finds the deepest ancestor element within its structure -- it is\r
- * that element that will enwrap everything else.\r
+ * Wrap the inner child contents of each matched element (including text nodes) with an HTML\r
+ * structure. This wrapping process is most useful for injecting additional structure into a\r
+ * document, without ruining the original semantic qualities of a document. This works by going\r
+ * through the first element provided (which is generated, on the fly, from the provided HTML) and\r
+ * finds the deepest ancestor element within its structure -- it is that element that will enwrap\r
+ * everything else.\r
*/\r
public GQuery wrapInner(GQuery query) {\r
for (Element e : elements) {\r
}\r
\r
/**\r
- * Wrap the inner child contents of each matched element (including text\r
- * nodes) with an HTML structure. This wrapping process is most useful for\r
- * injecting additional structure into a document, without ruining the\r
- * original semantic qualities of a document. This works by going through the\r
- * first element provided (which is generated, on the fly, from the provided\r
- * HTML) and finds the deepest ancestor element within its structure -- it is\r
- * that element that will enwrap everything else.\r
+ * Wrap the inner child contents of each matched element (including text nodes) with an HTML\r
+ * structure. This wrapping process is most useful for injecting additional structure into a\r
+ * document, without ruining the original semantic qualities of a document. This works by going\r
+ * through the first element provided (which is generated, on the fly, from the provided HTML) and\r
+ * finds the deepest ancestor element within its structure -- it is that element that will enwrap\r
+ * everything else.\r
*/\r
public GQuery wrapInner(String html) {\r
return wrapInner($(html));\r
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 java.util.Arrays;
+import static com.google.gwt.user.client.Event.FOCUSEVENTS;
+import static com.google.gwt.user.client.Event.KEYEVENTS;
+import static com.google.gwt.user.client.Event.MOUSEEVENTS;
+import static com.google.gwt.user.client.Event.ONBLUR;
+import static com.google.gwt.user.client.Event.ONFOCUS;
+import static com.google.gwt.user.client.Event.ONKEYDOWN;
+import static com.google.gwt.user.client.Event.ONKEYPRESS;
+import static com.google.gwt.user.client.Event.ONKEYUP;
+import static com.google.gwt.user.client.Event.ONMOUSEDOWN;
+import static com.google.gwt.user.client.Event.ONMOUSEMOVE;
+import static com.google.gwt.user.client.Event.ONMOUSEOUT;
+import static com.google.gwt.user.client.Event.ONMOUSEOVER;
+import static com.google.gwt.user.client.Event.ONMOUSEUP;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.ClickEvent;
return "com.google.gwt.query.Query";
}
- public void gwtTearDown() {
- $(e).remove();
- e = null;
- }
-
public void gwtSetUp() {
if (e == null) {
testPanel = new HTML();
}
}
+ public void gwtTearDown() {
+ $(e).remove();
+ e = null;
+ }
+
+ public void testBindingWithNameSpace() {
+ String content = "<input type='text' id='test'></div>";
+ $(e).html(content);
+
+ $("#test", e)
+ .bind(
+ "focus.focusevents blur.focusevents keydown.keyevents keypress.keyevents keyup.keyevents "
+ + "mousedown.mouseevents mouseup.mouseevents mousemove.mouseevents mouseover.mouseevents "
+ + "mouseout.mouseevents", null, new Function() {
+ @Override
+ public void f() {
+ $("#test", e).val("event fired");
+ }
+ });
+
+ int allEventbits[] =
+ new int[] {
+ ONFOCUS, ONBLUR, ONKEYDOWN, ONKEYPRESS, ONKEYUP, ONMOUSEDOWN, ONMOUSEUP, ONMOUSEMOVE,
+ ONMOUSEOVER, ONMOUSEOUT};
+
+ for (int eventbits : allEventbits) {
+ $("#test", e).trigger(eventbits, 'c');
+
+ assertEquals("event fired", $("#test", e).val());
+ $("#test", e).val("");
+
+ }
+
+ // test unbind without namespace
+ $("#test", e).unbind("focus blur");
+
+ for (int eventbits : allEventbits) {
+ $("#test", e).trigger(eventbits, 'c');
+
+ if (eventbits != ONFOCUS && eventbits != ONBLUR) {
+ assertEquals("event fired", $("#test", e).val());
+ $("#test", e).val("");
+ } else {
+ assertEquals("", $("#test", e).val());
+ }
+
+ }
+
+ // test unbind event name + namespace
+ $("#test", e).unbind("keydown.keyevents keypress.keyevents keyup.keyevents");
+
+ for (int eventbits : allEventbits) {
+ $("#test", e).trigger(eventbits, 'c');
+
+ if ((eventbits & MOUSEEVENTS) == eventbits) {
+ assertEquals("event fired", $("#test", e).val());
+ $("#test", e).val("");
+ } else {
+ assertEquals("", $("#test", e).val());
+ }
+ }
+
+ // test unbind only on namespace
+ $("#test", e).unbind(".mouseevents");
+
+ for (int eventbits : allEventbits) {
+ $("#test", e).trigger(eventbits, 'c');
+
+ assertEquals("", $("#test", e).val());
+
+ }
+
+ }
+
+ public void testBindUnbindSubmitEvent() {
+ // Add a form and an iframe to the dom. The form target is the iframe
+ $(e).html(
+ "<form action='whatever' target='miframe'><input type='text' value='Hello'><input type='submit' value='Go'></form><iframe name='miframe' id='miframe' src=\"javascript:''\">");
+ testSubmitEventCont = 0;
+
+ // Add an onsubmit function to the form returning false to cancel the action
+ $("form").bind(EventsListener.ONSUBMIT, null, new Function() {
+ public boolean f(Event e) {
+ testSubmitEventCont++;
+ return false;
+ }
+ });
+
+ // Check that the onsubmit function is called and the iframe has not changed
+ $("form").submit();
+ assertEquals(1, testSubmitEventCont);
+
+ // Remove the binding
+ $("form").unbind(EventsListener.ONSUBMIT);
+
+ // Check that on submit function is not called and the form has been
+ // submitted
+ $("form").submit();
+ assertEquals(1, testSubmitEventCont);
+ }
+
+ public void testDelegate() {
+
+ $(e).html(
+ "<div class='mainDiv'><div class='subDiv'>Content 0<span>blop</span></div></div><div class='mainDiv'><div class='subDiv'>Content 0<span>blop</span></div></div>");
+
+ $(".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() {
+ @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 = "<div class='subDiv'>Content " + i + "<span>blop</span></div>";
+ $(mainDiv).append(html);
+ }
+ }
+
+ 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 testDie() {
$(e).html("<div id='div1'>content</div>");
$(".clickMe", e).live("click", new Function() {
assertEquals("yellow", $("p", e).css("color", false));
}
- /**
- * TODO: focus/blur doesn't work with HtmlUnit, investigate and report.
- */
- @DoNotRunWith({Platform.HtmlUnitLayout})
- public void testFocusBlur() {
- $(e).html("<p>Content</p>");
-
- // focus
- // FIXME: Html 2.1.0 failing but FF do not
- $("p", e).focus(new Function() {
- public void f(Element elem) {
- $(elem).css("border", "1px dotted black");
- }
- });
- $("p", e).focus();
- assertEquals("black", $("p", e).css("border-top-color", false));
- assertEquals("dotted", $("p", e).css("border-top-style", false));
- assertEquals("1px", $("p", e).css("border-top-width", false));
-
- // blur
- $("p", e).blur(new Function() {
- public void f(Element elem) {
- $(elem).css("border", "");
- }
- });
- $("p", e).blur();
- assertEquals("", $("p", e).css("border", false));
- }
-
public void testEventsPlugin() {
$(e).html("<p>Content</p>");
assertEquals("ABCabc", $("input", e).val());
}
+ /**
+ * TODO: focus/blur doesn't work with HtmlUnit, investigate and report.
+ */
+ @DoNotRunWith({Platform.HtmlUnitLayout})
+ public void testFocusBlur() {
+ $(e).html("<p>Content</p>");
+
+ // focus
+ // FIXME: Html 2.1.0 failing but FF do not
+ $("p", e).focus(new Function() {
+ public void f(Element elem) {
+ $(elem).css("border", "1px dotted black");
+ }
+ });
+ $("p", e).focus();
+ assertEquals("black", $("p", e).css("border-top-color", false));
+ assertEquals("dotted", $("p", e).css("border-top-style", false));
+ assertEquals("1px", $("p", e).css("border-top-width", false));
+
+ // blur
+ $("p", e).blur(new Function() {
+ public void f(Element elem) {
+ $(elem).css("border", "");
+ }
+ });
+ $("p", e).blur();
+ assertEquals("", $("p", e).css("border", false));
+ }
+
public void testLazyMethods() {
$(e).css(CSS.COLOR.with(RGBColor.WHITE));
assertEquals("white", $(e).css("color", false));
}
+ public void testLiveWithMultipleEvent() {
+
+ $(e).html("<div id='div1'><div id='div2'>Content 1<span id='span1'> blop</span></div></div>");
+
+ $(".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() {
+ 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 testLiveWithMultipleFunction() {
$(e).html("<div id='div1'><div id='div2'>Content 1<span id='span1'> blop</span></div></div>");
}
- public void testDelegate() {
-
- $(e).html(
- "<div class='mainDiv'><div class='subDiv'>Content 0<span>blop</span></div></div><div class='mainDiv'><div class='subDiv'>Content 0<span>blop</span></div></div>");
+ public void testMouseenterEvent() {
+ String content = "<div id='test'>blop</div>";
+ $(e).html(content);
- $(".mainDiv", e).delegate(".subDiv", "click", new Function() {
+ $("#test", e).mouseenter(new Function() {
@Override
public void f(Element e) {
- $(e).css(CSS.COLOR.with(RGBColor.RED));
+ e.setInnerText("test succeed");
}
- });
-
- $(".mainDiv", e).delegate(".subDiv", Event.ONMOUSEOVER, new Function() {
+ }).mouseover(new Function() {
@Override
- public void f(Element e) {
- $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.YELLOW));
+ public void f() {
+ fail("mouseover handler should not be fired");
}
});
- for (Element mainDiv : $(".mainDiv", e).elements()) {
- for (int i = 0; i < 3; i++) {
- String html = "<div class='subDiv'>Content " + i + "<span>blop</span></div>";
- $(mainDiv).append(html);
- }
- }
+ $("#test", e).mouseenter();
- assertEquals(8, $(".subDiv", e).length());
+ assertEquals("test succeed", $("#test", e).text());
- $("span", e).click().trigger(Event.ONMOUSEOVER);
+ // unbind the mouseover event should not remove the mouseenter
+ $("#test", e).text("blop").unbind("mouseover");
- for (Element el : $(".subDiv", e).elements()) {
- assertEquals("red", $(el).css(CSS.COLOR, false));
- assertEquals("yellow", $(el).css(CSS.BACKGROUND_COLOR, false));
- }
+ $("#test", e).mouseenter();
- }
+ assertEquals("test succeed", $("#test", e).text());
- public void testUnDelegate() {
+ $("#test", e).text("blop").unbind("mouseenter");
- $(e).html(
- "<div class='mainDiv'><div class='subDiv'>Content 0<span>blop</span></div></div><div class='mainDiv'><div class='subDiv'>Content 0<span>blop</span></div></div>");
+ $("#test", e).mouseenter();
- $(".mainDiv", e).delegate(".subDiv", "click", new Function() {
+ assertEquals("blop", $("#test", e).text());
+
+ // try the bind function
+ $("#test", e).bind("mouseenter", new Function() {
@Override
public void f(Element e) {
- $(e).css(CSS.COLOR.with(RGBColor.RED));
+ e.setInnerText("test succeed");
}
- });
-
- $(".mainDiv", e).delegate(".subDiv", Event.ONMOUSEOVER, new Function() {
+ }).mouseover(new Function() {
@Override
- public void f(Element e) {
- $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.YELLOW));
+ public void f() {
+ fail("mouseover handler should not be fired");
}
});
- for (Element mainDiv : $(".mainDiv", e).elements()) {
- for (int i = 0; i < 3; i++) {
- String html = "<div class='subDiv'>Content " + i + "<span>blop</span></div>";
- $(mainDiv).append(html);
- }
- }
-
- 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
- $(el).css(CSS.COLOR.with(RGBColor.BLACK), CSS.BACKGROUND_COLOR.with(RGBColor.WHITE));
- }
-
- $(".mainDiv", e).undelegate(".subDiv", Event.ONCLICK);
+ $("#test", e).mouseenter();
- $("span", e).click().trigger(Event.ONMOUSEOVER);
+ assertEquals("test succeed", $("#test", e).text());
- for (Element el : $(".subDiv", e).elements()) {
- assertEquals("black", $(el).css(CSS.COLOR, false));
- assertEquals("yellow", $(el).css(CSS.BACKGROUND_COLOR, false));
- // reset
- $(el).css(CSS.COLOR.with(RGBColor.BLACK), CSS.BACKGROUND_COLOR.with(RGBColor.WHITE));
- }
+ $("#test", e).text("blop").unbind("mouseenter");
- $(".mainDiv", e).undelegate(".subDiv", "mouseover");
+ $("#test", e).mouseenter();
- $("span", e).click().trigger(Event.ONMOUSEOVER);
+ assertEquals("blop", $("#test", e).text());
- 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(
- "<div class='mainDiv'><div class='subDiv'>Content 0<span>blop</span></div></div><div class='mainDiv'><div class='subDiv'>Content 0<span>blop</span></div></div>");
+ public void testMouseleaveEvent() {
+ String content = "<div id='test'>blop</div>";
+ $(e).html(content);
- $(".mainDiv", e).delegate(".subDiv", "click", new Function() {
+ $("#test", e).mouseleave(new Function() {
@Override
public void f(Element e) {
- $(e).css(CSS.COLOR.with(RGBColor.RED));
+ e.setInnerText("test succeed");
}
- });
-
- $(".mainDiv", e).delegate(".subDiv", Event.ONMOUSEOVER, new Function() {
+ }).mouseout(new Function() {
@Override
- public void f(Element e) {
- $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.YELLOW));
+ public void f() {
+ fail("mouseout handler should not be fired");
}
});
- for (Element mainDiv : $(".mainDiv", e).elements()) {
- for (int i = 0; i < 3; i++) {
- String html = "<div class='subDiv'>Content " + i + "<span>blop</span></div>";
- $(mainDiv).append(html);
- }
- }
-
- assertEquals(8, $(".subDiv", e).length());
+ $("#test", e).mouseleave();
- $("span", e).click().trigger(Event.ONMOUSEOVER);
+ assertEquals("test succeed", $("#test", e).text());
- for (Element el : $(".subDiv", e).elements()) {
- assertEquals("red", $(el).css(CSS.COLOR, false));
- assertEquals("yellow", $(el).css(CSS.BACKGROUND_COLOR, false));
- // reset
- $(el).css(CSS.COLOR.with(RGBColor.BLACK), CSS.BACKGROUND_COLOR.with(RGBColor.WHITE));
- }
+ // unbind the mouseout event should not remove the mouseleave
+ $("#test", e).text("blop").unbind("mouseout");
- $(".mainDiv", e).undelegate(".subDiv");
+ $("#test", e).mouseleave();
- $("span", e).click().trigger(Event.ONMOUSEOVER);
+ assertEquals("test succeed", $("#test", e).text());
- for (Element el : $(".subDiv", e).elements()) {
- assertEquals("black", $(el).css(CSS.COLOR, false));
- assertEquals("white", $(el).css(CSS.BACKGROUND_COLOR, false));
- }
- }
+ $("#test", e).text("blop").unbind("mouseleave");
- public void testUnDelegateAll2() {
+ $("#test", e).mouseleave();
- $(e).html(
- "<div class='mainDiv'><div class='subDiv'>Content 0<span>blop</span></div></div><div class='mainDiv'><div class='subDiv'>Content 0<span>blop</span></div></div>");
+ assertEquals("blop", $("#test", e).text());
- $(".mainDiv", e).delegate(".subDiv", "click", new Function() {
+ // try the bind method directly
+ $("#test", e).bind("mouseleave", new Function() {
@Override
public void f(Element e) {
- $(e).css(CSS.COLOR.with(RGBColor.RED));
+ e.setInnerText("test succeed");
+ }
+ }).mouseout(new Function() {
+ @Override
+ public void f() {
+ fail("mouseout handler should not be fired");
}
});
- $(".mainDiv", e).delegate(".subDiv", Event.ONMOUSEOVER, new Function() {
+ $("#test", e).mouseleave();
+
+ assertEquals("test succeed", $("#test", e).text());
+
+ $("#test", e).text("blop").unbind("mouseleave");
+
+ $("#test", e).mouseleave();
+
+ assertEquals("blop", $("#test", e).text());
+
+ }
+
+ public void testMultipleEvents() {
+ String content = "<input type='text' id='test'></div>";
+ $(e).html(content);
+
+ $("#test", e).bind(FOCUSEVENTS | KEYEVENTS | MOUSEEVENTS, null, new Function() {
@Override
- public void f(Element e) {
- $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.YELLOW));
+ public void f() {
+ $("#test", e).val("event fired");
}
});
- for (Element mainDiv : $(".mainDiv", e).elements()) {
- for (int i = 0; i < 3; i++) {
- String html = "<div class='subDiv'>Content " + i + "<span>blop</span></div>";
- $(mainDiv).append(html);
+ int allEventbits[] =
+ new int[] {
+ ONFOCUS, ONBLUR, ONKEYDOWN, ONKEYPRESS, ONKEYUP, ONMOUSEDOWN, ONMOUSEUP, ONMOUSEMOVE,
+ ONMOUSEOVER, ONMOUSEOUT};
+
+ for (int eventbits : allEventbits) {
+ $("#test", e).trigger(eventbits, 'c');
+
+ assertEquals("event fired", $("#test", e).val());
+ $("#test", e).val("");
+
+ }
+
+ // unbind focus event
+ $("#test", e).unbind(FOCUSEVENTS);
+
+ for (int eventbits : allEventbits) {
+ $("#test", e).trigger(eventbits, 'c');
+
+ if (eventbits == ONBLUR || eventbits == ONFOCUS) {
+ assertEquals("", $("#test", e).val());
+ } else {
+ assertEquals("event fired", $("#test", e).val());
+ $("#test", e).val("");
}
+
}
- assertEquals(8, $(".subDiv", e).length());
+ // unbind focus event
+ $("#test", e).unbind(KEYEVENTS);
- $("span", e).click().trigger(Event.ONMOUSEOVER);
+ for (int eventbits : allEventbits) {
+ $("#test", e).trigger(eventbits, 'c');
+
+ if ((eventbits & MOUSEEVENTS) == eventbits) {
+ assertEquals("event fired", $("#test", e).val());
+ $("#test", e).val("");
+ } else {
+ assertEquals("", $("#test", e).val());
+ }
- for (Element el : $(".subDiv", e).elements()) {
- assertEquals("red", $(el).css(CSS.COLOR, false));
- assertEquals("yellow", $(el).css(CSS.BACKGROUND_COLOR, false));
- // reset
- $(el).css(CSS.COLOR.with(RGBColor.BLACK), CSS.BACKGROUND_COLOR.with(RGBColor.WHITE));
}
- $(".mainDiv", e).undelegate();
+ // unbind some mouse events
+ $("#test", e).unbind(ONMOUSEDOWN | ONMOUSEUP | ONMOUSEMOVE | ONMOUSEOVER);
- $("span", e).click().trigger(Event.ONMOUSEOVER);
+ for (int eventbits : allEventbits) {
+ $("#test", e).trigger(eventbits, 'c');
- for (Element el : $(".subDiv", e).elements()) {
- assertEquals("black", $(el).css(CSS.COLOR, false));
- assertEquals("white", $(el).css(CSS.BACKGROUND_COLOR, false));
+ if (eventbits == ONMOUSEOUT) {
+ assertEquals("event fired", $("#test", e).val());
+ $("#test", e).val("");
+ } else {
+ assertEquals("", $("#test", e).val());
+ }
+
+ }
+
+ // unbind one event
+ $("#test", e).unbind(ONMOUSEOUT);
+
+ for (int eventbits : allEventbits) {
+ $("#test", e).trigger(eventbits, 'c');
+ assertEquals("", $("#test", e).val());
}
+
}
- public void testLiveWithMultipleEvent() {
+ public void testMultipleEventsString() {
+ String content = "<input type='text' id='test'></div>";
+ $(e).html(content);
- $(e).html("<div id='div1'><div id='div2'>Content 1<span id='span1'> blop</span></div></div>");
+ int allEventbits[] =
+ new int[] {
+ ONFOCUS, ONBLUR, ONKEYDOWN, ONKEYPRESS, ONKEYUP, ONMOUSEDOWN, ONMOUSEUP, ONMOUSEMOVE,
+ ONMOUSEOVER, ONMOUSEOUT};
- $(".myClass", e).live("click mouseover", new Function() {
- public void f(Element e) {
- $(e).css(CSS.COLOR.with(RGBColor.RED));
- }
- });
+ $("#test", e).bind(
+ "focus blur keydown keypress keyup mousedown mouseup mousemove mouseover mouseout", null,
+ new Function() {
+ @Override
+ public void f() {
+ $("#test", e).val("event fired");
+ }
+ });
- $("#div1", e).addClass("myClass");
+ for (int eventbits : allEventbits) {
+ $("#test", e).trigger(eventbits, 'c');
- $("#div1", e).click();
+ assertEquals("event fired", $("#test", e).val());
+ $("#test", e).val("");
- assertEquals("red", $("#div1", e).css(CSS.COLOR, false));
+ }
- $("#div1", e).css(CSS.COLOR.with(RGBColor.BLACK));
+ $("#test", e).unbind("focus blur keydown keypress keyup");
- $("#div1", e).trigger(Event.ONMOUSEOVER);
- assertEquals("red", $("#div1", e).css(CSS.COLOR, false));
+ for (int eventbits : allEventbits) {
+ $("#test", e).trigger(eventbits, 'c');
- $(".myClass2", e).live(Event.ONCLICK | Event.ONMOUSEDOWN, new Function() {
- public void f(Element e) {
- $(e).css(CSS.COLOR.with(RGBColor.YELLOW));
+ if ((eventbits & MOUSEEVENTS) == eventbits) {
+ assertEquals("event fired", $("#test", e).val());
+ $("#test", e).val("");
+ } else {
+ assertEquals("", $("#test", e).val());
}
- });
-
- $("#div2", e).addClass("myClass2");
+ }
- $("#div2", e).click();
+ $("#test", e).unbind("mousedown mouseup mousemove mouseover").unbind("mouseout");
- assertEquals("yellow", $("#div2", e).css(CSS.COLOR, false));
+ for (int eventbits : allEventbits) {
+ $("#test", e).trigger(eventbits, 'c');
- $("#div2", e).css(CSS.COLOR.with(RGBColor.BLACK));
+ assertEquals("", $("#test", e).val());
- $("#div2", e).trigger(Event.ONMOUSEDOWN);
- assertEquals("yellow", $("#div2", e).css(CSS.COLOR, false));
+ }
}
public void testNamedBinding() {
$(e).html("<p>Content</p>");
- $("p", e, Events.Events).bind("click.first.namespace", null, new Function() {
- ;
+ $("p", e, Events.Events).bind("click.first.namespace", 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", 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", "red",new Function() {
public void f(Element elem) {
$(elem).css(CSS.FONT_SIZE.with(Length.px(24)));
+
+ assertEquals("red", getData()[0]);
}
});
$("p", e, Events.Events).trigger(Event.ONCLICK);
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("<div id=ra></div>");
GQuery g = $("#ra", e);
g.resize();
}
- public void testBindUnbindSubmitEvent() {
- // Add a form and an iframe to the dom. The form target is the iframe
- $(e).html(
- "<form action='whatever' target='miframe'><input type='text' value='Hello'><input type='submit' value='Go'></form><iframe name='miframe' id='miframe' src=\"javascript:''\">");
- testSubmitEventCont = 0;
+ @DoNotRunWith({Platform.HtmlUnitLayout})
+ public void testResizeWindowEvent() {
+ GQuery w = $(GQuery.window);
- // Add an onsubmit function to the form returning false to cancel the action
- $("form").bind(EventsListener.ONSUBMIT, null, new Function() {
- public boolean f(Event e) {
- testSubmitEventCont++;
- return false;
+ delayTestFinish(100);
+ w.bind("resize", null, new Function() {
+ public void f(Element e) {
+ finishTest();
}
});
- // Check that the onsubmit function is called and the iframe has not changed
- $("form").submit();
- assertEquals(1, testSubmitEventCont);
-
- // Remove the binding
- $("form").unbind(EventsListener.ONSUBMIT);
-
- // Check that on submit function is not called and the form has been
- // submitted
- $("form").submit();
- assertEquals(1, testSubmitEventCont);
+ Window.resizeTo(w.width(), w.height() + 100);
}
/**
assertEquals("black", $("p").css("color", false));
}
- public void testWidgetEvents() {
- final Button b = new Button("click-me");
- b.addClickHandler(new ClickHandler() {
- public void onClick(ClickEvent event) {
- b.getElement().getStyle().setBackgroundColor("black");
- }
- });
- RootPanel.get().add(b);
- $(b).click(lazy().css(CSS.COLOR.with(RGBColor.RED)).done());
-
- $(b).click();
- assertEquals("red", $("button").css("color", false));
- assertEquals("black", $("button").css("background-color", false));
- RootPanel.get().remove(b);
+ public void testUnDelegate() {
- $(e).append($(b));
- $(b).css(CSS.COLOR.with(RGBColor.YELLOW), CSS.BACKGROUND_COLOR.with(RGBColor.BLUE));
- $(b).click();
- assertEquals("red", $("button").css("color", false));
- assertEquals("black", $("button").css("background-color", false));
- }
+ $(e).html(
+ "<div class='mainDiv'><div class='subDiv'>Content 0<span>blop</span></div></div><div class='mainDiv'><div class='subDiv'>Content 0<span>blop</span></div></div>");
- public void testMultipleEvents() {
- String content = "<input type='text' id='test'></div>";
- $(e).html(content);
+ $(".mainDiv", e).delegate(".subDiv", "click", new Function() {
+ @Override
+ public void f(Element e) {
+ $(e).css(CSS.COLOR.with(RGBColor.RED));
+ }
+ });
- $("#test", e).bind(FOCUSEVENTS | KEYEVENTS | MOUSEEVENTS, null, new Function() {
+ $(".mainDiv", e).delegate(".subDiv", Event.ONMOUSEOVER, new Function() {
@Override
- public void f() {
- $("#test", e).val("event fired");
+ public void f(Element e) {
+ $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.YELLOW));
}
});
- int allEventbits[] =
- new int[] {
- ONFOCUS, ONBLUR, ONKEYDOWN, ONKEYPRESS, ONKEYUP, ONMOUSEDOWN, ONMOUSEUP, ONMOUSEMOVE,
- ONMOUSEOVER, ONMOUSEOUT};
+ for (Element mainDiv : $(".mainDiv", e).elements()) {
+ for (int i = 0; i < 3; i++) {
+ String html = "<div class='subDiv'>Content " + i + "<span>blop</span></div>";
+ $(mainDiv).append(html);
+ }
+ }
- for (int eventbits : allEventbits) {
- $("#test", e).trigger(eventbits, 'c');
+ assertEquals(8, $(".subDiv", e).length());
- assertEquals("event fired", $("#test", e).val());
- $("#test", e).val("");
+ $("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
+ $(el).css(CSS.COLOR.with(RGBColor.BLACK), CSS.BACKGROUND_COLOR.with(RGBColor.WHITE));
}
- // unbind focus event
- $("#test", e).unbind(FOCUSEVENTS);
-
- for (int eventbits : allEventbits) {
- $("#test", e).trigger(eventbits, 'c');
+ $(".mainDiv", e).undelegate(".subDiv", Event.ONCLICK);
- if (eventbits == ONBLUR || eventbits == ONFOCUS) {
- assertEquals("", $("#test", e).val());
- } else {
- assertEquals("event fired", $("#test", e).val());
- $("#test", e).val("");
- }
+ $("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
+ $(el).css(CSS.COLOR.with(RGBColor.BLACK), CSS.BACKGROUND_COLOR.with(RGBColor.WHITE));
}
- // unbind focus event
- $("#test", e).unbind(KEYEVENTS);
-
- for (int eventbits : allEventbits) {
- $("#test", e).trigger(eventbits, 'c');
+ $(".mainDiv", e).undelegate(".subDiv", "mouseover");
- if ((eventbits & MOUSEEVENTS) == eventbits) {
- assertEquals("event fired", $("#test", e).val());
- $("#test", e).val("");
- } else {
- assertEquals("", $("#test", e).val());
- }
+ $("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));
}
+ }
- // unbind some mouse events
- $("#test", e).unbind(ONMOUSEDOWN | ONMOUSEUP | ONMOUSEMOVE | ONMOUSEOVER);
+ public void testUnDelegateAll() {
- for (int eventbits : allEventbits) {
- $("#test", e).trigger(eventbits, 'c');
+ $(e).html(
+ "<div class='mainDiv'><div class='subDiv'>Content 0<span>blop</span></div></div><div class='mainDiv'><div class='subDiv'>Content 0<span>blop</span></div></div>");
- if (eventbits == ONMOUSEOUT) {
- assertEquals("event fired", $("#test", e).val());
- $("#test", e).val("");
- } else {
- assertEquals("", $("#test", e).val());
+ $(".mainDiv", e).delegate(".subDiv", "click", new Function() {
+ @Override
+ public void f(Element e) {
+ $(e).css(CSS.COLOR.with(RGBColor.RED));
}
+ });
- }
-
- // unbind one event
- $("#test", e).unbind(ONMOUSEOUT);
+ $(".mainDiv", e).delegate(".subDiv", Event.ONMOUSEOVER, new Function() {
+ @Override
+ public void f(Element e) {
+ $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.YELLOW));
+ }
+ });
- for (int eventbits : allEventbits) {
- $("#test", e).trigger(eventbits, 'c');
- assertEquals("", $("#test", e).val());
+ for (Element mainDiv : $(".mainDiv", e).elements()) {
+ for (int i = 0; i < 3; i++) {
+ String html = "<div class='subDiv'>Content " + i + "<span>blop</span></div>";
+ $(mainDiv).append(html);
+ }
}
- }
-
- public void testMultipleEventsString() {
- String content = "<input type='text' id='test'></div>";
- $(e).html(content);
+ assertEquals(8, $(".subDiv", e).length());
- int allEventbits[] =
- new int[] {
- ONFOCUS, ONBLUR, ONKEYDOWN, ONKEYPRESS, ONKEYUP, ONMOUSEDOWN, ONMOUSEUP, ONMOUSEMOVE,
- ONMOUSEOVER, ONMOUSEOUT};
+ $("span", e).click().trigger(Event.ONMOUSEOVER);
- $("#test", e).bind(
- "focus blur keydown keypress keyup mousedown mouseup mousemove mouseover mouseout", null,
- new Function() {
- @Override
- public void f() {
- $("#test", e).val("event fired");
- }
- });
+ for (Element el : $(".subDiv", e).elements()) {
+ assertEquals("red", $(el).css(CSS.COLOR, false));
+ assertEquals("yellow", $(el).css(CSS.BACKGROUND_COLOR, false));
+ // reset
+ $(el).css(CSS.COLOR.with(RGBColor.BLACK), CSS.BACKGROUND_COLOR.with(RGBColor.WHITE));
+ }
- for (int eventbits : allEventbits) {
- $("#test", e).trigger(eventbits, 'c');
+ $(".mainDiv", e).undelegate(".subDiv");
- assertEquals("event fired", $("#test", e).val());
- $("#test", e).val("");
+ $("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));
}
+ }
- $("#test", e).unbind("focus blur keydown keypress keyup");
+ public void testUnDelegateAll2() {
- for (int eventbits : allEventbits) {
- $("#test", e).trigger(eventbits, 'c');
+ $(e).html(
+ "<div class='mainDiv'><div class='subDiv'>Content 0<span>blop</span></div></div><div class='mainDiv'><div class='subDiv'>Content 0<span>blop</span></div></div>");
- if ((eventbits & MOUSEEVENTS) == eventbits) {
- assertEquals("event fired", $("#test", e).val());
- $("#test", e).val("");
- } else {
- assertEquals("", $("#test", e).val());
+ $(".mainDiv", e).delegate(".subDiv", "click", new Function() {
+ @Override
+ public void f(Element e) {
+ $(e).css(CSS.COLOR.with(RGBColor.RED));
}
- }
-
- $("#test", e).unbind("mousedown mouseup mousemove mouseover").unbind("mouseout");
-
- for (int eventbits : allEventbits) {
- $("#test", e).trigger(eventbits, 'c');
+ });
- assertEquals("", $("#test", e).val());
+ $(".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 = "<div class='subDiv'>Content " + i + "<span>blop</span></div>";
+ $(mainDiv).append(html);
+ }
}
- }
-
- public void testBindingWithNameSpace() {
- String content = "<input type='text' id='test'></div>";
- $(e).html(content);
+ assertEquals(8, $(".subDiv", e).length());
- $("#test", e)
- .bind(
- "focus.focusevents blur.focusevents keydown.keyevents keypress.keyevents keyup.keyevents "
- + "mousedown.mouseevents mouseup.mouseevents mousemove.mouseevents mouseover.mouseevents "
- + "mouseout.mouseevents", null, new Function() {
- @Override
- public void f() {
- $("#test", e).val("event fired");
- }
- });
-
- int allEventbits[] =
- new int[] {
- ONFOCUS, ONBLUR, ONKEYDOWN, ONKEYPRESS, ONKEYUP, ONMOUSEDOWN, ONMOUSEUP, ONMOUSEMOVE,
- ONMOUSEOVER, ONMOUSEOUT};
+ $("span", e).click().trigger(Event.ONMOUSEOVER);
- for (int eventbits : allEventbits) {
- $("#test", e).trigger(eventbits, 'c');
+ for (Element el : $(".subDiv", e).elements()) {
+ assertEquals("red", $(el).css(CSS.COLOR, false));
+ assertEquals("yellow", $(el).css(CSS.BACKGROUND_COLOR, false));
+ // reset
+ $(el).css(CSS.COLOR.with(RGBColor.BLACK), CSS.BACKGROUND_COLOR.with(RGBColor.WHITE));
+ }
- assertEquals("event fired", $("#test", e).val());
- $("#test", e).val("");
+ $(".mainDiv", e).undelegate();
- }
-
- //test unbind without namespace
- $("#test", e).unbind("focus blur");
-
- for (int eventbits : allEventbits) {
- $("#test", e).trigger(eventbits, 'c');
-
- if (eventbits != ONFOCUS && eventbits != ONBLUR){
- assertEquals("event fired", $("#test", e).val());
- $("#test", e).val("");
- }else{
- assertEquals("", $("#test", e).val());
- }
+ $("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));
}
-
- //test unbind event name + namespace
- $("#test", e).unbind("keydown.keyevents keypress.keyevents keyup.keyevents");
-
- for (int eventbits : allEventbits) {
- $("#test", e).trigger(eventbits, 'c');
+ }
- if ((eventbits & MOUSEEVENTS) == eventbits) {
- assertEquals("event fired", $("#test", e).val());
- $("#test", e).val("");
- } else {
- assertEquals("", $("#test", e).val());
+ public void testWidgetEvents() {
+ final Button b = new Button("click-me");
+ b.addClickHandler(new ClickHandler() {
+ public void onClick(ClickEvent event) {
+ b.getElement().getStyle().setBackgroundColor("black");
}
- }
-
- //test unbind only on namespace
- $("#test", e).unbind(".mouseevents");
-
- for (int eventbits : allEventbits) {
- $("#test", e).trigger(eventbits, 'c');
-
- assertEquals("", $("#test", e).val());
+ });
+ RootPanel.get().add(b);
+ $(b).click(lazy().css(CSS.COLOR.with(RGBColor.RED)).done());
- }
+ $(b).click();
+ assertEquals("red", $("button").css("color", false));
+ assertEquals("black", $("button").css("background-color", false));
+ RootPanel.get().remove(b);
+ $(e).append($(b));
+ $(b).css(CSS.COLOR.with(RGBColor.YELLOW), CSS.BACKGROUND_COLOR.with(RGBColor.BLUE));
+ $(b).click();
+ assertEquals("red", $("button").css("color", false));
+ assertEquals("black", $("button").css("background-color", false));
}
}