aboutsummaryrefslogtreecommitdiffstats
path: root/gwtquery-core
diff options
context:
space:
mode:
authorJulien Dramaix <julien.dramaix@gmail.com>2012-08-22 22:01:02 +0000
committerJulien Dramaix <julien.dramaix@gmail.com>2012-08-22 22:01:02 +0000
commita428b4a1b58a126a3e8190a04cd129543b96d895 (patch)
tree631634cecf5660ed53466f67c610773829b6a9bd /gwtquery-core
parentfef084488982ea32cd56b58857c4c7cac42fa089 (diff)
downloadgwtquery-a428b4a1b58a126a3e8190a04cd129543b96d895.tar.gz
gwtquery-a428b4a1b58a126a3e8190a04cd129543b96d895.zip
implements mouseleave mouseenter special events + bug fixing on event mechanism
Diffstat (limited to 'gwtquery-core')
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java2257
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java277
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java340
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/GqEvent.java9
-rw-r--r--gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java909
5 files changed, 1965 insertions, 1827 deletions
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java
index 134e84cb..7bbae11e 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java
@@ -1,16 +1,14 @@
/*
* Copyright 2011, The gwtquery team.
*
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.gwt.query.client;
@@ -76,7 +74,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
private enum DomMan {
AFTER, APPEND, BEFORE, PREPEND;
}
-
+
/**
* A POJO used to store the top/left CSS positioning values of an element.
*/
@@ -99,16 +97,16 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Class used internally to create DOM element from html snippet
+ * Class used internally to create DOM element from html snippet
*/
private static class TagWrapper {
public static final TagWrapper DEFAULT = new TagWrapper(0, "", "");
- private String postWrap;
+ private String postWrap;
private String preWrap;
private int wrapDepth;
-
+
public TagWrapper(int wrapDepth, String preWrap, String postWrap) {
- this.wrapDepth=wrapDepth;
+ this.wrapDepth = wrapDepth;
this.postWrap = postWrap;
this.preWrap = preWrap;
}
@@ -123,17 +121,17 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* The body element in the current page.
*/
public static final BodyElement body = Document.get().getBody();
-
+
/**
* Object to store element data.
*/
protected static JsCache dataCache = null;
-
+
/**
* The document element in the current page.
*/
public static final Document document = Document.get();
-
+
/**
* Static reference Effects plugin
*/
@@ -153,14 +151,15 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* A static reference to the GQuery class.
*/
public static Class<GQuery> GQUERY = GQuery.class;
-
+
private static final String OLD_DATA_PREFIX = "old-";
private static JsMap<Class<? extends GQuery>, Plugin<? extends GQuery>> plugins;
// Sizzle POS regex : usefull in some methods
// TODO: Share this static with SelectorEngineSizzle
- private static final String POS_REGEX = ":(nth|eq|gt|lt|first|last|even|odd)(?:\\((\\d*)\\))?(?=[^\\-]|$)";
+ private static final String POS_REGEX =
+ ":(nth|eq|gt|lt|first|last|even|odd)(?:\\((\\d*)\\))?(?=[^\\-]|$)";
/**
* Implementation class used for style manipulations.
@@ -173,23 +172,23 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* Static reference to the Widgets plugin
*/
public static Class<Widgets> Widgets = com.google.gwt.query.client.plugins.Widgets.Widgets;
-
+
/**
* The window object.
*/
public static final Element window = window();
-
+
private static Element windowData = null;
-
+
private static JsNamedArray<TagWrapper> wrapperMap;
-
+
/**
* Create an empty GQuery object.
*/
public static GQuery $() {
return new GQuery(JsNodeArray.create());
}
-
+
/**
* Wrap a GQuery around an existing element.
*/
@@ -201,8 +200,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* Wrap a GQuery around an event's target element.
*/
public static GQuery $(Event event) {
- return event == null ? $()
- : $((Element) event.getCurrentEventTarget().cast());
+ return event == null ? $() : $((Element) event.getCurrentEventTarget().cast());
}
/**
@@ -211,19 +209,16 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
public static GQuery $(Function f) {
return $(f.getElement());
}
-
+
/**
* Wrap a GQuery around an existing element, event, node or nodelist.
*/
public static GQuery $(JavaScriptObject e) {
- return
- JsUtils.isWindow(e) ? GQuery.$(e.<Element>cast()) :
- JsUtils.isElement(e) ? GQuery.$(e.<Element>cast()) :
- JsUtils.isEvent(e) ? GQuery.$(e.<Event>cast()) :
- JsUtils.isNodeList(e) ? GQuery.$(e.<NodeList<Element>>cast()) :
- $();
+ return JsUtils.isWindow(e) ? GQuery.$(e.<Element> cast()) : JsUtils.isElement(e) ? GQuery.$(e
+ .<Element> cast()) : JsUtils.isEvent(e) ? GQuery.$(e.<Event> cast()) : JsUtils
+ .isNodeList(e) ? GQuery.$(e.<NodeList<Element>> cast()) : $();
}
-
+
/**
* Create a new GQuery given a list of nodes, elements or widgets
*/
@@ -245,7 +240,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* Wrap a GQuery around an existing node.
*/
public static GQuery $(Node n) {
- return $((Element)n);
+ return $((Element) n);
}
/**
@@ -256,20 +251,18 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * This function accepts a string containing a CSS selector which is then used
- * to match a set of elements, or it accepts raw HTML creating a GQuery
- * element containing those elements.
- * Xpath selector is supported in browsers with native xpath engine.
+ * This function accepts a string containing a CSS selector which is then used to match a set of
+ * elements, or it accepts raw HTML creating a GQuery element containing those elements. Xpath
+ * selector is supported in browsers with native xpath engine.
*/
public static GQuery $(String selectorOrHtml) {
return $(selectorOrHtml, document);
}
/**
- * This function accepts a string containing a CSS selector which is then used
- * to match a set of elements, or it accepts raw HTML creating a GQuery
- * element containing those elements. The second parameter is is a class
- * reference to a plugin to be used.
+ * This function accepts a string containing a CSS selector which is then used to match a set of
+ * elements, or it accepts raw HTML creating a GQuery element containing those elements. The
+ * second parameter is is a class reference to a plugin to be used.
*
* Xpath selector is supported in browsers with native xpath engine.
*/
@@ -278,11 +271,10 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * This function accepts a string containing a CSS selector which is then used
- * to match a set of elements, or it accepts raw HTML creating a GQuery
- * element containing those elements. The second parameter is the context to
- * use for the selector, or the document where the new elements will be
- * created.
+ * This function accepts a string containing a CSS selector which is then used to match a set of
+ * elements, or it accepts raw HTML creating a GQuery element containing those elements. The
+ * second parameter is the context to use for the selector, or the document where the new elements
+ * will be created.
*
* Xpath selector is supported in browsers with native xpath engine.
*/
@@ -297,21 +289,19 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
return new GQuery().select(selectorOrHtml, ctx);
}
- /**
- * This function accepts a string containing a CSS selector which is then used
- * to match a set of elements, or it accepts raw HTML creating a GQuery
- * element containing those elements. The second parameter is the context to
- * use for the selector. The third parameter is the class plugin to use.
+ /**
+ * This function accepts a string containing a CSS selector which is then used to match a set of
+ * elements, or it accepts raw HTML creating a GQuery element containing those elements. The
+ * second parameter is the context to use for the selector. The third parameter is the class
+ * plugin to use.
*
* Xpath selector is supported in browsers with native xpath engine.
*/
@SuppressWarnings("unchecked")
- public static <T extends GQuery> T $(String selector, Node context,
- Class<T> plugin) {
+ public static <T extends GQuery> T $(String selector, Node context, Class<T> plugin) {
try {
if (plugins != null) {
- T gquery = (T) plugins.get(plugin).init(
- new GQuery().select(selector, context));
+ T gquery = (T) plugins.get(plugin).init(new GQuery().select(selector, context));
return gquery;
}
throw new RuntimeException("No plugin for class " + plugin);
@@ -320,12 +310,11 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
}
- /**
- * This function accepts a string containing a CSS selector which is then used
- * to match a set of elements, or it accepts raw HTML creating a GQuery
- * element containing those elements. The second parameter is the context to
- * use for the selector, or the document where the new elements will be
- * created.
+ /**
+ * This function accepts a string containing a CSS selector which is then used to match a set of
+ * elements, or it accepts raw HTML creating a GQuery element containing those elements. The
+ * second parameter is the context to use for the selector, or the document where the new elements
+ * will be created.
*
* Xpath selector is supported in browsers with native xpath engine.
*/
@@ -334,19 +323,18 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * This function accepts a string containing a CSS selector which is then used
- * to match a set of elements, or it accepts raw HTML creating a GQuery
- * element containing those elements. The second parameter is the context to
- * use for the selector. The third parameter is the class plugin to use.
- *
+ * This function accepts a string containing a CSS selector which is then used to match a set of
+ * elements, or it accepts raw HTML creating a GQuery element containing those elements. The
+ * second parameter is the context to use for the selector. The third parameter is the class
+ * plugin to use.
+ *
* Xpath selector is supported in browsers with native xpath engine.
*/
- public static <T extends GQuery> T $(String selector, Widget context,
- Class<T> plugin) {
+ public static <T extends GQuery> T $(String selector, Widget context, Class<T> plugin) {
return $(selector, context.getElement(), plugin);
}
- /**
+ /**
* wraps a GQuery or a plugin object
*/
public static <T extends GQuery> T $(T gq) {
@@ -370,43 +358,43 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
/**
* Perform an ajax request to the server.
*/
- public static void ajax(Properties p) {
- ajax(p);
- }
+ public static void ajax(Properties p) {
+ ajax(p);
+ }
/**
* Perform an ajax request to the server.
*/
- public static void ajax(Settings settings) {
- Ajax.ajax(settings);
- }
+ public static void ajax(Settings settings) {
+ Ajax.ajax(settings);
+ }
/**
* Perform an ajax request to the server.
*/
- public static void ajax(String url, Settings settings) {
- Ajax.ajax(url, settings);
- }
+ public static void ajax(String url, Settings settings) {
+ Ajax.ajax(url, settings);
+ }
@SuppressWarnings("unchecked")
protected static GQuery cleanHtmlString(String elem, Document doc) {
-
+
String tag = tagNameRegex.exec(elem).get(1);
-
- if (tag == null){
- throw new RuntimeException("HTML snippet doesn't contain any tag");
+
+ if (tag == null) {
+ throw new RuntimeException("HTML snippet doesn't contain any tag");
}
-
- if (wrapperMap == null){
+
+ if (wrapperMap == null) {
initWrapperMap();
}
-
+
TagWrapper wrapper = wrapperMap.get(tag.toLowerCase());
-
- if (wrapper == null){
+
+ if (wrapper == null) {
wrapper = TagWrapper.DEFAULT;
}
-
+
// TODO: fix IE link tag serialization
// TODO: fix IE <script> tag
Element div = doc.createDivElement();
@@ -421,18 +409,18 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Return true if the element b is contained in a.
- */
- public static boolean contains(Element a, Element b) {
- return engine.contains(a, b);
- }
+ * Return true if the element b is contained in a.
+ */
+ public static boolean contains(Element a, Element b) {
+ return engine.contains(a, b);
+ }
/**
- * Get the element data matching the key.
- */
- public static Object data(Element e, String key) {
- return GQuery.data(e, key, null);
- }
+ * Get the element data matching the key.
+ */
+ public static Object data(Element e, String key) {
+ return GQuery.data(e, key, null);
+ }
protected static <S> Object data(Element item, String name, S value) {
if (dataCache == null) {
@@ -454,44 +442,44 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
return name != null ? d.get(name) : id;
}
-
+
/**
* Execute a function around each object
*/
- public static void each(JsArrayMixed objects, Function f) {
- for (int i = 0, l = objects.length(); i < l; i++) {
- f.f(i, objects.getObject(i));
- }
- }
+ public static void each(JsArrayMixed objects, Function f) {
+ for (int i = 0, l = objects.length(); i < l; i++) {
+ f.f(i, objects.getObject(i));
+ }
+ }
/**
- * Execute a function around each object
- */
- public static <T> void each(List<T> objects, Function f) {
- for (int i = 0, l = objects.size(); i < l; i++) {
- f.f(i, objects.get(i));
- }
- }
+ * Execute a function around each object
+ */
+ public static <T> void each(List<T> objects, Function f) {
+ for (int i = 0, l = objects.size(); i < l; i++) {
+ f.f(i, objects.get(i));
+ }
+ }
/**
* Execute a function around each object
*/
- public static <T> void each(T[] objects, Function f) {
- for (int i = 0, l = objects.length; i < l; i++) {
- f.f(i, objects[i]);
- }
- }
+ public static <T> void each(T[] objects, Function f) {
+ for (int i = 0, l = objects.length; i < l; i++) {
+ f.f(i, objects[i]);
+ }
+ }
/**
* Perform an ajax request to the server using GET.
*/
- public static void get(String url, Properties data, final Function onSuccess) {
- Ajax.get(url, data, onSuccess);
- }
+ public static void get(String url, Properties data, final Function onSuccess) {
+ Ajax.get(url, data, onSuccess);
+ }
/**
- * We will use the fact as GWT use the widget itself as EventListener ! If no
- * Widget associated with the element, this method returns null.
+ * We will use the fact as GWT use the widget itself as EventListener ! If no Widget associated
+ * with the element, this method returns null.
*/
protected static Widget getAssociatedWidget(Element e) {
try {
@@ -512,40 +500,37 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
}
} catch (Exception e2) {
- // Some times this code could raise an exception.
+ // Some times this code could raise an exception.
// We do not want GQuery to fail, but in dev-move we log the error.
e2.printStackTrace();
}
return null;
}
- private static AttributeImpl getAttributeImpl(){
- if (attributeImpl == null){
+ private static AttributeImpl getAttributeImpl() {
+ if (attributeImpl == null) {
attributeImpl = GWT.create(AttributeImpl.class);
}
return attributeImpl;
}
-
+
/**
- * Perform an ajax request to the server using POST and
- * parsing the json response.
- */
- public static void getJSON(String url, Properties data,
- final Function onSuccess) {
- Ajax.getJSON(url, data, onSuccess);
- }
-
+ * Perform an ajax request to the server using POST and parsing the json response.
+ */
+ public static void getJSON(String url, Properties data, final Function onSuccess) {
+ Ajax.getJSON(url, data, onSuccess);
+ }
+
/**
- * Perform an ajax request to the server using scripts tags and
- * parsing the json response. The request is not subject to the
- * same origin policy restrictions.
+ * Perform an ajax request to the server using scripts tags and parsing the json response. The
+ * request is not subject to the same origin policy restrictions.
*
- * Server side should accept a parameter to specify the callback
- * funcion name, and it must return a valid json object wrapped
- * this callback function.
+ * Server side should accept a parameter to specify the callback funcion name, and it must return
+ * a valid json object wrapped this callback function.
*
* Example:
- <pre>
+ *
+ * <pre>
Client code:
getJSONP("http://server.exampe.com/getData.php",$$("myCallback:'?', otherParameter='whatever'"),
new Function(){ public void f() {
@@ -557,14 +542,13 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
myCallback({"k1":"v1", "k2":"v2"});
</pre>
*
- */
- public static void getJSONP(String url, Properties data,
- final Function onSuccess) {
+ */
+ public static void getJSONP(String url, Properties data, final Function onSuccess) {
Ajax.getJSONP(url, data, onSuccess);
}
-
- protected static DocumentStyleImpl getStyleImpl(){
- if (styleImpl == null){
+
+ protected static DocumentStyleImpl getStyleImpl() {
+ if (styleImpl == null) {
styleImpl = GWT.create(DocumentStyleImpl.class);
}
return styleImpl;
@@ -573,48 +557,49 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
/**
* Return only the set of objects with match the predicate.
*/
- @SuppressWarnings("unchecked")
- public static <T> T[] grep(T[] objects, Predicate f) {
- ArrayList<Object> ret = new ArrayList<Object>();
- for (int i = 0, l = objects.length; i < l; i++) {
- if (f.f(objects[i], i)) {
- ret.add(objects[i]);
- }
- }
- return (T[]) ret.toArray(new Object[0]);
- }
+ @SuppressWarnings("unchecked")
+ public static <T> T[] grep(T[] objects, Predicate f) {
+ ArrayList<Object> ret = new ArrayList<Object>();
+ for (int i = 0, l = objects.length; i < l; i++) {
+ if (f.f(objects[i], i)) {
+ ret.add(objects[i]);
+ }
+ }
+ return (T[]) ret.toArray(new Object[0]);
+ }
private static boolean hasClass(Element e, String clz) {
return e.getClassName().matches("(^|.*\\s)" + clz + "(\\s.*|$)");
}
- private static void initWrapperMap(){
-
+ private static void initWrapperMap() {
+
TagWrapper tableWrapper = new TagWrapper(1, "<table>", "</table>");
- TagWrapper selectWrapper = new TagWrapper(1, "<select multiple=\"multiple\">", "</select>");
+ TagWrapper selectWrapper = new TagWrapper(1, "<select multiple=\"multiple\">", "</select>");
TagWrapper trWrapper = new TagWrapper(3, "<table><tbody><tr>", "</tr></tbody></table>");
-
+
wrapperMap = JsNamedArray.create();
wrapperMap.put("option", selectWrapper);
wrapperMap.put("optgroup", selectWrapper);
- wrapperMap.put("legend", new TagWrapper(1, "<fieldset>", "</fieldset>") );
+ wrapperMap.put("legend", new TagWrapper(1, "<fieldset>", "</fieldset>"));
wrapperMap.put("thead", tableWrapper);
wrapperMap.put("tbody", tableWrapper);
wrapperMap.put("tfoot", tableWrapper);
wrapperMap.put("colgroup", tableWrapper);
wrapperMap.put("caption", tableWrapper);
- wrapperMap.put("tr", new TagWrapper(2, "<table><tbody>", "</tbody></table>"));
+ wrapperMap.put("tr", new TagWrapper(2, "<table><tbody>", "</tbody></table>"));
wrapperMap.put("td", trWrapper);
- wrapperMap.put("th", trWrapper);
- wrapperMap.put("col", new TagWrapper(2, "<table><tbody></tbody><colgroup>", "</colgroup></table>"));
- wrapperMap.put("area", new TagWrapper(1, "<map>", "</map>"));
-
+ wrapperMap.put("th", trWrapper);
+ wrapperMap.put("col", new TagWrapper(2, "<table><tbody></tbody><colgroup>",
+ "</colgroup></table>"));
+ wrapperMap.put("area", new TagWrapper(1, "<map>", "</map>"));
+
}
private static GQuery innerHtml(String html, Document doc) {
return $(cleanHtmlString(html, doc));
}
-
+
protected static String[] jsArrayToString(JsArrayString array) {
if (GWT.isScript()) {
return jsArrayToString0(array);
@@ -626,14 +611,14 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
return result;
}
}
-
+
private static native String[] jsArrayToString0(JsArrayString array) /*-{
return array;
}-*/;
/**
- * Return a lazy version of the GQuery interface. Lazy function calls are
- * simply queued up and not executed immediately.
+ * Return a lazy version of the GQuery interface. Lazy function calls are simply queued up and not
+ * executed immediately.
*/
public static LazyGQuery<?> lazy() {
return $().createLazy();
@@ -641,14 +626,12 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
/**
* Perform an ajax request to the server using POST.
- */
- public static void post(String url, Properties data,
- final Function onSuccess) {
- Ajax.post(url, data, onSuccess);
- }
-
- public static <T extends GQuery> Class<T> registerPlugin(Class<T> plugin,
- Plugin<T> pluginFactory) {
+ */
+ public static void post(String url, Properties data, final Function onSuccess) {
+ Ajax.post(url, data, onSuccess);
+ }
+
+ public static <T extends GQuery> Class<T> registerPlugin(Class<T> plugin, Plugin<T> pluginFactory) {
if (plugins == null) {
plugins = JsMap.createObject().cast();
}
@@ -661,9 +644,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
if (n)
n.scrollIntoView()
}-*/;
-
+
private static native void setElementValue(Element e, String value) /*-{
- e.value = value;
+ e.value = value;
}-*/;
private static native Element window() /*-{
@@ -683,7 +666,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
*/
// TODO: remove this and use elements, change return type of get()
private NodeList<Element> nodeList = JavaScriptObject.createArray().cast();
-
+
private GQuery previousObject;
private GQuery() {
@@ -700,7 +683,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
private GQuery(JsNodeArray nodes) {
- this(nodes.<NodeList<Element>>cast());
+ this(nodes.<NodeList<Element>> cast());
}
private GQuery(NodeList<Element> list) {
@@ -715,10 +698,10 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* It also update the selector appending the new one.
*/
public GQuery add(GQuery elementsToAdd) {
- return pushStack(JsUtils.copyNodeList(nodeList, elementsToAdd.nodeList, true).<JsNodeArray>cast(), "add",
- getSelector() + "," + elementsToAdd.getSelector());
+ return pushStack(JsUtils.copyNodeList(nodeList, elementsToAdd.nodeList, true)
+ .<JsNodeArray> cast(), "add", getSelector() + "," + elementsToAdd.getSelector());
}
-
+
/**
* Add elements to the set of matched elements if they are not included yet.
*/
@@ -731,8 +714,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
*/
public GQuery addClass(String... classes) {
for (Element e : elements) {
- //issue 81 : ensure that the element is an Element node.
- if (Element.is(e)){
+ // issue 81 : ensure that the element is an Element node.
+ if (Element.is(e)) {
for (String clz : classes) {
e.addClassName(clz);
}
@@ -742,58 +725,55 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Insert content after each of the matched elements. The elements must
- * already be inserted into the document (you can't insert an element after
- * another if it's not in the page).
+ * Insert content after each of the matched elements. The elements must already be inserted into
+ * the document (you can't insert an element after another if it's not in the page).
*/
public GQuery after(GQuery query) {
return domManip(query, DomMan.AFTER);
}
/**
- * Insert content after each of the matched elements. The elements must
- * already be inserted into the document (you can't insert an element after
- * another if it's not in the page).
+ * Insert content after each of the matched elements. The elements must already be inserted into
+ * the document (you can't insert an element after another if it's not in the page).
*/
public GQuery after(Node n) {
return domManip($(n), DomMan.AFTER);
}
/**
- * Insert content after each of the matched elements. The elements must
- * already be inserted into the document (you can't insert an element after
- * another if it's not in the page).
+ * Insert content after each of the matched elements. The elements must already be inserted into
+ * the document (you can't insert an element after another if it's not in the page).
*/
public GQuery after(String html) {
return domManip(html, DomMan.AFTER);
}
- private void allNextSiblingElements(Element firstChildElement,
- JsNodeArray result, Element elem, GQuery until, String filterSelector) {
-
- while (firstChildElement != null) {
-
- if (until != null && until.index(firstChildElement) != -1){
+ private void allNextSiblingElements(Element firstChildElement, JsNodeArray result, Element elem,
+ GQuery until, String filterSelector) {
+
+ while (firstChildElement != null) {
+
+ if (until != null && until.index(firstChildElement) != -1) {
return;
}
-
- if (firstChildElement != elem
- && (filterSelector == null || $(firstChildElement).is(filterSelector))) {
- result.addNode(firstChildElement);
+
+ if (firstChildElement != elem
+ && (filterSelector == null || $(firstChildElement).is(filterSelector))) {
+ result.addNode(firstChildElement);
}
firstChildElement = firstChildElement.getNextSiblingElement();
}
}
- private void allPreviousSiblingElements(Element firstChildElement,
- JsNodeArray result, GQuery until, String filterSelector) {
+ private void allPreviousSiblingElements(Element firstChildElement, JsNodeArray result,
+ GQuery until, String filterSelector) {
while (firstChildElement != null) {
- if (until != null && until.index(firstChildElement) != -1){
+ if (until != null && until.index(firstChildElement) != -1) {
return;
}
-
- if(filterSelector == null || $(firstChildElement).is(filterSelector)){
- result.addNode(firstChildElement);
+
+ if (filterSelector == null || $(firstChildElement).is(filterSelector)) {
+ result.addNode(firstChildElement);
}
firstChildElement = getPreviousSiblingElement(firstChildElement);
@@ -801,9 +781,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Add the previous selection to the current selection. Useful for traversing
- * elements, and then adding something that was matched before the last
- * traversal.
+ * Add the previous selection to the current selection. Useful for traversing elements, and then
+ * adding something that was matched before the last traversal.
*/
public GQuery andSelf() {
return add(previousObject);
@@ -811,15 +790,14 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
/**
*
- * The animate() method allows you to create animation effects on any numeric
- * Attribute, CSS property, or color CSS property.
+ * The animate() method allows you to create animation effects on any numeric Attribute, CSS
+ * property, or color CSS property.
*
- * Concerning to numeric properties, values are treated as a number of pixels
- * unless otherwise specified. The units em and % can be specified where
- * applicable.
+ * Concerning to numeric properties, values are treated as a number of pixels unless otherwise
+ * specified. The units em and % can be specified where applicable.
*
- * By default animate considers css properties, if you wanted to animate element
- * attributes you should to prepend the symbol dollar to the attribute name.
+ * By default animate considers css properties, if you wanted to animate element attributes you
+ * should to prepend the symbol dollar to the attribute name.
*
* Example:
*
@@ -830,12 +808,11 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* $("table").animate("$width:'500'"), 400, Easing.LINEAR);
* </pre>
*
- * In addition to numeric values, each property can take the strings 'show',
- * 'hide', and 'toggle'. These shortcuts allow for custom hiding and showing
- * animations that take into account the display type of the element. Animated
- * properties can also be relative. If a value is supplied with a leading +=
- * or -= sequence of characters, then the target value is computed by adding
- * or subtracting the given number from the current value of the property.
+ * In addition to numeric values, each property can take the strings 'show', 'hide', and 'toggle'.
+ * These shortcuts allow for custom hiding and showing animations that take into account the
+ * display type of the element. Animated properties can also be relative. If a value is supplied
+ * with a leading += or -= sequence of characters, then the target value is computed by adding or
+ * subtracting the given number from the current value of the property.
*
* Example:
*
@@ -853,8 +830,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
*
* The duration of the animation is 500ms.
*
- * For color css properties, values can be specified via hexadecimal or rgb or
- * literal values.
+ * For color css properties, values can be specified via hexadecimal or rgb or literal values.
*
* Example:
*
@@ -863,23 +839,21 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* </pre>
*
* @param prop the property to animate : "cssName:'value'"
- * @param funcs an array of {@link Function} called once the animation is
- * complete
+ * @param funcs an array of {@link Function} called once the animation is complete
*/
public GQuery animate(Object stringOrProperties, Function... funcs) {
return as(Effects).animate(stringOrProperties, funcs);
}
/**
- * The animate() method allows you to create animation effects on any numeric
- * Attribute, CSS property, or color CSS property.
+ * The animate() method allows you to create animation effects on any numeric Attribute, CSS
+ * property, or color CSS property.
*
- * Concerning to numeric properties, values are treated as a number of pixels
- * unless otherwise specified. The units em and % can be specified where
- * applicable.
+ * Concerning to numeric properties, values are treated as a number of pixels unless otherwise
+ * specified. The units em and % can be specified where applicable.
*
- * By default animate considers css properties, if you wanted to animate element
- * attributes you should to prepend the symbol dollar to the attribute name.
+ * By default animate considers css properties, if you wanted to animate element attributes you
+ * should to prepend the symbol dollar to the attribute name.
*
* Example:
*
@@ -891,12 +865,11 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* $("table").animate(Properties.create("{$width: '500', $border: '10'}"), 400, Easing.LINEAR);
* </pre>
*
- * In addition to numeric values, each property can take the strings 'show',
- * 'hide', and 'toggle'. These shortcuts allow for custom hiding and showing
- * animations that take into account the display type of the element. Animated
- * properties can also be relative. If a value is supplied with a leading +=
- * or -= sequence of characters, then the target value is computed by adding
- * or subtracting the given number from the current value of the property.
+ * In addition to numeric values, each property can take the strings 'show', 'hide', and 'toggle'.
+ * These shortcuts allow for custom hiding and showing animations that take into account the
+ * display type of the element. Animated properties can also be relative. If a value is supplied
+ * with a leading += or -= sequence of characters, then the target value is computed by adding or
+ * subtracting the given number from the current value of the property.
*
* Example:
*
@@ -906,8 +879,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* $("#foo").animate(Properties.create("{top:'+=500px',left:'+=500px'}"), 400, Easing.SWING);
* </pre>
*
- * For color css properties, values can be specified via hexadecimal or rgb or
- * literal values.
+ * For color css properties, values can be specified via hexadecimal or rgb or literal values.
*
* Example:
*
@@ -915,9 +887,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* $("#foo").animate("backgroundColor:'red', color:'#ffffff', borderColor:'rgb(129, 0, 70)'"), 400, Easing.SWING);
* </pre>
*
- * @param stringOrProperties a String or a {@link Properties} object containing css properties to animate.
- * @param funcs an array of {@link Function} called once the animation is
- * complete
+ * @param stringOrProperties a String or a {@link Properties} object containing css properties to
+ * animate.
+ * @param funcs an array of {@link Function} called once the animation is complete
* @param duration the duration in milliseconds of the animation
* @param easing the easing function to use for the transition
*/
@@ -926,15 +898,14 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * The animate() method allows you to create animation effects on any numeric
- * Attribute, CSS properties, or color CSS property.
+ * The animate() method allows you to create animation effects on any numeric Attribute, CSS
+ * properties, or color CSS property.
*
- * Concerning to numeric property, values are treated as a number of pixels
- * unless otherwise specified. The units em and % can be specified where
- * applicable.
+ * Concerning to numeric property, values are treated as a number of pixels unless otherwise
+ * specified. The units em and % can be specified where applicable.
*
- * By default animate considers css properties, if you wanted to animate element
- * attributes you should to prepend the symbol dollar to the attribute name.
+ * By default animate considers css properties, if you wanted to animate element attributes you
+ * should to prepend the symbol dollar to the attribute name.
*
* Example:
*
@@ -945,12 +916,11 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* $("table").animate("$width:'500'"), 400);
* </pre>
*
- * In addition to numeric values, each property can take the strings 'show',
- * 'hide', and 'toggle'. These shortcuts allow for custom hiding and showing
- * animations that take into account the display type of the element. Animated
- * properties can also be relative. If a value is supplied with a leading +=
- * or -= sequence of characters, then the target value is computed by adding
- * or subtracting the given number from the current value of the property.
+ * In addition to numeric values, each property can take the strings 'show', 'hide', and 'toggle'.
+ * These shortcuts allow for custom hiding and showing animations that take into account the
+ * display type of the element. Animated properties can also be relative. If a value is supplied
+ * with a leading += or -= sequence of characters, then the target value is computed by adding or
+ * subtracting the given number from the current value of the property.
*
* Example:
*
@@ -965,8 +935,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* </pre>
*
*
- * For color css properties, values can be specified via hexadecimal or rgb or
- * literal values.
+ * For color css properties, values can be specified via hexadecimal or rgb or literal values.
*
* Example:
*
@@ -976,8 +945,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
*
*
* @param prop the property to animate : "cssName:'value'"
- * @param funcs an array of {@link Function} called once the animation is
- * complete
+ * @param funcs an array of {@link Function} called once the animation is complete
* @param duration the duration in milliseconds of the animation
*/
public GQuery animate(Object stringOrProperties, int duration, Function... funcs) {
@@ -985,39 +953,35 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Append content to the inside of every matched element. This operation is
- * similar to doing an appendChild to all the specified elements, adding them
- * into the document.
+ * Append content to the inside of every matched element. This operation is similar to doing an
+ * appendChild to all the specified elements, adding them into the document.
*/
public GQuery append(GQuery query) {
return domManip(query, DomMan.APPEND);
}
/**
- * Append content to the inside of every matched element. This operation is
- * similar to doing an appendChild to all the specified elements, adding them
- * into the document.
+ * Append content to the inside of every matched element. This operation is similar to doing an
+ * appendChild to all the specified elements, adding them into the document.
*/
public GQuery append(Node n) {
return domManip($(n), DomMan.APPEND);
}
/**
- * Append content to the inside of every matched element. This operation is
- * similar to doing an appendChild to all the specified elements, adding them
- * into the document.
+ * Append content to the inside of every matched element. This operation is similar to doing an
+ * appendChild to all the specified elements, adding them into the document.
*/
public GQuery append(String html) {
return domManip(html, DomMan.APPEND);
}
/**
- * All of the matched set of elements will be inserted at the end of the
- * element(s) specified by the parameter other.
+ * All of the matched set of elements will be inserted at the end of the element(s) specified by
+ * the parameter other.
*
- * The operation $(A).appendTo(B) is, essentially, the reverse of doing a
- * regular $(A).append(B), instead of appending B to A, you're appending A to
- * B.
+ * The operation $(A).appendTo(B) is, essentially, the reverse of doing a regular $(A).append(B),
+ * instead of appending B to A, you're appending A to B.
*/
public GQuery appendTo(GQuery other) {
other.append(this);
@@ -1025,12 +989,11 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * All of the matched set of elements will be inserted at the end of the
- * element(s) specified by the parameter other.
+ * All of the matched set of elements will be inserted at the end of the element(s) specified by
+ * the parameter other.
*
- * The operation $(A).appendTo(B) is, essentially, the reverse of doing a
- * regular $(A).append(B), instead of appending B to A, you're appending A to
- * B.
+ * The operation $(A).appendTo(B) is, essentially, the reverse of doing a regular $(A).append(B),
+ * instead of appending B to A, you're appending A to B.
*/
public GQuery appendTo(Node n) {
GQuery a = $(n);
@@ -1040,12 +1003,11 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * All of the matched set of elements will be inserted at the end of the
- * element(s) specified by the parameter other.
+ * All of the matched set of elements will be inserted at the end of the element(s) specified by
+ * the parameter other.
*
- * The operation $(A).appendTo(B) is, essentially, the reverse of doing a
- * regular $(A).append(B), instead of appending B to A, you're appending A to
- * B.
+ * The operation $(A).appendTo(B) is, essentially, the reverse of doing a regular $(A).append(B),
+ * instead of appending B to A, you're appending A to B.
*/
public GQuery appendTo(String html) {
$(html).append(this);
@@ -1067,15 +1029,13 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
return (T) p.init(this);
}
}
- throw new RuntimeException("No plugin registered for class "
- + plugin.getName());
+ throw new RuntimeException("No plugin registered for class " + plugin.getName());
}
/**
* Set a key/value object as properties to all matched elements.
*
- * Example: $("img").attr(new
- * Properties("src: 'test.jpg', alt: 'Test Image'"))
+ * Example: $("img").attr(new Properties("src: 'test.jpg', alt: 'Test Image'"))
*/
public GQuery attr(Properties properties) {
for (String name : properties.keys()) {
@@ -1083,30 +1043,28 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
return this;
}
-
+
/**
- * Access a property on the first matched element. This method makes it easy
- * to retrieve a property value from the first matched element. If the element
- * does not have an attribute with such a name, empty string is returned.
- * Attributes include title, alt, src, href, width, style, etc.
+ * Access a property on the first matched element. This method makes it easy to retrieve a
+ * property value from the first matched element. If the element does not have an attribute with
+ * such a name, empty string is returned. Attributes include title, alt, src, href, width, style,
+ * etc.
*/
public String attr(String name) {
return isEmpty() ? "" : get(0).getAttribute(name);
- }
-
+ }
+
/**
* Set a single property to a computed value, on all matched elements.
*/
public GQuery attr(String key, Function closure) {
int i = 0;
for (Element e : elements) {
- Object val = closure.f(e.<com.google.gwt.dom.client.Element>cast(), i++);
+ Object val = closure.f(e.<com.google.gwt.dom.client.Element> cast(), i++);
$(e).attr(key, val);
}
return this;
}
-
-
/**
* Set a single property to a value, on all matched elements.
@@ -1114,34 +1072,31 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
public GQuery attr(String key, Object value) {
assert key != null : "key cannot be null";
assert !"$H".equalsIgnoreCase(key) : "$H is a GWT reserved attribute. Changing its value will break your application.";
-
+
getAttributeImpl().setAttribute(this, key, value);
-
+
return this;
}
/**
- * Insert content before each of the matched elements. The elements must
- * already be inserted into the document (you can't insert an element before
- * another if it's not in the page).
+ * Insert content before each of the matched elements. The elements must already be inserted into
+ * the document (you can't insert an element before another if it's not in the page).
*/
public GQuery before(GQuery query) {
return domManip(query, DomMan.BEFORE);
}
/**
- * Insert content before each of the matched elements. The elements must
- * already be inserted into the document (you can't insert an element before
- * another if it's not in the page).
+ * Insert content before each of the matched elements. The elements must already be inserted into
+ * the document (you can't insert an element before another if it's not in the page).
*/
public GQuery before(Node n) {
return domManip($(n), DomMan.BEFORE);
}
/**
- * Insert content before each of the matched elements. The elements must
- * already be inserted into the document (you can't insert an element before
- * another if it's not in the page).
+ * Insert content before each of the matched elements. The elements must already be inserted into
+ * the document (you can't insert an element before another if it's not in the page).
*/
public GQuery before(String html) {
return domManip(html, DomMan.BEFORE);
@@ -1150,39 +1105,57 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
/**
* Binds a set of handlers to a particular Event for each matched element.
*
- * The event handlers are passed as Functions that you can use to prevent
- * default behavior. To stop both default action and event bubbling, the
- * function event handler has to return false.
+ * The event handlers are passed as Functions that you can use to prevent default behavior. To
+ * stop both default action and event bubbling, the function event handler has to return false.
*
- * You can pass an additional Object data to your Function as the second
- * parameter
+ * You can pass an additional Object data to your Function as the second parameter
*
*/
public GQuery bind(int eventbits, final Object data, final Function... funcs) {
return as(Events).bind(eventbits, data, funcs);
}
+
+ /**
+ * Binds a set of handlers to a particular Event for each matched element.
+ *
+ * The event handlers are passed as Functions that you can use to prevent default behavior. To
+ * stop both default action and event bubbling, the function event handler has to return false.
+ *
+ *
+ */
+ public GQuery bind(int eventbits, final Function... funcs) {
+ return as(Events).bind(eventbits, null, funcs);
+ }
/**
* Binds a set of handlers to a particular Event for each matched element.
*
- * The event handlers are passed as Functions that you can use to prevent
- * default behavior. To stop both default action and event bubbling, the
- * function event handler has to return false.
+ * The event handlers are passed as Functions that you can use to prevent default behavior. To
+ * stop both default action and event bubbling, the function event handler has to return false.
*
- * You can pass an additional Object data to your Function as the second
- * parameter
+ * You can pass an additional Object data to your Function as the second parameter
*
*/
- public GQuery bind(String eventType, final Object data,
- final Function... funcs) {
+ public GQuery bind(String eventType, final Object data, final Function... funcs) {
return as(Events).bind(eventType, data, funcs);
}
/**
+ * Binds a set of handlers to a particular Event for each matched element.
+ *
+ * The event handlers are passed as Functions that you can use to prevent default behavior. To
+ * stop both default action and event bubbling, the function event handler has to return false.
+ *
+ *
+ */
+ public GQuery bind(String eventType, final Function... funcs) {
+ return as(Events).bind(eventType, null, funcs);
+ }
+
+ /**
* Bind Handlers or fire Events for each matched element.
*/
- private GQuery bindOrFire(int eventbits, final Object data,
- final Function... funcs) {
+ private GQuery bindOrFire(int eventbits, final Object data, final Function... funcs) {
if (funcs.length == 0) {
return trigger(eventbits);
} else {
@@ -1191,8 +1164,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Bind a set of functions to the blur event of each matched element.
- * Or trigger the blur event if no functions are provided.
+ * Bind a set of functions to the blur event of each matched element. Or trigger the blur event if
+ * no functions are provided.
*/
public GQuery blur(Function... f) {
bindOrFire(Event.ONBLUR, null, f);
@@ -1203,17 +1176,17 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Bind a set of functions to the change event of each matched element. Or
- * trigger the event if no functions are provided.
+ * Bind a set of functions to the change event of each matched element. Or trigger the event if no
+ * functions are provided.
*/
public GQuery change(Function... f) {
return bindOrFire(Event.ONCHANGE, null, f);
}
/**
- * Get a set of elements containing all of the unique immediate children of
- * each of the matched set of elements. Also note: while parents() will look
- * at all ancestors, children() will only consider immediate child elements.
+ * Get a set of elements containing all of the unique immediate children of each of the matched
+ * set of elements. Also note: while parents() will look at all ancestors, children() will only
+ * consider immediate child elements.
*/
public GQuery children() {
JsNodeArray result = JsNodeArray.create();
@@ -1224,9 +1197,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Get a set of elements containing all of the unique children of each of the
- * matched set of elements. This set is filtered with the expressions that
- * will cause only elements matching any of the selectors to be collected.
+ * Get a set of elements containing all of the unique children of each of the matched set of
+ * elements. This set is filtered with the expressions that will cause only elements matching any
+ * of the selectors to be collected.
*/
public GQuery children(String... filters) {
return children().filter(filters);
@@ -1246,10 +1219,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
}
-
/**
- * Remove from the Effects queue all {@link Function} that have not yet been
- * run.
+ * Remove from the Effects queue all {@link Function} that have not yet been run.
*/
public GQuery clearQueue() {
return as(Queue).clearQueue();
@@ -1263,16 +1234,16 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Bind a set of functions to the click event of each matched element. Or
- * trigger the event if no functions are provided.
+ * Bind a set of functions to the click event of each matched element. Or trigger the event if no
+ * functions are provided.
*/
public GQuery click(Function... f) {
return bindOrFire(Event.ONCLICK, null, f);
}
/**
- * Clone matched DOM Elements and select the clones. This is useful for moving
- * copies of the elements to another location in the DOM.
+ * Clone matched DOM Elements and select the clones. This is useful for moving copies of the
+ * elements to another location in the DOM.
*/
public GQuery clone() {
JsNodeArray result = JsNodeArray.create();
@@ -1286,9 +1257,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Get the first ancestor element that matches the selector (for each matched
- * element), beginning at the current element and progressing up through the
- * DOM tree.
+ * Get the first ancestor element that matches the selector (for each matched element), beginning
+ * at the current element and progressing up through the DOM tree.
*
* @param selector
* @return
@@ -1298,12 +1268,11 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Get the first ancestor element that matches the selector (for each matched
- * element), beginning at the current element and progressing up through the
- * DOM tree until reach the <code>context</code> node.
+ * Get the first ancestor element that matches the selector (for each matched element), beginning
+ * at the current element and progressing up through the DOM tree until reach the
+ * <code>context</code> node.
*
- * If no context is passed in then the context of the gQuery object will be
- * used instead.
+ * If no context is passed in then the context of the gQuery object will be used instead.
*
*/
public GQuery closest(String selector, Node context) {
@@ -1318,10 +1287,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
for (Element e : elements) {
Element current = e;
- while (current != null && current.getOwnerDocument() != null
- && current != context) {
- boolean match = pos != null ? pos.index(current) > -1 : $(current).is(
- selector);
+ while (current != null && current.getOwnerDocument() != null && current != context) {
+ boolean match = pos != null ? pos.index(current) > -1 : $(current).is(selector);
if (match) {
result.addNode(current);
break;
@@ -1336,11 +1303,10 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Returns a {@link Map} object as key a selector and as value the list of
- * ancestor elements matching this selectors, beginning at the first matched
- * element and progressing up through the DOM. This method allows retrieving
- * the list of ancestors matching many selectors by traversing the DOM only
- * one time.
+ * Returns a {@link Map} object as key a selector and as value the list of ancestor elements
+ * matching this selectors, beginning at the first matched element and progressing up through the
+ * DOM. This method allows retrieving the list of ancestors matching many selectors by traversing
+ * the DOM only one time.
*
* @param selector
* @return
@@ -1350,10 +1316,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Returns a {@link Map} object as key a selector and as value the list of
- * ancestor elements matching this selectors, beginning at the first matched
- * element and progressing up through the DOM until reach the
- * <code>context</code> node.. This method allows retrieving the list of
+ * Returns a {@link Map} object as key a selector and as value the list of ancestor elements
+ * matching this selectors, beginning at the first matched element and progressing up through the
+ * DOM until reach the <code>context</code> node.. This method allows retrieving the list of
* ancestors matching many selectors by traversing the DOM only one time.
*
* @param selector
@@ -1371,20 +1336,17 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
JsNamedArray<GQuery> matches = JsNamedArray.create();
for (String selector : selectors) {
if (!matches.exists(selector)) {
- matches.put(selector, selector.matches(POS_REGEX) ? $(selector,
- context) : null);
+ matches.put(selector, selector.matches(POS_REGEX) ? $(selector, context) : null);
}
}
Element current = first;
- while (current != null && current.getOwnerDocument() != null
- && current != context) {
+ while (current != null && current.getOwnerDocument() != null && current != context) {
// for each selector, check if the current element match it.
for (String selector : matches.keys()) {
GQuery pos = matches.get(selector);
- boolean match = pos != null ? pos.index(current) > -1
- : $(current).is(selector);
+ boolean match = pos != null ? pos.index(current) > -1 : $(current).is(selector);
if (match) {
JsNodeArray elementsMatchingSelector = results.get(selector).cast();
@@ -1416,8 +1378,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Find all the child nodes inside the matched elements (including text
- * nodes), or the content document, if the element is an iframe.
+ * Find all the child nodes inside the matched elements (including text nodes), or the content
+ * document, if the element is an iframe.
*/
public GQuery contents() {
JsNodeArray result = JsNodeArray.create();
@@ -1439,12 +1401,11 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Set CSS a single style property on every matched element using type-safe
- * enumerations.
+ * Set CSS a single style property on every matched element using type-safe enumerations.
*
- * The best way to use this method (i.e. to generate a CssSetter) is to take
- * the desired css property defined in {@link CSS} class and call the
- * {@link TakesCssValue#with(HasCssName)} method on it.
+ * The best way to use this method (i.e. to generate a CssSetter) is to take the desired css
+ * property defined in {@link CSS} class and call the {@link TakesCssValue#with(HasCssName)}
+ * method on it.
*
*
* ex :
@@ -1469,8 +1430,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Return a style property on the first matched element using type-safe
- * enumerations.
+ * Return a style property on the first matched element using type-safe enumerations.
*
* Ex : $("#myId").css(CSS.BACKGROUND_COLOR);
*/
@@ -1479,16 +1439,14 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Return a style property on the first matched element using type-safe
- * enumerations.
+ * Return a style property on the first matched element using type-safe enumerations.
*
- * The parameter force has a special meaning here: - When force is false,
- * returns the value of the css property defined in the style attribute of the
- * element. - Otherwise it returns the real computed value.
+ * The parameter force has a special meaning here: - When force is false, returns the value of the
+ * css property defined in the style attribute of the element. - Otherwise it returns the real
+ * computed value.
*
- * For instance if you define 'display=none' not in the element style but in
- * the css stylesheet, it returns an empty string unless you pass the
- * parameter force=true.
+ * For instance if you define 'display=none' not in the element style but in the css stylesheet,
+ * it returns an empty string unless you pass the parameter force=true.
*
* Ex : $("#myId").css(CSS.WIDTH, true);
*/
@@ -1497,9 +1455,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Set a key/value object as style properties to all matched elements. This
- * serves as the best way to set a large number of style properties on all
- * matched elements. You can use either js maps or pure css syntax.
+ * Set a key/value object as style properties to all matched elements. This serves as the best way
+ * to set a large number of style properties on all matched elements. You can use either js maps
+ * or pure css syntax.
*
* Example:
*
@@ -1515,7 +1473,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
return this;
}
-
/**
* Return a style property on the first matched element.
*/
@@ -1526,16 +1483,15 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
/**
* Return a style property on the first matched element.
*
- * The parameter force has a special meaning here:
+ * The parameter force has a special meaning here:
* <ul>
- * <li>When force is false, returns the value of the css property
- * defined in the style attribute of the element.
+ * <li>When force is false, returns the value of the css property defined in the style attribute
+ * of the element.
* <li>Otherwise it returns the real computed value.
* </ul>
*
- * For instance if you don't define 'display=none'in the element style but in
- * the css stylesheet, it returns an empty string unless you pass the
- * parameter force=true.
+ * For instance if you don't define 'display=none'in the element style but in the css stylesheet,
+ * it returns an empty string unless you pass the parameter force=true.
*/
public String css(String name, boolean force) {
return isEmpty() ? "" : getStyleImpl().curCSS(get(0), name, force);
@@ -1553,9 +1509,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Set CSS a single style property on every matched element using type-safe
- * enumerations. This method allows you to set manually the value or set
- * <i>inherit</i> value
+ * Set CSS a single style property on every matched element using type-safe enumerations. This
+ * method allows you to set manually the value or set <i>inherit</i> value
*
* ex :
*
@@ -1577,25 +1532,23 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
/**
* Returns the numeric value of a css property.
*
- * The parameter force has a special meaning: - When force is false, returns
- * the value of the css property defined in the set of style attributes. -
- * When true returns the real computed value.
+ * The parameter force has a special meaning: - When force is false, returns the value of the css
+ * property defined in the set of style attributes. - When true returns the real computed value.
*/
public double cur(String prop, boolean force) {
return isEmpty() ? 0 : getStyleImpl().cur(get(0), prop, force);
}
/**
- * Returns value at named data store for the element, as set by data(name,
- * value).
+ * Returns value at named data store for the element, as set by data(name, value).
*/
public Object data(String name) {
return isEmpty() ? null : data(get(0), name, null);
}
/**
- * Returns value at named data store for the element, as set by data(name,
- * value) with desired return type.
+ * Returns value at named data store for the element, as set by data(name, value) with desired
+ * return type.
*
* @param clz return type class literal
*/
@@ -1615,18 +1568,17 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Bind a set of functions to the dblclick event of each matched element. Or
- * trigger the event if no functions are provided.
+ * Bind a set of functions to the dblclick event of each matched element. Or trigger the event if
+ * no functions are provided.
*/
public GQuery dblclick(Function... f) {
return bindOrFire(Event.ONDBLCLICK, null, f);
}
/**
- * Insert a delay (in ms) in the GQuery queue, and optionally execute one o
- * more functions if provided when the delay finishes.
- * It uses the effects queue namespace, so you can stack any of the methods in the effects
- * plugin.
+ * Insert a delay (in ms) in the GQuery queue, and optionally execute one o more functions if
+ * provided when the delay finishes. It uses the effects queue namespace, so you can stack any of
+ * the methods in the effects plugin.
*
* Example:
*
@@ -1636,20 +1588,20 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* .fadeIn(400);
* </pre>
*
- * When this statement is executed, the element slides up for 300 milliseconds
- * and then pauses for 800 milliseconds before fading in for 400 milliseconds.
- * Aditionally after those 800 milliseconds the element color is set to red.
+ * When this statement is executed, the element slides up for 300 milliseconds and then pauses for
+ * 800 milliseconds before fading in for 400 milliseconds. Aditionally after those 800
+ * milliseconds the element color is set to red.
*
- * NOTE that this methods affects only methods which uses the queue like effects.
- * So the following example is wrong:
+ * NOTE that this methods affects only methods which uses the queue like effects. So the following
+ * example is wrong:
*
* <pre>
* $("#foo").css(CSS.COLOR.with(RGBColor.RED)).delay(800).css(CSS.COLOR.with(RGBColor.BLACK));
* </pre>
*
- * The code above will not insert a delay of 800 ms between the css() calls !
- * For this kind of behavior, you should execute these methods puting them in inline
- * functions passed as argument to the delay() method, or adding them to the queue.
+ * The code above will not insert a delay of 800 ms between the css() calls ! For this kind of
+ * behavior, you should execute these methods puting them in inline functions passed as argument
+ * to the delay() method, or adding them to the queue.
*
* <pre>
* $("#foo").css(CSS.COLOR.with(RGBColor.RED)).delay(800, lazy().css(CSS.COLOR.with(RGBColor.BLACK)).done());
@@ -1661,12 +1613,11 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Insert a delay (in ms) in the queue identified by the
- * <code>queueName</code> parameter, and optionally execute one o
- * more functions if provided when the delay finishes.
+ * Insert a delay (in ms) in the queue identified by the <code>queueName</code> parameter, and
+ * optionally execute one o more functions if provided when the delay finishes.
*
- * If <code>queueName</code> is null or
- * equats to 'fx', the delay will be inserted to the Effects queue.
+ * If <code>queueName</code> is null or equats to 'fx', the delay will be inserted to the Effects
+ * queue.
*
* Example :
*
@@ -1676,9 +1627,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* .queue("colorQueue", lazy().css(CSS.COLOR.with(RGBColor.BLACK)).dequeue("colorQueue").done());
* </pre>
*
- * When this statement is executed, the text color of the element changes to
- * red and then wait for 800 milliseconds before changes the text color to
- * black.
+ * When this statement is executed, the text color of the element changes to red and then wait for
+ * 800 milliseconds before changes the text color to black.
*
*/
public GQuery delay(int milliseconds, String queueName, Function... f) {
@@ -1686,9 +1636,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Attach <code>handlers</code> to one or more events for all elements that
- * match the <code>selector</code>, now or in the future, based on a specific
- * set of root elements.
+ * Attach <code>handlers</code> to one or more events for all elements that match the
+ * <code>selector</code>, now or in the future, based on a specific set of root elements.
*
* Example:
*
@@ -1700,8 +1649,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* });
* </pre>
*
- * This code above add an handler on click event on all cell (the existing
- * oneand the future cell) of all table. This code is equivalent to :
+ * This code above add an handler on click event on all cell (the existing oneand the future cell)
+ * of all table. This code is equivalent to :
*
* <pre>
* $("table").each(new Function(){
@@ -1715,8 +1664,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
*
* </pre>
*
- * You can attach the handlers to many events by using the '|' operator
- * ex:
+ * You can attach the handlers to many events by using the '|' operator ex:
+ *
* <pre>
* $("div.main").delegate(".subMain", Event.ONCLICK | Event.ONDBLCLICK, new Function(){...});
* </pre>
@@ -1726,12 +1675,12 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Attach <code>handlers</code> to one or more events for all elements that match the <code>selector</code>,
- * now or in the future, based on a specific set of root elements.
- * The <code>data</code> parameter allows us
- * to pass data to the handler.
- *
+ * Attach <code>handlers</code> to one or more events for all elements that match the
+ * <code>selector</code>, now or in the future, based on a specific set of root elements. The
+ * <code>data</code> parameter allows us to pass data to the handler.
+ *
* Example:
+ *
* <pre>
* $("table").delegate("td", "click", new Function(){
* public void f(Element e){
@@ -1739,8 +1688,10 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* }
* });
* </pre>
- * This code above add an handler on click event on all cell (the existing oneand the future cell) of all table.
- * This code is equivalent to :
+ *
+ * This code above add an handler on click event on all cell (the existing oneand the future cell)
+ * of all table. This code is equivalent to :
+ *
* <pre>
* $("table").each(new Function(){
* public void f(Element table){
@@ -1753,14 +1704,13 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
*
* </pre>
*
- * You can pass attach the handlers to many events by using the '|' operator
- * ex:
+ * You can pass attach the handlers to many events by using the '|' operator ex:
+ *
* <pre>
* $("div.main").delegate(".subMain", Event.ONCLICK | Event.ONDBLCLICK, new Function(){...});
* </pre>
*/
- public GQuery delegate(String selector, int eventbits, Object data,
- Function... handlers) {
+ public GQuery delegate(String selector, int eventbits, Object data, Function... handlers) {
for (Element e : elements) {
$(selector, e).live(eventbits, data, handlers);
@@ -1770,9 +1720,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Attach <code>handlers</code> to one or more events for all elements that
- * match the <code>selector</code>, now or in the future, based on a specific
- * set of root elements.
+ * Attach <code>handlers</code> to one or more events for all elements that match the
+ * <code>selector</code>, now or in the future, based on a specific set of root elements.
*
* Example:
*
@@ -1784,8 +1733,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* });
* </pre>
*
- * This code above add an handler on click event on all cell (the existing
- * oneand the future cell) of all table. This code is equivalent to :
+ * This code above add an handler on click event on all cell (the existing oneand the future cell)
+ * of all table. This code is equivalent to :
*
* <pre>
* $("table").each(new Function(){
@@ -1801,20 +1750,20 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
*
* You can pass attach the handlers to many events by specifying a String with espaced event type.
* ex:
+ *
* <pre>
* $("div.main").delegate(".subMain", "click dblclick", new Function(){...});
* </pre>
+ *
* </pre>
*/
- public GQuery delegate(String selector, String eventType,
- Function... handlers) {
+ public GQuery delegate(String selector, String eventType, Function... handlers) {
return delegate(selector, eventType, null, handlers);
}
/**
- * Attach <code>handlers</code> to one or more events for all elements that
- * match the <code>selector</code>, now or in the future, based on a specific
- * set of root elements.
+ * Attach <code>handlers</code> to one or more events for all elements that match the
+ * <code>selector</code>, now or in the future, based on a specific set of root elements.
*
* Example:
*
@@ -1826,8 +1775,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* });
* </pre>
*
- * This code above add an handler on click event on all cell (the existing
- * oneand the future cell) of all table. This code is equivalent to :
+ * This code above add an handler on click event on all cell (the existing oneand the future cell)
+ * of all table. This code is equivalent to :
*
* <pre>
* $("table").each(new Function(){
@@ -1841,13 +1790,14 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
*
* You can pass attach the handlers to many events by specifying a String with espaced event type.
* ex:
+ *
* <pre>
* $("div.main").delegate(".subMain", "click dblclick", new Function(){...});
* </pre>
+ *
* </pre>
*/
- public GQuery delegate(String selector, String eventType, Object data,
- Function... handlers) {
+ public GQuery delegate(String selector, String eventType, Object data, Function... handlers) {
for (Element e : elements) {
$(selector, e).live(eventType, data, handlers);
}
@@ -1856,61 +1806,57 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Execute the next function on the Effects queue for the matched elements.
- * This method is usefull to tell when a function you add in the Effects queue
- * is ended and so the next function in the queue can start.
+ * Execute the next function on the Effects queue for the matched elements. This method is usefull
+ * to tell when a function you add in the Effects queue is ended and so the next function in the
+ * queue can start.
*
- * Note: you should be sure to call dequeue() in all functions of a queue chain,
- * otherwise the queue execution will be stopped.
+ * Note: you should be sure to call dequeue() in all functions of a queue chain, otherwise the
+ * queue execution will be stopped.
*/
public GQuery dequeue() {
return as(Queue).dequeue();
}
/**
- * Execute the next function on the queue named as queueName for the matched elements.
- * This method is usefull to tell when a function you add in the Effects queue is
- * ended and so the next function in the queue can start.
+ * Execute the next function on the queue named as queueName for the matched elements. This method
+ * is usefull to tell when a function you add in the Effects queue is ended and so the next
+ * function in the queue can start.
*/
public GQuery dequeue(String queueName) {
return as(Queue).dequeue(queueName);
}
/**
- * Detach all matched elements from the DOM. This method is the same than
- * {@link #remove()} method except all data and event handlers are not remove
- * from the element. This method is useful when removed elements are to be
- * reinserted into the DOM at a later time.
+ * Detach all matched elements from the DOM. This method is the same than {@link #remove()} method
+ * except all data and event handlers are not remove from the element. This method is useful when
+ * removed elements are to be reinserted into the DOM at a later time.
*/
public GQuery detach() {
return remove(null, false);
}
/**
- * Detach from the DOM all matched elements filtered by the
- * <code>filter</code>.. This method is the same than {@link #remove(String)}
- * method except all data and event handlers are not remove from the element.
- * This method is useful when removed elements are to be reinserted into the
- * DOM at a later time.
+ * Detach from the DOM all matched elements filtered by the <code>filter</code>.. This method is
+ * the same than {@link #remove(String)} method except all data and event handlers are not remove
+ * from the element. This method is useful when removed elements are to be reinserted into the DOM
+ * at a later time.
*/
public GQuery detach(String filter) {
return remove(filter, false);
}
/**
- * Remove all event handlers previously attached using
- * {@link #live(String, Function)}. In order for this method to function
- * correctly, the selector used with it must match exactly the selector
- * initially used with {@link #live(String, Function)}
+ * Remove all event handlers previously attached using {@link #live(String, Function)}. In order
+ * for this method to function correctly, the selector used with it must match exactly the
+ * selector initially used with {@link #live(String, Function)}
*/
public GQuery die() {
return die(0);
}
/**
- * Remove an event handlers previously attached using
- * {@link #live(int, Function)} In order for this method to function
- * correctly, the selector used with it must match exactly the selector
+ * Remove an event handlers previously attached using {@link #live(int, Function)} In order for
+ * this method to function correctly, the selector used with it must match exactly the selector
* initially used with {@link #live(int, Function)}
*/
public GQuery die(int eventbits) {
@@ -1918,9 +1864,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Remove an event handlers previously attached using
- * {@link #live(String, Function)} In order for this method to function
- * correctly, the selector used with it must match exactly the selector
+ * Remove an event handlers previously attached using {@link #live(String, Function)} In order for
+ * this method to function correctly, the selector used with it must match exactly the selector
* initially used with {@link #live(String, Function)}
*/
public GQuery die(String eventName) {
@@ -1932,18 +1877,20 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
if (elms.length == 0) {
elms = elements;
}
- for (int i = 0, l = elms.length; i < l;i ++) {
+ for (int i = 0, l = elms.length; i < l; i++) {
Element e = elms[i];
if (e.getNodeType() == Node.DOCUMENT_NODE) {
- e = e.<Document>cast().getBody();
+ e = e.<Document> cast().getBody();
}
for (int j = 0, size = g.size(); j < size; j++) {
// Widget w = getAssociatedWidget(g.get(j));
// GqUi.detachWidget(w);
-
+
Node n = g.get(j);
- // If an element selected is inserted elsewhere, it will be moved into the target (not cloned).
- // If there is more than one target element, however, cloned copies of the inserted element will be created for each target after the first
+ // If an element selected is inserted elsewhere, it will be moved into the target (not
+ // cloned).
+ // If there is more than one target element, however, cloned copies of the inserted element
+ // will be created for each target after the first
if (i > 0) {
n = n.cloneNode(true);
}
@@ -1955,8 +1902,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
newNodes.addNode(e.appendChild(n));
break;
case AFTER:
- newNodes.addNode(e.getParentNode().insertBefore(n,
- e.getNextSibling()));
+ newNodes.addNode(e.getParentNode().insertBefore(n, e.getNextSibling()));
break;
case BEFORE:
newNodes.addNode(e.getParentNode().insertBefore(n, e));
@@ -1989,16 +1935,15 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Run one or more Functions over each element of the GQuery. You have to
- * override one of these funcions: public void f(Element e) public String
- * f(Element e, int i)
+ * Run one or more Functions over each element of the GQuery. You have to override one of these
+ * funcions: public void f(Element e) public String f(Element e, int i)
*/
public GQuery each(Function... f) {
if (f != null) {
for (Function f1 : f) {
int i = 0;
for (Element e : elements) {
- f1.f(e.<com.google.gwt.dom.client.Element>cast(), i++);
+ f1.f(e.<com.google.gwt.dom.client.Element> cast(), i++);
}
}
}
@@ -2006,17 +1951,17 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Returns the working set of nodes as a Java array. <b>Do NOT</b> attempt to
- * modify this array, e.g. assign to its elements, or call Arrays.sort()
+ * Returns the working set of nodes as a Java array. <b>Do NOT</b> attempt to modify this array,
+ * e.g. assign to its elements, or call Arrays.sort()
*/
public Element[] elements() {
return elements;
}
/**
- * Remove all child nodes from the set of matched elements. In the case of a
- * document element, it removes all the content You should call this method
- * whenever you create a new iframe and you want to add dynamic content to it.
+ * Remove all child nodes from the set of matched elements. In the case of a document element, it
+ * removes all the content You should call this method whenever you create a new iframe and you
+ * want to add dynamic content to it.
*/
public GQuery empty() {
for (Element e : elements) {
@@ -2037,17 +1982,16 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Revert the most recent 'destructive' operation, changing the set of matched
- * elements to its previous state (right before the destructive operation).
+ * Revert the most recent 'destructive' operation, changing the set of matched elements to its
+ * previous state (right before the destructive operation).
*/
public GQuery end() {
return previousObject != null ? previousObject : new GQuery();
}
/**
- * Reduce GQuery to element in the specified position. This method accept
- * negative index. A negative index is counted from the end of the matched
- * set:
+ * Reduce GQuery to element in the specified position. This method accept negative index. A
+ * negative index is counted from the end of the matched set:
*
* Example:
*
@@ -2065,17 +2009,16 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Bind a set of functions to the error event of each matched element. Or
- * trigger the event if no functions are provided.
+ * Bind a set of functions to the error event of each matched element. Or trigger the event if no
+ * functions are provided.
*/
public GQuery error(Function... f) {
return bindOrFire(Event.ONERROR, null, f);
}
-
-
+
/**
- * Fade in all matched elements by adjusting their opacity. The effect will
- * take 1000 milliseconds to complete
+ * Fade in all matched elements by adjusting their opacity. The effect will take 1000 milliseconds
+ * to complete
*/
public GQuery fadeIn(Function... f) {
return $(as(Effects).fadeIn(f));
@@ -2087,10 +2030,10 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
public GQuery fadeIn(int millisecs, Function... f) {
return $(as(Effects).fadeIn(millisecs, f));
}
-
+
/**
- * Fade out all matched elements by adjusting their opacity. The effect will
- * take 1000 milliseconds to complete
+ * Fade out all matched elements by adjusting their opacity. The effect will take 1000
+ * milliseconds to complete
*/
public GQuery fadeOut(Function... f) {
return $(as(Effects).fadeOut(f));
@@ -2104,20 +2047,18 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Toggle the visibility of all matched elements by adjusting their opacity and
- * firing an optional callback after completion. Only the opacity is adjusted for
- * this animation, meaning that all of the matched elements should already
- * have some form of height and width associated with them.
+ * Toggle the visibility of all matched elements by adjusting their opacity and firing an optional
+ * callback after completion. Only the opacity is adjusted for this animation, meaning that all of
+ * the matched elements should already have some form of height and width associated with them.
*/
public Effects fadeToggle(int millisecs, Function... f) {
return as(Effects).fadeToggle(millisecs, f);
}
/**
- * Removes all elements from the set of matched elements that do not match the
- * specified function. The function is called with a context equal to the
- * current element. If the function returns false, then the element is removed
- * - anything else and the element is kept.
+ * Removes all elements from the set of matched elements that do not match the specified function.
+ * The function is called with a context equal to the current element. If the function returns
+ * false, then the element is removed - anything else and the element is kept.
*/
public GQuery filter(Predicate filterFn) {
JsNodeArray result = JsNodeArray.create();
@@ -2131,22 +2072,18 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Removes all elements from the set of matched elements that do not pass the
- * specified css expression. This method is used to narrow down the results of
- * a search.
+ * Removes all elements from the set of matched elements that do not pass the specified css
+ * expression. This method is used to narrow down the results of a search.
*/
- //TODO performance bad...
+ // TODO performance bad...
public GQuery filter(String... filters) {
JsNodeArray array = JsNodeArray.create();
- /*StringBuilder filterBuilder = new StringBuilder();
- for (int i = 0; i < filters.length ; i++){
- filterBuilder.append(filters[i]);
- if (i < filters.length - 1){
- filterBuilder.append(",");
- }
- }
-
- String filter = filterBuilder.toString();*/
+ /*
+ * StringBuilder filterBuilder = new StringBuilder(); for (int i = 0; i < filters.length ; i++){
+ * filterBuilder.append(filters[i]); if (i < filters.length - 1){ filterBuilder.append(","); } }
+ *
+ * String filter = filterBuilder.toString();
+ */
for (String f : filters) {
for (Element e : elements) {
@@ -2169,17 +2106,15 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
}
}
-
+
return pushStack(unique(array), "filter", filters[0]);
}
/**
- * Searches for all elements that match the specified css expression. This
- * method is a good way to find additional descendant elements with which to
- * process.
+ * Searches for all elements that match the specified css expression. This method is a good way to
+ * find additional descendant elements with which to process.
*
- * Provide a comma-separated list of expressions to apply multiple filters at
- * once.
+ * Provide a comma-separated list of expressions to apply multiple filters at once.
*/
public GQuery find(String... filters) {
JsNodeArray array = JsNodeArray.create();
@@ -2201,9 +2136,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Bind a set of functions to the focus event of each matched element. Or
- * trigger the event and move the input focus to the first element
- * if no functions are provided.
+ * Bind a set of functions to the focus event of each matched element. Or trigger the event and
+ * move the input focus to the first element if no functions are provided.
*/
public GQuery focus(Function... f) {
bindOrFire(Event.ONFOCUS, null, f);
@@ -2214,17 +2148,16 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Return all elements matched in the GQuery as a NodeList. @see #elements()
- * for a method which returns them as an immutable Java array.
+ * Return all elements matched in the GQuery as a NodeList. @see #elements() for a method which
+ * returns them as an immutable Java array.
*/
public NodeList<Element> get() {
return nodeList;
}
-
/**
- * Return the ith element matched. This method accept negative index. A
- * negative index is counted from the end of the matched set.
+ * Return the ith element matched. This method accept negative index. A negative index is counted
+ * from the end of the matched set.
*
* Example:
*
@@ -2253,8 +2186,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Return the previous set of matched elements prior to the last destructive
- * operation (e.g. query)
+ * Return the previous set of matched elements prior to the last destructive operation (e.g.
+ * query)
*/
public GQuery getPreviousObject() {
return previousObject;
@@ -2275,21 +2208,19 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Returns true any of the specified classes are present on any of the matched
- * Reduce the set of matched elements to all elements after a given position.
- * The position of the element in the set of matched elements starts at 0 and
- * goes to length - 1.
+ * Returns true any of the specified classes are present on any of the matched Reduce the set of
+ * matched elements to all elements after a given position. The position of the element in the set
+ * of matched elements starts at 0 and goes to length - 1.
*/
public GQuery gt(int pos) {
return $(slice(pos + 1, -1));
}
/**
- * Reduce the set of matched elements to those that have a descendant
- * that matches the Element.
+ * Reduce the set of matched elements to those that have a descendant that matches the Element.
*/
public GQuery has(final Element elem) {
- return filter(new Predicate(){
+ return filter(new Predicate() {
public boolean f(Element e, int index) {
return engine.contains(e, elem);
}
@@ -2297,11 +2228,10 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Reduce the set of matched elements to those that have a descendant
- * that matches the selector.
+ * Reduce the set of matched elements to those that have a descendant that matches the selector.
*/
public GQuery has(final String selector) {
- return filter(new Predicate(){
+ return filter(new Predicate() {
public boolean f(Element e, int index) {
return !$(selector, e).isEmpty();
}
@@ -2309,8 +2239,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Returns true any of the specified classes are present on any of the matched
- * elements.
+ * Returns true any of the specified classes are present on any of the matched elements.
*/
public boolean hasClass(String... classes) {
for (Element e : elements) {
@@ -2324,8 +2253,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Get the current computed, pixel, height of the first matched element. It
- * does not include margin, padding nor border.
+ * Get the current computed, pixel, height of the first matched element. It does not include
+ * margin, padding nor border.
*/
public int height() {
return (int) cur("height", true);
@@ -2342,8 +2271,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Set the height style property of every matched element. It's useful for
- * using 'percent' or 'em' units Example: $(".a").width("100%")
+ * Set the height style property of every matched element. It's useful for using 'percent' or 'em'
+ * units Example: $(".a").width("100%")
*/
public GQuery height(String height) {
return css("height", height);
@@ -2360,27 +2289,25 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
data(e, "oldDisplay", getStyleImpl().curCSS(e, "display", false));
}
}
-
+
// Set the display value in a separate for loop to avoid constant reflow
// Reflows is very bad in performance point of view
- for (Element e : elements){
+ for (Element e : elements) {
e.getStyle().setDisplay(Display.NONE);
}
-
+
return this;
}
/**
- * Bind a function to the mouseover event of each matched element. A method
- * for simulating hovering (moving the mouse on, and off, an object). This is
- * a custom method which provides an 'in' to a frequent task. Whenever the
- * mouse cursor is moved over a matched element, the first specified function
- * is fired. Whenever the mouse moves off of the element, the second specified
+ * Bind a function to the mouseover event of each matched element. A method for simulating
+ * hovering (moving the mouse on, and off, an object). This is a custom method which provides an
+ * 'in' to a frequent task. Whenever the mouse cursor is moved over a matched element, the first
+ * specified function is fired. Whenever the mouse moves off of the element, the second specified
* function fires.
*/
public GQuery hover(Function fover, Function fout) {
- return bind(Event.ONMOUSEOVER, null, fover).bind(Event.ONMOUSEOUT, null,
- fout);
+ return bind(Event.ONMOUSEOVER, null, fover).bind(Event.ONMOUSEOUT, null, fout);
}
/**
@@ -2432,32 +2359,30 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Returns the inner height of the first matched element, including padding
- * but not the vertical scrollbar height, border, or margin.
+ * Returns the inner height of the first matched element, including padding but not the vertical
+ * scrollbar height, border, or margin.
*/
public int innerHeight() {
return isEmpty() ? 0 : get(0).getClientHeight();
}
/**
- * Returns the inner width of the first matched element, including padding but
- * not the vertical scrollbar width, border, or margin.
+ * Returns the inner width of the first matched element, including padding but not the vertical
+ * scrollbar width, border, or margin.
*/
public int innerWidth() {
return isEmpty() ? 0 : get(0).getClientWidth();
}
/**
- * Insert all of the matched elements after another, specified, set of
- * elements.
+ * Insert all of the matched elements after another, specified, set of elements.
*/
public GQuery insertAfter(Element elem) {
return insertAfter($(elem));
}
-
+
/**
- * Insert all of the matched elements after another, specified, set of
- * elements.
+ * Insert all of the matched elements after another, specified, set of elements.
*/
public GQuery insertAfter(GQuery query) {
for (Element e : elements) {
@@ -2467,30 +2392,27 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Insert all of the matched elements after another, specified, set of
- * elements.
+ * Insert all of the matched elements after another, specified, set of elements.
*/
public GQuery insertAfter(String selector) {
return insertAfter($(selector));
}
/**
- * Insert all of the matched elements before another, specified, set of
- * elements.
+ * Insert all of the matched elements before another, specified, set of elements.
*
- * The elements must already be inserted into the document (you can't insert
- * an element after another if it's not in the page).
+ * The elements must already be inserted into the document (you can't insert an element after
+ * another if it's not in the page).
*/
public GQuery insertBefore(Element item) {
return insertBefore($(item));
}
/**
- * Insert all of the matched elements before another, specified, set of
- * elements.
+ * Insert all of the matched elements before another, specified, set of elements.
*
- * The elements must already be inserted into the document (you can't insert
- * an element after another if it's not in the page).
+ * The elements must already be inserted into the document (you can't insert an element after
+ * another if it's not in the page).
*/
public GQuery insertBefore(GQuery query) {
for (Element e : elements) {
@@ -2500,27 +2422,26 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Insert all of the matched elements before another, specified, set of
- * elements.
+ * Insert all of the matched elements before another, specified, set of elements.
*
- * The elements must already be inserted into the document (you can't insert
- * an element after another if it's not in the page).
+ * The elements must already be inserted into the document (you can't insert an element after
+ * another if it's not in the page).
*/
public GQuery insertBefore(String selector) {
return insertBefore($(selector));
}
/**
- * Checks the current selection against an expression and returns true, if at
- * least one element of the selection fits the given expression. Does return
- * false, if no element fits or the expression is not valid.
+ * Checks the current selection against an expression and returns true, if at least one element of
+ * the selection fits the given expression. Does return false, if no element fits or the
+ * expression is not valid.
*/
public boolean is(String... filters) {
return !filter(filters).isEmpty();
}
/**
- * Returns true if the number of matched elements is 0.
+ * Returns true if the number of matched elements is 0.
*/
public boolean isEmpty() {
return size() == 0;
@@ -2534,8 +2455,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Bind a set of functions to the keydown event of each matched element. Or
- * trigger the event if no functions are provided.
+ * Bind a set of functions to the keydown event of each matched element. Or trigger the event if
+ * no functions are provided.
*/
public GQuery keydown(Function... f) {
return bindOrFire(Event.ONKEYDOWN, null, f);
@@ -2549,8 +2470,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Bind a set of functions to the keypress event of each matched element. Or
- * trigger the event if no functions are provided.
+ * Bind a set of functions to the keypress event of each matched element. Or trigger the event if
+ * no functions are provided.
*/
public GQuery keypress(Function... f) {
return bindOrFire(Event.ONKEYPRESS, null, f);
@@ -2564,8 +2485,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Bind a set of functions to the keyup event of each matched element. Or
- * trigger the event if no functions are provided.
+ * Bind a set of functions to the keyup event of each matched element. Or trigger the event if no
+ * functions are provided.
*/
public GQuery keyup(Function... f) {
return bindOrFire(Event.ONKEYUP, null, f);
@@ -2593,24 +2514,23 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Returns the number of elements currently matched. The size function will
- * return the same value.
+ * Returns the number of elements currently matched. The size function will return the same value.
*/
public int length() {
return size();
}
/**
- * Attach a handler for this event to all elements which match the current
- * selector, now and in the future.
+ * Attach a handler for this event to all elements which match the current selector, now and in
+ * the future.
*/
public GQuery live(int eventbits, Function... funcs) {
return as(Events).live(eventbits, null, funcs);
}
/**
- * Attach a handler for this event to all elements which match the current
- * selector, now and in the future.
+ * Attach a handler for this event to all elements which match the current selector, now and in
+ * the future.
*/
public GQuery live(int eventbits, Object data, Function... funcs) {
return as(Events).live(eventbits, data, funcs);
@@ -2618,8 +2538,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
/**
* <p>
- * Attach a handler for this event to all elements which match the current
- * selector, now and in the future.
+ * Attach a handler for this event to all elements which match the current selector, now and in
+ * the future.
* <p>
* <p>
* Ex :
@@ -2632,10 +2552,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* });
* </pre>
*
- * With this code, all elements with class "clickable" present in the DOM or
- * added to the DOM in the future will be clickable. The text color will be
- * changed to red when they will be clicked. So if after in the code, you add
- * another element :
+ * With this code, all elements with class "clickable" present in the DOM or added to the DOM in
+ * the future will be clickable. The text color will be changed to red when they will be clicked.
+ * So if after in the code, you add another element :
*
* <pre>
* $("body").append("<div class='clickable'>Click me and I will be red</div>");
@@ -2644,8 +2563,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* The click on this new element will also trigger the handler.
* </p>
* <p>
- * In the same way, if you add "clickable" class on some existing element,
- * these elements will be clickable also.
+ * In the same way, if you add "clickable" class on some existing element, these elements will be
+ * clickable also.
* </p>
* <p>
* <h3>important remarks</h3>
@@ -2662,8 +2581,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* }
* });
* </pre>
- * The {@link Function} will be called only on elements having the class
- * "clickable" and being descendant of myElement.</li>
+ * The {@link Function} will be called only on elements having the class "clickable" and being
+ * descendant of myElement.</li>
* </ul>
* </p>
*/
@@ -2673,9 +2592,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
/**
* <p>
- * Attach a handler for this event to all elements which match the current
- * selector, now and in the future. The <code>data</code> parameter allows us
- * to pass data to the handler.
+ * Attach a handler for this event to all elements which match the current selector, now and in
+ * the future. The <code>data</code> parameter allows us to pass data to the handler.
* <p>
* <p>
* Ex :
@@ -2688,10 +2606,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* });
* </pre>
*
- * With this code, all elements with class "clickable" present in the DOM or
- * added to the DOM in the future will be clickable. The text color will be
- * changed to red when they will be clicked. So if after in the code, you add
- * another element :
+ * With this code, all elements with class "clickable" present in the DOM or added to the DOM in
+ * the future will be clickable. The text color will be changed to red when they will be clicked.
+ * So if after in the code, you add another element :
*
* <pre>
* $("body").append("<div class='clickable'>Click me and I will be red</div>");
@@ -2700,8 +2617,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* The click on this new element will also trigger the handler.
* </p>
* <p>
- * In the same way, if you add "clickable" class on some existing element,
- * these elements will be clickable also.
+ * In the same way, if you add "clickable" class on some existing element, these elements will be
+ * clickable also.
* </p>
* <p>
* <h3>important remarks</h3>
@@ -2718,8 +2635,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* }
* });
* </pre>
- * The {@link Function} will be called only on elements having the class
- * "clickable" and being descendant of myElement.</li>
+ * The {@link Function} will be called only on elements having the class "clickable" and being
+ * descendant of myElement.</li>
* </ul>
* </p>
*/
@@ -2734,29 +2651,27 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
public GQuery load(Function f) {
return bind(Event.ONLOAD, null, f);
}
-
+
/**
* Load data from the server and place the returned HTML into the matched element.
*
- * The url allows us to specify a portion of the remote document to be inserted.
- * This is achieved with a special syntax for the url parameter.
- * If one or more space characters are included in the string, the portion of
- * the string following the first space is assumed to be a GQuery selector that
- * determines the content to be loaded.
+ * The url allows us to specify a portion of the remote document to be inserted. This is achieved
+ * with a special syntax for the url parameter. If one or more space characters are included in
+ * the string, the portion of the string following the first space is assumed to be a GQuery
+ * selector that determines the content to be loaded.
*
*/
public GQuery load(String url) {
return load(url, null, null);
}
-
+
/**
* Load data from the server and place the returned HTML into the matched element.
*
- * The url allows us to specify a portion of the remote document to be inserted.
- * This is achieved with a special syntax for the url parameter.
- * If one or more space characters are included in the string, the portion of
- * the string following the first space is assumed to be a GQuery selector that
- * determines the content to be loaded.
+ * The url allows us to specify a portion of the remote document to be inserted. This is achieved
+ * with a special syntax for the url parameter. If one or more space characters are included in
+ * the string, the portion of the string following the first space is assumed to be a GQuery
+ * selector that determines the content to be loaded.
*
*/
public GQuery load(String url, Properties data, final Function onSuccess) {
@@ -2764,25 +2679,24 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Reduce the set of matched elements to all elements before a given position.
- * The position of the element in the set of matched elements starts at 0 and
- * goes to length - 1.
+ * Reduce the set of matched elements to all elements before a given position. The position of the
+ * element in the set of matched elements starts at 0 and goes to length - 1.
*/
public GQuery lt(int pos) {
return $(slice(0, pos));
}
/**
- * Pass each element in the current matched set through a function, producing
- * a new array containing the return values.
- * When the call to the function returns a null it is not added to the array.
+ * Pass each element in the current matched set through a function, producing a new array
+ * containing the return values. When the call to the function returns a null it is not added to
+ * the array.
*/
public <W> List<W> map(Function f) {
ArrayList<W> ret = new ArrayList<W>();
int i = 0;
for (Element e : elements) {
@SuppressWarnings("unchecked")
- W o = (W)f.f(e.<com.google.gwt.dom.client.Element>cast(), i++);
+ W o = (W) f.f(e.<com.google.gwt.dom.client.Element> cast(), i++);
if (o != null) {
ret.add(o);
}
@@ -2790,51 +2704,77 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
return ret;
}
-
/**
- * Bind a set of functions to the mousedown event of each matched element. Or
- * trigger the event if no functions are provided.
+ * Bind a set of functions to the mousedown event of each matched element. Or trigger the event if
+ * no functions are provided.
*/
public GQuery mousedown(Function... f) {
return bindOrFire(Event.ONMOUSEDOWN, null, f);
}
-
+
+ /**
+ * Bind an event handler to be fired when the mouse enter an element, or trigger that handler on
+ * an element if no functions are provided.
+ *
+ * The mouseenter event differs from mouseover in the way it handles event bubbling. When
+ * mouseover is used on an element having inner element(s), then when the mouse pointer moves hover
+ * of the Inner element, the handler would be triggered. This is usually undesirable behavior. The
+ * mouseenter event, on the other hand, only triggers its handler when the mouse enters the
+ * element it is bound to, not a descendant.
+ */
+ public GQuery mouseenter(Function... f) {
+ return as(Events).mouseenter(f);
+ }
+
/**
- * Bind a set of functions to the mousemove event of each matched element. Or
- * trigger the event if no functions are provided.
+ * Bind an event handler to be fired when the mouse leaves an element, or trigger that handler on
+ * an element if no functions are provided.
+ *
+ * The mouseleave event differs from mouseout in the way it handles event bubbling. When
+ * mouseout is used on an element having inner element(s), then when the mouse pointer moves out
+ * of the Inner element, the handler would be triggered. This is usually undesirable behavior. The
+ * mouseleave event, on the other hand, only triggers its handler when the mouse leaves the
+ * element it is bound to, not a descendant.
+ */
+ public GQuery mouseleave(Function... f) {
+ return as(Events).mouseleave(f);
+ }
+
+ /**
+ * Bind a set of functions to the mousemove event of each matched element. Or trigger the event if
+ * no functions are provided.
*/
public GQuery mousemove(Function... f) {
return bindOrFire(Event.ONMOUSEMOVE, null, f);
}
/**
- * Bind a set of functions to the mouseout event of each matched element. Or
- * trigger the event if no functions are provided.
+ * Bind a set of functions to the mouseout event of each matched element. Or trigger the event if
+ * no functions are provided.
*/
public GQuery mouseout(Function... f) {
return bindOrFire(Event.ONMOUSEOUT, null, f);
}
/**
- * Bind a set of functions to the mouseover event of each matched element. Or
- * trigger the event if no functions are provided.
+ * Bind a set of functions to the mouseover event of each matched element. Or trigger the event if
+ * no functions are provided.
*/
public GQuery mouseover(Function... f) {
return bindOrFire(Event.ONMOUSEOVER, null, f);
}
/**
- * Bind a set of functions to the mouseup event of each matched element. Or
- * trigger the event if no functions are provided.
+ * Bind a set of functions to the mouseup event of each matched element. Or trigger the event if
+ * no functions are provided.
*/
public GQuery mouseup(Function... f) {
return bindOrFire(Event.ONMOUSEUP, null, f);
}
/**
- * Get a set of elements containing the unique next siblings of each of the
- * given set of elements. next only returns the very next sibling for each
- * element, not all next siblings see {#nextAll}.
+ * Get a set of elements containing the unique next siblings of each of the given set of elements.
+ * next only returns the very next sibling for each element, not all next siblings see {#nextAll}.
*/
public GQuery next() {
JsNodeArray result = JsNodeArray.create();
@@ -2848,10 +2788,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Get a set of elements containing the unique next siblings of each of the
- * given set of elements filtered by 1 or more selectors. next only returns
- * the very next sibling for each element, not all next siblings see
- * {#nextAll}.
+ * Get a set of elements containing the unique next siblings of each of the given set of elements
+ * filtered by 1 or more selectors. next only returns the very next sibling for each element, not
+ * all next siblings see {#nextAll}.
*/
public GQuery next(String... selectors) {
JsNodeArray result = JsNodeArray.create();
@@ -2865,75 +2804,72 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Get all following siblings of each element in the set of matched
- * elements.
+ * Get all following siblings of each element in the set of matched elements.
*/
public GQuery nextAll() {
return nextAll(null);
}
-
+
/**
- * Get all following siblings of each element in the set of matched
- * elements, filtered by a selector.
+ * Get all following siblings of each element in the set of matched elements, filtered by a
+ * selector.
*/
public GQuery nextAll(String filter) {
JsNodeArray result = JsNodeArray.create();
for (Element e : elements) {
allNextSiblingElements(e.getNextSiblingElement(), result, null, null, filter);
}
-
+
return pushStack(unique(result), "nextAll", getSelector());
}
/**
- * Get all following siblings of each element up to but not including the
- * element matched by the selector.
+ * Get all following siblings of each element up to but not including the element matched by the
+ * selector.
*
* @param selector
* @return
*/
public GQuery nextUntil(String selector) {
- return nextUntil($(selector), null);
+ return nextUntil($(selector), null);
}
-
+
/**
- * Get all following siblings of each element up to but not including the
- * element matched by the selector, filtered by a selector.
+ * Get all following siblings of each element up to but not including the element matched by the
+ * selector, filtered by a selector.
*
* @param selector
* @return
*/
public GQuery nextUntil(String selector, String filter) {
- return nextUntil($(selector), filter);
+ return nextUntil($(selector), filter);
}
/**
- * Get all following siblings of each element up to but not including the
- * element matched by the DOM node.
+ * Get all following siblings of each element up to but not including the element matched by the
+ * DOM node.
*
* @param selector
* @return
*/
public GQuery nextUntil(Element until) {
- return nextUntil($(until), null);
+ return nextUntil($(until), null);
}
-
/**
- * Get all following siblings of each element up to but not including the
- * element matched by the DOM node, filtered by a selector.
+ * Get all following siblings of each element up to but not including the element matched by the
+ * DOM node, filtered by a selector.
*
* @param selector
* @return
*/
public GQuery nextUntil(Element until, String filter) {
- return nextUntil($(until), filter);
+ return nextUntil($(until), filter);
}
-
-
+
/**
- * Get all following siblings of each element up to but not including the
- * element matched by the GQuery object.
+ * Get all following siblings of each element up to but not including the element matched by the
+ * GQuery object.
*
* @param selector
* @return
@@ -2942,10 +2878,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
return nextUntil(until, null);
}
-
/**
- * Get all following siblings of each element up to but not including the
- * element matched by the GQuery object, filtered by a selector
+ * Get all following siblings of each element up to but not including the element matched by the
+ * GQuery object, filtered by a selector
*
* @param selector
* @return
@@ -2958,10 +2893,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
return pushStack(unique(result), "nextUntil", getSelector());
}
-
/**
- * Removes the specified Element from the set of matched elements. This method
- * is used to remove a single Element from a jQuery object.
+ * Removes the specified Element from the set of matched elements. This method is used to remove a
+ * single Element from a jQuery object.
*/
public GQuery not(Element elem) {
JsNodeArray array = JsNodeArray.create();
@@ -2974,8 +2908,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Removes any elements inside the passed set of elements from the set of
- * matched elements.
+ * Removes any elements inside the passed set of elements from the set of matched elements.
*/
public GQuery not(GQuery gq) {
GQuery ret = this;
@@ -2986,8 +2919,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Removes elements matching the specified expression from the set of matched
- * elements.
+ * Removes elements matching the specified expression from the set of matched elements.
*/
public GQuery not(String... filters) {
GQuery ret = this;
@@ -2998,28 +2930,26 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Get the current offset of the first matched element, in pixels, relative to
- * the document. The returned object contains two integer properties, top and
- * left. The method works only with visible elements.
+ * Get the current offset of the first matched element, in pixels, relative to the document. The
+ * returned object contains two integer properties, top and left. The method works only with
+ * visible elements.
*/
public com.google.gwt.query.client.GQuery.Offset offset() {
Element e = get(0);
- return e == null ? new Offset(0, 0) : new Offset(e.getAbsoluteLeft(),
- e.getAbsoluteTop());
+ return e == null ? new Offset(0, 0) : new Offset(e.getAbsoluteLeft(), e.getAbsoluteTop());
}
/**
- * Returns a GQuery collection with the positioned parent of the first matched
- * element. This is the first parent of the element that has position (as in
- * relative or absolute). This method only works with visible elements.
+ * Returns a GQuery collection with the positioned parent of the first matched element. This is
+ * the first parent of the element that has position (as in relative or absolute). This method
+ * only works with visible elements.
*/
public GQuery offsetParent() {
if (isEmpty()) {
return $();
}
Element offParent = JsUtils.or(get(0).getOffsetParent(), body);
- while (offParent != null
- && !"body".equalsIgnoreCase(offParent.getTagName())
+ while (offParent != null && !"body".equalsIgnoreCase(offParent.getTagName())
&& !"html".equalsIgnoreCase(offParent.getTagName())
&& "static".equals(getStyleImpl().curCSS(offParent, "position", true))) {
offParent = offParent.getOffsetParent();
@@ -3028,31 +2958,29 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Binds a handler to a particular Event (like Event.ONCLICK) for each matched
- * element. The handler is executed only once for each element.
+ * Binds a handler to a particular Event (like Event.ONCLICK) for each matched element. The
+ * handler is executed only once for each element.
*
- * The event handler is passed as a Function that you can use to prevent
- * default behavior. To stop both default action and event bubbling, the
- * function event handler has to return false.
+ * The event handler is passed as a Function that you can use to prevent default behavior. To stop
+ * both default action and event bubbling, the function event handler has to return false.
*
- * You can pass an additional Object data to your Function as the second
- * parameter
+ * You can pass an additional Object data to your Function as the second parameter
*/
public GQuery one(int eventbits, final Object data, final Function f) {
return as(Events).one(eventbits, data, f);
}
/**
- * Get the current computed height for the first element in the set of matched
- * elements, including padding, border, but not the margin.
+ * Get the current computed height for the first element in the set of matched elements, including
+ * padding, border, but not the margin.
*/
public int outerHeight() {
return outerHeight(false);
}
-
+
/**
- * Get the current computed height for the first element in the set of matched
- * elements, including padding, border, and optionally margin.
+ * Get the current computed height for the first element in the set of matched elements, including
+ * padding, border, and optionally margin.
*/
public int outerHeight(boolean includeMargin) {
if (isEmpty()) {
@@ -3065,19 +2993,18 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
return outerHeight;
}
-
/**
- * Get the current computed width for the first element in the set of matched
- * elements, including padding, border, but not the margin.
+ * Get the current computed width for the first element in the set of matched elements, including
+ * padding, border, but not the margin.
*/
public int outerWidth() {
return outerWidth(false);
}
/**
- * Get the current computed width for the first element in the set of matched
- * elements, including padding and border and optionally margin.
+ * Get the current computed width for the first element in the set of matched elements, including
+ * padding and border and optionally margin.
*/
public int outerWidth(boolean includeMargin) {
if (isEmpty()) {
@@ -3092,8 +3019,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Get a set of elements containing the unique parents of the matched set of
- * elements.
+ * Get a set of elements containing the unique parents of the matched set of elements.
*/
public GQuery parent() {
JsNodeArray result = JsNodeArray.create();
@@ -3107,35 +3033,34 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Get a set of elements containing the unique parents of the matched set of
- * elements. You may use an optional expressions to filter the set of parent
- * elements that will match one of them.
+ * Get a set of elements containing the unique parents of the matched set of elements. You may use
+ * an optional expressions to filter the set of parent elements that will match one of them.
*/
public GQuery parent(String... filters) {
return parent().filter(filters);
}
/**
- * Get a set of elements containing the unique ancestors of the matched set of
- * elements (except for the root element).
+ * Get a set of elements containing the unique ancestors of the matched set of elements (except
+ * for the root element).
*/
public GQuery parents() {
return parentsUntil(null);
}
/**
- * Get a set of elements containing the unique ancestors of the matched set of
- * elements (except for the root element). The matched elements are filtered,
- * returning those that match any of the filters.
+ * Get a set of elements containing the unique ancestors of the matched set of elements (except
+ * for the root element). The matched elements are filtered, returning those that match any of the
+ * filters.
*/
public GQuery parents(String... filters) {
return parents().filter(filters);
}
/**
- * Get the ancestors of each element in the current set of matched elements,
- * up to but not including the element matched by the selector.
- *
+ * Get the ancestors of each element in the current set of matched elements, up to but not
+ * including the element matched by the selector.
+ *
*/
public GQuery parentsUntil(String selector) {
JsNodeArray result = JsNodeArray.create();
@@ -3153,10 +3078,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Gets the top and left position of an element relative to its offset parent.
- * The returned object contains two Integer properties, top and left. For
- * accurate calculations make sure to use pixel values for margins, borders
- * and padding. This method only works with visible elements.
+ * Gets the top and left position of an element relative to its offset parent. The returned object
+ * contains two Integer properties, top and left. For accurate calculations make sure to use pixel
+ * values for margins, borders and padding. This method only works with visible elements.
*/
public com.google.gwt.query.client.GQuery.Offset position() {
if (isEmpty()) {
@@ -3188,51 +3112,44 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
offset = offset.add(-leftMargin, -topMargin);
// Add offsetParent borders
- int parentOffsetBorderTop = (int) getStyleImpl().cur(offsetParent,
- "borderTopWidth", true);
- int parentOffsetBorderLeft = (int) getStyleImpl().cur(offsetParent,
- "borderLeftWidth", true);
- parentOffset = parentOffset.add(parentOffsetBorderLeft,
- parentOffsetBorderTop);
+ int parentOffsetBorderTop = (int) getStyleImpl().cur(offsetParent, "borderTopWidth", true);
+ int parentOffsetBorderLeft = (int) getStyleImpl().cur(offsetParent, "borderLeftWidth", true);
+ parentOffset = parentOffset.add(parentOffsetBorderLeft, parentOffsetBorderTop);
// Subtract the two offsets
return offset.add(-parentOffset.left, -parentOffset.top);
}
/**
- * Prepend content to the inside of every matched element. This operation is
- * the best way to insert elements inside, at the beginning, of all matched
- * elements.
+ * Prepend content to the inside of every matched element. This operation is the best way to
+ * insert elements inside, at the beginning, of all matched elements.
*/
public GQuery prepend(GQuery query) {
return domManip(query, DomMan.PREPEND);
}
/**
- * Prepend content to the inside of every matched element. This operation is
- * the best way to insert elements inside, at the beginning, of all matched
- * elements.
+ * Prepend content to the inside of every matched element. This operation is the best way to
+ * insert elements inside, at the beginning, of all matched elements.
*/
public GQuery prepend(Node n) {
return domManip($(n), DomMan.PREPEND);
}
-
+
/**
- * Prepend content to the inside of every matched element. This operation is
- * the best way to insert elements inside, at the beginning, of all matched
- * elements.
+ * Prepend content to the inside of every matched element. This operation is the best way to
+ * insert elements inside, at the beginning, of all matched elements.
*/
public GQuery prepend(String html) {
return domManip(html, DomMan.PREPEND);
}
-
+
/**
- * All of the matched set of elements will be inserted at the beginning of the
- * element(s) specified by the parameter other.
+ * All of the matched set of elements will be inserted at the beginning of the element(s)
+ * specified by the parameter other.
*
- * The operation $(A).prependTo(B) is, essentially, the reverse of doing a
- * regular $(A).prepend(B), instead of prepending B to A, you're prepending A
- * to B.
+ * The operation $(A).prependTo(B) is, essentially, the reverse of doing a regular
+ * $(A).prepend(B), instead of prepending B to A, you're prepending A to B.
*/
public GQuery prependTo(GQuery other) {
other.prepend(this);
@@ -3240,12 +3157,11 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * All of the matched set of elements will be inserted at the beginning of the
- * element(s) specified by the parameter other.
+ * All of the matched set of elements will be inserted at the beginning of the element(s)
+ * specified by the parameter other.
*
- * The operation $(A).prependTo(B) is, essentially, the reverse of doing a
- * regular $(A).prepend(B), instead of prepending B to A, you're prepending A
- * to B.
+ * The operation $(A).prependTo(B) is, essentially, the reverse of doing a regular
+ * $(A).prepend(B), instead of prepending B to A, you're prepending A to B.
*/
public GQuery prependTo(Node n) {
$(n).prepend(this);
@@ -3253,22 +3169,20 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * All of the matched set of elements will be inserted at the beginning of the
- * element(s) specified by the parameter other.
+ * All of the matched set of elements will be inserted at the beginning of the element(s)
+ * specified by the parameter other.
*
- * The operation $(A).prependTo(B) is, essentially, the reverse of doing a
- * regular $(A).prepend(B), instead of prepending B to A, you're prepending A
- * to B.
+ * The operation $(A).prependTo(B) is, essentially, the reverse of doing a regular
+ * $(A).prepend(B), instead of prepending B to A, you're prepending A to B.
*/
public GQuery prependTo(String html) {
$(html).prepend(this);
return this;
}
-
+
/**
- * Get a set of elements containing the unique previous siblings of each of
- * the matched set of elements. Only the immediately previous sibling is
- * returned, not all previous siblings.
+ * Get a set of elements containing the unique previous siblings of each of the matched set of
+ * elements. Only the immediately previous sibling is returned, not all previous siblings.
*/
public GQuery prev() {
JsNodeArray result = JsNodeArray.create();
@@ -3280,11 +3194,11 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
return new GQuery(unique(result));
}
-
+
/**
- * Get a set of elements containing the unique previous siblings of each of
- * the matched set of elements filtered by selector. Only the immediately
- * previous sibling is returned, not all previous siblings.
+ * Get a set of elements containing the unique previous siblings of each of the matched set of
+ * elements filtered by selector. Only the immediately previous sibling is returned, not all
+ * previous siblings.
*/
public GQuery prev(String... selectors) {
JsNodeArray result = JsNodeArray.create();
@@ -3296,106 +3210,95 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
return new GQuery(unique(result)).filter(selectors);
}
-
- /**
- * Get all preceding siblings of each element in the set of matched
- * elements.
- */
- public GQuery prevAll() {
- return prevAll(null);
- }
-
- /**
- * Get all preceding siblings of each element in the set of matched elements
- * filtered by a selector.
- */
- public GQuery prevAll(String selector) {
- JsNodeArray result = JsNodeArray.create();
- for (Element e : elements) {
- allPreviousSiblingElements(getPreviousSiblingElement(e), result,
- null, selector);
- }
- return pushStack(unique(result), "prevAll", getSelector());
- }
-
- /**
- * Get all preceding siblings of each element up to but not including the
- * element matched by the <code>selector</code>.
- *
- * The elements are returned in order from the closest sibling to the
- * farthest.
- */
- public GQuery prevUntil(String selector) {
- return prevUntil($(selector), null);
- }
-
- /**
- * Get all preceding siblings of each element up to but not including the
- * <code>until</code> element.
- *
- * The elements are returned in order from the closest sibling to the
- * farthest.
- */
- public GQuery prevUntil(Element until) {
- return prevUntil($(until), null);
- }
-
- /**
- * Get all preceding siblings of each element up to but not including the
- * <code>until</code> element.
- *
- * The elements are returned in order from the closest sibling to the
- * farthest.
- */
- public GQuery prevUntil(GQuery until) {
- return prevUntil(until, null);
- }
-
- /**
- * Get all preceding siblings of each element matching the
- * <code>filter</code> up to but not including the element matched by the
- * <code>selector</code>.
- *
- * The elements are returned in order from the closest sibling to the
- * farthest.
- */
- public GQuery prevUntil(String selector, String filter) {
- return prevUntil($(selector), filter);
- }
-
- /**
- * Get all preceding siblings of each element matching the
- * <code>filter</code> up to but not including the <code>until</code>
- * element.
- *
- */
- public GQuery prevUntil(Element until, String filter) {
- return prevUntil($(until), filter);
- }
-
- /**
- * Get all preceding siblings of each element matching the
- * <code>filter</code> up to but not including the element matched by the
- * <code>until</code> element.
- *
- */
- public GQuery prevUntil(GQuery until, String filter) {
- JsNodeArray result = JsNodeArray.create();
- for (Element e : elements) {
- allPreviousSiblingElements(getPreviousSiblingElement(e), result,
- until, filter);
- }
- return pushStack(unique(result), "prevUntil", getSelector());
- }
+
+ /**
+ * Get all preceding siblings of each element in the set of matched elements.
+ */
+ public GQuery prevAll() {
+ return prevAll(null);
+ }
+
+ /**
+ * Get all preceding siblings of each element in the set of matched elements filtered by a
+ * selector.
+ */
+ public GQuery prevAll(String selector) {
+ JsNodeArray result = JsNodeArray.create();
+ for (Element e : elements) {
+ allPreviousSiblingElements(getPreviousSiblingElement(e), result, null, selector);
+ }
+ return pushStack(unique(result), "prevAll", getSelector());
+ }
+
+ /**
+ * Get all preceding siblings of each element up to but not including the element matched by the
+ * <code>selector</code>.
+ *
+ * The elements are returned in order from the closest sibling to the farthest.
+ */
+ public GQuery prevUntil(String selector) {
+ return prevUntil($(selector), null);
+ }
+
+ /**
+ * Get all preceding siblings of each element up to but not including the <code>until</code>
+ * element.
+ *
+ * The elements are returned in order from the closest sibling to the farthest.
+ */
+ public GQuery prevUntil(Element until) {
+ return prevUntil($(until), null);
+ }
+
+ /**
+ * Get all preceding siblings of each element up to but not including the <code>until</code>
+ * element.
+ *
+ * The elements are returned in order from the closest sibling to the farthest.
+ */
+ public GQuery prevUntil(GQuery until) {
+ return prevUntil(until, null);
+ }
+
+ /**
+ * Get all preceding siblings of each element matching the <code>filter</code> up to but not
+ * including the element matched by the <code>selector</code>.
+ *
+ * The elements are returned in order from the closest sibling to the farthest.
+ */
+ public GQuery prevUntil(String selector, String filter) {
+ return prevUntil($(selector), filter);
+ }
+
+ /**
+ * Get all preceding siblings of each element matching the <code>filter</code> up to but not
+ * including the <code>until</code> element.
+ *
+ */
+ public GQuery prevUntil(Element until, String filter) {
+ return prevUntil($(until), filter);
+ }
+
+ /**
+ * Get all preceding siblings of each element matching the <code>filter</code> up to but not
+ * including the element matched by the <code>until</code> element.
+ *
+ */
+ public GQuery prevUntil(GQuery until, String filter) {
+ JsNodeArray result = JsNodeArray.create();
+ for (Element e : elements) {
+ allPreviousSiblingElements(getPreviousSiblingElement(e), result, until, filter);
+ }
+ return pushStack(unique(result), "prevUntil", getSelector());
+ }
/**
* Accesses a boolean property on the first matched element.
*
* @param key the name of the boolean property to be accessed
*
- * @return <code>true</code> if at least one element is matched and the
- * specified boolean property is set to <code>true</code> on the first
- * matched element; <code>false</code> otherwise
+ * @return <code>true</code> if at least one element is matched and the specified boolean property
+ * is set to <code>true</code> on the first matched element; <code>false</code> otherwise
*
*/
public boolean prop(String key) {
@@ -3427,14 +3330,12 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* Sets a boolean property to a computed value on all matched elements.
*
* @param key the name of the boolean property to be set
- * @param closure the closure to be used to compute the value the specified
- * boolean property should be set to; the <code>closure</code> is
- * {@linkplain Function#f(com.google.gwt.dom.client.Element, int)
- * passed} the target element and its index as arguments and is
- * expected to return either a <code>Boolean</code> value or an
- * object whose textual representation is converted to a
- * <code>Boolean</code> value; <code>null</code> return values are
- * ignored
+ * @param closure the closure to be used to compute the value the specified boolean property
+ * should be set to; the <code>closure</code> is
+ * {@linkplain Function#f(com.google.gwt.dom.client.Element, int) passed} the target
+ * element and its index as arguments and is expected to return either a
+ * <code>Boolean</code> value or an object whose textual representation is converted to a
+ * <code>Boolean</code> value; <code>null</code> return values are ignored
*
* @return this <code>GQuery</code> object
*
@@ -3442,13 +3343,13 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
public GQuery prop(String key, Function closure) {
assert key != null : "Key is null";
assert closure != null : "Closure is null";
-
+
int i = 0;
for (Element e : elements) {
Object value = closure.f(e, i++);
if (value != null) {
- e.setPropertyBoolean(key, value instanceof Boolean ? (Boolean) value
- : Boolean.valueOf(value.toString()));
+ e.setPropertyBoolean(key, value instanceof Boolean ? (Boolean) value : Boolean
+ .valueOf(value.toString()));
}
}
@@ -3464,8 +3365,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Show the number of functions in the efects queue to be executed on the
- * first matched element.
+ * Show the number of functions in the efects queue to be executed on the first matched element.
*/
public int queue() {
return as(Queue).queue();
@@ -3489,22 +3389,21 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
*
* </pre>
*
- * When this statement is executed, the element move to 500 px to left for 400
- * ms, then its background color is changed to red and then move to 500px to
- * right for 400ms, and finally its color is set to yellow.
+ * When this statement is executed, the element move to 500 px to left for 400 ms, then its
+ * background color is changed to red and then move to 500px to right for 400ms, and finally its
+ * color is set to yellow.
*
- * Please note that {@link #dequeue()} function is needed at the end of your
- * function to start the next function in the queue. In lazy() methods you should
- * call dequeue() just before the done() call.
- * {@see #dequeue()}
+ * Please note that {@link #dequeue()} function is needed at the end of your function to start the
+ * next function in the queue. In lazy() methods you should call dequeue() just before the done()
+ * call. {@see #dequeue()}
*/
public GQuery queue(Function... f) {
return as(Queue).queue(f);
}
/**
- * Show the number of functions in the queued named as queueName to be
- * executed on the first matched element.
+ * Show the number of functions in the queued named as queueName to be executed on the first
+ * matched element.
*/
public int queue(String queueName) {
return as(Queue).queue();
@@ -3526,14 +3425,12 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* .queue("myQueue", lazy().css(CSS.COLOR.with(RGBColor.YELLOW)).dequeue("myQueue").done());
* </pre>
*
- * When this statement is executed, the background color of the element is set
- * to red, then wait 500ms before to set the text color of the element to
- * yellow. right for 400ms.
+ * When this statement is executed, the background color of the element is set to red, then wait
+ * 500ms before to set the text color of the element to yellow. right for 400ms.
*
- * Please note that {@link #dequeue()} function is needed at the end of your
- * function to start the next function in the queue. In lazy() methods you should
- * call dequeue() just before the done() call.
- * {@see #dequeue()}
+ * Please note that {@link #dequeue()} function is needed at the end of your function to start the
+ * next function in the queue. In lazy() methods you should call dequeue() just before the done()
+ * call. {@see #dequeue()}
*/
public GQuery queue(String queueName, Function... f) {
return as(Queue).queue(queueName, f);
@@ -3547,17 +3444,16 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Removes from the DOM all matched elements filtered by the
- * <code>filter</code>.
+ * Removes from the DOM all matched elements filtered by the <code>filter</code>.
*/
public GQuery remove(String filter) {
return remove(filter, true);
}
/**
- * Removes all matched elements from the DOM and cleans their data and bound
- * events if the value of <code>clean</code> parameter is set to true. The
- * <code> filter</code> parameter allows to filter the matched set to remove.
+ * Removes all matched elements from the DOM and cleans their data and bound events if the value
+ * of <code>clean</code> parameter is set to true. The <code> filter</code> parameter allows to
+ * filter the matched set to remove.
*/
protected GQuery remove(String filter, boolean clean) {
for (Element e : elements) {
@@ -3578,7 +3474,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
return this;
}
-
+
/**
* Remove the named attribute from every element in the matched set.
*/
@@ -3592,7 +3488,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
*/
public GQuery removeClass(String... classes) {
for (Element e : elements) {
- if (Element.is(e)){
+ if (Element.is(e)) {
for (String clz : classes) {
e.removeClassName(clz);
}
@@ -3600,7 +3496,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
return this;
}
-
+
private void removeData(Element item, String name) {
if (dataCache == null) {
windowData = JavaScriptObject.createObject().cast();
@@ -3631,9 +3527,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Replaces the element <code>elem</code> by the specified selector with the
- * matched elements. This function is the complement to replaceWith() which
- * does the same task with the parameters reversed.
+ * Replaces the element <code>elem</code> by the specified selector with the matched elements.
+ * This function is the complement to replaceWith() which does the same task with the parameters
+ * reversed.
*
* @return a {@link GQuery} object containing the new elements.
*/
@@ -3642,9 +3538,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Replaces the elements matched by the target with the selected elements.
- * This function is the complement to replaceWith() which does the same task
- * with the parameters reversed.
+ * Replaces the elements matched by the target with the selected elements. This function is the
+ * complement to replaceWith() which does the same task with the parameters reversed.
*
* @return a {@link GQuery} object containing the new elements.
*/
@@ -3652,8 +3547,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
// if there is only one element and it is not attached to the dom, we have
// to clone it to be reused on each element of target (if target contains
// more than one element)
- boolean mustBeCloned = length() == 1
- && parents().filter("body").length() == 0;
+ boolean mustBeCloned = length() == 1 && parents().filter("body").length() == 0;
List<Element> newElements = new ArrayList<Element>();
for (int i = 0, l = target.size(); i < l; i++) {
@@ -3665,9 +3559,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Replaces the elements matched by the specified selector with the matched
- * elements. This function is the complement to replaceWith() which does the
- * same task with the parameters reversed.
+ * Replaces the elements matched by the specified selector with the matched elements. This
+ * function is the complement to replaceWith() which does the same task with the parameters
+ * reversed.
*
* @return a {@link GQuery} object containing the new elements.
*/
@@ -3678,19 +3572,18 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
/**
* Replaces all matched elements with the specified element.
*
- * @return the GQuery element that was just replaced, which has been removed
- * from the DOM and not the new element that has replaced it.
+ * @return the GQuery element that was just replaced, which has been removed from the DOM and not
+ * the new element that has replaced it.
*/
public GQuery replaceWith(Element elem) {
return replaceWith($(elem));
}
/**
- * Replaces all matched elements with elements selected by <code>target</code>
- * .
+ * Replaces all matched elements with elements selected by <code>target</code> .
*
- * @return the GQuery element that was just replaced, which has been removed
- * from the DOM and not the new element that has replaced it.
+ * @return the GQuery element that was just replaced, which has been removed from the DOM and not
+ * the new element that has replaced it.
*/
public GQuery replaceWith(GQuery target) {
for (Element el : elements) {
@@ -3711,8 +3604,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
/**
* Replaces all matched elements with the specified HTML.
*
- * @return the GQuery element that was just replaced, which has been removed
- * from the DOM and not the new element that has replaced it.
+ * @return the GQuery element that was just replaced, which has been removed from the DOM and not
+ * the new element that has replaced it.
*/
public GQuery replaceWith(String html) {
for (Element el : elements) {
@@ -3730,13 +3623,12 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Bind a set of functions to the resize event of each matched element, or
- * tigger the resize event if no functions are provided.
+ * Bind a set of functions to the resize event of each matched element, or tigger the resize event
+ * if no functions are provided.
*
- * Note that although all elements can be configured to handle resize
- * events, by default only window will trigger it when it is resized,
- * for an arbitrary element you have to trigger the event after resizing
- * the object.
+ * Note that although all elements can be configured to handle resize events, by default only
+ * window will trigger it when it is resized, for an arbitrary element you have to trigger the
+ * event after resizing the object.
*
*/
public GQuery resize(Function... f) {
@@ -3744,7 +3636,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Bind an event handler to the "resize" JavaScript event, or trigger that event on an element.
+ * Bind an event handler to the "resize" JavaScript event, or trigger that event on an element.
*/
public GQuery resize(final Function f) {
return bindOrFire(EventsListener.ONRESIZE, null, f);
@@ -3756,8 +3648,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
public void restoreCssAttrs(String... cssProps) {
for (Element e : elements) {
for (String a : cssProps) {
- getStyleImpl().setStyleProperty(e, a, (String) data(e, OLD_DATA_PREFIX + a,
- null));
+ getStyleImpl().setStyleProperty(e, a, (String) data(e, OLD_DATA_PREFIX + a, null));
}
}
}
@@ -3774,8 +3665,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Bind a set of functions to the scroll event of each matched element. Or
- * trigger the event if no functions are provided.
+ * Bind a set of functions to the scroll event of each matched element. Or trigger the event if no
+ * functions are provided.
*/
public GQuery scroll(Function... f) {
return bindOrFire(Event.ONSCROLL, null, f);
@@ -3793,10 +3684,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
/**
* Scrolls the first matched element into view.
*
- * If ensure == true, it crawls up the DOM hierarchy, adjusting the scrollLeft
- * and scrollTop properties of each scroll-able element to ensure that the
- * specified element is completely in view. It adjusts each scroll position by
- * the minimum amount necessary.
+ * If ensure == true, it crawls up the DOM hierarchy, adjusting the scrollLeft and scrollTop
+ * properties of each scroll-able element to ensure that the specified element is completely in
+ * view. It adjusts each scroll position by the minimum amount necessary.
*/
public GQuery scrollIntoView(boolean ensure) {
if (!isEmpty() && ensure) {
@@ -3808,8 +3698,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Gets the scroll left offset of the first matched element. This method works
- * for both visible and hidden elements.
+ * Gets the scroll left offset of the first matched element. This method works for both visible
+ * and hidden elements.
*/
public int scrollLeft() {
Element e = get(0);
@@ -3826,8 +3716,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * The scroll left offset is set to the passed value on all matched elements.
- * This method works for both visible and hidden elements.
+ * The scroll left offset is set to the passed value on all matched elements. This method works
+ * for both visible and hidden elements.
*/
public GQuery scrollLeft(int left) {
for (Element e : elements) {
@@ -3842,12 +3732,12 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
/**
*
- * Scrolls the contents of all matched elements to the specified co-ordinate
- * becoming the top left corner of the viewable area.
+ * Scrolls the contents of all matched elements to the specified co-ordinate becoming the top left
+ * corner of the viewable area.
*
- * This method is only useful where there are areas of the document not
- * viewable within the current viewable area of the window and the visible
- * property of the window's scrollbar must be set to true.
+ * This method is only useful where there are areas of the document not viewable within the
+ * current viewable area of the window and the visible property of the window's scrollbar must be
+ * set to true.
*
*/
public GQuery scrollTo(int left, int top) {
@@ -3856,8 +3746,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Gets the scroll top offset of the first matched element. This method works
- * for both visible and hidden elements.
+ * Gets the scroll top offset of the first matched element. This method works for both visible and
+ * hidden elements.
*/
public int scrollTop() {
Element e = get(0);
@@ -3874,8 +3764,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * The scroll top offset is set to the passed value on all matched elements.
- * This method works for both visible and hidden elements.
+ * The scroll top offset is set to the passed value on all matched elements. This method works for
+ * both visible and hidden elements.
*/
public GQuery scrollTop(int top) {
for (Element e : elements) {
@@ -3904,17 +3794,16 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Force the current matched set of elements to become the specified array of
- * elements.
+ * Force the current matched set of elements to become the specified array of elements.
*/
public GQuery setArray(NodeList<Element> list) {
if (list != null) {
- nodeList.<JsCache>cast().clear();
+ nodeList.<JsCache> cast().clear();
int l = list.getLength();
elements = new Element[l];
for (int i = 0; i < l; i++) {
elements[i] = list.getItem(i);
- nodeList.<JsObjectArray<Element>>cast().add(list.getItem(i));
+ nodeList.<JsObjectArray<Element>> cast().add(list.getItem(i));
}
}
return this;
@@ -3935,50 +3824,50 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
public GQuery show() {
for (Element e : elements) {
String currentDisplay = e.getStyle().getDisplay();
- String oldDisplay = (String) data(e,"oldDisplay", null);
-
- //reset the display
- if (oldDisplay == null && "none".equals(currentDisplay)){
+ String oldDisplay = (String) data(e, "oldDisplay", null);
+
+ // reset the display
+ if (oldDisplay == null && "none".equals(currentDisplay)) {
getStyleImpl().setStyleProperty(e, "display", "");
currentDisplay = "";
}
-
- //check if the stylesheet impose display: none. If it is the case, determine
- //the default display for the tag and store it at the element level
- if ("".equals(currentDisplay) && !getStyleImpl().isVisible(e)){
+
+ // check if the stylesheet impose display: none. If it is the case, determine
+ // the default display for the tag and store it at the element level
+ if ("".equals(currentDisplay) && !getStyleImpl().isVisible(e)) {
data(e, "oldDisplay", getStyleImpl().defaultDisplay(e.getNodeName()));
}
}
-
+
// set the display value in a separate for loop to avoid constant reflow
- // because broswer reflow is triggered each time we gonna set and after get (in isVisibleProperty() method)
+ // because broswer reflow is triggered each time we gonna set and after get (in
+ // isVisibleProperty() method)
// the diplay property. Reflows is very bad in performance point of view
for (Element e : elements) {
String currentDisplay = e.getStyle().getDisplay();
- if ("".equals(currentDisplay) || "none".equals(currentDisplay)){
- getStyleImpl().setStyleProperty(e, "display", JsUtils.or((String) data(e,
- "oldDisplay", null), ""));
+ if ("".equals(currentDisplay) || "none".equals(currentDisplay)) {
+ getStyleImpl().setStyleProperty(e, "display",
+ JsUtils.or((String) data(e, "oldDisplay", null), ""));
}
}
return this;
}
-
+
/**
- * Get a set of elements containing all of the unique siblings of each of the
- * matched set of elements.
+ * Get a set of elements containing all of the unique siblings of each of the matched set of
+ * elements.
*/
public GQuery siblings() {
JsNodeArray result = JsNodeArray.create();
for (Element e : elements) {
- allNextSiblingElements(e.getParentElement().getFirstChildElement(),
- result, e, null, null);
+ allNextSiblingElements(e.getParentElement().getFirstChildElement(), result, e, null, null);
}
return new GQuery(unique(result));
}
/**
- * Get a set of elements containing all of the unique siblings of each of the
- * matched set of elements filtered by the provided set of selectors.
+ * Get a set of elements containing all of the unique siblings of each of the matched set of
+ * elements filtered by the provided set of selectors.
*/
public GQuery siblings(String... selectors) {
return siblings().filter(selectors);
@@ -4007,98 +3896,94 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Reveal all matched elements by adjusting their height and firing an
- * optional callback after completion.
+ * Reveal all matched elements by adjusting their height and firing an optional callback after
+ * completion.
*/
public Effects slideDown(Function... f) {
return as(Effects).slideDown(f);
}
/**
- * Reveal all matched elements by adjusting their height and firing an
- * optional callback after completion.
+ * Reveal all matched elements by adjusting their height and firing an optional callback after
+ * completion.
*/
public Effects slideDown(int millisecs, Function... f) {
return as(Effects).slideDown(millisecs, f);
}
/**
- * Toggle the visibility of all matched elements by adjusting their height and
- * firing an optional callback after completion. Only the height is adjusted
- * for this animation, causing all matched elements to be hidden or shown in a
- * "sliding" manner
+ * Toggle the visibility of all matched elements by adjusting their height and firing an optional
+ * callback after completion. Only the height is adjusted for this animation, causing all matched
+ * elements to be hidden or shown in a "sliding" manner
*/
public Effects slideToggle(int millisecs, Function... f) {
return as(Effects).slideToggle(millisecs, f);
}
/**
- * Hide all matched elements by adjusting their height and firing an optional
- * callback after completion.
+ * Hide all matched elements by adjusting their height and firing an optional callback after
+ * completion.
*/
public Effects slideUp(Function... f) {
return as(Effects).slideUp(f);
}
/**
- * Hide all matched elements by adjusting their height and firing an optional
- * callback after completion.
+ * Hide all matched elements by adjusting their height and firing an optional callback after
+ * completion.
*/
public Effects slideUp(int millisecs, Function... f) {
return as(Effects).slideUp(millisecs, f);
}
/**
- * When .stop() is called on an element, the currently-running animation (if any)
- * is immediately stopped. If, for instance, an element is being hidden with .slideUp()
- * when .stop() is called, the element will now still be displayed, but will be
- * a fraction of its previous height. Callback functions are not called but
- * the next animation in the queue begins immediately.
+ * When .stop() is called on an element, the currently-running animation (if any) is immediately
+ * stopped. If, for instance, an element is being hidden with .slideUp() when .stop() is called,
+ * the element will now still be displayed, but will be a fraction of its previous height.
+ * Callback functions are not called but the next animation in the queue begins immediately.
*/
public GQuery stop() {
return stop(false);
}
/**
- * When .stop() is called on an element, the currently-running animation (if any)
- * is immediately stopped. If, for instance, an element is being hidden with .slideUp()
- * when .stop() is called, the element will now still be displayed, but will be
- * a fraction of its previous height. Callback functions are not called but
- * the next animation in the queue begins immediately.
+ * When .stop() is called on an element, the currently-running animation (if any) is immediately
+ * stopped. If, for instance, an element is being hidden with .slideUp() when .stop() is called,
+ * the element will now still be displayed, but will be a fraction of its previous height.
+ * Callback functions are not called but the next animation in the queue begins immediately.
*
- * If the clearQueue parameter is provided with a value of true, then the rest of the
- * animations in the queue are removed and never run.
+ * If the clearQueue parameter is provided with a value of true, then the rest of the animations
+ * in the queue are removed and never run.
*/
public GQuery stop(boolean clearQueue) {
return stop(clearQueue, false);
}
/**
- * When .stop() is called on an element, the currently-running animation (if any)
- * is immediately stopped. If, for instance, an element is being hidden with .slideUp()
- * when .stop() is called, the element will now still be displayed, but will be
- * a fraction of its previous height. Callback functions are not called but
- * the next animation in the queue begins immediately.
+ * When .stop() is called on an element, the currently-running animation (if any) is immediately
+ * stopped. If, for instance, an element is being hidden with .slideUp() when .stop() is called,
+ * the element will now still be displayed, but will be a fraction of its previous height.
+ * Callback functions are not called but the next animation in the queue begins immediately.
*
- * If the clearQueue parameter is provided with a value of true, then the rest of the
- * animations in the queue are removed and never run.
+ * If the clearQueue parameter is provided with a value of true, then the rest of the animations
+ * in the queue are removed and never run.
*
- * If the jumpToEnd property is provided with a value of true, the current animation stops,
- * but the element is immediately given its target values for each CSS property.
- * The callback functions are then immediately called, if provided.
+ * If the jumpToEnd property is provided with a value of true, the current animation stops, but
+ * the element is immediately given its target values for each CSS property. The callback
+ * functions are then immediately called, if provided.
*/
public GQuery stop(boolean clearQueue, boolean jumpToEnd) {
return as(Queue).stop(clearQueue, jumpToEnd);
}
/**
- * Bind a set of functions to the submit event of each matched element.
- * Or submit a form if no functions are provided.
+ * Bind a set of functions to the submit event of each matched element. Or submit a form if no
+ * functions are provided.
*/
public GQuery submit(Function... funcs) {
return bindOrFire(EventsListener.ONSUBMIT, null, funcs);
}
-
+
/**
* Return the concatened text contained in the matched elements.
*/
@@ -4109,7 +3994,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
return result;
}
-
+
/**
* Set the innerText of every matched element.
*/
@@ -4134,7 +4019,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
return this;
}
-
+
/**
* Toggle among two or more function calls every other click.
*/
@@ -4153,8 +4038,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Adds or removes the specified classes to each matched element depending on
- * the class's presence.
+ * Adds or removes the specified classes to each matched element depending on the class's
+ * presence.
*/
public GQuery toggleClass(String... classes) {
for (Element e : elements) {
@@ -4170,11 +4055,10 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Adds or removes the specified classes to each matched element depending on
- * the value of the switch argument.
+ * Adds or removes the specified classes to each matched element depending on the value of the
+ * switch argument.
*
- * if addOrRemove is true, the class is added and in the case of false it is
- * removed.
+ * if addOrRemove is true, the class is added and in the case of false it is removed.
*/
public GQuery toggleClass(String clz, boolean addOrRemove) {
if (addOrRemove) {
@@ -4191,14 +4075,14 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
public int top() {
return (int) cur("top", true);
}
-
+
/**
* Produces a string representation of the matched elements.
*/
public String toString() {
return toString(false);
}
-
+
/**
* Produces a string representation of the matched elements.
*/
@@ -4212,21 +4096,23 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
try {
elStr = JsUtils.isXML(e) ? JsUtils.XML2String(e) : e.getString();
} catch (Exception e2) {
- elStr = "< " + (e == null ? "null" : e.getNodeName()) + "(gquery, error getting the element string representation: " + e2.getMessage() + ")/>";
+ elStr =
+ "< " + (e == null ? "null" : e.getNodeName())
+ + "(gquery, error getting the element string representation: " + e2.getMessage()
+ + ")/>";
}
r += (pretty && r.length() > 0 ? "\n " : "") + elStr;
}
return r;
}
-
+
/**
* Trigger a set of events on each matched element.
*
- * For keyboard events you can pass a second parameter which represents the
- * key-code of the pushed key.
+ * For keyboard events you can pass a second parameter which represents the key-code of the pushed
+ * key.
*
- * Example: fire(Event.ONCLICK | Event.ONFOCUS) Example: fire(Event.ONKEYDOWN.
- * 'a');
+ * Example: fire(Event.ONCLICK | Event.ONFOCUS) Example: fire(Event.ONKEYDOWN. 'a');
*/
public GQuery trigger(int eventbits, int... keys) {
return as(Events).trigger(eventbits, keys);
@@ -4238,22 +4124,21 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
public GQuery unbind(int eventbits) {
return as(Events).unbind(eventbits);
}
-
+
/**
- * Removes the function passed from the set of events which match
- * the eventbits.
+ * Removes the function passed from the set of events which match the eventbits.
*/
public GQuery unbind(int eventbits, Function f) {
return as(Events).unbind(eventbits, null, f);
}
-
+
/**
* Removes all events that match the eventList.
*/
public GQuery unbind(String eventList) {
return unbind(eventList, null);
}
-
+
/**
* Removes all events that match the eventList.
*/
@@ -4268,17 +4153,17 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
public GQuery undelegate() {
return as(Events).undelegate();
}
-
+
/**
* Undelegate is a way of removing event handlers that have been bound using
* {@link #delegate(String, int, Function...)} method
*/
public GQuery undelegate(String selector) {
- for (Element e : elements){
- $(selector, e).die();
- }
-
- return this;
+ for (Element e : elements) {
+ $(selector, e).die();
+ }
+
+ return this;
}
/**
@@ -4286,11 +4171,11 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* {@link #delegate(String, int, Function...)} method
*/
public GQuery undelegate(String selector, int eventBit) {
- for (Element e : elements){
- $(selector, e).die(eventBit);
- }
-
- return this;
+ for (Element e : elements) {
+ $(selector, e).die(eventBit);
+ }
+
+ return this;
}
/**
@@ -4298,25 +4183,24 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* {@link #delegate(String, int, Function...)} method
*/
public GQuery undelegate(String selector, String eventName) {
- for (Element e : elements){
- $(selector, e).die(eventName);
- }
-
- return this;
+ for (Element e : elements) {
+ $(selector, e).die(eventName);
+ }
+
+ return this;
}
/**
- * Remove all duplicate elements from an array of elements. Note that this
- * only works on arrays of DOM elements, not strings or numbers.
+ * Remove all duplicate elements from an array of elements. Note that this only works on arrays of
+ * DOM elements, not strings or numbers.
*/
public JsNodeArray unique(NodeList<Element> result) {
return JsUtils.unique(result.<JsArray<Element>> cast()).cast();
}
/**
- * This method removes the element's parent. The matched elements replaces
- * their parents within the DOM structure. It is the inverse of
- * {@link GQuery#wrap(GQuery)} method
+ * This method removes the element's parent. The matched elements replaces their parents within
+ * the DOM structure. It is the inverse of {@link GQuery#wrap(GQuery)} method
*
* @return
*/
@@ -4332,13 +4216,12 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Gets the content of the value attribute of the first matched element,
- * returns only the first value even if it is a multivalued element. To get an
- * array of all values in multivalues elements use vals()
+ * Gets the content of the value attribute of the first matched element, returns only the first
+ * value even if it is a multivalued element. To get an array of all values in multivalues
+ * elements use vals()
*
- * When the first element is a radio-button and is not checked, then it looks
- * for the first checked radio-button that has the same name in the list of
- * matched elements.
+ * When the first element is a radio-button and is not checked, then it looks for the first
+ * checked radio-button that has the same name in the list of matched elements.
*
* When there are not matched elements it returns null.
*/
@@ -4351,26 +4234,26 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Sets the value attribute of every matched element based in the return
- * value of the function evaluated for this element.
+ * Sets the value attribute of every matched element based in the return value of the function
+ * evaluated for this element.
*
- * NOTE: in jquery the function receives the arguments in different
- * way, first index and them the actual value, but we use the normal way
- * in gquery Function, first the element and second the index.
+ * NOTE: in jquery the function receives the arguments in different way, first index and them the
+ * actual value, but we use the normal way in gquery Function, first the element and second the
+ * index.
*/
public GQuery val(Function f) {
- for (int i = 0; i < size(); i++){
+ for (int i = 0; i < size(); i++) {
eq(i).val(f.f(get(i), i).toString());
}
return this;
}
/**
- * Sets the 'value' attribute of every matched element, but
- * does not set the checked flag to checkboxes or radiobuttons.
+ * Sets the 'value' attribute of every matched element, but does not set the checked flag to
+ * checkboxes or radiobuttons.
*
- * If you wanted to set values in collections of checkboxes o radiobuttons
- * use val(String[]) instead
+ * If you wanted to set values in collections of checkboxes o radiobuttons use val(String[])
+ * instead
*/
public GQuery val(String value) {
for (Element e : elements) {
@@ -4384,15 +4267,16 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
*
* There is a different behaviour depending on the element type:
* <ul>
- * <li>select multiple: options whose value match any of the passed values will be set.
- * <li>select single: the last option whose value matches any of the passed values will be set.
- * <li>input radio: the last input whose value matches any of the passed values will be set.
- * <li>input checkbox: inputs whose value match any of the passed values will be set.
- * <li>textarea, button, and other input: value will set to a string result of joining with coma, all passed values
+ * <li>select multiple: options whose value match any of the passed values will be set.
+ * <li>select single: the last option whose value matches any of the passed values will be set.
+ * <li>input radio: the last input whose value matches any of the passed values will be set.
+ * <li>input checkbox: inputs whose value match any of the passed values will be set.
+ * <li>textarea, button, and other input: value will set to a string result of joining with coma,
+ * all passed values
* </ul>
*
- * NOTE: if you wanted call this function with just one parameter, you have to
- * pass an array signature to avoid call the overloaded val(String) method:
+ * NOTE: if you wanted call this function with just one parameter, you have to pass an array
+ * signature to avoid call the overloaded val(String) method:
*
* $(...).val(new String[]{"value"});
*/
@@ -4420,8 +4304,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
} else if ("input".equalsIgnoreCase(name)) {
InputElement ie = InputElement.as(e);
String type = ie.getType();
- if ("radio".equalsIgnoreCase((type))
- || "checkbox".equalsIgnoreCase(type)){
+ if ("radio".equalsIgnoreCase((type)) || "checkbox".equalsIgnoreCase(type)) {
ie.setChecked(false);
for (String v : values) {
if (ie.getValue().equals(v)) {
@@ -4440,15 +4323,14 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Gets the content of the value attribute of the first matched element,
- * returns more than one value if it is a multiple select.
+ * Gets the content of the value attribute of the first matched element, returns more than one
+ * value if it is a multiple select.
*
- * When the first element is a radio-button and is not checked, then it looks
- * for a the first checked radio-button that has the same name in the list of
- * matched elements.
+ * When the first element is a radio-button and is not checked, then it looks for a the first
+ * checked radio-button that has the same name in the list of matched elements.
*
- * This method always returns an array. If no valid value can be determined
- * the array will be empty, otherwise it will contain one or more values.
+ * This method always returns an array. If no valid value can be determined the array will be
+ * empty, otherwise it will contain one or more values.
*/
public String[] vals() {
if (!isEmpty()) {
@@ -4457,7 +4339,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
SelectElement se = SelectElement.as(e);
if (se.isMultiple()) {
JsArrayString result = JsArrayString.createArray().cast();
- for (int i = 0, l = se.getOptions().getLength(); i < l; i++){
+ for (int i = 0, l = se.getOptions().getLength(); i < l; i++) {
OptionElement oe = se.getOptions().getItem(i);
if (oe.isSelected()) {
result.set(result.length(), oe.getValue());
@@ -4465,15 +4347,15 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
return result.length() > 0 ? jsArrayToString(result) : null;
} else if (se.getSelectedIndex() >= 0) {
- return new String[]{se.getOptions().getItem(se.getSelectedIndex()).getValue()};
+ return new String[] {se.getOptions().getItem(se.getSelectedIndex()).getValue()};
}
} else if (e.getNodeName().equalsIgnoreCase("input")) {
InputElement ie = InputElement.as(e);
- return new String[]{ie.getValue()};
+ return new String[] {ie.getValue()};
} else if (e.getNodeName().equalsIgnoreCase("textarea")) {
- return new String[]{TextAreaElement.as(e).getValue()};
+ return new String[] {TextAreaElement.as(e).getValue()};
} else if (e.getNodeName().equalsIgnoreCase("button")) {
- return new String[]{ButtonElement.as(e).getValue()};
+ return new String[] {ButtonElement.as(e).getValue()};
}
}
return new String[0];
@@ -4485,8 +4367,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Return the first non null attached widget from the matched elements or null
- * if there isn't any.
+ * Return the first non null attached widget from the matched elements or null if there isn't any.
*/
@SuppressWarnings("unchecked")
public <W extends Widget> W widget() {
@@ -4494,8 +4375,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Return the nth non null attached widget from the matched elements or null
- * if there isn't any.
+ * Return the nth non null attached widget from the matched elements or null if there isn't any.
*/
public <W extends Widget> W widget(int n) {
for (Element e : elements) {
@@ -4526,11 +4406,10 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Return the list of attached widgets instance of the provided class matching
- * the query.
+ * Return the list of attached widgets instance of the provided class matching the query.
*
- * This method is very useful for decoupled views, so as we can access widgets
- * from other views without maintaining methods which export them.
+ * This method is very useful for decoupled views, so as we can access widgets from other views
+ * without maintaining methods which export them.
*
*/
@SuppressWarnings("unchecked")
@@ -4551,8 +4430,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Get the current computed, pixel, width of the first matched element. It
- * does not include margin, padding nor border.
+ * Get the current computed, pixel, width of the first matched element. It does not include
+ * margin, padding nor border.
*/
public int width() {
return (int) cur("width", true);
@@ -4569,26 +4448,22 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Wrap each matched element with the specified HTML content. This wrapping
- * process is most useful for injecting additional structure into a document,
- * without ruining the original semantic qualities of a document. This works
- * by going through the first element provided (which is generated, on the
- * fly, from the provided HTML) and finds the deepest descendant element
- * within its structure -- it is that element that will enwrap everything
- * else.
+ * Wrap each matched element with the specified HTML content. This wrapping process is most useful
+ * for injecting additional structure into a document, without ruining the original semantic
+ * qualities of a document. This works by going through the first element provided (which is
+ * generated, on the fly, from the provided HTML) and finds the deepest descendant element within
+ * its structure -- it is that element that will enwrap everything else.
*/
public GQuery wrap(Element elem) {
return wrap($(elem));
}
/**
- * Wrap each matched element with the specified HTML content. This wrapping
- * process is most useful for injecting additional structure into a document,
- * without ruining the original semantic qualities of a document. This works
- * by going through the first element provided (which is generated, on the
- * fly, from the provided HTML) and finds the deepest descendant element
- * within its structure -- it is that element that will enwrap everything
- * else.
+ * Wrap each matched element with the specified HTML content. This wrapping process is most useful
+ * for injecting additional structure into a document, without ruining the original semantic
+ * qualities of a document. This works by going through the first element provided (which is
+ * generated, on the fly, from the provided HTML) and finds the deepest descendant element within
+ * its structure -- it is that element that will enwrap everything else.
*/
public GQuery wrap(GQuery query) {
for (Element e : elements) {
@@ -4598,45 +4473,39 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Wrap each matched element with the specified HTML content. This wrapping
- * process is most useful for injecting additional structure into a document,
- * without ruining the original semantic qualities of a document. This works
- * by going through the first element provided (which is generated, on the
- * fly, from the provided HTML) and finds the deepest descendant element
- * within its structure -- it is that element that will enwrap everything
- * else.
+ * Wrap each matched element with the specified HTML content. This wrapping process is most useful
+ * for injecting additional structure into a document, without ruining the original semantic
+ * qualities of a document. This works by going through the first element provided (which is
+ * generated, on the fly, from the provided HTML) and finds the deepest descendant element within
+ * its structure -- it is that element that will enwrap everything else.
*/
public GQuery wrap(String html) {
return wrap($(html));
}
/**
- * Wrap all the elements in the matched set into a single wrapper element.
- * This is different from .wrap() where each element in the matched set would
- * get wrapped with an element. This wrapping process is most useful for
- * injecting additional structure into a document, without ruining the
+ * Wrap all the elements in the matched set into a single wrapper element. This is different from
+ * .wrap() where each element in the matched set would get wrapped with an element. This wrapping
+ * process is most useful for injecting additional structure into a document, without ruining the
* original semantic qualities of a document.
*
- * This works by going through the first element provided (which is generated,
- * on the fly, from the provided HTML) and finds the deepest descendant
- * element within its structure -- it is that element that will enwrap
- * everything else.
+ * This works by going through the first element provided (which is generated, on the fly, from
+ * the provided HTML) and finds the deepest descendant element within its structure -- it is that
+ * element that will enwrap everything else.
*/
public GQuery wrapAll(Element elem) {
return wrapAll($(elem));
}
/**
- * Wrap all the elements in the matched set into a single wrapper element.
- * This is different from .wrap() where each element in the matched set would
- * get wrapped with an element. This wrapping process is most useful for
- * injecting additional structure into a document, without ruining the
+ * Wrap all the elements in the matched set into a single wrapper element. This is different from
+ * .wrap() where each element in the matched set would get wrapped with an element. This wrapping
+ * process is most useful for injecting additional structure into a document, without ruining the
* original semantic qualities of a document.
*
- * This works by going through the first element provided (which is generated,
- * on the fly, from the provided HTML) and finds the deepest descendant
- * element within its structure -- it is that element that will enwrap
- * everything else.
+ * This works by going through the first element provided (which is generated, on the fly, from
+ * the provided HTML) and finds the deepest descendant element within its structure -- it is that
+ * element that will enwrap everything else.
*/
public GQuery wrapAll(GQuery query) {
if (!isEmpty()) {
@@ -4646,8 +4515,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
for (Element e : wrap.elements) {
Node n = e;
- while (n.getFirstChild() != null
- && n.getFirstChild().getNodeType() == Node.ELEMENT_NODE) {
+ while (n.getFirstChild() != null && n.getFirstChild().getNodeType() == Node.ELEMENT_NODE) {
n = n.getFirstChild();
}
$((Element) n).append(this);
@@ -4657,42 +4525,38 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Wrap all the elements in the matched set into a single wrapper element.
- * This is different from .wrap() where each element in the matched set would
- * get wrapped with an element. This wrapping process is most useful for
- * injecting additional structure into a document, without ruining the
+ * Wrap all the elements in the matched set into a single wrapper element. This is different from
+ * .wrap() where each element in the matched set would get wrapped with an element. This wrapping
+ * process is most useful for injecting additional structure into a document, without ruining the
* original semantic qualities of a document.
*
- * This works by going through the first element provided (which is generated,
- * on the fly, from the provided HTML) and finds the deepest descendant
- * element within its structure -- it is that element that will enwrap
- * everything else.
+ * This works by going through the first element provided (which is generated, on the fly, from
+ * the provided HTML) and finds the deepest descendant element within its structure -- it is that
+ * element that will enwrap everything else.
*/
public GQuery wrapAll(String html) {
return wrapAll($(html));
}
/**
- * Wrap the inner child contents of each matched element (including text
- * nodes) with an HTML structure. This wrapping process is most useful for
- * injecting additional structure into a document, without ruining the
- * original semantic qualities of a document. This works by going through the
- * first element provided (which is generated, on the fly, from the provided
- * HTML) and finds the deepest ancestor element within its structure -- it is
- * that element that will enwrap everything else.
+ * Wrap the inner child contents of each matched element (including text nodes) with an HTML
+ * structure. This wrapping process is most useful for injecting additional structure into a
+ * document, without ruining the original semantic qualities of a document. This works by going
+ * through the first element provided (which is generated, on the fly, from the provided HTML) and
+ * finds the deepest ancestor element within its structure -- it is that element that will enwrap
+ * everything else.
*/
public GQuery wrapInner(Element elem) {
return wrapInner($(elem));
}
/**
- * Wrap the inner child contents of each matched element (including text
- * nodes) with an HTML structure. This wrapping process is most useful for
- * injecting additional structure into a document, without ruining the
- * original semantic qualities of a document. This works by going through the
- * first element provided (which is generated, on the fly, from the provided
- * HTML) and finds the deepest ancestor element within its structure -- it is
- * that element that will enwrap everything else.
+ * Wrap the inner child contents of each matched element (including text nodes) with an HTML
+ * structure. This wrapping process is most useful for injecting additional structure into a
+ * document, without ruining the original semantic qualities of a document. This works by going
+ * through the first element provided (which is generated, on the fly, from the provided HTML) and
+ * finds the deepest ancestor element within its structure -- it is that element that will enwrap
+ * everything else.
*/
public GQuery wrapInner(GQuery query) {
for (Element e : elements) {
@@ -4702,13 +4566,12 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Wrap the inner child contents of each matched element (including text
- * nodes) with an HTML structure. This wrapping process is most useful for
- * injecting additional structure into a document, without ruining the
- * original semantic qualities of a document. This works by going through the
- * first element provided (which is generated, on the fly, from the provided
- * HTML) and finds the deepest ancestor element within its structure -- it is
- * that element that will enwrap everything else.
+ * Wrap the inner child contents of each matched element (including text nodes) with an HTML
+ * structure. This wrapping process is most useful for injecting additional structure into a
+ * document, without ruining the original semantic qualities of a document. This works by going
+ * through the first element provided (which is generated, on the fly, from the provided HTML) and
+ * finds the deepest ancestor element within its structure -- it is that element that will enwrap
+ * everything else.
*/
public GQuery wrapInner(String html) {
return wrapInner($(html));
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java
index dd677ef3..d655bd83 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java
@@ -1,16 +1,14 @@
/*
* Copyright 2011, The gwtquery team.
*
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.gwt.query.client.plugins;
@@ -18,11 +16,12 @@ package com.google.gwt.query.client.plugins;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.dom.client.Node;
-import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.query.client.Function;
import com.google.gwt.query.client.GQuery;
import com.google.gwt.query.client.js.JsUtils;
import com.google.gwt.query.client.plugins.events.EventsListener;
+import com.google.gwt.query.client.plugins.events.EventsListener.SpecialEvent;
+import com.google.gwt.query.client.plugins.events.GqEvent;
import com.google.gwt.user.client.Event;
/**
@@ -30,18 +29,17 @@ import com.google.gwt.user.client.Event;
*/
public class Events extends GQuery {
- public static final Class<Events> Events =
- registerPlugin(Events.class, new Plugin<Events>() {
- public Events init(GQuery gq) {
- return new Events(gq);
- }
- });
-
+ public static final Class<Events> Events = registerPlugin(Events.class, new Plugin<Events>() {
+ public Events init(GQuery gq) {
+ return new Events(gq);
+ }
+ });
+
/**
* Don't apply events on text and comment nodes !!
*/
- private static boolean isEventCapable(Node n){
- return JsUtils.isWindow(n) || n.getNodeType() != 3 && n.getNodeType() != 8;
+ private static boolean isEventCapable(Node n) {
+ return JsUtils.isWindow(n) || n.getNodeType() != 3 && n.getNodeType() != 8;
}
public Events(GQuery gq) {
@@ -51,17 +49,15 @@ public class Events extends GQuery {
/**
* Binds a set of handlers to a particular Event for each matched element.
*
- * The event handlers are passed as Functions that you can use to prevent
- * default behavior. To stop both default action and event bubbling, the
- * function event handler has to return false.
+ * The event handlers are passed as Functions that you can use to prevent default behavior. To
+ * stop both default action and event bubbling, the function event handler has to return false.
*
- * You can pass an additional Object data to your Function as the second
- * parameter
+ * You can pass an additional Object data to your Function as the second parameter
*
*/
public Events bind(int eventbits, Object data, Function... funcs) {
for (Element e : elements()) {
- if (isEventCapable(e)){
+ if (isEventCapable(e)) {
EventsListener.getInstance(e).bind(eventbits, data, funcs);
}
}
@@ -71,20 +67,18 @@ public class Events extends GQuery {
/**
* Binds a set of handlers to a particular Event for each matched element.
*
- * The namespace is a way to group events of the same type, making easier
- * unbind specific handlers.
+ * The namespace is a way to group events of the same type, making easier unbind specific
+ * handlers.
*
- * The event handlers are passed as Functions that you can use to prevent
- * default behavior. To stop both default action and event bubbling, the
- * function event handler has to return false.
+ * The event handlers are passed as Functions that you can use to prevent default behavior. To
+ * stop both default action and event bubbling, the function event handler has to return false.
*
* You can pass an additional Object data to your Function
*
*/
- public Events bind(int eventbits, String namespace, Object data,
- Function... funcs) {
+ public Events bind(int eventbits, String namespace, Object data, Function... funcs) {
for (Element e : elements()) {
- if (isEventCapable(e)){
+ if (isEventCapable(e)) {
EventsListener.getInstance(e).bind(eventbits, namespace, data, funcs);
}
}
@@ -94,75 +88,108 @@ public class Events extends GQuery {
/**
* Binds a set of handlers to a particular Event for each matched element.
*
- * The name could contain a namespace which is a way to group events of the
- * same type, making easier unbind specific handlers.
+ * The name could contain a namespace which is a way to group events of the same type, making
+ * easier unbind specific handlers.
*
- * The event handlers are passed as Functions that you can use to prevent
- * default behavior. To stop both default action and event bubbling, the
- * function event handler has to return false.
+ * The event handlers are passed as Functions that you can use to prevent default behavior. To
+ * stop both default action and event bubbling, the function event handler has to return false.
*
* You can pass an additional Object data to your Function
*
*/
public Events bind(String event, Object data, Function... funcs) {
for (Element e : elements()) {
- if (isEventCapable(e)){
+ if (isEventCapable(e)) {
EventsListener.getInstance(e).bind(event, data, funcs);
}
}
return this;
}
+ public GQuery die(int eventbits) {
+ EventsListener.getInstance(Element.is(currentContext) ? (Element) currentContext : body).die(
+ eventbits, currentSelector);
+ return this;
+ }
+
/**
- * Remove an event handlers previously attached using live() The selector used
- * with it must match exactly the selector initially used with live(). if
- * <code>eventName</code> is null, all event handlers corresponding of the
- * GQuery selector will be removed
+ * Remove an event handlers previously attached using live() The selector used with it must match
+ * exactly the selector initially used with live(). if <code>eventName</code> is null, all event
+ * handlers corresponding of the GQuery selector will be removed
*/
public GQuery die(String eventName) {
- EventsListener.getInstance(
- Element.is(currentContext) ? (Element) currentContext : body).die(
- eventName, currentSelector);
+ EventsListener.getInstance(Element.is(currentContext) ? (Element) currentContext : body).die(
+ eventName, currentSelector);
return this;
}
- public GQuery die(int eventbits) {
- EventsListener.getInstance(
- Element.is(currentContext) ? (Element) currentContext : body).die(
- eventbits, currentSelector);
+ public GQuery live(int eventbits, final Object data, Function... funcs) {
+ EventsListener.getInstance(Element.is(currentContext) ? (Element) currentContext : body).live(
+ eventbits, currentSelector, data, funcs);
return this;
+
}
public GQuery live(String eventName, final Object data, Function... funcs) {
- EventsListener.getInstance(
- Element.is(currentContext) ? (Element) currentContext : body).live(
+ EventsListener.getInstance(Element.is(currentContext) ? (Element) currentContext : body).live(
eventName, currentSelector, data, funcs);
return this;
}
-
- public GQuery live(int eventbits, final Object data, Function... funcs) {
- EventsListener.getInstance(
- Element.is(currentContext) ? (Element) currentContext : body).live(
- eventbits, currentSelector, data, funcs);
- return this;
+ /**
+ * Bind an event handler to be fired when the mouse enter an element, or trigger that handler on
+ * an element if no functions are provided.
+ *
+ * The mouseenter event differs from mouseover in the way it handles event bubbling. When
+ * mouseover is used on an element having inner element(s), then when the mouse pointer moves
+ * hover of the Inner element, the handler would be triggered. This is usually undesirable
+ * behavior. The mouseenter event, on the other hand, only triggers its handler when the mouse
+ * enters the element it is bound to, not a descendant.
+ */
+ public GQuery mouseenter(Function... f) {
+ if (f == null || f.length == 0) {
+ // handle trigger of mouseleave
+ return triggerHtmlEvent("mouseenter");
+ }
+
+ return bind("mouseenter", null, f);
}
+ // TODO handle unbind !!
+
+ /**
+ * Bind an event handler to be fired when the mouse leaves an element, or trigger that handler on
+ * an element if no functions are provided.
+ *
+ * The mouseleave event differs from mouseout in the way it handles event bubbling. When mouseout
+ * is used on an element having inner element(s), then when the mouse pointer moves out of the
+ * Inner element, the handler would be triggered. This is usually undesirable behavior. The
+ * mouseleave event, on the other hand, only triggers its handler when the mouse leaves the
+ * element it is bound to, not a descendant.
+ */
+ public GQuery mouseleave(Function... fs) {
+
+ if (fs == null || fs.length == 0) {
+ // handle trigger of mouseleave
+ return triggerHtmlEvent("mouseleave");
+ }
+
+ return bind("mouseleave", null, fs);
+
+ }
/**
- * Binds a handler to a particular Event (like Event.ONCLICK) for each matched
- * element. The handler is executed only once for each element.
+ * Binds a handler to a particular Event (like Event.ONCLICK) for each matched element. The
+ * handler is executed only once for each element.
*
- * The event handler is passed as a Function that you can use to prevent
- * default behavior. To stop both default action and event bubbling, the
- * function event handler has to return false.
+ * The event handler is passed as a Function that you can use to prevent default behavior. To stop
+ * both default action and event bubbling, the function event handler has to return false.
*
- * You can pass an additional Object data to your Function as the second
- * parameter
+ * You can pass an additional Object data to your Function as the second parameter
*/
public Events one(int eventbits, final Object data, final Function f) {
for (Element e : elements()) {
- if (isEventCapable(e)){
+ if (isEventCapable(e)) {
EventsListener.getInstance(e).bind(eventbits, data, f, 1);
}
}
@@ -170,17 +197,14 @@ public class Events extends GQuery {
}
/**
- * Execute all handlers and behaviors attached to the matched elements for the
- * given event types.
+ * Execute all handlers and behaviors attached to the matched elements for the given event types.
*
- * Different event types can be passed joining these using the or bit wise
- * operator.
+ * Different event types can be passed joining these using the or bit wise operator.
*
- * For keyboard events you can pass a second parameter which represents the
- * key-code of the pushed key.
+ * For keyboard events you can pass a second parameter which represents the key-code of the pushed
+ * key.
*
- * Example: fire(Event.ONCLICK | Event.ONFOCUS) Example: fire(Event.ONKEYDOWN.
- * 'a');
+ * Example: fire(Event.ONCLICK | Event.ONFOCUS) Example: fire(Event.ONKEYDOWN. 'a');
*/
public Events trigger(int eventbits, int... keys) {
if ((eventbits | Event.ONBLUR) == Event.ONBLUR)
@@ -188,79 +212,84 @@ public class Events extends GQuery {
if ((eventbits | Event.ONCHANGE) == Event.ONCHANGE)
dispatchEvent(document.createChangeEvent());
if ((eventbits | Event.ONCLICK) == Event.ONCLICK)
- dispatchEvent(document.createClickEvent(0, 0, 0, 0, 0, false, false,
- false, false));
+ dispatchEvent(document.createClickEvent(0, 0, 0, 0, 0, false, false, false, false));
if ((eventbits | Event.ONDBLCLICK) == Event.ONDBLCLICK)
- dispatchEvent(document.createDblClickEvent(0, 0, 0, 0, 0, false, false,
- false, false));
+ dispatchEvent(document.createDblClickEvent(0, 0, 0, 0, 0, false, false, false, false));
if ((eventbits | Event.ONFOCUS) == Event.ONFOCUS)
dispatchEvent(document.createFocusEvent());
if ((eventbits | Event.ONKEYDOWN) == Event.ONKEYDOWN)
- dispatchEvent(document.createKeyDownEvent(false, false, false, false,
- keys[0]));
+ dispatchEvent(document.createKeyDownEvent(false, false, false, false, keys[0]));
if ((eventbits | Event.ONKEYPRESS) == Event.ONKEYPRESS)
- dispatchEvent(document.createKeyPressEvent(false, false, false, false,
- keys[0], 0));
+ dispatchEvent(document.createKeyPressEvent(false, false, false, false, keys[0], 0));
if ((eventbits | Event.ONKEYUP) == Event.ONKEYUP)
- dispatchEvent(document.createKeyUpEvent(false, false, false, false,
- keys[0]));
+ dispatchEvent(document.createKeyUpEvent(false, false, false, false, keys[0]));
if ((eventbits | Event.ONLOSECAPTURE) == Event.ONLOSECAPTURE)
triggerHtmlEvent("losecapture");
if ((eventbits | Event.ONMOUSEDOWN) == Event.ONMOUSEDOWN)
- dispatchEvent(document.createMouseDownEvent(0, 0, 0, 0, 0, false, false,
- false, false, NativeEvent.BUTTON_LEFT));
+ dispatchEvent(document.createMouseDownEvent(0, 0, 0, 0, 0, false, false, false, false,
+ NativeEvent.BUTTON_LEFT));
if ((eventbits | Event.ONMOUSEMOVE) == Event.ONMOUSEMOVE)
- dispatchEvent(document.createMouseMoveEvent(0, 0, 0, 0, 0, false, false,
- false, false, NativeEvent.BUTTON_LEFT));
+ dispatchEvent(document.createMouseMoveEvent(0, 0, 0, 0, 0, false, false, false, false,
+ NativeEvent.BUTTON_LEFT));
if ((eventbits | Event.ONMOUSEOUT) == Event.ONMOUSEOUT)
- dispatchEvent(document.createMouseOutEvent(0, 0, 0, 0, 0, false, false,
- false, false, NativeEvent.BUTTON_LEFT, null));
+ dispatchEvent(document.createMouseOutEvent(0, 0, 0, 0, 0, false, false, false, false,
+ NativeEvent.BUTTON_LEFT, null));
if ((eventbits | Event.ONMOUSEOVER) == Event.ONMOUSEOVER)
- dispatchEvent(document.createMouseOverEvent(0, 0, 0, 0, 0, false, false,
- false, false, NativeEvent.BUTTON_LEFT, null));
+ dispatchEvent(document.createMouseOverEvent(0, 0, 0, 0, 0, false, false, false, false,
+ NativeEvent.BUTTON_LEFT, null));
if ((eventbits | Event.ONMOUSEUP) == Event.ONMOUSEUP)
- dispatchEvent(document.createMouseUpEvent(0, 0, 0, 0, 0, false, false,
- false, false, NativeEvent.BUTTON_LEFT));
+ dispatchEvent(document.createMouseUpEvent(0, 0, 0, 0, 0, false, false, false, false,
+ NativeEvent.BUTTON_LEFT));
if ((eventbits | Event.ONSCROLL) == Event.ONSCROLL)
dispatchEvent(document.createScrollEvent());
if ((eventbits | Event.ONERROR) == Event.ONERROR)
dispatchEvent(document.createErrorEvent());
if ((eventbits | Event.ONMOUSEWHEEL) == Event.ONMOUSEWHEEL)
- dispatchEvent(document.createMouseEvent("mousewheel", true, true, 0, 0,
- 0, 0, 0, false, false, false, false, NativeEvent.BUTTON_LEFT, null));
+ dispatchEvent(document.createMouseEvent("mousewheel", true, true, 0, 0, 0, 0, 0, false,
+ false, false, false, NativeEvent.BUTTON_LEFT, null));
if (eventbits == EventsListener.ONSUBMIT) {
Event evt = document.createHtmlEvent("submit", true, true).cast();
dispatchEvent(evt, new Function() {
public native void f(Element e) /*-{
- e.submit();
- }-*/;
+ e.submit();
+ }-*/;
});
}
if (eventbits == EventsListener.ONRESIZE)
triggerHtmlEvent("resize");
return this;
}
-
+
/**
* Trigger a html event in all matched elements.
*
* @param htmlEvent An string representing the html event desired
* @functions a set of function to run if the event is not canceled.
*/
- public Events triggerHtmlEvent(String htmlEvent, Function...functions) {
- dispatchEvent(document.createHtmlEvent(htmlEvent, true, true), functions);
+ public Events triggerHtmlEvent(String htmlEvent, Function... functions) {
+ SpecialEvent specialEvent = EventsListener.special.get(htmlEvent);
+ boolean isSpecialEvent = specialEvent != null;
+
+ String originalEventName = htmlEvent;
+ String delegateEventName = isSpecialEvent ? specialEvent.getDelegateType() : htmlEvent;
+
+ NativeEvent e = document.createHtmlEvent(delegateEventName, true, true);
+
+ if (isSpecialEvent) {
+ GqEvent.setOriginalEventType(e, originalEventName);
+ }
+ dispatchEvent(e, functions);
return this;
}
/**
- * Removes all handlers, that matches the events bits passed, from each
- * element.
+ * Removes all handlers, that matches the events bits passed, from each element.
*
* Example: unbind(Event.ONCLICK | Event.ONMOUSEOVER)
*/
public Events unbind(int eventbits) {
for (Element e : elements()) {
- if (isEventCapable(e)){
+ if (isEventCapable(e)) {
EventsListener.getInstance(e).unbind(eventbits);
}
}
@@ -268,22 +297,21 @@ public class Events extends GQuery {
}
/**
- * Removes all handlers, that matches the events bits and the namespace
- * passed, from each element.
+ * Removes all handlers, that matches the events bits and the namespace passed, from each element.
*
* Example: unbind(Event.ONCLICK | Event.ONMOUSEOVER, "my.namespace")
*/
public Events unbind(int eventbits, String name, Function f) {
for (Element e : elements()) {
- if (isEventCapable(e)){
- EventsListener.getInstance(e).unbind(eventbits, name, f);
+ if (isEventCapable(e)) {
+ EventsListener.getInstance(e).unbind(eventbits, name, null, f);
}
}
return this;
}
/**
- * Removes all handlers, that matches the event name passed.
+ * Removes all handlers, that matches the event name passed.
*
* This name could contain a namespace.
*
@@ -292,29 +320,37 @@ public class Events extends GQuery {
public Events unbind(String name) {
return unbind(name, null);
}
-
+
/**
- * Removes the function passed as parameter from the event list matching
- * the event name passed.
+ * Removes the function passed as parameter from the event list matching the event name passed.
* This name could contain a namespace.
*
* Example: unbind("click.my.namespace", myFunction)
*/
public Events unbind(String name, Function f) {
for (Element e : elements()) {
- if (isEventCapable(e)){
+ if (isEventCapable(e)) {
EventsListener.getInstance(e).unbind(name, f);
}
}
return this;
}
-
- private void dispatchEvent(NativeEvent evt, Function...funcs) {
+
+ public Events undelegate() {
for (Element e : elements()) {
- if (isEventCapable(e)){
+ if (isEventCapable(e)) {
+ EventsListener.getInstance(e).cleanEventDelegation();
+ }
+ }
+ return this;
+ }
+
+ private void dispatchEvent(NativeEvent evt, Function... funcs) {
+ for (Element e : elements()) {
+ if (isEventCapable(e)) {
e.dispatchEvent(evt);
- if (!JsUtils.isDefaultPrevented(evt)){
- for (Function f: funcs) {
+ if (!JsUtils.isDefaultPrevented(evt)) {
+ for (Function f : funcs) {
f.setEvent(Event.as(evt));
f.f(e);
}
@@ -322,14 +358,5 @@ public class Events extends GQuery {
}
}
}
-
- public Events undelegate(){
- for (Element e : elements()) {
- if (isEventCapable(e)){
- EventsListener.getInstance(e).cleanEventDelegation();
- }
- }
- return this;
- }
}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java
index f76afbd7..ba3e084e 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java
@@ -1,72 +1,137 @@
/*
* Copyright 2011, The gwtquery team.
*
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.gwt.query.client.plugins.events;
import static com.google.gwt.query.client.GQuery.$;
-import java.util.ArrayList;
-import java.util.List;
-
import com.google.gwt.core.client.Duration;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.EventTarget;
import com.google.gwt.dom.client.NodeList;
import com.google.gwt.query.client.Function;
+import com.google.gwt.query.client.GQuery;
import com.google.gwt.query.client.js.JsCache;
import com.google.gwt.query.client.js.JsMap;
import com.google.gwt.query.client.js.JsNamedArray;
import com.google.gwt.query.client.js.JsObjectArray;
-import com.google.gwt.regexp.shared.RegExp;
-import com.google.gwt.regexp.shared.SplitResult;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.EventListener;
+import java.util.ArrayList;
+import java.util.List;
+
/**
- * This class implements an event queue instance for one Element. The queue
- * instance is configured as the default event listener in GWT.
+ * This class implements an event queue instance for one Element. The queue instance is configured
+ * as the default event listener in GWT.
*
- * The reference to this queue is stored as a unique variable in the element's
- * DOM
+ * The reference to this queue is stored as a unique variable in the element's DOM
*
- * The class takes care of calling the appropriate functions for each browser
- * event and it also calls sinkEvents method.
+ * The class takes care of calling the appropriate functions for each browser event and it also
+ * calls sinkEvents method.
*
*/
public class EventsListener implements EventListener {
+ public interface SpecialEvent {
+ String getDelegateType();
+
+ String getOriginalType();
+
+ Function createDelegateHandler(Function originalHandler);
+ }
+
+ /**
+ * Used for simulating mouseenter and mouseleave events
+ */
+ public static class MouseSpecialEvent implements SpecialEvent {
+
+ private String originalType;
+ private String delegateType;
+
+ public MouseSpecialEvent(String originalType, String delegateType) {
+ this.originalType = originalType;
+ this.delegateType = delegateType;
+ }
+
+ public String getDelegateType() {
+ return delegateType;
+ }
+
+ public String getOriginalType() {
+ return originalType;
+ }
+
+ public Function createDelegateHandler(Function originalHandler) {
+ return new SpecialMouseEventHandler(originalHandler);
+ }
+ }
+
+ private interface HandlerWrapper {
+ Function getOriginalHandler();
+ }
+ private static class SpecialMouseEventHandler extends Function implements HandlerWrapper {
+
+ private Function delegateHandler;
+
+ public SpecialMouseEventHandler(Function originalHandler) {
+ this.delegateHandler = originalHandler;
+ }
+
+ @Override
+ public boolean f(Event e, Object data) {
+ EventTarget eventTarget = e.getCurrentEventTarget();
+ Element target = eventTarget != null ? eventTarget.<Element> cast() : null;
+
+ EventTarget relatedEventTarget = e.getRelatedEventTarget();
+ Element related = relatedEventTarget != null ? relatedEventTarget.<Element> cast() : null;
+
+ // For mousenter/leave call the handler if related is outside the target.
+ if (related == null || (related != target && !GQuery.contains(target, related))) {
+ return delegateHandler != null ? delegateHandler.f(e, data) : false;
+ }
+
+ return false;
+ }
+
+ public Function getOriginalHandler() {
+ return delegateHandler;
+ }
+ }
+
private static class BindFunction {
Object data;
Function function;
String nameSpace = "";
+ // for special event like mouseleave, mouseenter
+ String originalEventType;
int times = -1;
int type;
- BindFunction(int t, String n, Function f, Object d) {
+ BindFunction(int t, String n, String originalEventType, Function f, Object d) {
type = t;
function = f;
data = d;
+ this.originalEventType = originalEventType;
if (n != null) {
nameSpace = n;
}
}
- BindFunction(int t, String n, Function f, Object d, int times) {
- this(t, n, f, d);
+ BindFunction(int t, String n, String originalEventType, Function f, Object d, int times) {
+ this(t, n, originalEventType, f, d);
this.times = times;
}
@@ -84,26 +149,35 @@ public class EventsListener implements EventListener {
/**
* Remove a set of events. The bind function will not be fire anymore for those events
+ *
* @param eventBits the set of events to unsink
*
*/
- public int unsink(int eventBits){
- if (eventBits <= 0){
+ public int unsink(int eventBits) {
+ if (eventBits <= 0) {
type = 0;
- }else{
+ } else {
type = type & ~eventBits;
}
-
+
return type;
}
-
+
@Override
public String toString() {
return "bind function for event type " + type;
}
-
+
public boolean isEquals(Function f) {
- return function.equals(f);
+ assert f != null : "function f cannot be null";
+ Function functionToCompare =
+ function instanceof HandlerWrapper ? ((HandlerWrapper) function).getOriginalHandler()
+ : function;
+ return f.equals(functionToCompare);
+ }
+
+ public Object getOriginalEventType() {
+ return originalEventType;
}
}
@@ -129,11 +203,11 @@ public class EventsListener implements EventListener {
bindFunctions = JsObjectArray.create();
bindFunctionBySelector.put(cssSelector, bindFunctions);
}
-
+
bindFunctions.add(f);
}
-
- public void clean(){
+
+ public void clean() {
bindFunctionBySelector = JsNamedArray.create();
}
@@ -152,22 +226,22 @@ public class EventsListener implements EventListener {
return true;
}
- // Compute the live selectors which respond to this event type
+ // Compute the live selectors which respond to this event type
List<String> validSelectors = new ArrayList<String>();
for (String cssSelector : bindFunctionBySelector.keys()) {
JsObjectArray<BindFunction> bindFunctions = bindFunctionBySelector.get(cssSelector);
- for (int i = 0; bindFunctions != null && i < bindFunctions.length(); i++) {
- BindFunction f = bindFunctions.get(i);
+ for (int i = 0; bindFunctions != null && i < bindFunctions.length(); i++) {
+ BindFunction f = bindFunctions.get(i);
if (f.hasEventType(event.getTypeInt())) {
validSelectors.add(cssSelector);
break;
}
}
}
-
+
// Create a structure of elements which matches the selectors
- JsNamedArray<NodeList<Element>> realCurrentTargetBySelector =
- $(eventTarget).closest(validSelectors.toArray(new String[0]), liveContextElement);
+ JsNamedArray<NodeList<Element>> realCurrentTargetBySelector =
+ $(eventTarget).closest(validSelectors.toArray(new String[0]), liveContextElement);
// nothing matches the selectors
if (realCurrentTargetBySelector.length() == 0) {
return true;
@@ -177,8 +251,8 @@ public class EventsListener implements EventListener {
GqEvent gqEvent = GqEvent.create(event);
for (String cssSelector : realCurrentTargetBySelector.keys()) {
JsObjectArray<BindFunction> bindFunctions = bindFunctionBySelector.get(cssSelector);
- for (int i = 0; bindFunctions != null && i < bindFunctions.length(); i++) {
- BindFunction f = bindFunctions.get(i);
+ for (int i = 0; bindFunctions != null && i < bindFunctions.length(); i++) {
+ BindFunction f = bindFunctions.get(i);
if (f.hasEventType(event.getTypeInt())) {
NodeList<Element> n = realCurrentTargetBySelector.get(cssSelector);
for (int j = 0; n != null && j < n.getLength(); j++) {
@@ -187,7 +261,7 @@ public class EventsListener implements EventListener {
// handlers for this element bound to this element
if (stopElement == null || element.equals(stopElement)) {
gqEvent.setCurrentElementTarget(element);
-
+
if (!f.fire(gqEvent)) {
stopElement = element;
}
@@ -220,13 +294,13 @@ public class EventsListener implements EventListener {
@Override
public String toString() {
- return "live bind function for selector "
- + bindFunctionBySelector.<JsCache>cast().tostring();
+ return "live bind function for selector "
+ + bindFunctionBySelector.<JsCache> cast().tostring();
}
/**
- * Return the element whose the listener fired last. It represent the
- * context element where the {@link LiveBindFunction} was binded
+ * Return the element whose the listener fired last. It represent the context element where the
+ * {@link LiveBindFunction} was binded
*
*/
private Element getCurrentEventTarget(Event e) {
@@ -256,8 +330,16 @@ public class EventsListener implements EventListener {
public static int ONSUBMIT = GqEvent.ONSUBMIT;
public static int ONRESIZE = GqEvent.ONRESIZE;
-
- private static RegExp eventStringPattern = RegExp.compile("^([^\\.]*)\\.?(.*$)");
+ public static String MOUSEENTER = "mouseenter";
+ public static String MOUSELEAVE = "mouseleave";
+
+ public static JsMap<String, SpecialEvent> special;
+
+ static {
+ special = JsMap.create();
+ special.put(MOUSEENTER, new MouseSpecialEvent(MOUSEENTER, "mouseover"));
+ special.put(MOUSELEAVE, new MouseSpecialEvent(MOUSELEAVE, "mouseout"));
+ }
public static void clean(Element e) {
EventsListener ret = getGQueryEventListener(e);
@@ -299,7 +381,7 @@ public class EventsListener implements EventListener {
elem.__gwtlistener = elem.__listener;
elem.__gqueryevent = gqevent;
}-*/;
-
+
// Gwt does't handle submit nor resize events in DOM.sinkEvents
private static native void sinkEvent(Element elem, String name) /*-{
if (!elem.__gquery)
@@ -317,7 +399,6 @@ public class EventsListener implements EventListener {
else
elem.attachEvent("on" + name, handle);
}-*/;
-
int eventBits = 0;
double lastEvnt = 0;
@@ -327,7 +408,7 @@ public class EventsListener implements EventListener {
private Element element;
private JsObjectArray<BindFunction> elementEvents = JsObjectArray.createArray().cast();
-
+
private JsMap<Integer, LiveBindFunction> liveBindFunctionByEventType = JsMap.create();
private EventsListener(Element element) {
@@ -339,53 +420,66 @@ public class EventsListener implements EventListener {
bind(eventbits, null, data, funcs);
}
- public void bind(int eventbits, final Object data, final Function function,
- int times) {
- bind(eventbits, null, data, function, times);
+ public void bind(int eventbits, final Object data, final Function function, int times) {
+ bind(eventbits, null, null, data, function, times);
}
- public void bind(int eventbits, String name, final Object data,
- Function... funcs) {
+ public void bind(int eventbits, String name, final Object data, Function... funcs) {
for (Function function : funcs) {
- bind(eventbits, name, data, function, -1);
+ bind(eventbits, name, null, data, function, -1);
}
}
- public void bind(int eventbits, String namespace, final Object data,
+ public void bind(int eventbits, String namespace, String originalEventType, final Object data,
final Function function, int times) {
if (function == null) {
- unbind(eventbits, namespace, null);
+ unbind(eventbits, namespace, originalEventType, null);
return;
}
eventBits |= eventbits;
sink();
- elementEvents.add(new BindFunction(eventbits, namespace, function, data,
+ elementEvents.add(new BindFunction(eventbits, namespace, originalEventType, function, data,
times));
}
public void bind(String events, final Object data, Function... funcs) {
String[] parts = events.split("[\\s,]+");
-
- for (String event: parts){
- SplitResult subParts = eventStringPattern.split(event);
-
- String nameSpace = subParts.get(2);
- String eventName = subParts.get(1);
+
+ for (String event : parts) {
+
+ String nameSpace = null;
+ String eventName = event;
+
+ //seperate possible namespace
+ //jDramaix: I removed old regex ^([^.]*)\.?(.*$) because it didn't work on IE8...
+ String[] subparts = event.split("\\.", 2);
+
+ if (subparts.length == 2){
+ nameSpace = subparts[1];
+ eventName = subparts[0];
+ }
+
+ //handle special event like mouseenter or mouseleave
+ SpecialEvent hook = special.get(eventName);
+ eventName = hook != null ? hook.getDelegateType() : eventName;
+ String originalEventName = hook != null ? hook.getOriginalType() : null;
+
int b = getTypeInt(eventName);
for (Function function : funcs) {
- bind(b, nameSpace, data, function, -1);
+ Function handler = hook != null ? hook.createDelegateHandler(function) : function;
+ bind(b, nameSpace, originalEventName, data, handler, -1);
}
}
}
-
+
public void die(String eventNames, String cssSelector) {
die(getEventBits(eventNames), cssSelector);
}
public void die(int eventbits, String cssSelector) {
if (eventbits == 0) {
- for (String k :liveBindFunctionByEventType.keys()) {
- LiveBindFunction liveBindFunction = liveBindFunctionByEventType.<JsCache>cast().get(k);
+ for (String k : liveBindFunctionByEventType.keys()) {
+ LiveBindFunction liveBindFunction = liveBindFunctionByEventType.<JsCache> cast().get(k);
liveBindFunction.removeBindFunctionForSelector(cssSelector);
}
} else {
@@ -398,9 +492,13 @@ public class EventsListener implements EventListener {
public void dispatchEvent(Event event) {
int etype = getTypeInt(event.getType());
+ String originalEventType = GqEvent.getOriginalEventType(event);
+
for (int i = 0; i < elementEvents.length(); i++) {
BindFunction listener = elementEvents.get(i);
- if (listener.hasEventType(etype)) {
+ if (listener.hasEventType(etype)
+ && (originalEventType == null || originalEventType
+ .equals(listener.getOriginalEventType()))) {
if (!listener.fire(event)) {
event.stopPropagation();
event.preventDefault();
@@ -410,22 +508,20 @@ public class EventsListener implements EventListener {
}
/**
- * Return the original gwt EventListener associated with this element, before
- * gquery replaced it to introduce its own event handler.
+ * Return the original gwt EventListener associated with this element, before gquery replaced it
+ * to introduce its own event handler.
*/
public EventListener getOriginalEventListener() {
return getGwtEventListener(element);
}
- public void live(String eventNames, String cssSelector, Object data,
- Function... f) {
+ public void live(String eventNames, String cssSelector, Object data, Function... f) {
live(getEventBits(eventNames), cssSelector, data, f);
}
-
- public void live(int eventbits, String cssSelector, Object data,
- Function... funcs) {
+
+ public void live(int eventbits, String cssSelector, Object data, Function... funcs) {
for (int i = 0; i < 28; i++) {
- int event = (int)Math.pow(2,i);
+ int event = (int) Math.pow(2, i);
if ((eventbits & event) == event) {
// is a LiveBindFunction already attached for this kind of event
@@ -438,9 +534,10 @@ public class EventsListener implements EventListener {
liveBindFunctionByEventType.put(event, liveBindFunction);
}
- for (Function f: funcs) {
- liveBindFunction.addBindFunctionForSelector(cssSelector,
- new BindFunction(event, "live", f, data));
+ for (Function f : funcs) {
+ // TODO handle special event by passing original event name
+ liveBindFunction.addBindFunctionForSelector(cssSelector, new BindFunction(event, "live",
+ null, f, data));
}
}
}
@@ -455,7 +552,7 @@ public class EventsListener implements EventListener {
}
lastEvnt = now;
lastType = event.getTypeInt();
-
+
// Execute the original Gwt listener
if (getOriginalEventListener() != null) {
getOriginalEventListener().onBrowserEvent(event);
@@ -465,28 +562,32 @@ public class EventsListener implements EventListener {
}
public void unbind(int eventbits) {
- unbind(eventbits, null, null);
+ unbind(eventbits, null, null, null);
}
- public void unbind(int eventbits, String namespace, Function f) {
+ public void unbind(int eventbits, String namespace, String originalEventType, Function f) {
JsObjectArray<BindFunction> newList = JsObjectArray.createArray().cast();
for (int i = 0; i < elementEvents.length(); i++) {
BindFunction listener = elementEvents.get(i);
-
- boolean matchNS = namespace == null || namespace.isEmpty()
- || listener.nameSpace.equals(namespace);
+
+ boolean matchNS =
+ namespace == null || namespace.isEmpty() || listener.nameSpace.equals(namespace);
boolean matchEV = eventbits <= 0 || listener.hasEventType(eventbits);
+ boolean matchOEVT =
+ (originalEventType == null && listener.getOriginalEventType() == null)
+ || (originalEventType != null && originalEventType.equals(listener
+ .getOriginalEventType()));
boolean matchFC = f == null || listener.isEquals(f);
-
- if (matchNS && matchEV && matchFC) {
+
+ if (matchNS && matchEV && matchFC && matchOEVT) {
int currentEventbits = listener.unsink(eventbits);
-
- if (currentEventbits == 0){
- //the BindFunction doesn't listen anymore on any events
+
+ if (currentEventbits == 0) {
+ // the BindFunction doesn't listen anymore on any events
continue;
}
}
-
+
newList.add(listener);
}
elementEvents = newList;
@@ -494,18 +595,30 @@ public class EventsListener implements EventListener {
}
public void unbind(String events, Function f) {
-
+
String[] parts = events.split("[\\s,]+");
-
- for (String event: parts){
- SplitResult subParts = eventStringPattern.split(event);
+
+ for (String event : parts) {
+ String nameSpace = null;
+ String eventName = event;
- String nameSpace = subParts.get(2);
- String eventName = subParts.get(1);
+ //seperate possible namespace
+ //jDramaix: I removed old regex ^([^.]*)\.?(.*$) because it didn't work on IE8...
+ String[] subparts = event.split("\\.", 2);
+ if (subparts.length == 2){
+ nameSpace = subparts[1];
+ eventName = subparts[0];
+ }
+
+ //handle special event
+ SpecialEvent hook = special.get(eventName);
+ eventName = hook != null ? hook.getDelegateType() : eventName;
+ String originalEventName = hook != null ? hook.getOriginalType() : null;
+
int b = getTypeInt(eventName);
-
- unbind(b, nameSpace, f);
+
+ unbind(b, nameSpace, originalEventName, f);
}
}
@@ -516,7 +629,7 @@ public class EventsListener implements EventListener {
}
private void sink() {
- //ensure that the gwtQuery's event listener is set as event listener of the element
+ // ensure that the gwtQuery's event listener is set as event listener of the element
DOM.setEventListener((com.google.gwt.user.client.Element) element, this);
if (eventBits == ONSUBMIT) {
sinkEvent(element, "submit");
@@ -532,29 +645,30 @@ public class EventsListener implements EventListener {
}
}
-
+
private int getEventBits(String... events) {
int ret = 0;
- for (String e: events) {
+ for (String e : events) {
String[] parts = e.split("[\\s,]+");
for (String s : parts) {
- int event = getTypeInt(s);
- if (event > 0) {
- ret |= event;
- }
+ int event = getTypeInt(s);
+ if (event > 0) {
+ ret |= event;
+ }
}
- }
-
+ }
+
return ret;
}
-
+
private int getTypeInt(String eventName) {
- return "submit".equals(eventName) ? ONSUBMIT : "resize".equals(eventName) ? ONRESIZE : Event.getTypeInt(eventName);
+ return "submit".equals(eventName) ? ONSUBMIT : "resize".equals(eventName) ? ONRESIZE : Event
+ .getTypeInt(eventName);
}
public void cleanEventDelegation() {
- for (String k :liveBindFunctionByEventType.keys()) {
- LiveBindFunction function = liveBindFunctionByEventType.<JsCache>cast().get(k);
+ for (String k : liveBindFunctionByEventType.keys()) {
+ LiveBindFunction function = liveBindFunctionByEventType.<JsCache> cast().get(k);
function.clean();
}
}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/GqEvent.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/GqEvent.java
index cb1a69d7..b8fbd90e 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/GqEvent.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/GqEvent.java
@@ -1,6 +1,7 @@
package com.google.gwt.query.client.plugins.events;
import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.query.client.GQuery;
import com.google.gwt.user.client.Event;
@@ -21,6 +22,14 @@ import com.google.gwt.user.client.Event;
*
*/
public class GqEvent extends Event {
+
+ public static native void setOriginalEventType(NativeEvent evt, String originalEventName)/*-{
+ evt["__gwtquery_originalEventName"] = originalEventName;
+ }-*/;
+
+ public static native String getOriginalEventType(Event evt)/*-{
+ return evt["__gwtquery_originalEventName"] || null;
+ }-*/;
// Gwt Events class has not this event defined,
// so we have to select one power of 2 which is unused in Event class
diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java
index 5e405678..17eef27c 100644
--- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java
+++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java
@@ -16,9 +16,19 @@ package com.google.gwt.query.client;
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;
@@ -53,11 +63,6 @@ public class GQueryEventsTestGwt extends GWTTestCase {
return "com.google.gwt.query.Query";
}
- public void gwtTearDown() {
- $(e).remove();
- e = null;
- }
-
public void gwtSetUp() {
if (e == null) {
testPanel = new HTML();
@@ -70,6 +75,144 @@ public class GQueryEventsTestGwt extends GWTTestCase {
}
}
+ 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() {
@@ -163,35 +306,6 @@ public class GQueryEventsTestGwt extends GWTTestCase {
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>");
@@ -300,6 +414,35 @@ public class GQueryEventsTestGwt extends GWTTestCase {
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));
@@ -416,6 +559,46 @@ public class GQueryEventsTestGwt extends GWTTestCase {
}
+ 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>");
@@ -439,254 +622,269 @@ public class GQueryEventsTestGwt extends GWTTestCase {
}
- 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);
- }
- }
+ $("#test", e).mouseenter();
- assertEquals(8, $(".subDiv", e).length());
+ assertEquals("test succeed", $("#test", e).text());
- $("span", e).click().trigger(Event.ONMOUSEOVER);
+ $("#test", e).text("blop").unbind("mouseenter");
- 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("blop", $("#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));
- }
-
- $(".mainDiv", e).undelegate(".subDiv", "mouseover");
-
- $("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));
- }
}
- 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);
- }
- }
+ $("#test", e).mouseleave();
- assertEquals(8, $(".subDiv", e).length());
+ assertEquals("test succeed", $("#test", e).text());
- $("span", e).click().trigger(Event.ONMOUSEOVER);
+ // unbind the mouseout event should not remove the mouseleave
+ $("#test", e).text("blop").unbind("mouseout");
- 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));
- }
+ $("#test", e).mouseleave();
- $(".mainDiv", e).undelegate(".subDiv");
+ assertEquals("test succeed", $("#test", e).text());
- $("span", e).click().trigger(Event.ONMOUSEOVER);
+ $("#test", e).text("blop").unbind("mouseleave");
- for (Element el : $(".subDiv", e).elements()) {
- assertEquals("black", $(el).css(CSS.COLOR, false));
- assertEquals("white", $(el).css(CSS.BACKGROUND_COLOR, false));
- }
- }
+ $("#test", e).mouseleave();
- public void testUnDelegateAll2() {
+ assertEquals("blop", $("#test", e).text());
- $(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() {
+ // 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');
+
+ if (eventbits == ONMOUSEOUT) {
+ assertEquals("event fired", $("#test", e).val());
+ $("#test", e).val("");
+ } else {
+ assertEquals("", $("#test", e).val());
+ }
- for (Element el : $(".subDiv", e).elements()) {
- assertEquals("black", $(el).css(CSS.COLOR, false));
- assertEquals("white", $(el).css(CSS.BACKGROUND_COLOR, false));
}
+
+ // 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);
@@ -737,20 +935,6 @@ public class GQueryEventsTestGwt extends GWTTestCase {
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);
@@ -766,31 +950,18 @@ public class GQueryEventsTestGwt extends GWTTestCase {
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);
}
/**
@@ -881,224 +1052,178 @@ public class GQueryEventsTestGwt extends GWTTestCase {
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));
}
}