|
61 | 61 | // Set initial size to match initial content
|
62 | 62 | updateEditorHeight();
|
63 | 63 |
|
| 64 | + // Safely remove all content from the result div |
| 65 | + function clearResultDiv() { |
| 66 | + // Clearing the result div will break our reference to |
| 67 | + // the playlink icon, so let's save it if it exists |
| 68 | + var newPlayLink = document.getElementById("playlink"); |
| 69 | + if (newPlayLink) { |
| 70 | + playLink = resultDiv.removeChild(newPlayLink); |
| 71 | + } |
| 72 | + resultDiv.innerHTML = ""; |
| 73 | + } |
| 74 | + |
64 | 75 | function escapeHTML(unsafe) {
|
65 | 76 | return unsafe
|
66 | 77 | .replace(/&/g, "&")
|
|
123 | 134 | function handleResult(statusCode, message) {
|
124 | 135 | // Dispatch depending on result type
|
125 | 136 | if (result == null) {
|
| 137 | + clearResultDiv(); |
126 | 138 | resultDiv.style.backgroundColor = errorColor;
|
127 | 139 | resultDiv.innerHTML = errMsg;
|
128 | 140 | } else if (statusCode === SUCCESS) {
|
|
213 | 225 | // Registering handler for run button click
|
214 | 226 | runButton.addEventListener("click", function(ev) {
|
215 | 227 | resultDiv.style.display = "block";
|
| 228 | + clearResultDiv(); |
216 | 229 | resultDiv.innerHTML = "Running...";
|
217 | 230 |
|
218 | 231 | // clear previous markers, if any
|
|
229 | 242 | encodeURIComponent(program) + "&run=1";
|
230 | 243 | playLink.href = programUrl;
|
231 | 244 |
|
232 |
| - resultDiv.innerHTML = ''; // clear resultDiv, then add |
| 245 | + clearResultDiv(); // clear resultDiv, then add |
233 | 246 | resultDiv.appendChild(playLink); // playLink icon and message
|
234 | 247 | resultDiv.innerHTML += message;
|
235 | 248 | }
|
|
0 commit comments