OLD | NEW |
1 <!-- The <fiddle-sk> custom element declaration. | 1 <!-- The <fiddle-sk> custom element declaration. |
2 | 2 |
3 Handles displaying and running a fiddle. Note that the code | 3 Handles displaying and running a fiddle. Note that the code |
4 should be supplied as a child element textarea. | 4 should be supplied as a child element textarea. |
5 | 5 |
6 Attributes: | 6 Attributes: |
7 width - The width of the fiddle image. | 7 width - The width of the fiddle image. |
8 height - The height of the fiddle image. | 8 height - The height of the fiddle image. |
9 source - The index of the source image to use as input. | 9 source - The index of the source image to use as input. |
10 bug_link - If true then display a link to report a bug. | 10 bug_link - If true then display a link to report a bug. |
11 embed_button - If true then display the embed button. | 11 embed_button - If true then display the embed button. |
12 | 12 |
13 Methods: | 13 Methods: |
14 None. | 14 None. |
15 | 15 |
16 Events: | 16 Events: |
17 fiddle-success - generates an event when a succesful run is complete. The ev
ent contains | 17 fiddle-success - generates an event when a succesful run is complete. The ev
ent contains |
18 the hash of the new fiddle, to be used to retrieve the resultant images. | 18 the hash of the new fiddle, to be used to retrieve the resultant images. |
19 --> | 19 --> |
20 <link rel="stylesheet" href="/res/common/css/md.css" type="text/css" media="all"
> | 20 <link rel="stylesheet" href="/res/common/css/md.css" type="text/css" media="all"
> |
21 <link rel="import" href="bower_components/paper-spinner/paper-spinner.html"> | 21 <link rel="import" href="bower_components/paper-spinner/paper-spinner.html"> |
| 22 <link rel="import" href="bower_components/paper-checkbox/paper-checkbox.html"> |
22 <link rel="import" href="/res/common/imp/9/details-summary.html"> | 23 <link rel="import" href="/res/common/imp/9/details-summary.html"> |
23 <link rel="import" href="/res/common/imp/9/toggle.html"> | 24 <link rel="import" href="/res/common/imp/9/toggle.html"> |
24 <link rel="import" href="/res/imp/bower_components/paper-input/paper-input.html"
> | 25 <link rel="import" href="/res/imp/bower_components/paper-input/paper-input.html"
> |
25 <style type="text/css" media="screen"> | 26 <style type="text/css" media="screen"> |
26 .CodeMirror .error { | 27 .CodeMirror .error { |
27 background: #f88; | 28 background: #f88; |
28 } | 29 } |
29 | 30 |
30 .CodeMirror-lines, | 31 .CodeMirror-lines, |
31 .CodeMirror-scroll | 32 .CodeMirror-scroll |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 <div id=embedder> | 167 <div id=embedder> |
167 <h3>Embed as an iframe:</h3> | 168 <h3>Embed as an iframe:</h3> |
168 <input type="text" readonly size=150 value="<iframe src='https://fi
ddle.skia.org/iframe/{{fiddlehash}}' width='900' height='550' style='border: sol
id #00a 1px; border-radius: 5px;'/>"> | 169 <input type="text" readonly size=150 value="<iframe src='https://fi
ddle.skia.org/iframe/{{fiddlehash}}' width='900' height='550' style='border: sol
id #00a 1px; border-radius: 5px;'/>"> |
169 <p>Embed as an image with a backlink:</p> | 170 <p>Embed as an image with a backlink:</p> |
170 <input type="text" readonly size=150 value="<a href='https://fiddle
.skia.org/c/{{fiddlehash}}'><img src='https://fiddle.skia.org/c/{{fiddlehash}
}_raster.png'></a>"> | 171 <input type="text" readonly size=150 value="<a href='https://fiddle
.skia.org/c/{{fiddlehash}}'><img src='https://fiddle.skia.org/c/{{fiddlehash}
}_raster.png'></a>"> |
171 </div> | 172 </div> |
172 </template> | 173 </template> |
173 <toggle-display-sk disabled$={{_not_logged_in}}>Name</toggle-display-sk> | 174 <toggle-display-sk disabled$={{_not_logged_in}}>Name</toggle-display-sk> |
174 <div id=namer> | 175 <div id=namer> |
175 <h3>Create a name for this fiddle:</h3> | 176 <h3>Create a name for this fiddle:</h3> |
176 <paper-input id=name label="Name" size=40 auto-validate allowed-patter
n="[0-9a-zA-Z_]" value=""></paper-input> | 177 <paper-input id=name label="Name" placeholder="fiddle_name_goes_here"
size=40 auto-validate allowed-pattern="[0-9a-zA-Z_]" value="{{_name}}"></paper-i
nput> |
177 <!-- Add a pop-up menu here that has completions based on what's been
typed so far, and also any names that this page has loaded previously.--> | 178 <!-- Add a pop-up menu here that has completions based on what's been
typed so far, and also any names that this page has loaded previously.--> |
178 <button class=save on-tap="_submit_name">Save</button> | 179 <paper-checkbox id=overwrite title="Overwrite the existing name if one
exists.">Overwrite</paper-checkbox> |
| 180 <button class=save on-tap="_submit_name" disabled="{{_isEmpty(_name)}}
">Save</button> |
179 </div> | 181 </div> |
180 | 182 |
181 </div> | 183 </div> |
182 <div on-tap="_errSelect"> | 184 <div on-tap="_errSelect"> |
183 <template is="dom-if" if="{{_hasCompileErrors(_compile_errors)}}"> | 185 <template is="dom-if" if="{{_hasCompileErrors(_compile_errors)}}"> |
184 <h2>Compilation Errors</h2> | 186 <h2>Compilation Errors</h2> |
185 <template is="dom-repeat" items="{{_compile_errors}}"> | 187 <template is="dom-repeat" items="{{_compile_errors}}"> |
186 <pre class=compile-error data-line$="{{item.line}}" data-col$="{{item.
col}}">{{item.text}}</pre> | 188 <pre class=compile-error data-line$="{{item.line}}" data-col$="{{item.
col}}">{{item.text}}</pre> |
187 </template> | 189 </template> |
188 </template> | 190 </template> |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 }, | 266 }, |
265 _runtime_error: { | 267 _runtime_error: { |
266 type: String, | 268 type: String, |
267 value: "", | 269 value: "", |
268 reflectToAttribute: false, | 270 reflectToAttribute: false, |
269 }, | 271 }, |
270 _not_logged_in: { | 272 _not_logged_in: { |
271 type: Boolean, | 273 type: Boolean, |
272 value: true, | 274 value: true, |
273 reflectToAttribute: false, | 275 reflectToAttribute: false, |
274 } | 276 }, |
| 277 _name: { |
| 278 type: String, |
| 279 value: "", |
| 280 reflectToAttribute: false, |
| 281 }, |
275 }, | 282 }, |
276 | 283 |
277 ready: function() { | 284 ready: function() { |
278 this._errorLinesRe = /draw.cpp:([0-9]+):([0-9]+):/; | 285 this._errorLinesRe = /draw.cpp:([0-9]+):([0-9]+):/; |
279 | 286 |
280 this._editor = CodeMirror.fromTextArea($$$('textarea', this), { | 287 this._editor = CodeMirror.fromTextArea($$$('textarea', this), { |
281 theme: "default", | 288 theme: "default", |
282 lineNumbers: true, | 289 lineNumbers: true, |
283 matchBrackets: true, | 290 matchBrackets: true, |
284 lineWrapping: true, | 291 lineWrapping: true, |
(...skipping 18 matching lines...) Expand all Loading... |
303 sk.Login.then(function(status) { | 310 sk.Login.then(function(status) { |
304 this._not_logged_in = (status.Email == ""); | 311 this._not_logged_in = (status.Email == ""); |
305 }.bind(this)); | 312 }.bind(this)); |
306 }, | 313 }, |
307 | 314 |
308 _run: function() { | 315 _run: function() { |
309 this._run_impl({}); | 316 this._run_impl({}); |
310 }, | 317 }, |
311 | 318 |
312 _submit_name: function() { | 319 _submit_name: function() { |
313 this._run_impl({name: this.$.name.value}); | 320 this._run_impl({ |
| 321 name: this._name, |
| 322 overwrite: this.$.overwrite.checked, |
| 323 }); |
314 }, | 324 }, |
315 | 325 |
316 _run_impl: function(extra) { | 326 _run_impl: function(extra) { |
317 this._editor.save(); | 327 this._editor.save(); |
318 this.fiddlehash = ""; | 328 this.fiddlehash = ""; |
319 this.$.running.active = true; | 329 this.$.running.active = true; |
320 body = { | 330 body = { |
321 code: $$$('textarea', this).value, | 331 code: $$$('textarea', this).value, |
322 options: { | 332 options: { |
323 width: +this.width, | 333 width: +this.width, |
324 height: +this.height, | 334 height: +this.height, |
325 source: +this.source, | 335 source: +this.source, |
326 } | 336 } |
327 }; | 337 }; |
328 for (key in extra) { | 338 for (key in extra) { |
329 body[key] = extra[key]; | 339 body[key] = extra[key]; |
330 } | 340 } |
331 sk.post("/_/run", JSON.stringify(body)).then(JSON.parse).then(function(jso
n) { | 341 sk.post("/_/run", JSON.stringify(body)).then(JSON.parse).then(function(jso
n) { |
332 this.fiddlehash = json.fiddleHash; | 342 this.fiddlehash = json.fiddleHash; |
333 this._compile_errors = json.compile_errors || []; | 343 this._compile_errors = json.compile_errors || []; |
334 this._runtime_error = json.runtime_error || ""; | 344 this._runtime_error = json.runtime_error || ""; |
335 this.$.running.active = false; | 345 this.$.running.active = false; |
336 this.fire("fiddle-success", json.fiddleHash); | 346 this.fire("fiddle-success", json.fiddleHash); |
337 this._compile_errors.forEach(function(err) { | 347 this._compile_errors.forEach(function(err) { |
338 this._editor.addLineClass(+err.line-1, "wrap", "error"); | 348 this._editor.addLineClass(+err.line-1, "wrap", "error"); |
339 }.bind(this)); | 349 }.bind(this)); |
340 | 350 this.$.overwrite.checked = false; |
341 }.bind(this)).catch(function(err) { | 351 }.bind(this)).catch(function(err) { |
342 this.$.running.active = false; | 352 this.$.running.active = false; |
343 sk.errorMessage(err); | 353 sk.errorMessage(err); |
344 }.bind(this)); | 354 }.bind(this)); |
345 }, | 355 }, |
346 | 356 |
347 _errSelect: function(e) { | 357 _errSelect: function(e) { |
348 if (e.target.nodeName == "PRE") { | 358 if (e.target.nodeName == "PRE") { |
349 this._editor.setCursor(+e.target.dataset.line-1, +e.target.dataset.col-1
); | 359 this._editor.setCursor(+e.target.dataset.line-1, +e.target.dataset.col-1
); |
350 this._editor.focus(); | 360 this._editor.focus(); |
351 } | 361 } |
352 }, | 362 }, |
353 | 363 |
354 _bugLink: function(fiddleHash) { | 364 _bugLink: function(fiddleHash) { |
355 var comment = "Visit this link to see the issue on fiddle:\n\n https://fid
dle.skia.org/c/" + fiddleHash; | 365 var comment = "Visit this link to see the issue on fiddle:\n\n https://fid
dle.skia.org/c/" + fiddleHash; |
356 return "https://bugs.chromium.org/p/skia/issues/entry?" + sk.query.fromObj
ect({ | 366 return "https://bugs.chromium.org/p/skia/issues/entry?" + sk.query.fromObj
ect({ |
357 comment: comment, | 367 comment: comment, |
358 }); | 368 }); |
359 }, | 369 }, |
360 | 370 |
361 _hasImages: function(fiddlehash, compile_errors, runtime_error) { | 371 _hasImages: function(fiddlehash, compile_errors, runtime_error) { |
362 return fiddlehash != "" && runtime_error == "" && (compile_errors.length =
= 0); | 372 return fiddlehash != "" && runtime_error == "" && (compile_errors.length =
= 0); |
363 }, | 373 }, |
364 | 374 |
365 _hasCompileErrors: function(compile_errors) { | 375 _hasCompileErrors: function(compile_errors) { |
366 return compile_errors.length > 0; | 376 return compile_errors.length > 0; |
367 }, | 377 }, |
368 | 378 |
| 379 _isEmpty: function(name) { |
| 380 return name == ""; |
| 381 }, |
| 382 |
369 }); | 383 }); |
370 </script> | 384 </script> |
OLD | NEW |