|
33 | 33 | var statusElement = document.getElementById('status'); |
34 | 34 | var progressElement = document.getElementById('progress'); |
35 | 35 | var spinnerElement = document.getElementById('spinner'); |
| 36 | + var canvasElement = document.getElementById('canvas'); |
| 37 | + var outputElement = document.getElementById('output'); |
| 38 | + if (outputElement) outputElement.value = ''; // clear browser cache |
| 39 | + |
| 40 | + // As a default initial behavior, pop up an alert when webgl context is lost. To make your |
| 41 | + // application robust, you may want to override this behavior before shipping! |
| 42 | + // See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2 |
| 43 | + canvasElement.addEventListener('webglcontextlost', (e) => { |
| 44 | + alert('WebGL context lost. You will need to reload the page.'); |
| 45 | + e.preventDefault(); |
| 46 | + }, false); |
36 | 47 |
|
37 | 48 | var Module = { |
38 | | - print: (function() { |
39 | | - var element = document.getElementById('output'); |
40 | | - if (element) element.value = ''; // clear browser cache |
41 | | - return (...args) => { |
| 49 | + print(...args) { |
| 50 | + console.log(...args); |
| 51 | + // These replacements are necessary if you render to raw HTML |
| 52 | + //text = text.replace(/&/g, "&"); |
| 53 | + //text = text.replace(/</g, "<"); |
| 54 | + //text = text.replace(/>/g, ">"); |
| 55 | + //text = text.replace('\n', '<br>', 'g'); |
| 56 | + if (outputElement) { |
42 | 57 | var text = args.join(' '); |
43 | | - // These replacements are necessary if you render to raw HTML |
44 | | - //text = text.replace(/&/g, "&"); |
45 | | - //text = text.replace(/</g, "<"); |
46 | | - //text = text.replace(/>/g, ">"); |
47 | | - //text = text.replace('\n', '<br>', 'g'); |
48 | | - console.log(text); |
49 | | - if (element) { |
50 | | - element.value += text + "\n"; |
51 | | - element.scrollTop = element.scrollHeight; // focus on bottom |
52 | | - } |
53 | | - }; |
54 | | - })(), |
55 | | - canvas: (() => { |
56 | | - var canvas = document.getElementById('canvas'); |
57 | | - |
58 | | - // As a default initial behavior, pop up an alert when webgl context is lost. To make your |
59 | | - // application robust, you may want to override this behavior before shipping! |
60 | | - // See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2 |
61 | | - canvas.addEventListener("webglcontextlost", (e) => { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false); |
62 | | - |
63 | | - return canvas; |
64 | | - })(), |
65 | | - setStatus: (text) => { |
| 58 | + outputElement.value += text + "\n"; |
| 59 | + outputElement.scrollTop = outputElement.scrollHeight; // focus on bottom |
| 60 | + } |
| 61 | + }, |
| 62 | + canvas: canvasElement, |
| 63 | + setStatus(text) { |
66 | 64 | Module.setStatus.last ??= { time: Date.now(), text: '' }; |
67 | 65 | if (text === Module.setStatus.last.text) return; |
68 | 66 | var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/); |
69 | 67 | var now = Date.now(); |
70 | | - if (m && now - Module.setStatus.last.time < 30) return; // if this is a progress update, skip it if too soon |
| 68 | + // if this is a progress update, skip it if too soon |
| 69 | + if (m && now - Module.setStatus.last.time < 30) return; |
71 | 70 | Module.setStatus.last.time = now; |
72 | 71 | Module.setStatus.last.text = text; |
73 | 72 | if (m) { |
|
85 | 84 | statusElement.innerHTML = text; |
86 | 85 | }, |
87 | 86 | totalDependencies: 0, |
88 | | - monitorRunDependencies: (left) => { |
| 87 | + monitorRunDependencies(left) { |
89 | 88 | this.totalDependencies = Math.max(this.totalDependencies, left); |
90 | 89 | Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.'); |
91 | 90 | } |
|
0 commit comments