|
19 | 19 | function handleQuery(key, val) {
|
20 | 20 | Espruino.Core.Code.switchToCode(); // if in blockly
|
21 | 21 | switch(key){
|
22 |
| - case "code": |
| 22 | + case "code": // Passing "encodedURIcomponent code" within the URL |
23 | 23 | Espruino.Core.EditorJavaScript.setCode(val);
|
24 | 24 | break;
|
25 |
| - case "codeurl": |
26 |
| - Espruino.Core.EditorJavaScript.setCode("Loading from "+val+"..."); |
27 |
| - $.get(val, function(data){ |
| 25 | + case "codeurl": // Passing a URL for code within the URL |
| 26 | + Espruino.Core.EditorJavaScript.setCode("// Loading from "+val+"..."); |
| 27 | + $.ajax({ url: val, cache: false }).done(function( data ) { |
28 | 28 | Espruino.Core.EditorJavaScript.setCode(data);
|
29 | 29 | }).error(function(){
|
30 |
| - Espruino.Core.EditorJavaScript.setCode("ERROR"); |
| 30 | + Espruino.Core.EditorJavaScript.setCode("// Error loading "+val); |
31 | 31 | });
|
32 | 32 | break;
|
33 |
| - case "upload": |
| 33 | + case "upload": // Get "encodedURIcomponent code" from URL and upload it |
34 | 34 | Espruino.Core.MenuPortSelector.ensureConnected(function() {
|
35 | 35 | Espruino.Core.Terminal.focus(); // give the terminal focus
|
36 | 36 | Espruino.callProcessor("sending");
|
37 | 37 | Espruino.Core.CodeWriter.writeToEspruino(val);
|
38 | 38 | Espruino.Core.EditorJavaScript.setCode(val);
|
39 | 39 | });
|
40 | 40 | break;
|
41 |
| - case "gist": |
42 |
| - Espruino.Core.EditorJavaScript.setCode("Loading..."); |
| 41 | + case "gist": // Get code from a gist number in the URL |
| 42 | + Espruino.Core.EditorJavaScript.setCode("// Loading Gist "+val+"..."); |
43 | 43 | $.getJSON("https://api.github.com/gists/"+ val, function(data){
|
44 | 44 | if(data && data.files){
|
45 | 45 | var keys = Object.keys(data.files);
|
|
48 | 48 | }
|
49 | 49 | }
|
50 | 50 | }).error(function(){
|
51 |
| - Espruino.Core.EditorJavaScript.setCode("ERROR"); |
| 51 | + Espruino.Core.EditorJavaScript.setCode("// Error loading Gist "+val); |
52 | 52 | });
|
53 | 53 | break;
|
54 | 54 | }
|
|
0 commit comments