/** * 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); }
private GQuery domManip(String htmlString, DomMan type) { JsMap<Document, GQuery> cache = JsMap.createObject().cast(); for (Element e : elements) { Document d = JsUtils.getOwnerDocument(e); GQuery g = cache.get(d); if (g == null) { g = cleanHtmlString(htmlString, d); cache.put(d, g); } domManip(g.clone(), type, e); } return this; }
/** * 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. */ public GQuery wrapAll(GQuery query) { if (!isEmpty()) { GQuery wrap = query.clone(); if (get(0).getParentNode() != null) { wrap.insertBefore(get(0)); } for (Element e : wrap.elements) { Node n = e; while (n.getFirstChild() != null && n.getFirstChild().getNodeType() == Node.ELEMENT_NODE) { n = n.getFirstChild(); } $((Element) n).append(this); } } return this; }
"right" : "left") + ":-9000px; visibility:hidden'> </div>"); GQuery tempDiv = $("#gwt_chosen_temp_div"); tempDiv.append($selectElement.clone());
"right" : "left") + ":-9000px; visibility:hidden'> </div>"); GQuery tempDiv = $("#gwt_chosen_temp_div"); tempDiv.append($selectElement.clone());
"right" : "left") + ":-9000px; visibility:hidden'> </div>"); GQuery tempDiv = $("#gwt_chosen_temp_div"); tempDiv.append($selectElement.clone());