Skip to content
This repository was archived by the owner on Sep 30, 2020. It is now read-only.

Commit 2c3a69e

Browse files
committed
Modify HTML link from editor.js, add playground link on error
1 parent 6b6f667 commit 2c3a69e

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

index.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ <h2>Featuring</h2>
6868
println!("The program \"{}\" calculates the value {}",
6969
program, accumulator);
7070
}</div>
71-
<div id="result"></div>
71+
<div id="result">
72+
<a id="playlink" onclick="f1()" href="http://play.rust-lang.org/"><i class="icon-link-ext"></i></a>
73+
</div>
7274
</div>
7375
<div id="static-code">
7476
<pre class='rust'>
@@ -121,7 +123,7 @@ <h2>Featuring</h2>
121123

122124
return os;
123125
}
124-
126+
125127
var platform = detect_platform();
126128

127129
var rec_package_name = "nightly";
@@ -149,7 +151,7 @@ <h2>Featuring</h2>
149151
var rec_dl_addy = "http://static.rust-lang.org/dist/" + rec_download_file;
150152
var rec_inst_link = document.getElementById("inst-link");
151153
rec_inst_link.setAttribute("href", rec_dl_addy);
152-
154+
153155
</script>
154156
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.1.3/ace.js"></script>
155157
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/ace/1.1.3/mode-rust.js"></script>

js/editor.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var editorDiv = document.getElementById("editor");
1414
var staticCode = document.getElementById("static-code");
1515
var runButton = document.getElementById("run-code");
1616
var resultDiv = document.getElementById("result");
17+
var playLink = document.getElementById("playlink");
1718

1819
// Background colors for program result on success/error
1920
var successColor = "#E2EEF6";
@@ -125,10 +126,11 @@ function handleResult(statusCode, message) {
125126
function handleSuccess(message) {
126127
resultDiv.style.backgroundColor = successColor;
127128
var program = encodeURIComponent(editor.getValue());
128-
var output = "<a href=\"http://play.rust-lang.org/?code=" + program +
129-
"&run=1\"><i class=\"icon-link-ext\"></i></a>"
130-
// console.log(output);
131-
resultDiv.innerHTML = output + escapeHTML(message);
129+
playLink.href = "http://play.rust-lang.org/?code=" + program + "&run=1"
130+
// console.log(playLink.href);
131+
resultDiv.innerHTML = ''; // clear resultDiv, then add
132+
resultDiv.appendChild(playLink); // playLink icon and message
133+
resultDiv.innerHTML += escapeHTML(message);
132134
}
133135

134136
// Called when program run results in warning(s)
@@ -168,7 +170,12 @@ function handleProblem(message, problem) {
168170
}).join("<br />");
169171

170172
// Setting message
171-
resultDiv.innerHTML = cleanMessage;
173+
var program = encodeURIComponent(editor.getValue());
174+
playLink.href = "http://play.rust-lang.org/?code=" + program + "&run=1"
175+
// console.log(playLink.href);
176+
resultDiv.innerHTML = ''; // clear resultDiv, then add
177+
resultDiv.appendChild(playLink); // playLink icon and error message
178+
resultDiv.innerHTML += cleanMessage;
172179

173180
// Highlighting the lines
174181
var ranges = parseProblems(lines);

0 commit comments

Comments
 (0)