Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: experimental/webtry/res/js/webtry.js

Issue 656463002: add support for skfiddle width/height options (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add new db creation commands to the design documnt Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « experimental/webtry/main.cpp ('k') | experimental/webtry/res/webtry/css/webtry.css » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 img = document.getElementById('img'); 28 var img = document.getElementById('img');
29 var imageWidth = document.getElementById('image-width');
30 var imageHeight = document.getElementById('image-height');
29 var tryHistory = document.getElementById('tryHistory'); 31 var tryHistory = document.getElementById('tryHistory');
30 var parser = new DOMParser(); 32 var parser = new DOMParser();
31 var tryTemplate = document.getElementById('tryTemplate'); 33 var tryTemplate = document.getElementById('tryTemplate');
32 var sourcesTemplate = document.getElementById('sourcesTemplate'); 34 var sourcesTemplate = document.getElementById('sourcesTemplate');
33 35
34 var enableSource = document.getElementById('enableSource'); 36 var enableSource = document.getElementById('enableSource');
35 var selectedSource = document.getElementById('selectedSource'); 37 var selectedSource = document.getElementById('selectedSource');
36 var sourceCode = document.getElementById('sourceCode'); 38 var sourceCode = document.getElementById('sourceCode');
37 var chooseSource = document.getElementById('chooseSource'); 39 var chooseSource = document.getElementById('chooseSource');
38 var chooseList = document.getElementById('chooseList'); 40 var chooseList = document.getElementById('chooseList');
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 // The response is JSON of the form: 206 // The response is JSON of the form:
205 // { 207 // {
206 // "hash": "unique id for a try", 208 // "hash": "unique id for a try",
207 // "code": "source code for try" 209 // "code": "source code for try"
208 // } 210 // }
209 endWait(); 211 endWait();
210 body = JSON.parse(e.target.response); 212 body = JSON.parse(e.target.response);
211 code.value = body.code; 213 code.value = body.code;
212 editor.setValue(body.code); 214 editor.setValue(body.code);
213 img.src = '/i/'+body.hash+'.png'; 215 img.src = '/i/'+body.hash+'.png';
216 imageWidth.value = body.width;
217 imageHeight.value = body.height;
214 sourceSelectByID(body.source); 218 sourceSelectByID(body.source);
215 if (permalink) { 219 if (permalink) {
216 permalink.href = '/c/' + body.hash; 220 permalink.href = '/c/' + body.hash;
217 permalink.style.display='inline-block'; 221 permalink.style.display='inline-block';
218 } 222 }
219 } 223 }
220 224
221 225
222 /** 226 /**
223 * Add the given try image to the history of a workspace. 227 * Add the given try image to the history of a workspace.
(...skipping 14 matching lines...) Expand all
238 function codeComplete(e) { 242 function codeComplete(e) {
239 // The response is JSON of the form: 243 // The response is JSON of the form:
240 // { 244 // {
241 // "message": "you had an error...", 245 // "message": "you had an error...",
242 // "img": "<base64 encoded image but only on success>" 246 // "img": "<base64 encoded image but only on success>"
243 // } 247 // }
244 // 248 //
245 // The img is optional and only appears if there is a valid 249 // The img is optional and only appears if there is a valid
246 // image to display. 250 // image to display.
247 endWait(); 251 endWait();
248 console.log(e.target.response);
249 body = JSON.parse(e.target.response); 252 body = JSON.parse(e.target.response);
250 output.textContent = body.message; 253 output.textContent = body.message;
251 if (body.message) { 254 if (body.message) {
252 output.style.display = 'block'; 255 output.style.display = 'block';
253 } 256 }
254 if (stdout) { 257 if (stdout) {
255 stdout.textContent = body.stdout; 258 stdout.textContent = body.stdout;
256 if (body.stdout) { 259 if (body.stdout) {
257 stdout.style.display = 'block'; 260 stdout.style.display = 'block';
258 } 261 }
(...skipping 24 matching lines...) Expand all
283 286
284 function onSubmitCode() { 287 function onSubmitCode() {
285 beginWait(); 288 beginWait();
286 clearOutput(); 289 clearOutput();
287 var req = new XMLHttpRequest(); 290 var req = new XMLHttpRequest();
288 req.addEventListener('load', codeComplete); 291 req.addEventListener('load', codeComplete);
289 req.addEventListener('error', xhrError); 292 req.addEventListener('error', xhrError);
290 req.overrideMimeType('application/json'); 293 req.overrideMimeType('application/json');
291 req.open('POST', '/', true); 294 req.open('POST', '/', true);
292 req.setRequestHeader('content-type', 'application/json'); 295 req.setRequestHeader('content-type', 'application/json');
293 req.send(JSON.stringify({'code': editor.getValue(), 'name': workspaceNam e, 'source': sourceId})); 296 req.send(JSON.stringify({'code': editor.getValue(), 'width': parseInt(im ageWidth.value), 'height': parseInt(imageHeight.value), 'name': workspaceName, ' source': sourceId}));
294 } 297 }
295 run.addEventListener('click', onSubmitCode); 298 run.addEventListener('click', onSubmitCode);
296 299
297 300
298 function onEmbedClick() { 301 function onEmbedClick() {
299 embed.style.display='inline'; 302 embed.style.display='inline';
300 } 303 }
301 304
302 if (embedButton) { 305 if (embedButton) {
303 embedButton.addEventListener('click', onEmbedClick); 306 embedButton.addEventListener('click', onEmbedClick);
(...skipping 10 matching lines...) Expand all
314 } 317 }
315 318
316 // If loaded via HTML Imports then DOMContentLoaded will be long done. 319 // If loaded via HTML Imports then DOMContentLoaded will be long done.
317 if (document.readyState != "loading") { 320 if (document.readyState != "loading") {
318 onLoad(); 321 onLoad();
319 } else { 322 } else {
320 this.addEventListener('load', onLoad); 323 this.addEventListener('load', onLoad);
321 } 324 }
322 325
323 })(); 326 })();
OLDNEW
« no previous file with comments | « experimental/webtry/main.cpp ('k') | experimental/webtry/res/webtry/css/webtry.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698