ee3a1844e72c853b7bb5e6b09ae61a42a460de8a
[nit.git] / examples / pnacl / converter / converter / js / pnacl_js.js
1 // This file is part of NIT ( http://www.nitlanguage.org )
2 //
3 // Copyright 2014 Johan Kayser <kayser.johan@gmail.com>
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16
17 converterModule = null; // Global application object.
18
19 // Indicate load success.
20 function moduleDidLoad() {
21 converterModule = document.getElementById('converter');
22 // Send a message to the Native Client module.
23 if (converterModule != null) {
24 console.log('converterModule loaded.');
25 }
26 }
27
28 // The 'message' event handler. This handler is fired when the NaCl module
29 // posts a message to the browser by calling PPB_Messaging.PostMessage()
30 // (in C) or pp::Instance.PostMessage() (in C++). This implementation
31 // displays the result in the JS console, puts the result in the '#rez' input and make it visible.
32 function handleMessage(message_event) {
33 console.log(message_event.data.value.valueOf());
34 $('#rez').val(message_event.data.value.valueOf().toFixed(2));
35 $('#rez').css('visibility', 'visible');
36 }