List of usage examples for com.google.gwt.query.client GQuery children
public GQuery children(String... filters)
From source file:com.arcbees.chosen.client.ChosenImpl.java
License:Apache License
private void setup() { boolean isHidden = false; containerId = buildContainerId();//from ww w . jav a 2 s . com fWidth = $selectElement.outerWidth(); isRTL = LocaleInfo.getCurrentLocale().isRTL() || $selectElement.hasClass("chzn-rtl"); // Temporary fix. IIf the select element is inside a hidden container // GQuery cannot get the size of the select element. if (fWidth == 0) { $("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; } String containerClass = getContainerClass(); String cssClasses = isRTL ? containerClass + " " + css.chznRtl() : containerClass; // recopy classes present on the select element cssClasses += " " + selectElement.getClassName(); GQuery containerTemp = $(ChosenTemplate.templates.container(containerId, cssClasses).asString()) .width(fWidth); final SafeStylesBuilder ssb = new SafeStylesBuilder(); if (isRTL) { ssb.right(HORIZONTAL_OFFSET, Style.Unit.PX); } else { ssb.left(HORIZONTAL_OFFSET, Style.Unit.PX); } ssb.top(VERTICAL_OFFSET, Style.Unit.PX); containerTemp.html(buildContainerHtml(defaultText, ssb).asString()); // insert container after the select elements $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)); searchField = container.find("input").first(); searchResults = container.find("ul." + css.chznResults()).first(); searchFieldScale(fWidth); initSearchElement(ddWidth, isHidden); resultsBuild(true); setTabIndex(); fireEvent(new ReadyEvent(this)); }
From source file:com.arcbees.chosen.client.gwt.ChosenListBox.java
License:Apache License
private GQuery getFocusableElement() { GQuery chosen = getChosenElement(); GQuery focusableElement = chosen.children("a"); if (focusableElement.isEmpty()) { focusableElement = chosen.find("input"); }/*from w w w . jav a 2s. c o m*/ return focusableElement; }
From source file:com.pronoiahealth.olhie.client.widgets.booklist3d.BookList3D.java
License:Open Source License
/** * Used to add books in after the initial display * //from ww w .ja v a 2 s.com * @param bookDiv */ public void attachEventsToLst() { this.books = $("#bk-list > li > div.bk-book", bookList.getParentElement()); this.currentBookCnt = books.length(); books.each(new Function() { @Override public void f(Element e) { final GQuery book = $(e); final GQuery other = books.not(book); final GQuery parent = book.parent(); final GQuery page = book.children("div.bk-page"); final GQuery bookview = parent.find("button.bk-bookview"); final GQuery flipAction = parent.find("button.bk-bookback"); final GQuery content = page.children("div.bk-content"); final GQuery toc = page.find("div.bk-toc"); final GQuery tocPageMyCollectionsBtn = toc.find("a.bk-tocPage-myCollectionsBtn"); final GQuery tocPageCommentRatingBtn = toc.find("a.bk-tocPage-commentRatingBtn"); final GQuery tocItems = page.find("div.bk-toc-item"); final GQuery tocLinks = page.find("div.bk-toc-link"); final GQuery downloadContentBtns = page.find("a.bk-download-btn"); final GQuery viewContentBtns = page.find("a.bk-view-btn"); final GQuery linkContentBtns = page.find("a.bk-link-btn"); final IntHolder current = new IntHolder(); // Book Id final String bookId = book.attr("bookId"); // Bind the call back book.bind(Event.ONCLICK, new Function() { @Override public boolean f(Event e) { checkBookIsAuthorRequestEvent.fire(new CheckBookIsAuthorRequestEvent(bookId)); return false; } }); flipAction.bind(Event.ONCLICK, new Function() { @Override public boolean f(Event e) { // Toggle the button if (flipAction.hasClass("bk-bookback-pressed") == true) { flipAction.removeClass("bk-bookback-pressed"); } else { flipAction.addClass("bk-bookback-pressed"); } bookview.removeClass("bk-active"); boolean flipVal = false; Object flipObj = book.data("flip"); if (flipObj != null) { flipVal = (Boolean) flipObj; } if (flipVal == true) { book.data("opened", false).data("flip", false); book.removeClass("bk-viewback"); book.addClass("bk-bookdefault"); } else { book.data("opened", false).data("flip", true); book.removeClass("bk-viewinside").removeClass("bk-bookdefault"); book.addClass("bk-viewback"); } return true; } }); bookview.bind(Event.ONCLICK, new Function() { @Override public boolean f(Event e) { // If the view back cover was pressed need to reset // the button if (flipAction.hasClass("bk-bookback-pressed") == true) { flipAction.removeClass("bk-bookback-pressed"); } GQuery thisPt = $(e); other.data("opened", false); other.removeClass("bk-viewinside"); GQuery otherParent = other.parent().css(CSS.ZINDEX.with(0)); otherParent.find("button.bk-bookview").removeClass("bk-active"); if (!other.hasClass("bk-viewback")) { other.addClass("bk-bookdefault"); } boolean openedVal = false; Object openedObj = book.data("opened"); if (openedObj != null) { openedVal = (Boolean) openedObj; } if (openedVal == true) { thisPt.removeClass("bk-active"); book.data("opened", false).data("flip", false); book.removeClass("bk-viewinside"); book.addClass("bk-bookdefault"); } else { thisPt.addClass("bk-active"); book.data("opened", true).data("flip", false); book.removeClass("bk-viewback").removeClass("bk-bookdefault"); book.addClass("bk-viewinside"); parent.css(CSS.ZINDEX.with(currentBookCnt++)); current.setIntVal(0); content.removeClass("bk-content-current").eq(current.getIntVal()) .addClass("bk-content-current"); } return true; } }); // If it is a btn-success buton we want to add the book to the // users collection, otherwise remove for the collection. // Clear results container tocPageMyCollectionsBtn.bind(Event.ONCLICK, new Function() { @Override public boolean f(Event e) { GQuery anchor = $(e); boolean addToCollection = anchor.hasClass("btn-success"); adjustMyCollection(bookId, addToCollection); return false; } }); tocPageCommentRatingBtn.bind(Event.ONCLICK, new Function() { @Override public boolean f(Event e) { addUpdateComment(bookId); return false; } }); if (content.length() > 1) { GQuery navPrev = $("<span class=\"bk-page-prev\"><</span>"); GQuery navNext = $("<span class=\"bk-page-next\">></span>"); page.append($("<nav></nav>").append(navPrev).append(navNext)); navPrev.bind(Event.ONCLICK, new Function() { @Override public boolean f(Event e) { if (current.getIntVal() > 0) { current.subOne(); content.removeClass("bk-content-current").eq(current.getIntVal()) .addClass("bk-content-current"); } return false; } }); navNext.bind(Event.ONCLICK, new Function() { @Override public boolean f(Event e) { if (current.getIntVal() < content.length() - 1) { current.plusOne(); content.removeClass("bk-content-current").eq(current.getIntVal()) .addClass("bk-content-current"); } return false; } }); // TOC items tocItems.each(new Function() { @Override public void f(Element e) { GQuery item = $(e); item.bind(Event.ONCLICK, new Function() { @Override public boolean f(Event e) { GQuery thisItem = $(e); String refStr = thisItem.attr("item-ref"); int refInt = Integer.parseInt(refStr); if (refInt <= content.length() - 1) { current.setIntVal(refInt); content.removeClass("bk-content-current").eq(current.getIntVal()) .addClass("bk-content-current"); } return false; } }); } }); // TOC link tocLinks.each(new Function() { @Override public void f(Element e) { GQuery item = $(e); item.bind(Event.ONCLICK, new Function() { @Override public boolean f(Event e) { current.setIntVal(0); content.removeClass("bk-content-current").eq(current.getIntVal()) .addClass("bk-content-current"); return false; } }); } }); // Link buttons linkContentBtns.each(new Function() { @Override public void f(Element e) { GQuery btn = $(e); btn.bind(Event.ONCLICK, new Function() { @Override public boolean f(Event e) { GQuery thisAnchor = $(e); String href = thisAnchor.attr("href"); Window.open(href, "_black", ""); return false; } }); } }); // Download content buttons downloadContentBtns.each(new Function() { @Override public void f(Element e) { GQuery btn = $(e); btn.bind(Event.ONCLICK, new Function() { @Override public boolean f(Event e) { GQuery thisAnchor = $(e); String assetId = thisAnchor.attr("bookassetid"); downloadBookAssetEvent.fire(new DownloadBookAssetEvent(assetId)); return false; } }); } }); // view content buttons viewContentBtns.each(new Function() { @Override public void f(Element e) { GQuery btn = $(e); // fire action if they are not disabled btn.bind(Event.ONCLICK, new Function() { @Override public boolean f(Event e) { GQuery thisAnchor = $(e); String disabledStr = thisAnchor.attr("disabled"); boolean disabled = (disabledStr != null ? Boolean.parseBoolean(disabledStr) : false); if (disabled == false) { String assetId = thisAnchor.attr("bookassetid"); String contentTypeKey = thisAnchor.attr("viewable-content-key"); showViewBookassetDialogEvent .fire(new ShowViewBookassetDialogEvent(assetId, contentTypeKey)); } return false; } }); } }); } } }); // Add Tooltips $("[rel=tooltip]", bookList.getParentElement()).as(Tooltip).tooltip(); }
From source file:com.pronoiahealth.olhie.client.widgets.booklist3d.BookList3D.java
License:Open Source License
/** * Remove all events from list/* w ww.j av a 2 s.c om*/ */ public void removeEventsFromLst() { if (books != null) { books.each(new Function() { @Override public void f(Element e) { final GQuery book = $(e); final GQuery page = book.children("div.bk-page"); final GQuery parent = book.parent(); final GQuery bookview = parent.find("button.bk-bookview"); final GQuery flipAction = parent.find("button.bk-bookback"); final GQuery toc = page.find("div.bk-toc"); final GQuery tocPageMyCollectionsBtn = toc.find("a.bk-tocPage-myCollectionsBtn"); final GQuery content = page.children("div.bk-content"); final GQuery downloadContentBtns = page.find("a.bk-download-btn"); final GQuery viewContentBtns = page.find("a.bk-view-btn"); final GQuery tocItems = page.find("div.bk-toc-item"); final GQuery tocLinks = page.find("div.bk-toc-link"); book.unbind(Event.ONCLICK); flipAction.unbind(Event.ONCLICK); bookview.unbind(Event.ONCLICK); if (content.length() > 1) { GQuery navPrev = page.find(".bk-page-prev"); if (navPrev != null) { navPrev.unbind(Event.ONCLICK); navPrev.remove(); } GQuery navNext = page.find(".bk-page-next"); if (navNext != null) { navNext.unbind(Event.ONCLICK); navNext.remove(); } // Unbind TOC items tocItems.each().unbind(Event.ONCLICK); } tocPageMyCollectionsBtn.unbind(Event.ONCLICK); tocItems.each(new Function() { @Override public void f(com.google.gwt.dom.client.Element e) { $(e).unbind(Event.ONCLICK); } }); tocLinks.each(new Function() { @Override public void f(com.google.gwt.dom.client.Element e) { $(e).unbind(Event.ONCLICK); } }); viewContentBtns.each(new Function() { @Override public void f(com.google.gwt.dom.client.Element e) { $(e).unbind(Event.ONCLICK); } }); downloadContentBtns.each(new Function() { @Override public void f(com.google.gwt.dom.client.Element e) { $(e).unbind(Event.ONCLICK); } }); } }); } }
From source file:com.watopi.chosen.client.ChosenImpl.java
License:Open Source License
private void setup() { boolean isHidden = false; containerId = buildContainerId();/*from w w w .ja v a2 s. c om*/ fWidth = $selectElement.outerWidth(); //Temporary fix. IIf the select element is inside a hidden container //GQuery cannot get the size of the select element. if (fWidth == 0) { $("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; } isRTL = LocaleInfo.getCurrentLocale().isRTL() || $selectElement.hasClass("chzn-rtl"); String cssClasses = isRTL ? css.chznContainer() + " " + css.chznRtl() : css.chznContainer(); GQuery containerTemp = $(ChozenTemplate.templates.container(containerId, cssClasses).asString()) .width(fWidth); if (isMultiple) { containerTemp.html(ChozenTemplate.templates.contentMultiple(css.chznChoices(), css.searchField(), defaultText, css.defaultClass(), css.chznDrop(), css.chznResults(), (isRTL ? "right" : "left")) .asString()); } else { containerTemp.html(ChozenTemplate.templates.contentSingle(css.chznSingle(), css.chznDefault(), defaultText, css.chznDrop(), css.chznSearch(), css.chznResults(), (isRTL ? "right" : "left")) .asString()); } // insert container after the select elements $selectElement.hide().after(containerTemp); container = $("#" + containerId); container.addClass(isMultiple ? css.chznContainerMulti() : css.chznContainerSingle()); dropdown = container.find("div." + css.chznDrop()).first(); int ddTop = container.height(); int ddWidth = fWidth - getSideBorderPadding(dropdown, isHidden); dropdown.css(Properties.create("{\"width\": " + ddWidth + "px, \"top\": " + ddTop + "px}")); searchField = container.find("input").first(); searchResults = container.find("ul." + css.chznResults()).first(); searchFieldScale(); if (isMultiple) { searchChoices = container.find("ul." + css.chznChoices()).first(); searchContainer = container.find("li." + css.searchField()).first(); } else { searchContainer = container.find("div." + css.chznSearch()).first(); selectedItem = container.find("." + css.chznSingle()).first(); int searchFieldWidth = ddWidth - getSideBorderPadding(searchContainer, isHidden) - getSideBorderPadding(searchField, isHidden); searchField.css("width", searchFieldWidth + "px"); } resultsBuild(); setTabIndex(); fireEvent(new ReadyEvent(this)); }
From source file:com.watopi.chosen.client.gwt.ChosenListBox.java
License:Open Source License
/** * Adds an item to the an optgroup of the list box. If no optgroup exists, * the item will be add at the end ot the list box. * //from w w w . j a va 2s.c o m * @param item * the text of the item to be added * @param value * the value of the item to be added * @param itemIndex * the index inside the optgroup at which to insert the item * @param groupIndex * the index of the optGroup where the item will be inserted */ public void insertItemToGroup(String item, Direction dir, String value, int groupIndex, int itemIndex) { GQuery select = $(getElement()); GQuery optgroupList = select.children("optgroup"); int groupCount = optgroupList.size(); if (groupCount == 0) { // simply insert the item to the listbox insertItem(item, dir, value, itemIndex); return; } if (groupIndex < 0 || groupIndex > groupCount - 1) { groupIndex = groupCount - 1; } GQuery optgroup = optgroupList.eq(groupIndex); OptionElement option = Document.get().createOptionElement(); setOptionText(option, item, dir); option.setValue(value); int itemCount = optgroup.children().size(); if (itemIndex < 0 || itemIndex > itemCount - 1) { optgroup.append(option); } else { GQuery before = optgroup.children().eq(itemIndex); before.before(option); } }
From source file:org.otalo.ao.client.widget.chlist.client.ChosenImpl.java
License:Apache License
private void setup() { boolean isHidden = false; containerId = buildContainerId();/*from www . j a va 2 s. co m*/ fWidth = $selectElement.outerWidth(); //Temporary fix. IIf the select element is inside a hidden container //GQuery cannot get the size of the select element. if (fWidth == 0) { $("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; } isRTL = LocaleInfo.getCurrentLocale().isRTL() || $selectElement.hasClass("chzn-rtl"); String cssClasses = isRTL ? css.chznContainer() + " " + css.chznRtl() : css.chznContainer(); GQuery containerTemp = $(ChozenTemplate.templates.container(containerId, cssClasses).asString()) .width(fWidth); SafeStyles horizontalOffset = isRTL ? SafeStylesUtils.forRight(HORIZONTAL_OFFSET, Style.Unit.PX) : SafeStylesUtils.forLeft(HORIZONTAL_OFFSET, Style.Unit.PX); if (isMultiple) { containerTemp.html( ChozenTemplate.templates.contentMultiple(css.chznChoices(), css.searchField(), defaultText, css.defaultClass(), css.chznDrop(), css.chznResults(), horizontalOffset).asString()); } else { containerTemp.html(ChozenTemplate.templates.contentSingle(css.chznSingle(), css.chznDefault(), defaultText, css.chznDrop(), css.chznSearch(), css.chznResults(), horizontalOffset).asString()); } // insert container after the select elements $selectElement.hide().after(containerTemp); container = $("#" + containerId); container.addClass(isMultiple ? css.chznContainerMulti() : css.chznContainerSingle()); dropdown = container.find("div." + css.chznDrop()).first(); int ddTop = container.height(); int ddWidth = fWidth - getSideBorderPadding(dropdown, isHidden); dropdown.css(Properties.create("{\"width\": " + ddWidth + "px, \"top\": " + ddTop + "px}")); searchField = container.find("input").first(); searchResults = container.find("ul." + css.chznResults()).first(); searchFieldScale(); if (isMultiple) { searchChoices = container.find("ul." + css.chznChoices()).first(); searchContainer = container.find("li." + css.searchField()).first(); } else { searchContainer = container.find("div." + css.chznSearch()).first(); selectedItem = container.find("." + css.chznSingle()).first(); int searchFieldWidth = ddWidth - getSideBorderPadding(searchContainer, isHidden) - getSideBorderPadding(searchField, isHidden); searchField.css("width", searchFieldWidth + "px"); } resultsBuild(); setTabIndex(); fireEvent(new ReadyEvent(this)); }
From source file:org.otalo.ao.client.widget.chlist.gwt.ChosenListBox.java
License:Apache License
private GQuery getFocusableElement() { GQuery chosen = getChosenElement(); GQuery focusableElement = chosen.children("a"); if (focusableElement.isEmpty()) { focusableElement = chosen.find("input"); }/*w w w . ja v a 2 s . c o m*/ return focusableElement; }