var progress_bar = document.getElementById('progress_bar'); var progress_text = document.getElementById('progress_text'); var Module = { preRun: [], postRun: [], print: (function() { return function(text) { if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' '); // These replacements are necessary if you render to raw HTML //text = text.replace(/&/g, "&"); //text = text.replace(//g, ">"); //text = text.replace('\n', '
', 'g'); console.log(text); }; })(), printErr: function(text) { if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' '); if (0) { // XXX disabled for safety typeof dump == 'function') { dump(text + '\n'); // fast, straight to the real console } else { console.error(text); } }, canvas: (function() { var canvas = document.getElementById('canvas'); // As a default initial behavior, pop up an alert when webgl context is lost. To make your // application robust, you may want to override this behavior before shipping! // See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2 canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false); return canvas; })(), setStatus: function(text) { var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/); if (m) { text = m[1]; var perc = parseInt(m[2]) / parseInt(m[4]) * 100; if (perc > 0) { progress_bar.style.width = perc + '%'; progress_bar.innerHTML = perc.toFixed(1) + '%'; } } else { progress_bar.innerHTML = ''; } progress_text.innerHTML = text; }, totalDependencies: 0, monitorRunDependencies: function(left) { this.totalDependencies = Math.max(this.totalDependencies, left); Module.setStatus('Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')'); } }; Module.setStatus('Downloading...'); window.onerror = function() { Module.setStatus('Exception thrown, see JavaScript console'); Module.setStatus = function(text) { if (text) Module.printErr('[post-exception status] ' + text); }; };