|
38 | 38 | * If some tests are failing, load test suites individually to continue |
39 | 39 | * debugging. |
40 | 40 | */ |
41 | | -function loadSelected() { |
| 41 | +async function loadSelected() { |
42 | 42 | var output = document.getElementById('importExport'); |
43 | 43 | output.style.background = 'gray'; |
44 | 44 |
|
|
53 | 53 | if (boxList[i].checked) { |
54 | 54 | var testUrl = boxList[i].value; |
55 | 55 | if (testUrl) { |
56 | | - var xmlText = fetchFile(testUrl); |
| 56 | + var xmlText = await fetchFile(testUrl); |
57 | 57 | if (xmlText !== null) { |
58 | 58 | fromXml(testUrl, xmlText, /* opt_append */ true); |
| 59 | + // Clean up the workspace to normalize the position of blocks and |
| 60 | + // thus the order of functions in the generated code. |
| 61 | + Blockly.getMainWorkspace().cleanUp(); |
59 | 62 | } |
60 | 63 | } |
61 | 64 | } |
|
67 | 70 | /** |
68 | 71 | * Ask the user for a file name, then load that file's contents. |
69 | 72 | */ |
70 | | -function loadOther() { |
| 73 | +async function loadOther() { |
71 | 74 | var url = window.prompt('Enter URL of test file.'); |
72 | 75 | if (!url) { |
73 | 76 | return; |
74 | 77 | } |
75 | | - var xmlText = fetchFile(url); |
| 78 | + var xmlText = await fetchFile(url); |
76 | 79 | if (xmlText !== null) { |
77 | 80 | fromXml(url, xmlText); |
78 | 81 | } |
79 | 82 | } |
80 | 83 |
|
81 | | -function fetchFile(xmlUrl) { |
| 84 | +async function fetchFile(xmlUrl) { |
82 | 85 | try { |
83 | | - var xmlHttp = new XMLHttpRequest(); |
84 | | - xmlHttp.open('GET', xmlUrl, false); |
85 | | - xmlHttp.setRequestHeader('Content-Type', 'text/xml'); |
86 | | - xmlHttp.send(''); |
| 86 | + const response = await fetch(xmlUrl); |
| 87 | + if (!response.ok) { |
| 88 | + throw new Error(`Got a 404 when loading ${xmlUrl}`); |
| 89 | + } |
| 90 | + return response.text(); |
87 | 91 | } catch (e) { |
88 | 92 | // Attempt to diagnose the problem. |
89 | 93 | var msg = 'Error: Unable to load XML data.\n'; |
|
95 | 99 | alert(msg + '\n' + e); |
96 | 100 | return null; |
97 | 101 | } |
98 | | - return xmlHttp.responseText; |
99 | 102 | } |
100 | 103 |
|
101 | 104 | /** |
|
188 | 191 | function changeIndex() { |
189 | 192 | var oneBasedIndex = document.getElementById('indexing').checked; |
190 | 193 | demoWorkspace.options.oneBasedIndex = oneBasedIndex; |
191 | | - demoWorkspace.getToolbox().flyout_.workspace_.options.oneBasedIndex = oneBasedIndex; |
| 194 | + demoWorkspace.getToolbox().getFlyout().getWorkspace().options.oneBasedIndex = oneBasedIndex; |
192 | 195 | } |
193 | 196 | </script> |
194 | 197 |
|
|
0 commit comments