Created
January 2, 2018 09:25
-
-
Save smallnest/f98f2ebd4de1d09bf3e0a26ac3db29a4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function () { | |
$(".gq-anwser-btn").click(function () { | |
$(this).html($(this).html() == "隐藏答案" ? "显示答案" : "隐藏答案").next(".gq-anwser").toggle() | |
}) | |
$(".gq-run-btn").click(function () { | |
var $this = $(this), $code, $output | |
if ($this.prev().is(".output")) { | |
$output = $this.prev() | |
$code = $output.prev().find("textarea") | |
$output.removeClass().addClass("output bs-callout").html("<img src='/assets/compiling.gif' />") | |
} else { | |
$code = $this.prev().find("textarea") | |
$this.before("<div class='output bs-callout'><img src='/assets/compiling.gif' /></div>") | |
$output = $this.prev() | |
} | |
$.ajax({ | |
type: "POST", | |
headers: { | |
"x-requested-with": location.host | |
}, | |
dataType: "json", | |
data: { body: $code.val() }, | |
url: "https://cors-anywhere.herokuapp.com/https://play.golang.org/compile", | |
success: function (data) { | |
var output, cls | |
if(data.compile_errors){ | |
output = data.compile_errors | |
cls = "bs-callout-danger" | |
}else if(data.Errors){ | |
output = data.Errors | |
cls = "bs-callout-warning" | |
}else{ | |
if(data.output){ | |
output = data.output | |
}else { | |
output = $.map(data.Events,e=>e.Message).join("<br/>") | |
} | |
cls = "bs-callout-info" | |
} | |
$output.addClass(cls).html(output.replace(/\n/g, "<br/>")) | |
} | |
}); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment