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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 lineNumbers: true, | 179 lineNumbers: true, |
180 matchBrackets: true, | 180 matchBrackets: true, |
181 mode: "text/x-c++src", | 181 mode: "text/x-c++src", |
182 indentUnit: 4, | 182 indentUnit: 4, |
183 }); | 183 }); |
184 | 184 |
185 // Match the initial textarea size. | 185 // Match the initial textarea size. |
186 editor.setSize(editor.defaultCharWidth() * code.cols, | 186 editor.setSize(editor.defaultCharWidth() * code.cols, |
187 editor.defaultTextHeight() * code.rows); | 187 editor.defaultTextHeight() * code.rows); |
188 | 188 |
189 // Suppress changes to the first/last line (draw wrapper method) | |
190 editor.on('beforeChange', function(cm, change) { | |
191 if (change.from.line < 1 || change.from.line == cm.lineCount() - 1) | |
192 change.cancel(); | |
193 }); | |
194 | |
195 function beginWait() { | 189 function beginWait() { |
196 document.body.classList.add('waiting'); | 190 document.body.classList.add('waiting'); |
197 run.disabled = true; | 191 run.disabled = true; |
198 } | 192 } |
199 | 193 |
200 | 194 |
201 function endWait() { | 195 function endWait() { |
202 document.body.classList.remove('waiting'); | 196 document.body.classList.remove('waiting'); |
203 run.disabled = false; | 197 run.disabled = false; |
204 } | 198 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 */ | 235 */ |
242 function historyComplete(e) { | 236 function historyComplete(e) { |
243 // The response is JSON of the form: | 237 // The response is JSON of the form: |
244 // { | 238 // { |
245 // "hash": "unique id for a try", | 239 // "hash": "unique id for a try", |
246 // "code": "source code for try" | 240 // "code": "source code for try" |
247 // } | 241 // } |
248 endWait(); | 242 endWait(); |
249 body = JSON.parse(e.target.response); | 243 body = JSON.parse(e.target.response); |
250 code.value = body.code; | 244 code.value = body.code; |
| 245 editor.setValue(body.code); |
251 img.src = '/i/'+body.hash+'.png'; | 246 img.src = '/i/'+body.hash+'.png'; |
252 if (permalink) { | 247 if (permalink) { |
253 permalink.href = '/c/' + body.hash; | 248 permalink.href = '/c/' + body.hash; |
254 } | 249 } |
255 } | 250 } |
256 | 251 |
257 | 252 |
258 /** | 253 /** |
259 * Add the given try image to the history of a workspace. | 254 * Add the given try image to the history of a workspace. |
260 */ | 255 */ |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 | 331 |
337 | 332 |
338 // Add the images to the history if we are on a workspace page. | 333 // Add the images to the history if we are on a workspace page. |
339 if (tryHistory && history) { | 334 if (tryHistory && history) { |
340 for (var i=0; i<history.length; i++) { | 335 for (var i=0; i<history.length; i++) { |
341 addToHistory(history[i].hash, '/i/'+history[i].hash+'.png'); | 336 addToHistory(history[i].hash, '/i/'+history[i].hash+'.png'); |
342 } | 337 } |
343 } | 338 } |
344 | 339 |
345 })(workspaceName); | 340 })(workspaceName); |
OLD | NEW |