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

Commit ba21dcd

Browse files
committed
Generate link to playground only when icon clicked
1 parent 3135402 commit ba21dcd

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ <h2>Featuring</h2>
6969
program, accumulator);
7070
}</div>
7171
<div id="result">
72-
<a id="playlink" onclick="f1()" href="http://play.rust-lang.org/"><i class="icon-link-ext"></i></a>
72+
<a id="playlink" onclick="goPlayground()" ><i class="icon-link-ext"></i></a>
7373
</div>
7474
</div>
7575
<div id="static-code">

js/editor.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ function handleResult(statusCode, message) {
122122
}
123123
}
124124

125-
// Called on successful program run: display output and link to playground
125+
// Called on successful program run: display output and playground icon
126126
function handleSuccess(message) {
127127
resultDiv.style.backgroundColor = successColor;
128128
var program = encodeURIComponent(editor.getValue());
129-
playLink.href = "http://play.rust-lang.org/?code=" + program + "&run=1"
129+
// playLink.href = "http://play.rust-lang.org/?code=" + program + "&run=1"
130130
// console.log(playLink.href);
131131
resultDiv.innerHTML = ''; // clear resultDiv, then add
132132
resultDiv.appendChild(playLink); // playLink icon and message
@@ -171,7 +171,7 @@ function handleProblem(message, problem) {
171171

172172
// Setting message
173173
var program = encodeURIComponent(editor.getValue());
174-
playLink.href = "http://play.rust-lang.org/?code=" + program + "&run=1"
174+
// playLink.href = "http://play.rust-lang.org/?code=" + program + "&run=1"
175175
// console.log(playLink.href);
176176
resultDiv.innerHTML = ''; // clear resultDiv, then add
177177
resultDiv.appendChild(playLink); // playLink icon and error message
@@ -221,6 +221,14 @@ runButton.addEventListener("click", function(ev) {
221221
runProgram(program, handleResult);
222222
});
223223

224+
// When clicking on the playground icon, navigate to the playground itself
225+
function goPlayground() {
226+
var program = "http://play.rust-lang.org/?code=" +
227+
encodeURIComponent(editor.getValue()) + "&run=1"
228+
window.location = program
229+
// console.log(program);
230+
}
231+
224232
// Highlight active line when focused
225233
editor.on('focus', function() {
226234
editor.setHighlightActiveLine(true);

0 commit comments

Comments
 (0)