/** * 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() { public boolean f(Element e, int index) { return !$(selector, e).isEmpty(); } }); }
/** * 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() { public boolean f(Element e, int index) { return contains(e, elem); } }); }
/** * 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 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 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); }
/** * 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); }
/** * 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(); }
private boolean isDetached(GQuery element) { return element.parents().filter("body").isEmpty(); }
private boolean isDetached(GQuery element) { return element.parents().filter("body").isEmpty(); }
/** * 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(); for (Element e : elements) { Element next = e.getNextSiblingElement(); if (next != null) { result.addNode(next); } } return pushStack(result, "next", selectors[0]).filter(selectors); }
/** * 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); }
/** * 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(); for (Element e : elements) { Element next = getPreviousSiblingElement(e); if (next != null) { result.addNode(next); } } return new GQuery(unique(result)).filter(selectors); }
public GQuery scrollParent(final UiPlugin gQueryUi) { GQuery scrollParent; if ("fixed".equals(gQueryUi.css("position", false))) { return GQuery.$(getViewportElement()); } if (scrollParentPositionTest(gQueryUi)) { scrollParent = gQueryUi.parents().filter(new Predicate() { public boolean f(Element e, int index) { GQuery g = GQuery.$(e); String position = g.css("position", true); return ("relative".equals(position) || "absolute".equals(position) || "fixed" .equals(position)) && isOverflowEnabled(g); } }); } else { scrollParent = gQueryUi.parents().filter(new Predicate() { public boolean f(Element e, int index) { return isOverflowEnabled(GQuery.$(e)); } }); } return scrollParent.length() > 0 ? $(scrollParent.get(0)) : $(getViewportElement()); }
private boolean notHandleMouseDown(Element element, GqEvent mouseDownEvent) { boolean isNotBoutonLeft = mouseDownEvent.getButton() != NativeEvent.BUTTON_LEFT; Element eventTarget = mouseDownEvent.getEventTarget().cast(); boolean isElementCancel = false; if (options.getCancel() != null) { isElementCancel = $(eventTarget).parents().add($(eventTarget)).filter(options.getCancel()).length() > 0; } return isNotBoutonLeft || isElementCancel || !mouseCapture(element, mouseDownEvent); }
/** * 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) { if (filter == null || $(e).filter(filter).length() == 1) { if (clean) { // clean data linked to the children // TODO: "*" fails in queryselectorall (webkit mobile) cleanGQData($("*", e).elements()); // clean data linked to the element itself cleanGQData(e); } Widget w = getAssociatedWidget(e); if (w != null) { w.removeFromParent(); } else { e.removeFromParent(); } } } return this; }