OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 function $(id) { | |
6 return document.querySelector(id); | |
7 } | |
dmichael (off chromium)
2014/12/03 23:33:33
I wouldn't define $ in an example... you can just
binji
2014/12/03 23:56:50
Done.
| |
8 | |
9 function attachListeners() { | |
10 var number1El = $('#addend1'); | |
11 var number2El = $('#addend2'); | |
12 var resultEl = $('#result'); | |
13 | |
14 document.getElementById('addAsync').addEventListener('click', function() { | |
15 var value1 = parseInt(number1El.value); | |
16 var value2 = parseInt(number2El.value); | |
17 common.naclModule.postMessage([value1, value2]); | |
18 | |
19 // The result is returned in handleMessage below. | |
20 }); | |
21 | |
22 document.getElementById('addSync').addEventListener('click', function() { | |
23 var value1 = parseInt(number1El.value); | |
24 var value2 = parseInt(number2El.value); | |
25 var result = | |
26 common.naclModule.postMessageAndAwaitResponse([value1, value2]); | |
27 | |
28 // This is the result returned from the module synchronously (i.e. when the | |
29 // addSync button is pressed) | |
30 resultEl.textContent = result; | |
31 }); | |
32 } | |
33 | |
34 // Called by the common.js module. | |
35 function handleMessage(message_event) { | |
36 // This is the result returned from the module asynchronously (i.e. when the | |
37 // addAsync button is pressed) | |
38 result.textContent = message_event.data; | |
39 } | |
OLD | NEW |