*/\r
public class GQuery implements Lazy<GQuery, LazyGQuery> {\r
\r
+ private enum DomMan {\r
+ AFTER, APPEND, BEFORE, PREPEND;\r
+ }\r
+ \r
/**\r
* A POJO used to store the top/left CSS positioning values of an element.\r
*/\r
return top + "+" + left;\r
}\r
}\r
- \r
+\r
/**\r
* Class used internally to create DOM element from html snippet\r
- *\r
*/\r
private static class TagWrapper {\r
public static final TagWrapper DEFAULT = new TagWrapper(0, "", "");\r
- private int wrapDepth; \r
+ private String postWrap; \r
private String preWrap;\r
- private String postWrap;\r
+ private int wrapDepth;\r
\r
public TagWrapper(int wrapDepth, String preWrap, String postWrap) {\r
this.wrapDepth=wrapDepth;\r
}\r
}\r
\r
+ /**\r
+ * Implementation class to modify attributes.\r
+ */\r
+ protected static AttributeImpl attributeImpl = GWT.create(AttributeImpl.class);\r
+\r
/**\r
* The body element in the current page.\r
*/\r
public static final BodyElement body = Document.get().getBody();\r
-\r
+ \r
/**\r
- * The document element in the current page.\r
+ * Object to store element data.\r
*/\r
- public static final Document document = Document.get();\r
-\r
+ protected static JsCache dataCache = null;\r
+ \r
/**\r
- * A static reference to the GQuery class.\r
+ * The document element in the current page.\r
*/\r
- public static Class<GQuery> GQUERY = GQuery.class;\r
+ public static final Document document = Document.get();\r
\r
/**\r
- * Static references to GQuery core plugins\r
+ * Static reference Effects plugin\r
*/\r
public static Class<Effects> Effects = com.google.gwt.query.client.plugins.Effects.Effects;\r
- public static Class<Events> Events = com.google.gwt.query.client.plugins.Events.Events;\r
- public static Class<Widgets> Widgets = com.google.gwt.query.client.plugins.Widgets.Widgets;\r
\r
/**\r
- * The window object.\r
+ * Implementation engine used for CSS selectors.\r
*/\r
- public static final Element window = window();\r
+ protected static SelectorEngine engine;\r
\r
- protected static JsCache dataCache = null;\r
+ /**\r
+ * Static reference Events plugin\r
+ */\r
+ public static Class<Events> Events = com.google.gwt.query.client.plugins.Events.Events;\r
\r
- protected static SelectorEngine engine;\r
+ /**\r
+ * A static reference to the GQuery class.\r
+ */\r
+ public static Class<GQuery> GQUERY = GQuery.class;\r
\r
- private static final int FUNC_PREPEND = 0, FUNC_APPEND = 1, FUNC_AFTER = 2,\r
- FUNC_BEFORE = 3;\r
-\r
private static final String OLD_DATA_PREFIX = "old-";\r
\r
private static JsMap<Class<? extends GQuery>, Plugin<? extends GQuery>> plugins;\r
\r
- protected static DocumentStyleImpl styleImpl = GWT.create(DocumentStyleImpl.class);\r
-\r
- private static Element windowData = null;\r
-\r
// Sizzle POS regex : usefull in some methods\r
// TODO: Share this static with SelectorEngineSizzle\r
private static final String POS_REGEX = ":(nth|eq|gt|lt|first|last|even|odd)(?:\\((\\d*)\\))?(?=[^\\-]|$)";\r
- \r
+\r
+ /**\r
+ * Implementation class used for style manipulations.\r
+ */\r
+ protected static DocumentStyleImpl styleImpl = GWT.create(DocumentStyleImpl.class);\r
+\r
private static JsRegexp tagNameRegex = new JsRegexp("<([\\w:]+)");\r
+\r
+ /**\r
+ * Static reference to the Widgets plugin\r
+ */\r
+ public static Class<Widgets> Widgets = com.google.gwt.query.client.plugins.Widgets.Widgets;\r
+ \r
+ /**\r
+ * The window object.\r
+ */\r
+ public static final Element window = window();\r
\r
- private static final JsNamedArray<TagWrapper> wrapperMap;\r
+ private static Element windowData = null;\r
\r
- protected static AttributeImpl attributeImpl = GWT.create(AttributeImpl.class);\r
+ private static final JsNamedArray<TagWrapper> wrapperMap;\r
\r
static {\r
TagWrapper tableWrapper = new TagWrapper(1, "<table>", "</table>");\r
return new GQuery(element);\r
}\r
\r
- /**\r
- * Wrap a GQuery around the element of a Function callback.\r
- */\r
- public static GQuery $(Function f) {\r
- return $(f.getElement());\r
- }\r
-\r
/**\r
* Wrap a GQuery around an event's target element.\r
*/\r
: $((Element) event.getCurrentEventTarget().cast());\r
}\r
\r
+ /**\r
+ * Wrap a GQuery around the element of a Function callback.\r
+ */\r
+ public static GQuery $(Function f) {\r
+ return $(f.getElement());\r
+ }\r
+\r
/**\r
* Create a new GQuery given a list of nodes, elements or widgets\r
*/\r
return Properties.create(properties);\r
}\r
\r
- /**\r
- * Return a lazy version of the GQuery interface. Lazy function calls are\r
- * simply queued up and not executed immediately.\r
- */\r
- public static LazyGQuery<?> lazy() {\r
- return $().createLazy();\r
- }\r
-\r
- public static <T extends GQuery> Class<T> registerPlugin(Class<T> plugin,\r
- Plugin<T> pluginFactory) {\r
- if (plugins == null) {\r
- plugins = JsMap.createObject().cast();\r
- }\r
-\r
- plugins.put(plugin, pluginFactory);\r
- return plugin;\r
- }\r
- \r
@SuppressWarnings("unchecked")\r
protected static GQuery cleanHtmlString(String elem, Document doc) {\r
\r
}\r
return name != null ? d.get(name) : id;\r
}\r
+ \r
+ private static native void emptyDocument(Document d) /*-{\r
+ d.open();\r
+ d.write("<head/><body/>");\r
+ d.close();\r
+ }-*/;\r
\r
/**\r
* We will use the fact as GWT use the widget itself as EventListener ! If no\r
return null;\r
}\r
\r
- protected static String[] jsArrayToString(JsArrayString array) {\r
- if (GWT.isScript()) {\r
- return jsArrayToString0(array);\r
- } else {\r
- String result[] = new String[array.length()];\r
- for (int i = 0, l = result.length; i < l; i++) {\r
- result[i] = array.get(i);\r
- }\r
- return result;\r
- }\r
- }\r
-\r
- private static native void emptyDocument(Document d) /*-{\r
- d.open();\r
- d.write("<head/><body/>");\r
- d.close();\r
- }-*/;\r
-\r
private native static Document getContentDocument(Node n) /*-{\r
var d = n.contentDocument || n.contentWindow.document;\r
if (!d.body)\r
@com.google.gwt.query.client.GQuery::emptyDocument(Lcom/google/gwt/dom/client/Document;)(d);\r
return d;\r
}-*/;\r
- \r
+\r
private static Document getOwnerDocument(Node n) {\r
return n== null || n.getNodeType() == Node.DOCUMENT_NODE ? \r
n.<Document> cast() : n.getOwnerDocument();\r
private static GQuery innerHtml(String html, Document doc) {\r
return $(cleanHtmlString(html, doc));\r
}\r
+ \r
+ protected static String[] jsArrayToString(JsArrayString array) {\r
+ if (GWT.isScript()) {\r
+ return jsArrayToString0(array);\r
+ } else {\r
+ String result[] = new String[array.length()];\r
+ for (int i = 0, l = result.length; i < l; i++) {\r
+ result[i] = array.get(i);\r
+ }\r
+ return result;\r
+ }\r
+ }\r
\r
private static native String[] jsArrayToString0(JsArrayString array) /*-{\r
return array;\r
}-*/;\r
\r
+ /**\r
+ * Return a lazy version of the GQuery interface. Lazy function calls are\r
+ * simply queued up and not executed immediately.\r
+ */\r
+ public static LazyGQuery<?> lazy() {\r
+ return $().createLazy();\r
+ }\r
+\r
+ public static <T extends GQuery> Class<T> registerPlugin(Class<T> plugin,\r
+ Plugin<T> pluginFactory) {\r
+ if (plugins == null) {\r
+ plugins = JsMap.createObject().cast();\r
+ }\r
+\r
+ plugins.put(plugin, pluginFactory);\r
+ return plugin;\r
+ }\r
+\r
+ private static native void scrollIntoViewImpl(Node n) /*-{\r
+ if (n)\r
+ n.scrollIntoView()\r
+ }-*/;\r
+ \r
private static native void setElementAttribute(Element e, String key, String value) /*-{\r
if (value == null)\r
e.removeAttribute(key);\r
e[key] = value;\r
}-*/;\r
\r
+ \r
private static native void setElementValue(Element e, String value) /*-{\r
e.value = value;\r
}-*/;\r
- \r
- \r
- private static native void scrollIntoViewImpl(Node n) /*-{\r
- if (n)\r
- n.scrollIntoView()\r
- }-*/;\r
-\r
- private GQuery select(String selector, Node context) {\r
- if (engine == null) {\r
- engine = new SelectorEngine();\r
- }\r
-\r
- NodeList<Element> n = engine.select(selector, context == null ? document : context);\r
- currentSelector = selector;\r
- currentContext = context != null ? context : document;\r
- return setArray(n);\r
- }\r
\r
private static native Element window() /*-{\r
return $wnd;\r
}-*/;\r
\r
- protected String currentSelector;\r
protected Node currentContext;\r
\r
- /**\r
- * The nodeList of matched elements, modify this using setArray\r
- */\r
- private NodeList<Element> nodeList = JavaScriptObject.createArray().cast();\r
- \r
+ protected String currentSelector;\r
/**\r
* Immutable array of matched elements, modify this using setArray\r
*/\r
private Element[] elements = new Element[0];\r
\r
+ /**\r
+ * The nodeList of matched elements, modify this using setArray\r
+ */\r
+ private NodeList<Element> nodeList = JavaScriptObject.createArray().cast();\r
+ \r
private GQuery previousObject;\r
\r
- protected GQuery(GQuery gq) {\r
- this(gq == null ? null : gq.get());\r
- currentSelector = gq.getSelector();\r
- currentContext = gq.getContext();\r
- }\r
-\r
private GQuery() {\r
}\r
\r
this(JsNodeArray.create(element));\r
}\r
\r
+ protected GQuery(GQuery gq) {\r
+ this(gq == null ? null : gq.get());\r
+ currentSelector = gq.getSelector();\r
+ currentContext = gq.getContext();\r
+ }\r
+\r
private GQuery(JsNodeArray nodes) {\r
this(nodes.<NodeList<Element>>cast());\r
}\r
private GQuery(NodeList<Element> list) {\r
setArray(list);\r
}\r
- \r
+\r
/**\r
* Add elements to the set of matched elements if they are not included yet.\r
* \r
return pushStack(JsUtils.copyNodeList(nodeList, elementsToAdd.nodeList, true).<JsNodeArray>cast(), "add",\r
getSelector() + "," + elementsToAdd.getSelector());\r
}\r
-\r
+ \r
/**\r
* Add elements to the set of matched elements if they are not included yet.\r
*/\r
* another if it's not in the page).\r
*/\r
public GQuery after(GQuery query) {\r
- return domManip(query, FUNC_AFTER);\r
+ return domManip(query, DomMan.AFTER);\r
}\r
\r
/**\r
* another if it's not in the page).\r
*/\r
public GQuery after(Node n) {\r
- return domManip($(n), FUNC_AFTER);\r
+ return domManip($(n), DomMan.AFTER);\r
}\r
\r
/**\r
* another if it's not in the page).\r
*/\r
public GQuery after(String html) {\r
- return domManip(html, FUNC_AFTER);\r
+ return domManip(html, DomMan.AFTER);\r
+ }\r
+\r
+ private void allNextSiblingElements(Element firstChildElement,\r
+ JsNodeArray result, Element elem, String untilSelector) {\r
+ while (firstChildElement != null) {\r
+ \r
+ if (untilSelector != null && $(firstChildElement).is(untilSelector)){\r
+ return;\r
+ }\r
+ \r
+ if (firstChildElement != elem) {\r
+ result.addNode(firstChildElement);\r
+ }\r
+ firstChildElement = firstChildElement.getNextSiblingElement();\r
+ }\r
+ }\r
+\r
+ private void allPreviousSiblingElements(Element firstChildElement,\r
+ JsNodeArray result, String untilSelector) {\r
+ while (firstChildElement != null) {\r
+ if (untilSelector != null && $(firstChildElement).is(untilSelector)){\r
+ return;\r
+ }\r
+ result.addNode(firstChildElement);\r
+ firstChildElement = getPreviousSiblingElement(firstChildElement);\r
+ }\r
}\r
\r
/**\r
}\r
\r
/**\r
+ * \r
* The animate() method allows you to create animation effects on any numeric\r
* Attribute, CSS property, or color CSS property.\r
* \r
* Example:\r
* \r
* <pre class="code">\r
- * //move the element from its original position to the position top:500px and left:500px for 400ms.\r
- * //use a swing easing function for the transition\r
- * $("#foo").animate(Properties.create("{top:'500px',left:'500px'}"), 400, Easing.SWING);\r
- * // Change the width and border attributes of a table\r
- * $("table").animate(Properties.create("{$width: '500', $border: '10'}"), 400, Easing.LINEAR);\r
+ * //move the element from its original position to left:500px for 500ms\r
+ * $("#foo").animate("left:'500'");\r
+ * // Change the width attribute of a table\r
+ * $("table").animate("$width:'500'"), 400, Easing.LINEAR);\r
* </pre>\r
* \r
* In addition to numeric values, each property can take the strings 'show',\r
* Example:\r
* \r
* <pre class="code">\r
- * //move the element from its original position to 500px to the left and 5OOpx down for 400ms.\r
- * //use a swing easing function for the transition\r
- * $("#foo").animate(Properties.create("{top:'+=500px',left:'+=500px'}"), 400, Easing.SWING);\r
+ * //move the element from its original position to 500px to the left for 500ms and\r
+ * // change the background color of the element at the end of the animation\r
+ * $("#foo").animate("left:'+=500'", new Function(){\r
+ * \r
+ * public void f(Element e){\r
+ * $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.RED);\r
+ * }\r
+ * \r
+ * });\r
* </pre>\r
* \r
+ * The duration of the animation is 500ms.\r
+ * \r
* For color css properties, values can be specified via hexadecimal or rgb or\r
* literal values.\r
* \r
* Example:\r
* \r
* <pre class="code">\r
- * $("#foo").animate("backgroundColor:'red', color:'#ffffff', borderColor:'rgb(129, 0, 70)'"), 400, Easing.SWING);\r
+ * $("#foo").animate("backgroundColor:'red', color:'#ffffff', borderColor:'rgb(129, 0, 70)'");\r
* </pre>\r
* \r
- * @param stringOrProperties a String or a {@link Properties} object containing css properties to animate.\r
+ * @param prop the property to animate : "cssName:'value'"\r
* @param funcs an array of {@link Function} called once the animation is\r
* complete\r
- * @param duration the duration in milliseconds of the animation\r
- * @param easing the easing function to use for the transition\r
*/\r
- public GQuery animate(Object stringOrProperties, int duration, Easing easing, Function... funcs) {\r
- return as(Effects).animate(stringOrProperties, duration, easing, funcs);\r
+ public GQuery animate(Object stringOrProperties, Function... funcs) {\r
+ return as(Effects).animate(stringOrProperties, funcs);\r
}\r
\r
/**\r
- * \r
* The animate() method allows you to create animation effects on any numeric\r
* Attribute, CSS property, or color CSS property.\r
* \r
* Example:\r
* \r
* <pre class="code">\r
- * //move the element from its original position to left:500px for 500ms\r
- * $("#foo").animate("left:'500'");\r
- * // Change the width attribute of a table\r
- * $("table").animate("$width:'500'"), 400, Easing.LINEAR);\r
+ * //move the element from its original position to the position top:500px and left:500px for 400ms.\r
+ * //use a swing easing function for the transition\r
+ * $("#foo").animate(Properties.create("{top:'500px',left:'500px'}"), 400, Easing.SWING);\r
+ * // Change the width and border attributes of a table\r
+ * $("table").animate(Properties.create("{$width: '500', $border: '10'}"), 400, Easing.LINEAR);\r
* </pre>\r
* \r
* In addition to numeric values, each property can take the strings 'show',\r
* Example:\r
* \r
* <pre class="code">\r
- * //move the element from its original position to 500px to the left for 500ms and\r
- * // change the background color of the element at the end of the animation\r
- * $("#foo").animate("left:'+=500'", new Function(){\r
- * \r
- * public void f(Element e){\r
- * $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.RED);\r
- * }\r
- * \r
- * });\r
+ * //move the element from its original position to 500px to the left and 5OOpx down for 400ms.\r
+ * //use a swing easing function for the transition\r
+ * $("#foo").animate(Properties.create("{top:'+=500px',left:'+=500px'}"), 400, Easing.SWING);\r
* </pre>\r
* \r
- * The duration of the animation is 500ms.\r
- * \r
* For color css properties, values can be specified via hexadecimal or rgb or\r
* literal values.\r
* \r
* Example:\r
* \r
* <pre class="code">\r
- * $("#foo").animate("backgroundColor:'red', color:'#ffffff', borderColor:'rgb(129, 0, 70)'");\r
+ * $("#foo").animate("backgroundColor:'red', color:'#ffffff', borderColor:'rgb(129, 0, 70)'"), 400, Easing.SWING);\r
* </pre>\r
* \r
- * @param prop the property to animate : "cssName:'value'"\r
+ * @param stringOrProperties a String or a {@link Properties} object containing css properties to animate.\r
* @param funcs an array of {@link Function} called once the animation is\r
* complete\r
+ * @param duration the duration in milliseconds of the animation\r
+ * @param easing the easing function to use for the transition\r
*/\r
- public GQuery animate(Object stringOrProperties, Function... funcs) {\r
- return as(Effects).animate(stringOrProperties, funcs);\r
+ public GQuery animate(Object stringOrProperties, int duration, Easing easing, Function... funcs) {\r
+ return as(Effects).animate(stringOrProperties, duration, easing, funcs);\r
}\r
\r
/**\r
* into the document.\r
*/\r
public GQuery append(GQuery query) {\r
- return domManip(query, FUNC_APPEND);\r
+ return domManip(query, DomMan.APPEND);\r
}\r
\r
/**\r
* into the document.\r
*/\r
public GQuery append(Node n) {\r
- return domManip($(n), FUNC_APPEND);\r
+ return domManip($(n), DomMan.APPEND);\r
}\r
\r
/**\r
* into the document.\r
*/\r
public GQuery append(String html) {\r
- return domManip(html, FUNC_APPEND);\r
+ return domManip(html, DomMan.APPEND);\r
}\r
\r
/**\r
}\r
return this;\r
}\r
-\r
+ \r
/**\r
* Access a property on the first matched element. This method makes it easy\r
* to retrieve a property value from the first matched element. If the element\r
*/\r
public String attr(String name) {\r
return isEmpty() ? "" : get(0).getAttribute(name);\r
- }\r
- \r
+ } \r
+
/**\r
* Set a single property to a computed value, on all matched elements.\r
*/\r
$(e).attr(key, val);\r
}\r
return this;\r
- } \r
-
+ }\r
+ \r
+ \r
+\r
/**\r
* Set a single property to a value, on all matched elements.\r
*/\r
attributeImpl.setAttribute(this, key, value);\r
return this;\r
}\r
- \r
- \r
\r
/**\r
* Insert content before each of the matched elements. The elements must\r
* another if it's not in the page).\r
*/\r
public GQuery before(GQuery query) {\r
- return domManip(query, FUNC_BEFORE);\r
+ return domManip(query, DomMan.BEFORE);\r
}\r
\r
/**\r
* another if it's not in the page).\r
*/\r
public GQuery before(Node n) {\r
- return domManip($(n), FUNC_BEFORE);\r
+ return domManip($(n), DomMan.BEFORE);\r
}\r
\r
/**\r
* another if it's not in the page).\r
*/\r
public GQuery before(String html) {\r
- return domManip(html, FUNC_BEFORE);\r
+ return domManip(html, DomMan.BEFORE);\r
}\r
\r
/**\r
return as(Events).bind(eventType, data, funcs);\r
}\r
\r
+ /**\r
+ * Bind Handlers or fire Events for each matched element.\r
+ */\r
+ private GQuery bindOrFire(int eventbits, final Object data,\r
+ final Function... funcs) {\r
+ if (funcs.length == 0) {\r
+ return trigger(eventbits);\r
+ } else {\r
+ return bind(eventbits, data, funcs);\r
+ }\r
+ }\r
+\r
/**\r
* Bind a set of functions to the blur event of each matched element. \r
* Or trigger the blur event if no functions are provided.\r
return find(filters);\r
}\r
\r
+ private void cleanGQData(Element... elements) {\r
+ for (Element el : elements) {\r
+ EventsListener.clean(el);\r
+ removeData(el, null);\r
+ }\r
+ }\r
+\r
+ \r
/**\r
* Remove from the Effects queue all {@link Function} that have not yet been\r
* run.\r
return bindOrFire(Event.ONCLICK, null, f);\r
}\r
\r
- \r
/**\r
* Clone matched DOM Elements and select the clones. This is useful for moving\r
* copies of the elements to another location in the DOM.\r
return closest(selector, null);\r
}\r
\r
+ /**\r
+ * Get the first ancestor element that matches the selector (for each matched\r
+ * element), beginning at the current element and progressing up through the\r
+ * DOM tree until reach the <code>context</code> node.\r
+ * \r
+ * If no context is passed in then the context of the gQuery object will be\r
+ * used instead.\r
+ * \r
+ */\r
+ public GQuery closest(String selector, Node context) {\r
+ assert selector != null;\r
+\r
+ if (context == null) {\r
+ context = currentContext;\r
+ }\r
+\r
+ GQuery pos = selector.matches(POS_REGEX) ? $(selector, context) : null;\r
+ JsNodeArray result = JsNodeArray.create();\r
+\r
+ for (Element e : elements) {\r
+ Element current = e;\r
+ while (current != null && current.getOwnerDocument() != null\r
+ && current != context) {\r
+ boolean match = pos != null ? pos.index(current) > -1 : $(current).is(\r
+ selector);\r
+ if (match) {\r
+ result.addNode(current);\r
+ break;\r
+ } else {\r
+ current = current.getParentElement();\r
+ }\r
+ }\r
+ }\r
+\r
+ return $(unique(result));\r
+\r
+ }\r
+\r
/**\r
* Returns a {@link Map} object as key a selector and as value the list of\r
* ancestor elements matching this selectors, beginning at the first matched\r
return results;\r
}\r
\r
- /**\r
- * Get the first ancestor element that matches the selector (for each matched\r
- * element), beginning at the current element and progressing up through the\r
- * DOM tree until reach the <code>context</code> node.\r
- * \r
- * If no context is passed in then the context of the gQuery object will be\r
- * used instead.\r
- * \r
- */\r
- public GQuery closest(String selector, Node context) {\r
- assert selector != null;\r
-\r
- if (context == null) {\r
- context = currentContext;\r
- }\r
-\r
- GQuery pos = selector.matches(POS_REGEX) ? $(selector, context) : null;\r
- JsNodeArray result = JsNodeArray.create();\r
-\r
- for (Element e : elements) {\r
- Element current = e;\r
- while (current != null && current.getOwnerDocument() != null\r
- && current != context) {\r
- boolean match = pos != null ? pos.index(current) > -1 : $(current).is(\r
- selector);\r
- if (match) {\r
- result.addNode(current);\r
- break;\r
- } else {\r
- current = current.getParentElement();\r
- }\r
- }\r
- }\r
-\r
- return $(unique(result));\r
-\r
- }\r
-\r
/**\r
* Filter the set of elements to those that contain the specified text.\r
*/\r
return this;\r
}\r
\r
+\r
/**\r
* Return a style property on the first matched element.\r
*/\r
return this;\r
}\r
\r
-\r
/**\r
* Set CSS a single style property on every matched element using type-safe\r
* enumerations. This method allows you to set manually the value or set\r
/**\r
* Attach <code>handlers</code> to one or more events for all elements that\r
* match the <code>selector</code>, now or in the future, based on a specific\r
- * set of root elements.\r
+ * set of root elements. \r
* \r
* Example:\r
* \r
* <pre>\r
- * $("table").delegate("td", "click", new Function(){\r
+ * $("table").delegate("td", Event.ONCLICK, new Function(){\r
* public void f(Element e){\r
* $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.RED));\r
* }\r
* <pre>\r
* $("table").each(new Function(){\r
* public void f(Element table){\r
- * $("td", table).live("click", new Function(){\r
+ * $("td", table).live(Event.ONCLICK, new Function(){\r
* public void f(Element e){\r
* $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.RED));\r
* }\r
*\r
* </pre>\r
* \r
- * You can pass attach the handlers to many events by specifying a String with espaced event type.\r
+ * You can attach the handlers to many events by using the '|' operator\r
* ex:\r
* <pre>\r
- * $("div.main").delegate(".subMain", "click dblclick", new Function(){...});\r
- * </pre>\r
+ * $("div.main").delegate(".subMain", Event.ONCLICK | Event.ONDBLCLICK, new Function(){...});\r
* </pre>\r
*/\r
- public GQuery delegate(String selector, String eventType,\r
- Function... handlers) {\r
- return delegate(selector, eventType, null, handlers);\r
+ public GQuery delegate(String selector, int eventbits, Function... handlers) {\r
+ return delegate(selector, eventbits, null, handlers);\r
}\r
\r
/**\r
- * Attach <code>handlers</code> to one or more events for all elements that\r
- * match the <code>selector</code>, now or in the future, based on a specific\r
- * set of root elements.\r
- * \r
+ * Attach <code>handlers</code> to one or more events for all elements that match the <code>selector</code>, \r
+ * now or in the future, based on a specific set of root elements.\r
+ * The <code>data</code> parameter allows us\r
+ * to pass data to the handler.\r
+ *\r
* Example:\r
- * \r
* <pre>\r
* $("table").delegate("td", "click", new Function(){\r
* public void f(Element e){\r
* }\r
* });\r
* </pre>\r
- * \r
- * This code above add an handler on click event on all cell (the existing\r
- * oneand the future cell) of all table. This code is equivalent to :\r
- * \r
+ * This code above add an handler on click event on all cell (the existing oneand the future cell) of all table.\r
+ * This code is equivalent to :\r
* <pre>\r
* $("table").each(new Function(){\r
* public void f(Element table){\r
* }\r
* });\r
*\r
- * You can pass attach the handlers to many events by specifying a String with espaced event type.\r
+ * </pre>\r
+ * \r
+ * You can pass attach the handlers to many events by using the '|' operator\r
* ex:\r
* <pre>\r
- * $("div.main").delegate(".subMain", "click dblclick", new Function(){...});\r
- * </pre>\r
+ * $("div.main").delegate(".subMain", Event.ONCLICK | Event.ONDBLCLICK, new Function(){...});\r
* </pre>\r
*/\r
- public GQuery delegate(String selector, String eventType, Object data,\r
+ public GQuery delegate(String selector, int eventbits, Object data,\r
Function... handlers) {\r
+\r
for (Element e : elements) {\r
- $(selector, e).live(eventType, data, handlers);\r
+ $(selector, e).live(eventbits, data, handlers);\r
}\r
\r
return this;\r
/**\r
* Attach <code>handlers</code> to one or more events for all elements that\r
* match the <code>selector</code>, now or in the future, based on a specific\r
- * set of root elements. \r
+ * set of root elements.\r
* \r
* Example:\r
* \r
* <pre>\r
- * $("table").delegate("td", Event.ONCLICK, new Function(){\r
+ * $("table").delegate("td", "click", new Function(){\r
* public void f(Element e){\r
* $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.RED));\r
* }\r
* <pre>\r
* $("table").each(new Function(){\r
* public void f(Element table){\r
- * $("td", table).live(Event.ONCLICK, new Function(){\r
+ * $("td", table).live("click", new Function(){\r
* public void f(Element e){\r
* $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.RED));\r
* }\r
*\r
* </pre>\r
* \r
- * You can attach the handlers to many events by using the '|' operator\r
+ * You can pass attach the handlers to many events by specifying a String with espaced event type.\r
* ex:\r
* <pre>\r
- * $("div.main").delegate(".subMain", Event.ONCLICK | Event.ONDBLCLICK, new Function(){...});\r
+ * $("div.main").delegate(".subMain", "click dblclick", new Function(){...});\r
+ * </pre>\r
* </pre>\r
*/\r
- public GQuery delegate(String selector, int eventbits, Function... handlers) {\r
- return delegate(selector, eventbits, null, handlers);\r
+ public GQuery delegate(String selector, String eventType,\r
+ Function... handlers) {\r
+ return delegate(selector, eventType, null, handlers);\r
}\r
\r
/**\r
- * Attach <code>handlers</code> to one or more events for all elements that match the <code>selector</code>, \r
- * now or in the future, based on a specific set of root elements.\r
- * The <code>data</code> parameter allows us\r
- * to pass data to the handler.\r
- *\r
+ * Attach <code>handlers</code> to one or more events for all elements that\r
+ * match the <code>selector</code>, now or in the future, based on a specific\r
+ * set of root elements.\r
+ * \r
* Example:\r
+ * \r
* <pre>\r
* $("table").delegate("td", "click", new Function(){\r
* public void f(Element e){\r
* }\r
* });\r
* </pre>\r
- * This code above add an handler on click event on all cell (the existing oneand the future cell) of all table.\r
- * This code is equivalent to :\r
+ * \r
+ * This code above add an handler on click event on all cell (the existing\r
+ * oneand the future cell) of all table. This code is equivalent to :\r
+ * \r
* <pre>\r
* $("table").each(new Function(){\r
* public void f(Element table){\r
* }\r
* });\r
*\r
- * </pre>\r
- * \r
- * You can pass attach the handlers to many events by using the '|' operator\r
+ * You can pass attach the handlers to many events by specifying a String with espaced event type.\r
* ex:\r
* <pre>\r
- * $("div.main").delegate(".subMain", Event.ONCLICK | Event.ONDBLCLICK, new Function(){...});\r
+ * $("div.main").delegate(".subMain", "click dblclick", new Function(){...});\r
+ * </pre>\r
* </pre>\r
*/\r
- public GQuery delegate(String selector, int eventbits, Object data,\r
+ public GQuery delegate(String selector, String eventType, Object data,\r
Function... handlers) {\r
-\r
for (Element e : elements) {\r
- $(selector, e).live(eventbits, data, handlers);\r
+ $(selector, e).live(eventType, data, handlers);\r
}\r
\r
return this;\r
\r
/**\r
* Remove an event handlers previously attached using\r
- * {@link #live(String, Function)} In order for this method to function\r
+ * {@link #live(int, Function)} In order for this method to function\r
* correctly, the selector used with it must match exactly the selector\r
- * initially used with {@link #live(String, Function)}\r
+ * initially used with {@link #live(int, Function)}\r
*/\r
- public GQuery die(String eventName) {\r
- return as(Events).die(eventName);\r
+ public GQuery die(int eventbits) {\r
+ return as(Events).die(eventbits);\r
}\r
\r
/**\r
* Remove an event handlers previously attached using\r
- * {@link #live(int, Function)} In order for this method to function\r
+ * {@link #live(String, Function)} In order for this method to function\r
* correctly, the selector used with it must match exactly the selector\r
- * initially used with {@link #live(int, Function)}\r
+ * initially used with {@link #live(String, Function)}\r
*/\r
- public GQuery die(int eventbits) {\r
- return as(Events).die(eventbits);\r
+ public GQuery die(String eventName) {\r
+ return as(Events).die(eventName);\r
+ }\r
+\r
+ private GQuery domManip(GQuery g, DomMan type, Element... elms) {\r
+ int size = g.size();\r
+ JsNodeArray newNodes = JsNodeArray.create();\r
+ if (elms.length == 0) {\r
+ elms = elements;\r
+ }\r
+ for (int i = 0, l = elms.length; i < l;i ++) {\r
+ Element e = elms[i];\r
+ if (e.getNodeType() == Node.DOCUMENT_NODE) {\r
+ e = e.<Document>cast().getBody();\r
+ }\r
+ for (int j = 0; j < size; j++) {\r
+ // Widget w = getAssociatedWidget(g.get(j));\r
+ // GqUi.detachWidget(w);\r
+ \r
+ Node n = g.get(j);\r
+ // If an element selected is inserted elsewhere, it will be moved into the target (not cloned).\r
+ // If there is more than one target element, however, cloned copies of the inserted element will be created for each target after the first\r
+ if (size > 1 || i > 0) {\r
+ n = n.cloneNode(true);\r
+ }\r
+ switch (type) {\r
+ case PREPEND:\r
+ newNodes.addNode(e.insertBefore(n, e.getFirstChild()));\r
+ break;\r
+ case APPEND:\r
+ newNodes.addNode(e.appendChild(n));\r
+ break;\r
+ case AFTER:\r
+ newNodes.addNode(e.getParentNode().insertBefore(n,\r
+ e.getNextSibling()));\r
+ break;\r
+ case BEFORE:\r
+ newNodes.addNode(e.getParentNode().insertBefore(n, e));\r
+ break;\r
+ }\r
+ EventsListener.rebind(n.<Element> cast());\r
+ \r
+ // GqUi.attachWidget(w);\r
+ }\r
+ }\r
+ if (newNodes.size() > g.get().getLength()) {\r
+ g.setArray(newNodes);\r
+ }\r
+ return this;\r
+ }\r
+\r
+ // TODO: this should be handled by the other domManip method\r
+ private GQuery domManip(String htmlString, DomMan type) {\r
+ JsMap<Document, GQuery> cache = JsMap.createObject().cast();\r
+ for (Element e : elements) {\r
+ Document d = getOwnerDocument(e);\r
+ GQuery g = cache.get(d);\r
+ if (g == null) {\r
+ g = cleanHtmlString(htmlString, d);\r
+ cache.put(d, g);\r
+ }\r
+ domManip(g.clone(), type, e);\r
+ }\r
+ return this;\r
}\r
\r
/**\r
public GQuery error(Function... f) {\r
return bindOrFire(Event.ONERROR, null, f);\r
}\r
-\r
+ \r
+ \r
/**\r
* Fade in all matched elements by adjusting their opacity. The effect will\r
* take 1000 milliseconds to complete\r
public GQuery fadeIn(int millisecs, Function... f) {\r
return $(as(Effects).fadeIn(millisecs, f));\r
}\r
-\r
+ \r
/**\r
* Fade out all matched elements by adjusting their opacity. The effect will\r
* take 1000 milliseconds to complete\r
public Effects fadeToggle(int millisecs, Function... f) {\r
return as(Effects).fadeToggle(millisecs, f);\r
}\r
- \r
- \r
+\r
/**\r
* Removes all elements from the set of matched elements that do not match the\r
* specified function. The function is called with a context equal to the\r
}\r
return pushStack(unique(array), "filter", filters[0]);\r
}\r
- \r
+\r
/**\r
* Searches for all elements that match the specified css expression. This\r
* method is a good way to find additional descendant elements with which to\r
public NodeList<Element> get() {\r
return nodeList;\r
}\r
+ \r
\r
/**\r
* Return the ith element matched. This method accept negative index. A\r
return previousObject;\r
}\r
\r
+ private native Element getPreviousSiblingElement(Element elem) /*-{\r
+ var sib = elem.previousSibling;\r
+ while (sib && sib.nodeType != 1)\r
+ sib = sib.previousSibling;\r
+ return sib;\r
+ }-*/;\r
+\r
/**\r
* Return the selector representing the current set of matched elements.\r
*/\r
public GQuery gt(int pos) {\r
return $(slice(pos + 1, -1));\r
}\r
- \r
\r
/**\r
* Reduce the set of matched elements to those that have a descendant \r
- * that matches the selector.\r
+ * that matches the Element.\r
*/\r
- public GQuery has(final String selector) {\r
+ public GQuery has(final Element elem) {\r
return filter(new Predicate(){\r
public boolean f(Element e, int index) {\r
- return !$(selector, e).isEmpty();\r
+ return engine.contains(e, elem);\r
}\r
});\r
}\r
\r
/**\r
* Reduce the set of matched elements to those that have a descendant \r
- * that matches the Element.\r
+ * that matches the selector.\r
*/\r
- public GQuery has(final Element elem) {\r
+ public GQuery has(final String selector) {\r
return filter(new Predicate(){\r
public boolean f(Element e, int index) {\r
- return engine.contains(e, elem);\r
+ return !$(selector, e).isEmpty();\r
}\r
});\r
}\r
public GQuery insertAfter(Element elem) {\r
return insertAfter($(elem));\r
}\r
-\r
+ \r
/**\r
* Insert all of the matched elements after another, specified, set of\r
* elements.\r
public boolean is(String... filters) {\r
return !filter(filters).isEmpty();\r
}\r
- \r
+\r
/**\r
* Returns true if the number of matched elements is 0. \r
*/\r
return size() == 0;\r
}\r
\r
+ /**\r
+ * Return true if the first element is visible.isVisible\r
+ */\r
+ public boolean isVisible() {\r
+ return isEmpty() ? false : styleImpl.isVisible(get(0));\r
+ }\r
+\r
/**\r
* Bind a set of functions to the keydown event of each matched element. Or\r
* trigger the event if no functions are provided.\r
return size();\r
}\r
\r
+ /**\r
+ * Attach a handler for this event to all elements which match the current\r
+ * selector, now and in the future.\r
+ */\r
+ public GQuery live(int eventbits, Function... funcs) {\r
+ return as(Events).live(eventbits, null, funcs);\r
+ }\r
+\r
+ /**\r
+ * Attach a handler for this event to all elements which match the current\r
+ * selector, now and in the future.\r
+ */\r
+ public GQuery live(int eventbits, Object data, Function... funcs) {\r
+ return as(Events).live(eventbits, data, funcs);\r
+ }\r
+\r
/**\r
* <p>\r
* Attach a handler for this event to all elements which match the current\r
return as(Events).live(eventName, null, funcs);\r
}\r
\r
- /**\r
- * Attach a handler for this event to all elements which match the current\r
- * selector, now and in the future.\r
- */\r
- public GQuery live(int eventbits, Function... funcs) {\r
- return as(Events).live(eventbits, null, funcs);\r
- }\r
-\r
- /**\r
- * Attach a handler for this event to all elements which match the current\r
- * selector, now and in the future.\r
- */\r
- public GQuery live(int eventbits, Object data, Function... funcs) {\r
- return as(Events).live(eventbits, data, funcs);\r
- }\r
-\r
/**\r
* <p>\r
* Attach a handler for this event to all elements which match the current\r
return ret;\r
}\r
\r
+ \r
/**\r
* Bind a set of functions to the mousedown event of each matched element. Or\r
* trigger the event if no functions are provided.\r
public GQuery mousedown(Function... f) {\r
return bindOrFire(Event.ONMOUSEDOWN, null, f);\r
}\r
-\r
+ \r
/**\r
* Bind a set of functions to the mousemove event of each matched element. Or\r
* trigger the event if no functions are provided.\r
return pushStack(result, "next", selectors[0]).filter(selectors);\r
}\r
\r
- \r
/**\r
* Find all sibling elements after the current element.\r
*/\r
}\r
return pushStack(unique(result), "nextAll", getSelector());\r
}\r
- \r
+\r
/**\r
* Get all following siblings of each element up to but not including the\r
* element matched by the selector.\r
public int outerHeight() {\r
return outerHeight(false);\r
}\r
-\r
+ \r
/**\r
* Get the current computed height for the first element in the set of matched\r
* elements, including padding, border, and optionally margin.\r
}\r
return outerHeight;\r
}\r
+ \r
\r
/**\r
* Get the current computed width for the first element in the set of matched\r
public GQuery parents(String... filters) {\r
return parents().filter(filters);\r
}\r
- \r
+\r
/**\r
* Get the ancestors of each element in the current set of matched elements,\r
* up to but not including the element matched by the selector.\r
}\r
return new GQuery(unique(result));\r
}\r
- \r
\r
/**\r
* Gets the top and left position of an element relative to its offset parent.\r
* elements.\r
*/\r
public GQuery prepend(GQuery query) {\r
- return domManip(query, FUNC_PREPEND);\r
+ return domManip(query, DomMan.PREPEND);\r
}\r
\r
/**\r
* elements.\r
*/\r
public GQuery prepend(Node n) {\r
- return domManip($(n), FUNC_PREPEND);\r
+ return domManip($(n), DomMan.PREPEND);\r
}\r
-\r
+ \r
/**\r
* Prepend content to the inside of every matched element. This operation is\r
* the best way to insert elements inside, at the beginning, of all matched\r
* elements.\r
*/\r
public GQuery prepend(String html) {\r
- return domManip(html, FUNC_PREPEND);\r
+ return domManip(html, DomMan.PREPEND);\r
}\r
-\r
+ \r
/**\r
* All of the matched set of elements will be inserted at the beginning of the\r
* element(s) specified by the parameter other.\r
$(html).prepend(this);\r
return this;\r
}\r
-\r
+ \r
/**\r
* Get a set of elements containing the unique previous siblings of each of\r
* the matched set of elements. Only the immediately previous sibling is\r
}\r
return new GQuery(unique(result));\r
}\r
-\r
+ \r
/**\r
* Get a set of elements containing the unique previous siblings of each of\r
* the matched set of elements filtered by selector. Only the immediately\r
}\r
return new GQuery(unique(result)).filter(selectors);\r
}\r
-\r
/**\r
* Find all sibling elements in front of the current element.\r
*/\r
}\r
return pushStack(unique(result), "prevAll", getSelector());\r
}\r
- \r
+\r
/**\r
* Find all sibling elements in front of the current element.\r
*/\r
}\r
return pushStack(unique(result), "prevUntil", getSelector());\r
}\r
- \r
+\r
/**\r
* Accesses a boolean property on the first matched element.\r
* \r
\r
return this;\r
}\r
- \r
+\r
+ protected GQuery pushStack(JsNodeArray elts, String name, String selector) {\r
+ GQuery g = new GQuery(elts);\r
+ g.setPreviousObject(this);\r
+ g.setSelector(selector);\r
+ g.currentContext = currentContext;\r
+ return g;\r
+ }\r
+\r
/**\r
* Show the number of functions in the efects queue to be executed on the\r
* first matched element.\r
public int queue() {\r
return as(Queue).queue();\r
}\r
- \r
- /**\r
- * Show the number of functions in the queued named as queueName to be\r
- * executed on the first matched element.\r
- */\r
- public int queue(String queueName) {\r
- return as(Queue).queue();\r
- }\r
+\r
/**\r
* Put a set of {@link Function} at the end of the Effects queue.\r
* \r
return as(Queue).queue(f);\r
}\r
\r
+ /**\r
+ * Show the number of functions in the queued named as queueName to be\r
+ * executed on the first matched element.\r
+ */\r
+ public int queue(String queueName) {\r
+ return as(Queue).queue();\r
+ }\r
+\r
/**\r
* Put a set of {@link Function} at the end of a queue.\r
* \r
public GQuery remove(String filter) {\r
return remove(filter, true);\r
}\r
-\r
+\r
+ /**\r
+ * Removes all matched elements from the DOM and cleans their data and bound\r
+ * events if the value of <code>clean</code> parameter is set to true. The\r
+ * <code> filter</code> parameter allows to filter the matched set to remove.\r
+ */\r
+ protected GQuery remove(String filter, boolean clean) {\r
+ for (Element e : elements) {\r
+ if (filter == null || $(e).filter(filter).length() == 1) {\r
+ if (clean) {\r
+ // clean data linked to the children\r
+ cleanGQData($("*", e).elements());\r
+ // clean data linked to the element itself\r
+ cleanGQData(e);\r
+ }\r
+ Widget w = getAssociatedWidget(e);\r
+ if (w != null) {\r
+ w.removeFromParent();\r
+ } else {\r
+ e.removeFromParent();\r
+ }\r
+ }\r
+ }\r
+ return this;\r
+ }\r
+ \r
/**\r
* Remove the named attribute from every element in the matched set.\r
*/\r
}\r
return this;\r
}\r
+ \r
+ private void removeData(Element item, String name) {\r
+ if (dataCache == null) {\r
+ windowData = JavaScriptObject.createObject().cast();\r
+ dataCache = JavaScriptObject.createObject().cast();\r
+ }\r
+ item = item == window || item.getNodeName() == null ? windowData : item;\r
+ int id = item.hashCode();\r
+ if (name != null) {\r
+ if (dataCache.exists(id)) {\r
+ dataCache.getCache(id).delete(name);\r
+ }\r
+ if (dataCache.getCache(id).isEmpty()) {\r
+ removeData(item, null);\r
+ }\r
+ } else {\r
+ dataCache.delete(id);\r
+ }\r
+ }\r
\r
/**\r
* Removes named data store from an element.\r
}\r
return this;\r
}\r
- \r
+\r
/**\r
* Bind a set of functions to the resize event of each matched element, or\r
* tigger the resize event if no functions are provided.\r
return bindOrFire(EventsListener.ONRESIZE, null, f);\r
}\r
\r
+ /**\r
+ * Bind an event handler to the "resize" JavaScript event, or trigger that event on an element. \r
+ */\r
+ public GQuery resize(final Function f) {\r
+ return bindOrFire(EventsListener.ONRESIZE, null, f);\r
+ }\r
+\r
/**\r
* Save a set of Css properties of every matched element.\r
*/\r
}\r
}\r
}\r
- \r
- /**\r
- * Bind an event handler to the "resize" JavaScript event, or trigger that event on an element. \r
- */\r
- public GQuery resize(final Function f) {\r
- return bindOrFire(EventsListener.ONRESIZE, null, f);\r
- }\r
\r
/**\r
* Restore a set of previously saved Css properties in every matched element.\r
return as(Events).triggerHtmlEvent("select");\r
}\r
\r
+ private GQuery select(String selector, Node context) {\r
+ if (engine == null) {\r
+ engine = new SelectorEngine();\r
+ }\r
+\r
+ NodeList<Element> n = engine.select(selector, context == null ? document : context);\r
+ currentSelector = selector;\r
+ currentContext = context != null ? context : document;\r
+ return setArray(n);\r
+ }\r
+\r
/**\r
* Force the current matched set of elements to become the specified array of\r
* elements.\r
}\r
return this;\r
}\r
-\r
+ \r
/**\r
* Get a set of elements containing all of the unique siblings of each of the\r
* matched set of elements.\r
public GQuery stop(boolean clearQueue) {\r
return stop(clearQueue, false);\r
}\r
- \r
+\r
/**\r
* When .stop() is called on an element, the currently-running animation (if any) \r
* is immediately stopped. If, for instance, an element is being hidden with .slideUp() \r
public GQuery submit(Function... funcs) {\r
return bindOrFire(EventsListener.ONSUBMIT, null, funcs);\r
}\r
-\r
+ \r
/**\r
* Return the text contained in the first matched element.\r
*/\r
}\r
return result;\r
}\r
-\r
+ \r
/**\r
* Set the innerText of every matched element.\r
*/\r
}\r
return this;\r
}\r
-\r
+ \r
/**\r
* Toggle among two or more function calls every other click.\r
*/\r
public int top() {\r
return (int) cur("top", true);\r
}\r
-\r
+ \r
/**\r
* Produces a string representation of the matched elements.\r
*/\r
public String toString() {\r
return toString(false);\r
}\r
-\r
+ \r
/**\r
* Produces a string representation of the matched elements.\r
*/\r
}\r
return r;\r
}\r
-\r
+ \r
/**\r
* Trigger a set of events on each matched element.\r
* \r
public GQuery unbind(int eventbits) {\r
return as(Events).unbind(eventbits);\r
}\r
- \r
+\r
/**\r
* Remove all event delegation that have been bound using\r
* {@link #delegate(String, int, Function...)} {@link #live(int, Function...)} methods\r
* Undelegate is a way of removing event handlers that have been bound using\r
* {@link #delegate(String, int, Function...)} method\r
*/\r
- public GQuery undelegate(String selector, String eventName) {\r
+ public GQuery undelegate(String selector, int eventBit) {\r
for (Element e : elements){\r
- $(selector, e).die(eventName);\r
+ $(selector, e).die(eventBit);\r
}\r
\r
return this;\r
}\r
- \r
+\r
/**\r
* Undelegate is a way of removing event handlers that have been bound using\r
* {@link #delegate(String, int, Function...)} method\r
*/\r
- public GQuery undelegate(String selector, int eventBit) {\r
+ public GQuery undelegate(String selector, String eventName) {\r
for (Element e : elements){\r
- $(selector, e).die(eventBit);\r
+ $(selector, e).die(eventName);\r
}\r
\r
return this;\r
String[] v = vals();\r
return v == null ? null : v.length > 0 ? v[0] : "";\r
}\r
- \r
+\r
/**\r
* Sets the value attribute of every matched element based in the return\r
* value of the function evaluated for this element.\r
}\r
return this;\r
}\r
- \r
+\r
/**\r
* Sets the 'value' attribute of every matched element, but\r
* does not set the checked flag to checkboxes or radiobuttons.\r
}\r
return this;\r
}\r
- \r
+\r
/**\r
* Sets the value of every matched element.\r
* \r
return new String[0];\r
}\r
\r
- /**\r
- * Return true if the first element is visible.isVisible\r
- */\r
- public boolean isVisible() {\r
- return isEmpty() ? false : styleImpl.isVisible(get(0));\r
- }\r
- \r
@Deprecated\r
public boolean visible() {\r
return isVisible();\r
public GQuery wrapInner(String html) {\r
return wrapInner($(html));\r
}\r
-\r
- protected GQuery pushStack(JsNodeArray elts, String name, String selector) {\r
- GQuery g = new GQuery(elts);\r
- g.setPreviousObject(this);\r
- g.setSelector(selector);\r
- g.currentContext = currentContext;\r
- return g;\r
- }\r
-\r
- /**\r
- * Removes all matched elements from the DOM and cleans their data and bound\r
- * events if the value of <code>clean</code> parameter is set to true. The\r
- * <code> filter</code> parameter allows to filter the matched set to remove.\r
- */\r
- protected GQuery remove(String filter, boolean clean) {\r
- for (Element e : elements) {\r
- if (filter == null || $(e).filter(filter).length() == 1) {\r
- if (clean) {\r
- // clean data linked to the children\r
- cleanGQData($("*", e).elements());\r
- // clean data linked to the element itself\r
- cleanGQData(e);\r
- }\r
- Widget w = getAssociatedWidget(e);\r
- if (w != null) {\r
- w.removeFromParent();\r
- } else {\r
- e.removeFromParent();\r
- }\r
- }\r
- }\r
- return this;\r
- }\r
-\r
- private void allNextSiblingElements(Element firstChildElement,\r
- JsNodeArray result, Element elem, String untilSelector) {\r
- while (firstChildElement != null) {\r
- \r
- if (untilSelector != null && $(firstChildElement).is(untilSelector)){\r
- return;\r
- }\r
- \r
- if (firstChildElement != elem) {\r
- result.addNode(firstChildElement);\r
- }\r
- firstChildElement = firstChildElement.getNextSiblingElement();\r
- }\r
- }\r
-\r
- private void allPreviousSiblingElements(Element firstChildElement,\r
- JsNodeArray result, String untilSelector) {\r
- while (firstChildElement != null) {\r
- if (untilSelector != null && $(firstChildElement).is(untilSelector)){\r
- return;\r
- }\r
- result.addNode(firstChildElement);\r
- firstChildElement = getPreviousSiblingElement(firstChildElement);\r
- }\r
- }\r
-\r
- /**\r
- * Bind Handlers or fire Events for each matched element.\r
- */\r
- private GQuery bindOrFire(int eventbits, final Object data,\r
- final Function... funcs) {\r
- if (funcs.length == 0) {\r
- return trigger(eventbits);\r
- } else {\r
- return bind(eventbits, data, funcs);\r
- }\r
- }\r
-\r
- private void cleanGQData(Element... elements) {\r
- for (Element el : elements) {\r
- EventsListener.clean(el);\r
- removeData(el, null);\r
- }\r
- }\r
-\r
- private GQuery domManip(GQuery g, int func, Element... elms) {\r
- int size = g.size();\r
- JsNodeArray newNodes = JsNodeArray.create();\r
- if (elms.length == 0) {\r
- elms = elements;\r
- }\r
- for (int i = 0, l = elms.length; i < l;i ++) {\r
- Element e = elms[i];\r
- if (e.getNodeType() == Node.DOCUMENT_NODE) {\r
- e = e.<Document>cast().getBody();\r
- }\r
- for (int j = 0; j < size; j++) {\r
- // Widget w = getAssociatedWidget(g.get(j));\r
- // GqUi.detachWidget(w);\r
- \r
- Node n = g.get(j);\r
- // If an element selected is inserted elsewhere, it will be moved into the target (not cloned).\r
- // If there is more than one target element, however, cloned copies of the inserted element will be created for each target after the first\r
- if (size > 1 || i > 0) {\r
- n = n.cloneNode(true);\r
- }\r
- switch (func) {\r
- case FUNC_PREPEND:\r
- newNodes.addNode(e.insertBefore(n, e.getFirstChild()));\r
- break;\r
- case FUNC_APPEND:\r
- newNodes.addNode(e.appendChild(n));\r
- break;\r
- case FUNC_AFTER:\r
- newNodes.addNode(e.getParentNode().insertBefore(n,\r
- e.getNextSibling()));\r
- break;\r
- case FUNC_BEFORE:\r
- newNodes.addNode(e.getParentNode().insertBefore(n, e));\r
- break;\r
- }\r
- EventsListener.rebind(n.<Element> cast());\r
- \r
- // GqUi.attachWidget(w);\r
- }\r
- }\r
- if (newNodes.size() > g.get().getLength()) {\r
- g.setArray(newNodes);\r
- }\r
- return this;\r
- }\r
-\r
- // TODO: this should be handled by the other domManip method\r
- private GQuery domManip(String htmlString, int func) {\r
- JsMap<Document, GQuery> cache = JsMap.createObject().cast();\r
- for (Element e : elements) {\r
- Document d = getOwnerDocument(e);\r
- GQuery g = cache.get(d);\r
- if (g == null) {\r
- g = cleanHtmlString(htmlString, d);\r
- cache.put(d, g);\r
- }\r
- domManip(g.clone(), func, e);\r
- }\r
- return this;\r
- }\r
-\r
- private native Element getPreviousSiblingElement(Element elem) /*-{\r
- var sib = elem.previousSibling;\r
- while (sib && sib.nodeType != 1)\r
- sib = sib.previousSibling;\r
- return sib;\r
- }-*/;\r
-\r
- private void removeData(Element item, String name) {\r
- if (dataCache == null) {\r
- windowData = JavaScriptObject.createObject().cast();\r
- dataCache = JavaScriptObject.createObject().cast();\r
- }\r
- item = item == window || item.getNodeName() == null ? windowData : item;\r
- int id = item.hashCode();\r
- if (name != null) {\r
- if (dataCache.exists(id)) {\r
- dataCache.getCache(id).delete(name);\r
- }\r
- if (dataCache.getCache(id).isEmpty()) {\r
- removeData(item, null);\r
- }\r
- } else {\r
- dataCache.delete(id);\r
- }\r
- }\r
}\r