List of usage examples for com.google.gwt.query.client GQuery append
public GQuery append(String html)
From source file:be.dramaix.ai.slidingpuzzle.client.ConfigPanel.java
License:Apache License
private void init() { // build algorithm options SafeHtmlBuilder algorithmTypeOptions = new SafeHtmlBuilder(); for (AlgorithmType at : AlgorithmType.values()) { algorithmTypeOptions.append(Templates.INSTANCE.option(at.name(), at.getLabel())); }//from ww w .j a v a 2 s.c o m GQuery algorithmSelector = SELECTOR.getAlgorithmSelectElement(); algorithmSelector.append(algorithmTypeOptions.toSafeHtml().asString()); algorithmSelector.val(algorithmType.name()); // build heuristic options SafeHtmlBuilder heuristicTypeOptions = new SafeHtmlBuilder(); for (HeuristicType ht : HeuristicType.values()) { heuristicTypeOptions.append(Templates.INSTANCE.option(ht.name(), ht.getLabel())); } GQuery heuristicSelector = SELECTOR.getHeuristicSelectElement(); heuristicSelector.append(heuristicTypeOptions.toSafeHtml().asString()); heuristicSelector.val(heuristicType.name()); onDimensionChange(4); }
From source file:be.dramaix.ai.slidingpuzzle.client.Puzzle.java
License:Apache License
public void loadState(State s) { GQuery puzzle = SELECTOR.getPuzzleBoard(); puzzle.empty();/* www.j a v a2s .com*/ byte[] board = s.getAllCells(); for (int i = 0; i < board.length; i++) { byte value = board[i]; GQuery cell = $("<div class='tile'></div>"); if (value == 0) { cell.addClass("empty"); } else { cell.html("" + value); } puzzle.append(cell); } // int puzzleDimension = TILE_DIMENSION * dimension; puzzle.height(puzzleDimension).width(puzzleDimension); }
From source file:com.arcbees.chosen.client.ChosenImpl.java
License:Apache License
private void setup() { boolean isHidden = false; containerId = buildContainerId();/*from w ww . ja va 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
/** * Appends an item to the end of the list, adding the supplied class name to its class attribute. Specifying a * non-zero {@code indentLevel} will pad the item from the left by a fixed distance applied {@code indentLevel} * times.// w w w.ja va 2 s . co m * <p/> * For example, a call: * <p/> * {@code * addStyledItem("My Item", "item1", "highlighted", 1); * } * <p/> * will result in the addition to the end of the {@code <select>} element of: * <p/> * {@code * <option value="item1" class="highlighted" style="padding-left: 15px;" >My Item</option> * } * * @param label the item label to display to the user * @param value the value of the item, meaningful in the context of an HTML form * @param className the class name to add to this item (pass {@code null} to add no class name) * @param indentLevel the number of times to indent the item from the left (pass 0 for no indentation) */ public void addStyledItem(String label, String value, String className, int indentLevel) { if (indentLevel < 0) { throw new IllegalArgumentException("[indentLevel] must be non-negative."); } GQuery $selectElem = $(getElement()); OptionElement option = Document.get().createOptionElement(); option.setValue(value); option.setText(label); if (!(className == null || className.trim().isEmpty())) { option.addClassName(className); } if (indentLevel > 0) { int leftPadding = options.getResources().css().indent() * indentLevel; option.setAttribute("style", "padding-left: " + leftPadding + "px;"); } $selectElem.append(option); }
From source file:com.arcbees.chosen.client.gwt.ChosenListBox.java
License:Apache License
/** * Insert a group to the list box./*from w w w .j a va 2s .c o m*/ * * @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); } }
From source file:com.arcbees.chosen.client.gwt.ChosenListBox.java
License:Apache License
/** * Inserts an item into a group at the specified location. Additionally, the item can have an extra class name as * well as indent level assigned to it.//from w w w . ja v a2 s . c om * <p/> * <b>NB!</b> It is important to set text into the option after the option has been appended to the DOM * <br/>that's known bug in IE @see <a href="http://bugs.jquery.com/ticket/3041">jQuery bug tracker</a> * <p/> * * @param item the item label to display * @param value the value of the item in the HTML form context * @param className the class name to append to the option (pass {@code null} to append no class name) * @param dir allows specifying an RTL, LTR or inherited direction ({@code null} is LTR) * @param indentLevel the number of times to indent the item from the left (pass 0 for no indentation) * @param groupIndex the index of the group to insert the item into (if out of bounds, the last group will be used) * @param itemIndex the index of the item within a group (if out of bounds, item will be placed last in the group) */ public void insertStyledItemToGroup(String item, String value, String className, Direction dir, int indentLevel, int groupIndex, int itemIndex) { int pos = groupIndex; if (indentLevel < 0) { throw new IllegalArgumentException("[indentLevel] must be non-negative."); } GQuery optgroupList = $(OPTGROUP_TAG, getElement()); int groupCount = optgroupList.size(); if (groupCount == 0) { // simply insert the item to the listbox insertItem(item, dir, value, itemIndex); return; } if (pos < 0 || pos > groupCount - 1) { pos = groupCount - 1; } GQuery optgroup = optgroupList.eq(pos); OptionElement option = Document.get().createOptionElement(); if (!(className == null || className.trim().isEmpty())) { option.addClassName(className); } if (indentLevel > 0) { // Calculate total indentation, not forgetting that being in a group is adding one extra indent step int leftPadding = options.getResources().css().indent() * (indentLevel + 1); option.setAttribute("style", "padding-left: " + leftPadding + "px;"); } Element optGroupElement = optgroup.get(0); int itemCount = optGroupElement.getChildCount(); if (itemIndex < 0 || itemIndex > itemCount - 1) { optgroup.append(option); } else { GQuery before = $(optGroupElement.getChild(itemIndex)); before.before(option); } // setText must be after the element has been appended to the DOM - see javadoc setOptionText(option, item, dir); option.setValue(value); }
From source file:com.pronoiahealth.olhie.client.pages.AbstractPage.java
License:Open Source License
/** * Add full page scrolling. This can only be done before the page is loaded. * //from w w w .j a va 2 s. c o m * @param fullPageScrollingActive */ protected void addFullPageScrolling() { // Activate full page scrolling // Get the root div final GQuery gObj = AppSelectors.INSTANCE.getCenterBackground(); // Called when scrolling stops // Timer set in scroll event // Address weird Chrome/Safari (Webkit) issue // Just asking for some data from the element emitting // scroll events seems to refresh the display and // help fix the issue scrollStopTimer = new Timer() { @Override public void run() { int scrollTop = gObj.scrollTop(); // gObj.scrollTop(scrollTop + 3); // gObj.scrollTop(scrollTop); } }; // Make sure its overflow is set to auto gObj.css(CSS.OVERFLOW.with(Overflow.AUTO)); // State of scroll link gObj.data("scrollLinkActive", Boolean.FALSE); // Create the scroll link scrollLink = $("<a href=\"#\" class=\"ph-BulletinBoard-Scrollup\">Scroll</a>"); final Function fadeIn = new Function() { @Override public void f(Element e) { scrollLink.css(Properties.create("opacity: 1.0;")); // super.f(e); } }; final Function fadeOut = new Function() { @Override public void f(Element e) { scrollLink.css(Properties.create("opacity: 0.0;")); // super.f(e); } }; // Append the link to the root div gObj.append(scrollLink); // Bind the scroll event gObj.bind(Event.ONSCROLL, new Function() { @Override public boolean f(Event e) { // GQuery rootDiv = $(e); // int scrollTop = rootDiv.scrollTop(); // Set timer scrollStopTimer.cancel(); scrollStopTimer.schedule(500); // Test scroll top int scrollTop = gObj.scrollTop(); boolean scrollLinkActive = (Boolean) gObj.data("scrollLinkActive"); if (scrollTop >= 100 && scrollLinkActive == false) { gObj.data("scrollLinkActive", Boolean.TRUE); scrollLink.fadeIn(500, fadeIn); } else if (scrollTop < 100 && scrollLinkActive == true) { gObj.data("scrollLinkActive", Boolean.FALSE); scrollLink.fadeOut(500, fadeOut); } // return super.f(e); return false; } }); // Bind to the scrollup link scrollLink.bind(Event.ONCLICK, new Function() { @Override public boolean f(Event e) { gObj.animate("scrollTop: 0", 500, (Function) null); scrollLink.hide(); return false; } }); this.fullPageScrollingActive = true; }
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 www. j av a2 s . c om*/ * @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.scrolldiv.ScrollDiv.java
License:Open Source License
@PostConstruct protected void postConstruct() { // Activate full page scrolling // Get the root div final GQuery gObj = $(root); // Make sure its overflow is set to auto gObj.css(CSS.OVERFLOW.with(Overflow.AUTO)); // Create the scroll link scrollLink = $("<a href=\"#\" class=\"ph-BulletinBoard-Scrollup\">Scroll</a>"); // Append the link to the root div gObj.append(scrollLink); // Bind the scroll event gObj.bind(Event.ONSCROLL, new Function() { @Override/*from w ww.j a v a 2s .co m*/ public boolean f(Event e) { GQuery rootDiv = $(e); int scrollTop = rootDiv.scrollTop(); if (scrollTop > 100) { scrollLink.fadeIn(500, new Function() { @Override public void f(com.google.gwt.dom.client.Element e) { $(e).css(Properties.create("opacity: 1.0;")); // super.f(e); } }); } else { scrollLink.fadeOut(500, new Function() { @Override public void f(com.google.gwt.dom.client.Element e) { $(e).css(Properties.create("opacity: 0.0;")); // super.f(e); } }); } return super.f(e); } }); // Bind to the scrollup link scrollLink.bind(Event.ONCLICK, new Function() { @Override public boolean f(Event e) { gObj.animate("scrollTop: 0", 500, (Function) null); return false; } }); }
From source file:com.villagechief.gwt.hogan.client.HoganWidget.java
License:Apache License
public void add(Widget child, GQuery container) { child.removeFromParent();/*from w w w. j a v a 2s. co m*/ // Logical attach. getChildren().add(child); // Physical attach. container.append(child.getElement()); // Adopt. adopt(child); }