OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 var examples = [ | 5 var examples = [ |
6 {name: 'bullet', text: 'Bullet Physics'}, | 6 {name: 'bullet', text: 'Bullet Physics'}, |
7 {name: 'earth', text: 'Raycasted Earth'}, | 7 {name: 'earth', text: 'Raycasted Earth'}, |
8 {name: 'lua', text: 'Lua Interpreter'}, | 8 {name: 'lua', text: 'Lua Interpreter'}, |
9 {name: 'life', text: 'Game of Life'}, | 9 {name: 'life', text: 'Game of Life'}, |
10 {name: 'voronoi', text: 'Voronoi Simulation'}, | 10 {name: 'voronoi', text: 'Voronoi Simulation'}, |
11 {name: 'smoothlife', text: 'SmoothLife'}, | 11 {name: 'smoothlife', text: 'SmoothLife'}, |
12 {name: 'cube', text: 'Rotating Cube'}, | 12 {name: 'cube', text: 'Rotating Cube'}, |
13 ]; | 13 ]; |
14 var exampleMap = {}; // Created below. | 14 var exampleMap = {}; // Created below. |
15 | 15 |
16 var iframeEl = null; | |
17 var isChrome = /Chrome\/([^\s]+)/.test(navigator.userAgent); | 16 var isChrome = /Chrome\/([^\s]+)/.test(navigator.userAgent); |
18 var isMobile = /Mobi/.test(navigator.userAgent); | 17 var isMobile = /Mobi/.test(navigator.userAgent); |
19 var hasPnacl = navigator.mimeTypes['application/x-pnacl'] !== undefined; | 18 var hasPnacl = navigator.mimeTypes['application/x-pnacl'] !== undefined; |
20 | 19 |
21 if (isChrome && !isMobile) { | 20 if (isChrome && !isMobile) { |
22 if (hasPnacl) { | 21 if (hasPnacl) { |
23 makeExampleList(); | 22 makeExampleList(); |
24 window.onpopstate = function(popState) { | 23 if (history.state == null) { |
25 if (popState.state == null) { | 24 updateViewFromLocation(); |
26 updateViewFromLocation(); | 25 } |
27 } else { | 26 |
28 var exampleName = popState.state; | 27 window.onpopstate = function(event) { |
29 loadExample(popState.state); | 28 var exampleName = event.state; |
30 } | 29 loadExample(exampleName); |
31 } | 30 } |
32 } else { | 31 } else { |
33 // Older version of Chrome? | 32 // Older version of Chrome? |
34 showOldChromeErrorMessage(); | 33 showOldChromeErrorMessage(); |
35 } | 34 } |
36 } else { | 35 } else { |
37 // Not Chrome, or is mobile Chrome. | 36 // Not Chrome, or is mobile Chrome. |
38 showNotChromeErrorMessage(); | 37 showNotChromeErrorMessage(); |
39 } | 38 } |
40 | 39 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 123 |
125 function createExampleIframe(exampleName) { | 124 function createExampleIframe(exampleName) { |
126 createIframe(getExampleUrl(exampleName)); | 125 createIframe(getExampleUrl(exampleName)); |
127 } | 126 } |
128 | 127 |
129 function createHomeIframe() { | 128 function createHomeIframe() { |
130 createIframe('/static/home/index.html'); | 129 createIframe('/static/home/index.html'); |
131 } | 130 } |
132 | 131 |
133 function createIframe(src) { | 132 function createIframe(src) { |
134 var oldIframeEl = iframeEl; | 133 var iframeEl = document.querySelector('iframe'); |
135 | 134 if (iframeEl === null) { |
136 iframeEl = document.createElement('iframe'); | 135 iframeEl = document.createElement('iframe'); |
137 iframeEl.setAttribute('frameborder', '0'); | 136 iframeEl.setAttribute('frameborder', '0'); |
138 iframeEl.setAttribute('width', '100%'); | 137 iframeEl.setAttribute('width', '100%'); |
139 iframeEl.setAttribute('height', '100%'); | 138 iframeEl.setAttribute('height', '100%'); |
140 iframeEl.src = src; | 139 iframeEl.src = src; |
141 iframeEl.setAttribute('hidden', ''); | 140 document.querySelector('section').appendChild(iframeEl); |
142 iframeEl.onload = function() { | 141 } else { |
143 if (oldIframeEl) | 142 iframeEl.contentDocument.location.replace(src); |
144 oldIframeEl.parentNode.removeChild(oldIframeEl); | |
145 iframeEl.removeAttribute('hidden'); | |
146 } | 143 } |
147 document.querySelector('section').appendChild(iframeEl); | |
148 } | 144 } |
149 | 145 |
150 function pushState(exampleName) { | 146 function pushState(exampleName) { |
151 window.history.pushState(exampleName, '', '/demo/' + exampleName); | 147 window.history.pushState(exampleName, '', '/demo/' + exampleName); |
152 } | 148 } |
153 | 149 |
154 function replaceState(exampleName) { | 150 function replaceState(exampleName) { |
155 window.history.replaceState(exampleName, '', '/demo/' + exampleName); | 151 window.history.replaceState(exampleName, '', '/demo/' + exampleName); |
156 } | 152 } |
157 | 153 |
158 function replaceHomeState() { | 154 function replaceHomeState() { |
159 window.history.replaceState('home', '', '/demo'); | 155 window.history.replaceState('home', '', '/demo'); |
160 } | 156 } |
161 | 157 |
162 function showOldChromeErrorMessage() { | 158 function showOldChromeErrorMessage() { |
163 document.getElementById('old-chrome').removeAttribute('hidden'); | 159 document.getElementById('old-chrome').removeAttribute('hidden'); |
164 } | 160 } |
165 | 161 |
166 function showNotChromeErrorMessage() { | 162 function showNotChromeErrorMessage() { |
167 document.getElementById('not-chrome').removeAttribute('hidden'); | 163 document.getElementById('not-chrome').removeAttribute('hidden'); |
168 } | 164 } |
OLD | NEW |