Пример #1
0
  public InlineJS() {
    Label date =
        new Label(
            "<div style=\"text-align: left;\"><span id=\"theDate\">00.00.0000</span></div>",
            ContentMode.HTML);
    Label time =
        new Label(
            "<div style=\"text-align: left;\"><span id=\"theTime\">00.00.0000</span></div>",
            ContentMode.HTML);

    StringBuilder script = new StringBuilder();

    script.append("function setTime(){");
    script.append("var c = new Date();");
    script.append(
        "var date = fm(c.getDate()) + \".\" + fm(c.getMonth()+1) + \".\" + (c.getYear() + 1900);");
    script.append("var time = c.getHours() + ':' + fm(c.getMinutes()) + ':' + fm(c.getSeconds());");
    script.append("document.getElementById('theDate').innerHTML= date;");
    script.append("document.getElementById('theTime').innerHTML= time;");
    script.append("}");
    script.append("function fm(num) { if (num < 10) { return '0' + num; } return num; }");
    // script.append("setInterval(\"setTime()\", 1000);");
    script.append("setInterval(setTime, 1000);");
    JavaScript.getCurrent().execute(script.toString());

    addComponent(date);
    addComponent(time);
  }
Пример #2
0
  private void init() {
    this.setId("button-" + java.util.Calendar.getInstance().getTimeInMillis());
    setStyleName(STYLE_NAME + " mdl-js-button");

    // MDL button click listener. Force button blur event to be caught by MDL
    this.addClickListener(
        e -> {
          String mdlButtonClickJavascript =
              "document.getElementById('" + e.getButton().getId() + "').blur();";
          JavaScript.getCurrent().execute(mdlButtonClickJavascript);
        });
  }
Пример #3
0
 private static void addCallback(String jsCallbackName, JavaScriptFunction jsCallback) {
   JavaScript.getCurrent().addFunction(jsCallbackName, jsCallback);
 }
 private void reloadWindow() {
   JavaScript.getCurrent().execute("window.location.reload();");
 }
Пример #5
0
 private static void execute(String script) {
   JavaScript.getCurrent().execute(script);
 }