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 * A polyfill for HTML Templates. | 7 * A polyfill for HTML Templates. |
8 * | 8 * |
9 * This just adds in the content attribute, it doesn't stop scripts | 9 * This just adds in the content attribute, it doesn't stop scripts |
10 * from running nor does it stop other side-effects. | 10 * from running nor does it stop other side-effects. |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 var embed = document.getElementById('embed'); | 121 var embed = document.getElementById('embed'); |
122 var embedButton = document.getElementById('embedButton'); | 122 var embedButton = document.getElementById('embedButton'); |
123 var code = document.getElementById('code'); | 123 var code = document.getElementById('code'); |
124 var output = document.getElementById('output'); | 124 var output = document.getElementById('output'); |
125 var stdout = document.getElementById('stdout'); | 125 var stdout = document.getElementById('stdout'); |
126 var img = document.getElementById('img'); | 126 var img = document.getElementById('img'); |
127 var tryHistory = document.getElementById('tryHistory'); | 127 var tryHistory = document.getElementById('tryHistory'); |
128 var parser = new DOMParser(); | 128 var parser = new DOMParser(); |
129 var tryTemplate = document.getElementById('tryTemplate'); | 129 var tryTemplate = document.getElementById('tryTemplate'); |
130 | 130 |
131 var editor = CodeMirror.fromTextArea(code, { | |
jcgregorio
2014/05/01 13:27:30
Can we fix the editor so that it defaults to 100 c
f(malita)
2014/05/01 14:24:40
Done.
| |
132 theme: "ambiance", | |
133 lineNumbers: true, | |
134 matchBrackets: true, | |
135 mode: "text/x-c++src", | |
136 indentUnit: 4, | |
137 }); | |
138 | |
139 // Suppress changes to the first/last line (draw wrapper method) | |
140 editor.on('beforeChange', function(cm, change) { | |
141 if (change.from.line < 1 || change.from.line == cm.lineCount() - 1) | |
142 change.cancel(); | |
143 }); | |
131 | 144 |
132 function beginWait() { | 145 function beginWait() { |
133 document.body.classList.add('waiting'); | 146 document.body.classList.add('waiting'); |
134 run.disabled = true; | 147 run.disabled = true; |
135 } | 148 } |
136 | 149 |
137 | 150 |
138 function endWait() { | 151 function endWait() { |
139 document.body.classList.remove('waiting'); | 152 document.body.classList.remove('waiting'); |
140 run.disabled = false; | 153 run.disabled = false; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 | 264 |
252 function onSubmitCode() { | 265 function onSubmitCode() { |
253 beginWait(); | 266 beginWait(); |
254 clearOutput(); | 267 clearOutput(); |
255 var req = new XMLHttpRequest(); | 268 var req = new XMLHttpRequest(); |
256 req.addEventListener('load', codeComplete); | 269 req.addEventListener('load', codeComplete); |
257 req.addEventListener('error', xhrError); | 270 req.addEventListener('error', xhrError); |
258 req.overrideMimeType('application/json'); | 271 req.overrideMimeType('application/json'); |
259 req.open('POST', '/', true); | 272 req.open('POST', '/', true); |
260 req.setRequestHeader('content-type', 'application/json'); | 273 req.setRequestHeader('content-type', 'application/json'); |
261 req.send(JSON.stringify({'code': code.value, 'name': workspaceName})); | 274 req.send(JSON.stringify({'code': editor.getValue(), 'name': workspaceName} )); |
262 } | 275 } |
263 run.addEventListener('click', onSubmitCode); | 276 run.addEventListener('click', onSubmitCode); |
264 | 277 |
265 | 278 |
266 function onEmbedClick() { | 279 function onEmbedClick() { |
267 embed.style.display='inline'; | 280 embed.style.display='inline'; |
268 } | 281 } |
269 | 282 |
270 if (embedButton) { | 283 if (embedButton) { |
271 embedButton.addEventListener('click', onEmbedClick); | 284 embedButton.addEventListener('click', onEmbedClick); |
272 } | 285 } |
273 | 286 |
274 | 287 |
275 // Add the images to the history if we are on a workspace page. | 288 // Add the images to the history if we are on a workspace page. |
276 if (tryHistory && history) { | 289 if (tryHistory && history) { |
277 for (var i=0; i<history.length; i++) { | 290 for (var i=0; i<history.length; i++) { |
278 addToHistory(history[i].hash, '/i/'+history[i].hash+'.png'); | 291 addToHistory(history[i].hash, '/i/'+history[i].hash+'.png'); |
279 } | 292 } |
280 } | 293 } |
281 | 294 |
282 })(workspaceName); | 295 })(workspaceName); |
OLD | NEW |