/** * Returns true if the number of matched elements is 0. */ public boolean isEmpty() { return size() == 0; }
/** * Returns the number of elements currently matched. The size function will return the same value. */ public int length() { return size(); }
/** * Return the position of the first matched element in relation with its sibblings. */ public int index() { return prevAll().size(); }
/** * Reduce the set of matched elements to the final one in the set. */ public GQuery last() { return eq(size() - 1); }
/** * 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. */ public GQuery val(Function f) { for (int i = 0; i < size(); i++) { eq(i).val(f.f(get(i), i).toString()); } return this; }
/** * Selects a subset of the matched elements. */ public GQuery slice(int start, int end) { JsNodeArray slice = JsNodeArray.create(); int l = size(); if (end == -1 || end > l) { end = l; } for (int i = start; i < end; i++) { slice.addNode(get(i)); } return new GQuery(slice); }
/** * 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. */ public GQuery replaceAll(GQuery target) { // 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; List<Element> newElements = new ArrayList<Element>(); for (int i = 0, l = target.size(); i < l; i++) { GQuery that = (i > 0 && mustBeCloned) ? this.clone() : this; $(target.get(i)).replaceWith(that); newElements.addAll(Arrays.asList(that.elements)); } return $(newElements); }
/** * Load an external javascript library. The inserted script replaces the * element with the given id in the document. * * @deprecated use {@link com.google.gwt.query.client.plugins.ajax.Ajax#loadScript(String)} */ @Deprecated public static void loadScript(String url, String id) { GQuery gs = GQuery.$(DOM.createElement("script")); GQuery gp = GQuery.$("#" + id).parent(); if (gp.size() != 1) { gp = GQuery.$(GQuery.document.getBody()); } GQuery.$("#" + id).remove(); gp.append(gs.attr("src", url).attr("type", "text/javascript").attr("id", id)); }
int groupCount = optgroupList.size();
int groupCount = optgroupList.size();