summaryrefslogtreecommitdiff
path: root/examples/hybridshell/index.html
blob: 23a765c70ee5a2953ed0fb675441ab230cb7396d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
<html>
    <head>
        <title>QML/HTML Hybrid Shell</title>
        <style type="text/css">
        html, body {
            margin:0;
            padding:0;
            width:100%;
            height:100%;
        }
        #layout {
            height:100%;
            width:92%;
            margin: 0 auto;
        }
        #output {
            width:100%;
            margin-top:1%;
            height: 94%;
            display: block;
            border-radius: 5px;
            border-style: solid;
            border-color: #666666;
            background-image: -webkit-linear-gradient(left top,#dddddd, #ffffff)
        }
        #input {
            width:100%;
            height: 3%;
            margin-top:1%;
            margin-bottom:1%;
            display: block;
            background-color: #dddddd;
            border-radius: 3px;
            border-style: solid;
            border-color: #dddddd;
            background-image: -webkit-linear-gradient(left,#eeeeee, #cccccc)
        }
        </style>
        <script type="text/javascript" src="qrc:///qwebchannel/webchannel.js"></script>
        <script type="text/javascript">
        function out(line)
        {
            document.querySelector("#output").value += line + "\r\n";
        }
        function send()
        {
            var input = document.querySelector("#input");
            var text = input.value;
            out("> " + text);
            input.value = "";
            navigator.webChannel.exec(text);
        }

        function handleKey(code)
        {
            switch (code) {
                case 13:
                    send();
                    break;
            }
        }

        window.onload = function() {
            out("Starting...");

            var baseUrl = (/[?&]webChannelBaseUrl=([A-Za-z0-9\-:/\.]+)/.exec(location.search)[1]);
            new QWebChannel(baseUrl, function(webChannel) {
                window.navigator.webChannel = webChannel;
                out("Ready");
                webChannel.subscribe("stdout", out);
            });
        }
        </script>
    </head>
    <body>
        <div id="layout">
            <textarea readonly id="output" ></textarea>
            <input type="text" id="input" onkeyup="handleKey(event.keyCode)"></input>
        </div>
    </body>
</html>