Example usage for com.google.gwt.query.client GQuery data

List of usage examples for com.google.gwt.query.client GQuery data

Introduction

In this page you can find the example usage for com.google.gwt.query.client GQuery data.

Prototype

public Object data(String name) 

Source Link

Document

Returns value at named data store for the element, as set by data(name, value).

Usage

From source file:com.arcbees.gquery.tooltip.client.Tooltip.java

License:Apache License

public Tooltip tooltip(TooltipOptions options) {
    for (Element e : elements()) {
        GQuery $e = $(e);

        Map<String, TooltipImpl> impls = $e.data(TOOLTIP_DATA_KEY);
        if (impls == null) {
            impls = new HashMap<>();
            $e.data(TOOLTIP_DATA_KEY, impls);
        }//w  ww.  j av a  2 s.  c  om

        if (!impls.containsKey(notNullSelector(options.getSelector()))) {
            TooltipImpl impl;
            //use 2 different constructors for GWT optimization purpose
            if (options.getResources() == null) {
                impl = new TooltipImpl(e, options);
            } else {
                impl = new TooltipImpl(e, options, options.getResources());
            }

            impls.put(notNullSelector(options.getSelector()), impl);
        }
    }
    return this;
}

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  w  w w  .j  av a  2 s. c o m*/
 * @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\">&lt;</span>");
                GQuery navNext = $("<span class=\"bk-page-next\">&gt;</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:cu.softel.integro.client.shared.tooltip.Tooltip.java

License:Apache License

public Tooltip tooltip(TooltipOptions options) {
    for (Element e : elements()) {
        GQuery $e = $(e);
        if ($e.data(TOOLTIP_DATA_KEY) == null) {
            TooltipImpl impl;//from   ww  w .  j  a  v  a2s  . c  om
            //use 2 different constructors for GWT optimization purpose
            if (options.getResources() == null) {
                impl = new TooltipImpl(e, options);
            } else {
                impl = new TooltipImpl(e, options, options.getResources());
            }
            $e.data(TOOLTIP_DATA_KEY, impl);
        }
    }
    return this;
}

From source file:gwtquery.plugins.draggable.client.plugins.OpacityPlugin.java

License:Apache License

public void onStop(DraggableHandler handler, DragContext ctx, GqEvent e) {
    GQuery $element = (handler.getOptions().getHelperType() == HelperType.ORIGINAL) ? handler.getHelper()
            : $(ctx.getDraggable());/*  w  ww . j  av a  2 s.c  o m*/
    if ($element == null || $element.length() == 0) {
        return;
    }

    if ($element.data(OLD_OPACITY_KEY) == null) {
        return;
    }
    Double oldOpacity = $element.data(OLD_OPACITY_KEY, Double.class);
    $element.css(OPACITY_CSS_KEY, oldOpacity != null ? String.valueOf(oldOpacity) : "");
    $element.removeData(OLD_OPACITY_KEY);

}

From source file:org.bonitasoft.web.toolkit.client.ui.component.AutoCompleteTextInput.java

License:Open Source License

private void setEvents() {

    final GQuery input = $(inputElement);

    // ON TEXT CHANGE
    input.keypress(new Function() {

        @Override//  ww  w. j  av  a 2  s .  c o  m
        public boolean f(final Event e) {

            // Window.alert(e.getKeyCode() + " - " + e.getCharCode());

            switch (e.getKeyCode()) {
            case KeyCodes.KEY_ENTER:
                e.stopPropagation();
                return false;
            case KeyCodes.KEY_ESCAPE:
                AutoCompleteTextInput.this.reset();
                break;
            case KeyCodes.KEY_DELETE:
            case KeyCodes.KEY_BACKSPACE:
            case 0: // Character
            default:

                AutoCompleteTextInput.this.resetValue();

                // ClearTimeout if another key is pressed before the end of previous timeout
                if (input.data(AUTOCOMPLETE_ONCHANGE_TIMER) != null) {
                    final Timer t = (Timer) input.data(AUTOCOMPLETE_ONCHANGE_TIMER);
                    t.cancel();
                    input.removeData(AUTOCOMPLETE_ONCHANGE_TIMER);
                }

                final Timer t = new Timer() {

                    @Override
                    public void run() {
                        input.removeData(AUTOCOMPLETE_ONCHANGE_TIMER);
                        AutoCompleteTextInput.this.refresh();
                    }
                };
                input.data("AUTOCOMPLETE_ONCHANGE_TIMER", t);
                t.schedule(500);
                break;
            }

            return true;
        }
    });

    // ON TEXT BLUR
    input.blur(new Function() {

        @Override
        public void f() {
            if (input.data(AUTOCOMPLETE_ONCHANGE_TIMER) != null) {
                final Timer t = (Timer) input.data(AUTOCOMPLETE_ONCHANGE_TIMER);
                t.cancel();
                input.removeData(AUTOCOMPLETE_ONCHANGE_TIMER);
            }
            boolean isFocused = childrenFocused(dropdown.getElement());
            // && $(AutoCompleteTextInput.this.dropdown.getElement()).find(":focus").size() == 0) {
            if (!$(inputElement).is(".completed") && !isFocused) {

                AutoCompleteTextInput.this.reset();
                dropdown.close();
            }
        }

    });
}