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