- add sources.
[platform/framework/web/crosswalk.git] / src / native_client_sdk / src / gonacl_appengine / static / pnacl-demo-bullet / main.js
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
5 aM = null;
6
7 function moduleLoad() {
8   hideStatus();
9   init();
10   animate();
11   NaClAMBulletInit();
12   loadJenga20();
13
14   document.querySelector('#curtain').classList.add('lift');
15 }
16
17 function moduleLoadError() {
18   updateStatus('Load failed.');
19 }
20
21 function moduleLoadProgress(event) {
22   $('progress').style.display = 'block';
23
24   var loadPercent = 0.0;
25   var bar = document.getElementById('progress');
26   if (event.lengthComputable && event.total > 0) {
27     loadPercent = event.loaded / event.total * 100.0;
28     bar.value = loadPercent;
29     bar.max = 100;
30   } else {
31     // The total length is not yet known.
32     loadPercent = -1.0;
33   }
34 }
35
36 function moduleCrash(event) {
37   if (naclModule.exitStatus == -1) {
38     updateStatus('CRASHED');
39   } else {
40     updateStatus('EXITED [' + naclModule.exitStatus + ']');
41   }
42 }
43
44 function updateStatus(opt_message) {
45   document.querySelector('#curtain').classList.remove('lift');
46
47   var statusField = $('statusField');
48   if (statusField) {
49     statusField.style.display = 'block';
50     statusField.textContent = opt_message;
51   }
52 }
53
54 function hideStatus() {
55   $('statusField').style.display = 'none';
56   $('progress').style.display = 'none';
57 }
58
59 function pageDidLoad() {
60   updateStatus('Loading...');
61   console.log('started');
62
63   aM = new NaClAM('NaClAM');
64   aM.enable();
65
66   var embedWrap = document.createElement('div');
67   embedWrap.addEventListener('load', moduleLoad, true);
68   embedWrap.addEventListener('error', moduleLoadError, true);
69   embedWrap.addEventListener('progress', moduleLoadProgress, true);
70   embedWrap.addEventListener('crash', moduleCrash, true);
71   document.body.appendChild(embedWrap);
72
73   var embed = document.createElement('embed');
74   embed.setAttribute('id', 'NaClAM');
75   embed.setAttribute('width', '0');
76   embed.setAttribute('height', '0');
77   embed.setAttribute('type', 'application/x-pnacl');
78   embed.setAttribute('src', 'http://commondatastorage.googleapis.com/gonacl/demos/publish/229855/bullet/NaClAMBullet.nmf');
79   embedWrap.appendChild(embed);
80 }
81
82 window.addEventListener("load", pageDidLoad, false);