/** * 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). */ public GQuery insertBefore(GQuery query) { for (Element e : elements) { query.before(e); } return this; }
private static void replaceWidget(Widget oldWidget, Widget newWidget, boolean remove) { Widget parent = oldWidget.getParent(); boolean removed = false; // TODO: handle tables if (parent instanceof HTMLPanel) { ((HTMLPanel) parent).addAndReplaceElement(newWidget, (com.google.gwt.dom.client.Element) oldWidget.getElement()); if (!remove) { $(newWidget).before($(oldWidget)); } removed = true; } else if (parent instanceof ComplexPanel) { ((ComplexPanel) parent).add(newWidget); } else if (parent instanceof SimplePanel) { ((SimplePanel) parent).setWidget(newWidget); } else if (parent instanceof Panel) { ((Panel) parent).add(newWidget); } else { assert false : "Can not replace an attached widget whose parent is a " + parent.getClass().getName(); } if (remove && !removed && oldWidget.isAttached()) { oldWidget.removeFromParent(); } else { oldWidget.setVisible(false); } }
/** * 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. */ public GQuery replaceWith(GQuery target) { for (Element el : elements) { Element nextSibling = el.getNextSiblingElement(); if (nextSibling != null) { $(nextSibling).before(target); } else { Element parent = el.getParentElement(); $(parent).append(target); } $(el).remove(); } return this; }
/** * 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. */ public GQuery replaceWith(String html) { for (Element el : elements) { Element nextSibling = el.getNextSiblingElement(); if (nextSibling != null) { $(nextSibling).before(html); } else { Element parent = el.getParentElement(); $(parent).append(html); } $(el).remove(); } return this; }
/** * Insert a group to the list box. * * @param label the text of the group to be added * @param id the id of the optgroup element * @param index the index at which to insert it */ public void insertGroup(String label, String id, int index) { GQuery optGroup = $("<optgroup></optgroup>").attr("label", label); if (id != null) { optGroup.attr("id", id); } GQuery select = $(getElement()); int itemCount = SelectElement.as(getElement()).getLength(); if (index < 0 || index > itemCount) { select.append(optGroup); } else { GQuery before = select.children().eq(index); before.before(optGroup); } }
/** * Insert a group to the list box. * * @param label the text of the group to be added * @param id the id of the optgroup element * @param index the index at which to insert it */ public void insertGroup(String label, String id, int index) { GQuery optGroup = $("<optgroup></optgroup>").attr("label", label); if (id != null) { optGroup.attr("id", id); } GQuery select = $(getElement()); int itemCount = SelectElement.as(getElement()).getLength(); if (index < 0 || index > itemCount) { select.append(optGroup); } else { GQuery before = select.children().eq(index); before.before(optGroup); } }
/** * Insert a group to the list box. * * @param label the text of the group to be added * @param id the id of the optgroup element * @param index the index at which to insert it */ public void insertGroup(String label, String id, int index) { GQuery optGroup = $("<optgroup></optgroup>").attr("label", label); if (id != null){ optGroup.attr("id", id); } GQuery select = $(getElement()); int itemCount = SelectElement.as(getElement()).getLength(); if (index < 0 || index > itemCount) { select.append(optGroup); } else { GQuery before = select.children().eq(index); before.before(optGroup); } }
private void choiceBuild(OptionItem option) { if (isMultiple && maxSelectedOptionsReached()) { fireEvent(new MaxSelectedEvent(this)); return; } String choiceId = containerId + "_c_" + option.getArrayIndex(); choices++; searchContainer.before(ChozenTemplate.templates.choice(choiceId, css.searchChoice(), option.getHtml(), css.searchChoiceClose(), "" + option.getArrayIndex()).asString()); $('#' + choiceId).find("a").click(new Function() { public boolean f(final Event e) { choiceDestroyLinkClick(e); return false; } }); }
} else { GQuery before = $(optGroupElement.getChild(itemIndex)); before.before(option);
} else { GQuery before = $(optGroupElement.getChild(itemIndex)); before.before(option);
} else { GQuery before = optgroup.children().eq(itemIndex); before.before(option);
protected void addChoice(OptionItem option) { if (maxSelectedOptionsReached()) { fireEvent(new MaxSelectedEvent(this)); } else { String choiceId = getContainerId() + "_c_" + option.getArrayIndex(); choices++; SafeHtml html = fromTrustedString(option.getHtml()); searchContainer.before(ChosenTemplate.templates.choice(choiceId, getCss().searchChoice(), html, getCss().searchChoiceClose(), "" + option.getArrayIndex(), option.getValue(), getCss().iconCross()).asString()); $('#' + choiceId).find("a").click(new Function() { public boolean f(final Event e) { choiceDestroyLinkClick(e); return false; } }); } }
@Override protected void addChoice(OptionItem option) { if (maxSelectedOptionsReached()) { fireEvent(new MaxSelectedEvent(this)); } else { String choiceId = getContainerId() + "_c_" + option.getArrayIndex(); choices++; SafeHtml html = fromTrustedString(option.getHtml()); searchContainer.before(ChosenTemplate.templates.choice(choiceId, getCss().searchChoice(), html, getCss().searchChoiceClose(), "" + option.getArrayIndex(), option.getValue(), getCss().iconCross()).asString()); $('#' + choiceId).find("a").click(new Function() { public boolean f(final Event e) { choiceDestroyLinkClick(e); return false; } }); } }