2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012-2015 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.bck2brwsr.kosample.js;
20 import net.java.html.js.JavaScriptBody;
22 /** Use {@link JavaScriptBody} annotation on methods to
23 * directly interact with JavaScript. See
24 * http://bits.netbeans.org/html+java/1.2/net/java/html/js/package-summary.html
27 public final class Dialogs {
31 /** Shows confirmation dialog to the user.
33 * @param msg the message
34 * @param callback called back when the use accepts (can be null)
37 args = { "msg", "callback" },
39 body = "if (confirm(msg)) {\n"
40 + " callback.@java.lang.Runnable::run()();\n"
43 public static native void confirmByUser(String msg, Runnable callback);
49 " e = d.documentElement,\n" +
50 " g = d.getElementsByTagName('body')[0],\n" +
51 " x = w.innerWidth || e.clientWidth || g.clientWidth,\n" +
52 " y = w.innerHeight|| e.clientHeight|| g.clientHeight;\n" +
54 "return 'Screen size is ' + x + ' times ' + y;\n"
56 public static native String screenSize();
58 @JavaScriptBody(args = { "id" }, body =
59 "var e = window.document.getElementById(id);\n "
60 + "var ev = window.document.createEvent('MouseEvents');\n "
61 + "ev.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);\n "
62 + "e.dispatchEvent(ev);\n "
64 public static native void triggerClick(String id);