example: intro an emscripten wrapper around fibonacci
[nit.git] / examples / emscripten / fibonacci / www / index.html
1 <!DOCTYPE html>
2 <!-- This file is part of NIT ( http://www.nitlanguage.org )
3
4 Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 -->
18 <html>
19 <head>
20 <title>Fibonacci</title>
21 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
22 <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
23 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
24 <script>
25 // Redirect print to HTML
26 var Module = {
27 'print': function(text) {
28 $("#console").append(text + "<br>");
29 },
30 'noInitialRun': true,
31 };
32
33 $(document).ready(function() {
34 // Report full loading
35 $("#loading").text( "Loaded." );
36
37 // Callback
38 $("#in").keyup(function(){
39 if(event.keyCode == 13){
40 fib();
41 }
42 });
43 });
44
45 function fib() {
46 var input = $("#in").val();
47
48 // Invoke the full Nit program
49 ret = Module['callMain']([input]);
50 }
51 </script>
52 </head>
53 <body>
54
55 <div class="container">
56 <h1>Fibonacci calculator</h1>
57 <a href="https://github.com/privat/nit/blob/master/examples/fibonacci.nit">Nit source</a><br>
58 <a href="https://github.com/privat/nit/blob/master/examples/emscripten/fibonacci/www/index.html">HTML source</a>
59
60 <h2>Status</h2>
61 <p id="loading">Loading...</p>
62
63 <h2>Program Input</h2>
64 <input id="in" type="text" placeholder="12 (or any integer)"/><input type="button" value="Execute" onclick="fib();"/>
65
66 <h2>Program Output</h2>
67 <samp id="console"></samp>
68
69 <script src="fibonacci.js"></script>
70 </div>
71
72 </body>
73 </html>