1// Copyright (c) 2013 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
5function $(id) {
6  return document.getElementById(id);
7}
8
9function postAngleMessage() {
10  var xAngle = parseFloat($('xAngle').value);
11  var yAngle = parseFloat($('yAngle').value);
12  common.naclModule.postMessage([xAngle, yAngle]);
13}
14
15// Add event listeners after the NaCl module has loaded.  These listeners will
16// forward messages to the NaCl module via postMessage()
17function attachListeners() {
18  $('xAngle').addEventListener('change', postAngleMessage);
19  $('yAngle').addEventListener('change', postAngleMessage);
20  $('animateOff').addEventListener('click', function() {
21    $('animateOn').checked = '';
22    common.naclModule.postMessage(false);
23  });
24  $('animateOn').addEventListener('click', function() {
25    $('animateOff').checked = '';
26    common.naclModule.postMessage(true);
27  });
28}
29
30// Handle a message coming from the NaCl module.
31function handleMessage(event) {
32  if (!(event.data instanceof Array))
33    return;
34  if (event.data.length != 2)
35    return;
36
37  var xAngle = event.data[0];
38  var yAngle = event.data[1];
39  $('xAngle').value = xAngle;
40  $('yAngle').value = yAngle;
41}
42