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.
7 function moduleLoad() {
14 document.querySelector('#curtain').classList.add('lift');
17 function moduleLoadError() {
18 updateStatus('Load failed.');
21 function moduleLoadProgress(event) {
22 $('progress').style.display = 'block';
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;
31 // The total length is not yet known.
36 function moduleCrash(event) {
37 if (naclModule.exitStatus == -1) {
38 updateStatus('CRASHED');
40 updateStatus('EXITED [' + naclModule.exitStatus + ']');
44 function updateStatus(opt_message) {
45 document.querySelector('#curtain').classList.remove('lift');
47 var statusField = $('statusField');
49 statusField.style.display = 'block';
50 statusField.textContent = opt_message;
54 function hideStatus() {
55 $('statusField').style.display = 'none';
56 $('progress').style.display = 'none';
59 function pageDidLoad() {
60 updateStatus('Loading...');
61 console.log('started');
63 aM = new NaClAM('NaClAM');
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);
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);
82 window.addEventListener("load", pageDidLoad, false);