Example usage for com.vaadin.ui JavaScript eval

List of usage examples for com.vaadin.ui JavaScript eval

Introduction

In this page you can find the example usage for com.vaadin.ui JavaScript eval.

Prototype

public static void eval(String script) 

Source Link

Document

Executes the given JavaScript code in the browser.

Usage

From source file:org.vaadin.tori.ToriNavigator.java

License:Apache License

private void updatePageTitle(final String title) {
    String prefix = configuration.getPageTitlePrefix();

    StringBuilder sb = new StringBuilder();
    if (prefix != null) {
        sb.append(prefix);/* w  w w  . j  a va 2  s. c o  m*/
    }
    if (title != null && !title.isEmpty()) {
        if (!sb.toString().isEmpty()) {
            sb.append(" > ");
        }
        sb.append(title);
    }

    String pageTitle = sb.toString();
    Page.getCurrent().setTitle(pageTitle);

    // Liferay session.js resets the document.title after every request
    // (when logged in).
    // This hack is a workaround for the issue.
    JavaScript.eval(
            // @formatter:off
            //Liferay 6.0
            "try {" + "Liferay.Session._originalTitle = '" + pageTitle + "';" + "} catch(err){}" +
            //Liferay 6.2
                    "try {" + "Liferay.Session.display._state.data.pageTitle.initValue = '" + pageTitle + "';"
                    + "Liferay.Session.display._state.data.pageTitle.lazy.value = '" + pageTitle + "';"
                    + "} catch(err){}");
    // @formatter:on
}

From source file:org.vaadin.tori.util.ToriScheduler.java

License:Apache License

public void scheduleDeferred(final ScheduledCommand command) {
    if (deferredCommands.isEmpty()) {
        JavaScript.eval(DEFERRED_COMMAND_FUNCTION_NAME + FUNCTION);
        JavaScript.getCurrent().addFunction(DEFERRED_COMMAND_FUNCTION_NAME, new JavaScriptFunction() {
            @Override/*from   ww  w.ja  v  a  2  s . c o m*/
            public void call(final JSONArray arguments) throws JSONException {
                JavaScript.getCurrent().removeFunction(DEFERRED_COMMAND_FUNCTION_NAME);
                executeCommands(deferredCommands);

            }
        });
    }
    deferredCommands.add(command);
}

From source file:org.vaadin.tori.view.thread.PostsLayout.java

License:Apache License

private void renderUntil(final int untilIndex) {
    boolean postsAdded = false;
    while (renderedIndex <= untilIndex) {
        renderedIndex++;/*  ww  w . ja  v a 2 s .  c  o m*/
        if (posts != null) {
            if (renderedIndex < posts.size()) {
                postsAdded = true;
                final Component component = new PostComponent(posts.get(renderedIndex), presenter, prettyTime);
                addComponent(component);
                if (scrollToIndex != null && renderedIndex == scrollToIndex) {
                    // The component should be scrolled to
                    UI.getCurrent().scrollIntoView(component);
                    component.setId("scrollpostid");
                    JavaScript.eval(
                            "window.setTimeout(\"document.getElementById('scrollpostid').scrollIntoView(true)\",10)");
                    scrollToIndex = null;
                }
            } else {
                break;
            }
        }
    }

    if (!postsAdded) {
        List<String> styles = getState(false).styles;
        if ((styles == null || !styles.contains(STYLE_READY))) {
            ToriScheduler.get().executeManualCommands();
            addStyleName(STYLE_READY);
        }
    }
}

From source file:org.vaadin.tori.view.thread.PostsLayout.java

License:Apache License

@Override
public void beforeClientResponse(final boolean initial) {
    ToriScheduler.get().scheduleDeferred(new ScheduledCommand() {
        @Override/*w ww.  j ava  2s  .c o m*/
        public void execute() {
            renderUntil(renderedIndex + RENDER_BATCH_SIZE);
        }
    });
    if (initial && scrollToIndex == null) {
        // First render & no scroll to component specified -> scroll to
        // beginning
        UI.getCurrent().setScrollTop(0);
        JavaScript.eval("var el = document.getElementById('tori-ui');"
                + "if (el.getBoundingClientRect().top < 0) {" + "el.scrollIntoView(true); }");
    }
    super.beforeClientResponse(initial);
}

From source file:org.vaadin.tori.view.thread.ThreadViewImpl.java

License:Apache License

@Override
public void appendQuote(final String textToAppend) {
    reply.insertIntoMessage(textToAppend + "\n\n ");
    // Scroll to reply component
    UI.getCurrent().scrollIntoView(reply);

    if (Page.getCurrent().getWebBrowser().isIE()) {
        JavaScript.eval(
                "window.setTimeout(\"document.getElementById('" + REPLY_ID + "').scrollIntoView(true)\",100)");
    } else {//w w  w  . j av a  2 s. c  om
        JavaScript.eval("EPPZScrollTo.scrollVerticalToElementById('" + REPLY_ID + "', 0);");
    }
}