| OLD | NEW |
| 1 /** | 1 /** |
| 2 * Common JS that talks XHR back to the server and runs the code and receives | 2 * Common JS that talks XHR back to the server and runs the code and receives |
| 3 * the results. | 3 * the results. |
| 4 */ | 4 */ |
| 5 | 5 |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * All the functionality is wrapped up in this anonymous closure, but we need | 8 * All the functionality is wrapped up in this anonymous closure, but we need |
| 9 * to be told if we are on the workspace page or a normal try page, so the | 9 * to be told if we are on the workspace page or a normal try page, so the |
| 10 * workspaceName is passed into the closure, it must be set in the global | 10 * workspaceName is passed into the closure, it must be set in the global |
| 11 * namespace. If workspaceName is the empty string then we know we aren't | 11 * namespace. If workspaceName is the empty string then we know we aren't |
| 12 * running on a workspace page. | 12 * running on a workspace page. |
| 13 * | 13 * |
| 14 * If we are on a workspace page we also look for a 'history_' | 14 * If we are on a workspace page we also look for a 'history_' |
| 15 * variable in the global namespace which contains the list of tries | 15 * variable in the global namespace which contains the list of tries |
| 16 * that are included in this workspace. That variable is used to | 16 * that are included in this workspace. That variable is used to |
| 17 * populate the history list. | 17 * populate the history list. |
| 18 */ | 18 */ |
| 19 (function() { | 19 (function() { |
| 20 function onLoad() { | 20 function onLoad() { |
| 21 var run = document.getElementById('run'); | 21 var run = document.getElementById('run'); |
| 22 var permalink = document.getElementById('permalink'); | 22 var permalink = document.getElementById('permalink'); |
| 23 var embed = document.getElementById('embed'); | 23 var embed = document.getElementById('embed'); |
| 24 var embedButton = document.getElementById('embedButton'); | 24 var embedButton = document.getElementById('embedButton'); |
| 25 var code = document.getElementById('code'); | 25 var code = document.getElementById('code'); |
| 26 var output = document.getElementById('output'); | 26 var output = document.getElementById('output'); |
| 27 var stdout = document.getElementById('stdout'); | 27 var stdout = document.getElementById('stdout'); |
| 28 var gpu = document.getElementById('use-gpu'); | |
| 29 var img = document.getElementById('img'); | 28 var img = document.getElementById('img'); |
| 30 var imageWidth = document.getElementById('image-width'); | 29 var imageWidth = document.getElementById('image-width'); |
| 31 var imageHeight = document.getElementById('image-height'); | 30 var imageHeight = document.getElementById('image-height'); |
| 32 var tryHistory = document.getElementById('tryHistory'); | 31 var tryHistory = document.getElementById('tryHistory'); |
| 33 var parser = new DOMParser(); | 32 var parser = new DOMParser(); |
| 34 var tryTemplate = document.getElementById('tryTemplate'); | 33 var tryTemplate = document.getElementById('tryTemplate'); |
| 35 var sourcesTemplate = document.getElementById('sourcesTemplate'); | 34 var sourcesTemplate = document.getElementById('sourcesTemplate'); |
| 36 | 35 |
| 37 var enableSource = document.getElementById('enableSource'); | 36 var enableSource = document.getElementById('enableSource'); |
| 38 var selectedSource = document.getElementById('selectedSource'); | 37 var selectedSource = document.getElementById('selectedSource'); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 // "hash": "unique id for a try", | 208 // "hash": "unique id for a try", |
| 210 // "code": "source code for try" | 209 // "code": "source code for try" |
| 211 // } | 210 // } |
| 212 endWait(); | 211 endWait(); |
| 213 body = JSON.parse(e.target.response); | 212 body = JSON.parse(e.target.response); |
| 214 code.value = body.code; | 213 code.value = body.code; |
| 215 editor.setValue(body.code); | 214 editor.setValue(body.code); |
| 216 img.src = '/i/'+body.hash+'.png'; | 215 img.src = '/i/'+body.hash+'.png'; |
| 217 imageWidth.value = body.width; | 216 imageWidth.value = body.width; |
| 218 imageHeight.value = body.height; | 217 imageHeight.value = body.height; |
| 219 gpu.checked = body.gpu; | |
| 220 sourceSelectByID(body.source); | 218 sourceSelectByID(body.source); |
| 221 if (permalink) { | 219 if (permalink) { |
| 222 permalink.href = '/c/' + body.hash; | 220 permalink.href = '/c/' + body.hash; |
| 223 permalink.style.display='inline-block'; | 221 permalink.style.display='inline-block'; |
| 224 } | 222 } |
| 225 } | 223 } |
| 226 | 224 |
| 227 | 225 |
| 228 /** | 226 /** |
| 229 * Add the given try image to the history of a workspace. | 227 * Add the given try image to the history of a workspace. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 | 286 |
| 289 function onSubmitCode() { | 287 function onSubmitCode() { |
| 290 beginWait(); | 288 beginWait(); |
| 291 clearOutput(); | 289 clearOutput(); |
| 292 var req = new XMLHttpRequest(); | 290 var req = new XMLHttpRequest(); |
| 293 req.addEventListener('load', codeComplete); | 291 req.addEventListener('load', codeComplete); |
| 294 req.addEventListener('error', xhrError); | 292 req.addEventListener('error', xhrError); |
| 295 req.overrideMimeType('application/json'); | 293 req.overrideMimeType('application/json'); |
| 296 req.open('POST', '/', true); | 294 req.open('POST', '/', true); |
| 297 req.setRequestHeader('content-type', 'application/json'); | 295 req.setRequestHeader('content-type', 'application/json'); |
| 298 req.send(JSON.stringify({ | 296 req.send(JSON.stringify({'code': editor.getValue(), 'width': parseInt(im
ageWidth.value), 'height': parseInt(imageHeight.value), 'name': workspaceName, '
source': sourceId})); |
| 299 'code': editor.getValue(), | |
| 300 'width': parseInt(imageWidth.value), | |
| 301 'height': parseInt(imageHeight.value), | |
| 302 'name': workspaceName, | |
| 303 'source': sourceId, | |
| 304 'gpu': gpu.checked | |
| 305 })); | |
| 306 } | 297 } |
| 307 run.addEventListener('click', onSubmitCode); | 298 run.addEventListener('click', onSubmitCode); |
| 308 | 299 |
| 309 | 300 |
| 310 function onEmbedClick() { | 301 function onEmbedClick() { |
| 311 embed.style.display='inline'; | 302 embed.style.display='inline'; |
| 312 } | 303 } |
| 313 | 304 |
| 314 if (embedButton) { | 305 if (embedButton) { |
| 315 embedButton.addEventListener('click', onEmbedClick); | 306 embedButton.addEventListener('click', onEmbedClick); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 326 } | 317 } |
| 327 | 318 |
| 328 // If loaded via HTML Imports then DOMContentLoaded will be long done. | 319 // If loaded via HTML Imports then DOMContentLoaded will be long done. |
| 329 if (document.readyState != "loading") { | 320 if (document.readyState != "loading") { |
| 330 onLoad(); | 321 onLoad(); |
| 331 } else { | 322 } else { |
| 332 this.addEventListener('load', onLoad); | 323 this.addEventListener('load', onLoad); |
| 333 } | 324 } |
| 334 | 325 |
| 335 })(); | 326 })(); |
| OLD | NEW |