/** * 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)); }
/** * Toggle among two or more function calls every other click. */ public GQuery toggle(final Function... fn) { for (Element e : elements) { $(e).click(new Function() { int click = 0; public boolean f(Event e) { int n = fn.length == 1 ? 0 : (click++ % fn.length); return fn[n].f(e); } }); } return this; }
private void setup() { boolean isHidden = false; containerId = buildContainerId(); fWidth = $selectElement.outerWidth(); isRTL = LocaleInfo.getCurrentLocale().isRTL() || $selectElement.hasClass("chzn-rtl"); $("body").append("<div id='gwt_chosen_temp_div' style='display:block;position:absolute;" + (isRTL ? "right" : "left") + ":-9000px; visibility:hidden'> </div>"); GQuery tempDiv = $("#gwt_chosen_temp_div"); tempDiv.append($selectElement.clone()); fWidth = tempDiv.children("select").outerWidth(); tempDiv.remove(); isHidden = fWidth > 0; $(ChosenTemplate.templates.container(containerId, cssClasses).asString()).width(fWidth); containerTemp.html(buildContainerHtml(defaultText, ssb).asString()); $selectElement.hide().after(containerTemp); container = $("#" + containerId); container.addClass(isMultiple() ? css.chznContainerMulti() : css.chznContainerSingle()); dropdown = container.find("div." + css.chznDrop()).first(); int ddWidth = fWidth - getSideBorderPadding(dropdown, isHidden); dropdown.css("width", buildDropdownWidth(ddWidth));
@Override protected void searchFieldScale(int fWidth) { StringBuilder styleBlock = new StringBuilder("position:absolute; " + (isRTL() ? "right" : "left") + ": -1000px; top: -1000px; " + "visibility:hidden;"); String[] styleToCopy = {"font-size", "font-style", "font-weight", "font-family", "line-height", "text-transform", "letter-spacing"}; for (String style : styleToCopy) { styleBlock.append(style).append(':').append(getSearchField().css(style)).append(";"); } GQuery div = $("<div />").attr("style", styleBlock.toString()).text(getSearchField().val()); $("body").append(div); int w = div.width() + 25; div.remove(); if (w > fWidth - 10) { w = fWidth - 10; } getSearchField().css("width", w + "px"); }
/** * 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); } }
protected void containerMouseDownImpl(Event e, GQuery element) { if (!activeField) { $(document).click(clickTestAction); resultsShow(); } else if (!element.isEmpty() && (element.get(0) == selectedItem.get(0) || element.parents("a." + css.chznSingle()).length() > 0)) { e.preventDefault(); resultsToggle(); } if (!element.hasClass(css.activeResult())) { activateField(); } }
private void resultDeselect(int index) { OptionItem item = (OptionItem) selectItems.get(index); item.setSelected(false); // select option in original element OptionElement option = selectElement.getOptions().getItem(item.getOptionsIndex()); option.setSelected(false); $("#" + containerId + "_o_" + index).removeClass(css.resultSelected()).addClass( css.activeResult()).show(); resultClearHighlight(); winnowResults(); fireEvent(new ChosenChangeEvent(option.getValue(), index, false, this)); searchFieldScale(); }
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; } }); }
protected void release() { if (updateEventHandlerRegistration != null) { updateEventHandlerRegistration.removeHandler(); updateEventHandlerRegistration = null; } // empty the searchResult to speed up the container.remove() if (searchResults != null) { searchResults.html(""); } // remove method clean listener and cie container.remove(); $selectElement.removeClass(css.chznDone(), "chzn-done").show(); }
GQuery optgroupList = $(OPTGROUP_TAG, getElement()); int groupCount = optgroupList.size(); GQuery optgroup = optgroupList.eq(groupIndex); option.setValue(value); int itemCount = optgroup.children().size(); optgroup.append(option); } else { GQuery before = optgroup.children().eq(itemIndex); before.before(option);
throw new IllegalArgumentException("[indentLevel] must be non-negative."); GQuery optgroupList = $(OPTGROUP_TAG, getElement()); int groupCount = optgroupList.size(); GQuery optgroup = optgroupList.eq(pos); Element optGroupElement = optgroup.get(0); int itemCount = optGroupElement.getChildCount(); optgroup.append(option); } else { GQuery before = $(optGroupElement.getChild(itemIndex)); before.before(option);
/** * 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; }
@Override protected void resultsBuild(boolean init, String defaultText, boolean customFilter) { getSelectedItem().addClass(getCss().chznDefault()).find("span").text(defaultText); if (!customFilter && getSelectElement().getOptions().getLength() <= getOptions().getDisableSearchThreshold()) { getContainer().addClass(getCss().chznContainerSingleNoSearch()); } else { getContainer().removeClass(getCss().chznContainerSingleNoSearch()); } super.resultsBuild(init, defaultText, customFilter); }