2015-07-29 19:34:48 +08:00
|
|
|
$( document ).ready(function() {
|
|
|
|
|
2015-09-05 23:26:17 +08:00
|
|
|
// url
|
|
|
|
var url = window.location.pathname;
|
|
|
|
|
2015-09-25 04:32:41 +08:00
|
|
|
// Fix back button cache problem
|
|
|
|
window.onunload = function(){};
|
2015-09-24 22:47:33 +08:00
|
|
|
|
2015-09-14 14:39:53 +08:00
|
|
|
// Set theme
|
2017-09-20 04:59:16 +08:00
|
|
|
var theme = store.get('mdbook-theme');
|
2017-06-12 03:54:09 +08:00
|
|
|
if (theme === null || theme === undefined) { theme = 'light'; }
|
2015-09-14 14:39:53 +08:00
|
|
|
|
|
|
|
set_theme(theme);
|
|
|
|
|
2015-08-06 00:28:59 +08:00
|
|
|
// Syntax highlighting Configuration
|
|
|
|
hljs.configure({
|
|
|
|
tabReplace: ' ', // 4 spaces
|
|
|
|
languages: [], // Languages used for auto-detection
|
|
|
|
});
|
2017-08-08 06:36:38 +08:00
|
|
|
|
2017-06-29 12:35:20 +08:00
|
|
|
if (window.ace) {
|
|
|
|
// language-rust class needs to be removed for editable
|
|
|
|
// blocks or highlightjs will capture events
|
|
|
|
$('code.editable').removeClass('language-rust');
|
2015-08-06 00:28:59 +08:00
|
|
|
|
2017-06-29 12:35:20 +08:00
|
|
|
$('code').not('.editable').each(function(i, block) {
|
|
|
|
hljs.highlightBlock(block);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$('code').each(function(i, block) {
|
|
|
|
hljs.highlightBlock(block);
|
|
|
|
});
|
|
|
|
}
|
2017-08-08 06:36:38 +08:00
|
|
|
|
Add hljs class to all code blocks, regardless of highlighting
Fixes #179.
Highlight.js does not apply syntax highlighting to code blocks marked
no-highlight, nohighlight, plain, or text. When it finds blocks of those
languages, it does not add the `hljs` class to those code blocks either.
highlight.css and tomorrow-night.css use the `hljs` class to give code
blocks their backrgound color and text color, and we want that to apply
even if the code doesn't get syntax highlighting markup.
This is a somewhat hacky solution to get just that behavior! After this
commit, code blocks with no-highlight, nohighlight, plain, or text
language set on them will indeed get the hljs colors.
2016-11-14 10:14:00 +08:00
|
|
|
// Adding the hljs class gives code blocks the color css
|
|
|
|
// even if highlighting doesn't apply
|
|
|
|
$('code').addClass('hljs');
|
2015-08-06 00:28:59 +08:00
|
|
|
|
2015-12-30 23:30:08 +08:00
|
|
|
var KEY_CODES = {
|
|
|
|
PREVIOUS_KEY: 37,
|
|
|
|
NEXT_KEY: 39
|
|
|
|
};
|
|
|
|
|
|
|
|
$(document).on('keydown', function (e) {
|
2017-03-23 15:59:04 +08:00
|
|
|
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { return; }
|
2015-12-30 23:30:08 +08:00
|
|
|
switch (e.keyCode) {
|
|
|
|
case KEY_CODES.NEXT_KEY:
|
|
|
|
e.preventDefault();
|
2015-12-31 00:19:43 +08:00
|
|
|
if($('.nav-chapters.next').length) {
|
|
|
|
window.location.href = $('.nav-chapters.next').attr('href');
|
|
|
|
}
|
2015-12-30 23:30:08 +08:00
|
|
|
break;
|
|
|
|
case KEY_CODES.PREVIOUS_KEY:
|
|
|
|
e.preventDefault();
|
2015-12-31 00:19:43 +08:00
|
|
|
if($('.nav-chapters.previous').length) {
|
|
|
|
window.location.href = $('.nav-chapters.previous').attr('href');
|
|
|
|
}
|
2015-12-30 23:30:08 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2015-08-06 00:28:59 +08:00
|
|
|
|
2015-07-29 19:34:48 +08:00
|
|
|
// Interesting DOM Elements
|
|
|
|
var sidebar = $("#sidebar");
|
2017-06-16 03:12:28 +08:00
|
|
|
|
|
|
|
// Help keyboard navigation by always focusing on page content
|
|
|
|
$(".page").focus();
|
2015-12-28 06:17:59 +08:00
|
|
|
|
2015-09-24 22:47:33 +08:00
|
|
|
// Toggle sidebar
|
2017-06-09 21:51:30 +08:00
|
|
|
$("#sidebar-toggle").click(sidebarToggle);
|
|
|
|
|
|
|
|
// Hide sidebar on section link click if it occupies large space
|
|
|
|
// in relation to the whole screen (phone in portrait)
|
|
|
|
$("#sidebar a").click(function(event){
|
|
|
|
if (sidebar.width() > window.screen.width * 0.4) {
|
|
|
|
sidebarToggle();
|
2015-07-29 19:34:48 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-12-27 11:45:50 +08:00
|
|
|
// Scroll sidebar to current active section
|
|
|
|
var activeSection = sidebar.find(".active");
|
|
|
|
if(activeSection.length) {
|
|
|
|
sidebar.scrollTop(activeSection.offset().top);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-11 07:16:29 +08:00
|
|
|
// Theme button
|
|
|
|
$("#theme-toggle").click(function(){
|
|
|
|
if($('.theme-popup').length) {
|
|
|
|
$('.theme-popup').remove();
|
|
|
|
} else {
|
|
|
|
var popup = $('<div class="theme-popup"></div>')
|
2016-02-04 00:55:19 +08:00
|
|
|
.append($('<div class="theme" id="light">Light <span class="default">(default)</span><div>'))
|
2015-09-14 17:25:42 +08:00
|
|
|
.append($('<div class="theme" id="rust">Rust</div>'))
|
2015-09-14 14:39:53 +08:00
|
|
|
.append($('<div class="theme" id="coal">Coal</div>'))
|
2017-06-07 04:35:44 +08:00
|
|
|
.append($('<div class="theme" id="navy">Navy</div>'))
|
|
|
|
.append($('<div class="theme" id="ayu">Ayu</div>'));
|
2015-09-11 07:16:29 +08:00
|
|
|
|
|
|
|
|
2016-02-04 00:55:19 +08:00
|
|
|
popup.insertAfter(this);
|
2015-09-11 07:16:29 +08:00
|
|
|
|
|
|
|
$('.theme').click(function(){
|
|
|
|
var theme = $(this).attr('id');
|
2015-12-28 23:39:14 +08:00
|
|
|
set_theme(theme);
|
2015-09-11 07:16:29 +08:00
|
|
|
});
|
|
|
|
}
|
2017-06-23 19:18:06 +08:00
|
|
|
});
|
2015-09-11 07:16:29 +08:00
|
|
|
|
2017-06-23 19:18:06 +08:00
|
|
|
// Hide theme selector popup when clicking outside of it
|
|
|
|
$(document).click(function(event){
|
|
|
|
var popup = $('.theme-popup');
|
|
|
|
if(popup.length) {
|
|
|
|
var target = $(event.target);
|
|
|
|
if(!target.closest('.theme').length && !target.closest('#theme-toggle').length) {
|
|
|
|
popup.remove();
|
|
|
|
}
|
|
|
|
}
|
2015-09-11 07:16:29 +08:00
|
|
|
});
|
|
|
|
|
2015-09-14 14:39:53 +08:00
|
|
|
function set_theme(theme) {
|
2017-06-29 12:35:20 +08:00
|
|
|
let ace_theme;
|
2017-08-08 06:36:38 +08:00
|
|
|
|
2015-09-14 14:39:53 +08:00
|
|
|
if (theme == 'coal' || theme == 'navy') {
|
2017-06-07 04:35:44 +08:00
|
|
|
$("[href='ayu-highlight.css']").prop('disabled', true);
|
2015-09-14 14:39:53 +08:00
|
|
|
$("[href='tomorrow-night.css']").prop('disabled', false);
|
|
|
|
$("[href='highlight.css']").prop('disabled', true);
|
2017-08-08 06:36:38 +08:00
|
|
|
|
2017-06-29 12:35:20 +08:00
|
|
|
ace_theme = "ace/theme/tomorrow_night";
|
2017-06-07 04:35:44 +08:00
|
|
|
} else if (theme == 'ayu') {
|
|
|
|
$("[href='ayu-highlight.css']").prop('disabled', false);
|
|
|
|
$("[href='tomorrow-night.css']").prop('disabled', true);
|
|
|
|
$("[href='highlight.css']").prop('disabled', true);
|
2017-08-08 06:36:38 +08:00
|
|
|
|
2017-06-29 12:35:20 +08:00
|
|
|
ace_theme = "ace/theme/tomorrow_night";
|
2015-09-14 14:39:53 +08:00
|
|
|
} else {
|
2017-06-07 04:35:44 +08:00
|
|
|
$("[href='ayu-highlight.css']").prop('disabled', true);
|
2015-09-14 14:39:53 +08:00
|
|
|
$("[href='tomorrow-night.css']").prop('disabled', true);
|
|
|
|
$("[href='highlight.css']").prop('disabled', false);
|
2017-08-08 06:36:38 +08:00
|
|
|
|
2017-06-29 12:35:20 +08:00
|
|
|
ace_theme = "ace/theme/dawn";
|
|
|
|
}
|
2017-08-08 06:36:38 +08:00
|
|
|
|
2017-06-29 12:35:20 +08:00
|
|
|
if (window.ace && window.editors) {
|
|
|
|
window.editors.forEach(function(editor) {
|
|
|
|
editor.setTheme(ace_theme);
|
|
|
|
});
|
2015-09-14 14:39:53 +08:00
|
|
|
}
|
|
|
|
|
2017-09-20 04:59:16 +08:00
|
|
|
store.set('mdbook-theme', theme);
|
2015-09-14 14:39:53 +08:00
|
|
|
|
|
|
|
$('body').removeClass().addClass(theme);
|
|
|
|
}
|
2015-12-29 06:52:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
// Hide Rust code lines prepended with a specific character
|
|
|
|
var hiding_character = "#";
|
|
|
|
|
|
|
|
$("code.language-rust").each(function(i, block){
|
2015-12-29 20:08:25 +08:00
|
|
|
|
2016-01-01 07:32:12 +08:00
|
|
|
var code_block = $(this);
|
|
|
|
var pre_block = $(this).parent();
|
2015-12-29 20:08:25 +08:00
|
|
|
// hide lines
|
2016-01-01 07:32:12 +08:00
|
|
|
var lines = code_block.html().split("\n");
|
2015-12-29 19:26:32 +08:00
|
|
|
var first_non_hidden_line = false;
|
2015-12-29 20:08:25 +08:00
|
|
|
var lines_hidden = false;
|
2015-12-29 06:52:05 +08:00
|
|
|
|
|
|
|
for(var n = 0; n < lines.length; n++){
|
|
|
|
if($.trim(lines[n])[0] == hiding_character){
|
2015-12-29 20:08:25 +08:00
|
|
|
if(first_non_hidden_line){
|
2017-05-18 06:04:09 +08:00
|
|
|
lines[n] = "<span class=\"hidden\">" + "\n" + lines[n].replace(/(\s*)# ?/, "$1") + "</span>";
|
2015-12-29 20:08:25 +08:00
|
|
|
}
|
|
|
|
else {
|
2017-05-18 06:04:09 +08:00
|
|
|
lines[n] = "<span class=\"hidden\">" + lines[n].replace(/(\s*)# ?/, "$1") + "\n" + "</span>";
|
2015-12-29 20:08:25 +08:00
|
|
|
}
|
|
|
|
lines_hidden = true;
|
2015-12-29 19:26:32 +08:00
|
|
|
}
|
|
|
|
else if(first_non_hidden_line) {
|
|
|
|
lines[n] = "\n" + lines[n];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
first_non_hidden_line = true;
|
2015-12-29 06:52:05 +08:00
|
|
|
}
|
|
|
|
}
|
2016-01-01 07:32:12 +08:00
|
|
|
code_block.html(lines.join(""));
|
2015-12-29 20:08:25 +08:00
|
|
|
|
|
|
|
// If no lines were hidden, return
|
|
|
|
if(!lines_hidden) { return; }
|
|
|
|
|
|
|
|
// add expand button
|
2016-01-01 07:32:12 +08:00
|
|
|
pre_block.prepend("<div class=\"buttons\"><i class=\"fa fa-expand\"></i></div>");
|
2015-12-29 20:08:25 +08:00
|
|
|
|
2016-01-01 07:32:12 +08:00
|
|
|
pre_block.find("i").click(function(e){
|
2015-12-29 20:08:25 +08:00
|
|
|
if( $(this).hasClass("fa-expand") ) {
|
|
|
|
$(this).removeClass("fa-expand").addClass("fa-compress");
|
2016-01-01 07:32:12 +08:00
|
|
|
pre_block.find("span.hidden").removeClass("hidden").addClass("unhidden");
|
2015-12-29 20:08:25 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$(this).removeClass("fa-compress").addClass("fa-expand");
|
2016-01-01 07:32:12 +08:00
|
|
|
pre_block.find("span.unhidden").removeClass("unhidden").addClass("hidden");
|
2015-12-29 20:08:25 +08:00
|
|
|
}
|
|
|
|
});
|
2015-12-29 06:52:05 +08:00
|
|
|
});
|
|
|
|
|
2016-01-01 07:32:12 +08:00
|
|
|
// Process playpen code blocks
|
|
|
|
$(".playpen").each(function(block){
|
|
|
|
var pre_block = $(this);
|
|
|
|
// Add play button
|
|
|
|
var buttons = pre_block.find(".buttons");
|
|
|
|
if( buttons.length === 0 ) {
|
|
|
|
pre_block.prepend("<div class=\"buttons\"></div>");
|
|
|
|
buttons = pre_block.find(".buttons");
|
|
|
|
}
|
2017-08-08 06:05:33 +08:00
|
|
|
buttons.prepend("<i class=\"fa fa-play play-button hidden\"></i>");
|
2017-05-31 07:14:01 +08:00
|
|
|
buttons.prepend("<i class=\"fa fa-copy clip-button\"><i class=\"tooltiptext\"></i></i>");
|
2016-01-01 07:32:12 +08:00
|
|
|
|
2017-06-29 12:35:20 +08:00
|
|
|
let code_block = pre_block.find("code").first();
|
|
|
|
if (window.ace && code_block.hasClass("editable")) {
|
|
|
|
buttons.prepend("<i class=\"fa fa-history reset-button\"></i>");
|
|
|
|
}
|
|
|
|
|
2016-01-01 07:32:12 +08:00
|
|
|
buttons.find(".play-button").click(function(e){
|
|
|
|
run_rust_code(pre_block);
|
|
|
|
});
|
2017-05-31 07:14:01 +08:00
|
|
|
buttons.find(".clip-button").mouseout(function(e){
|
2017-06-01 03:07:30 +08:00
|
|
|
hideTooltip(e.currentTarget);
|
2017-05-31 07:14:01 +08:00
|
|
|
});
|
2017-06-29 12:35:20 +08:00
|
|
|
buttons.find(".reset-button").click(function() {
|
|
|
|
if (!window.ace) { return; }
|
|
|
|
let editor = window.ace.edit(code_block.get(0));
|
|
|
|
editor.setValue(editor.originalCode);
|
|
|
|
editor.clearSelection();
|
|
|
|
});
|
2016-01-01 07:32:12 +08:00
|
|
|
});
|
|
|
|
|
2017-05-31 07:14:01 +08:00
|
|
|
var clipboardSnippets = new Clipboard('.clip-button', {
|
|
|
|
text: function(trigger) {
|
2017-06-01 03:07:30 +08:00
|
|
|
hideTooltip(trigger);
|
2017-06-29 12:35:20 +08:00
|
|
|
let playpen = $(trigger).parents(".playpen");
|
2017-08-08 06:05:33 +08:00
|
|
|
return playpen_text(playpen);
|
2017-05-31 07:14:01 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
clipboardSnippets.on('success', function(e) {
|
|
|
|
e.clearSelection();
|
2017-06-01 03:07:30 +08:00
|
|
|
showTooltip(e.trigger, "Copied!");
|
2017-05-31 07:14:01 +08:00
|
|
|
});
|
|
|
|
clipboardSnippets.on('error', function(e) {
|
2017-06-01 03:07:30 +08:00
|
|
|
showTooltip(e.trigger, "Clipboard error!");
|
2017-05-31 07:14:01 +08:00
|
|
|
});
|
2017-08-08 06:05:33 +08:00
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: "https://play.rust-lang.org/meta/crates",
|
|
|
|
method: "POST",
|
|
|
|
crossDomain: true,
|
|
|
|
dataType: "json",
|
|
|
|
contentType: "application/json",
|
|
|
|
success: function(response){
|
2017-08-08 06:36:38 +08:00
|
|
|
// get list of crates available in the rust playground
|
|
|
|
let playground_crates = response.crates.map(function(item) {return item["id"];} );
|
|
|
|
$(".playpen").each(function(block) {
|
|
|
|
handle_crate_list_update($(this), playground_crates);
|
2017-08-08 06:05:33 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2015-07-29 19:34:48 +08:00
|
|
|
});
|
2016-01-01 07:32:12 +08:00
|
|
|
|
2017-08-08 06:05:33 +08:00
|
|
|
function playpen_text(playpen) {
|
|
|
|
let code_block = playpen.find("code").first();
|
|
|
|
|
|
|
|
if (window.ace && code_block.hasClass("editable")) {
|
|
|
|
let editor = window.ace.edit(code_block.get(0));
|
|
|
|
return editor.getValue();
|
|
|
|
} else {
|
|
|
|
return code_block.get(0).textContent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-08 06:36:38 +08:00
|
|
|
function handle_crate_list_update(playpen_block, playground_crates) {
|
|
|
|
// update the play buttons after receiving the response
|
|
|
|
update_play_button(playpen_block, playground_crates);
|
|
|
|
|
|
|
|
// and install on change listener to dynamically update ACE editors
|
|
|
|
if (window.ace) {
|
|
|
|
let code_block = playpen_block.find("code").first();
|
|
|
|
if (code_block.hasClass("editable")) {
|
|
|
|
let editor = window.ace.edit(code_block.get(0));
|
|
|
|
editor.on("change", function(e){
|
|
|
|
update_play_button(playpen_block, playground_crates);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// updates the visibility of play button based on `no_run` class and
|
|
|
|
// used crates vs ones available on http://play.rust-lang.org
|
|
|
|
function update_play_button(pre_block, playground_crates) {
|
2017-08-08 06:05:33 +08:00
|
|
|
var play_button = pre_block.find(".play-button");
|
|
|
|
|
2017-08-08 06:36:38 +08:00
|
|
|
var classes = pre_block.find("code").attr("class").split(" ");
|
|
|
|
// skip if code is `no_run`
|
|
|
|
if (classes.indexOf("no_run") > -1) {
|
|
|
|
play_button.addClass("hidden");
|
|
|
|
return;
|
|
|
|
}
|
2017-08-08 06:05:33 +08:00
|
|
|
|
2017-08-08 06:36:38 +08:00
|
|
|
// get list of `extern crate`'s from snippet
|
|
|
|
var txt = playpen_text(pre_block);
|
2017-08-08 06:05:33 +08:00
|
|
|
var re = /extern\s+crate\s+([a-zA-Z_0-9]+)\s*;/g;
|
|
|
|
var snippet_crates = [];
|
2017-08-08 06:36:38 +08:00
|
|
|
while (item = re.exec(txt)) {
|
2017-08-08 06:05:33 +08:00
|
|
|
snippet_crates.push(item[1]);
|
2017-08-08 06:36:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// check if all used crates are available on play.rust-lang.org
|
|
|
|
var all_available = snippet_crates.every(function(elem) {
|
|
|
|
return playground_crates.indexOf(elem) > -1;
|
|
|
|
});
|
2017-08-08 06:05:33 +08:00
|
|
|
|
|
|
|
if (all_available) {
|
|
|
|
play_button.removeClass("hidden");
|
|
|
|
} else {
|
|
|
|
play_button.addClass("hidden");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-01 03:07:30 +08:00
|
|
|
function hideTooltip(elem) {
|
|
|
|
elem.firstChild.innerText="";
|
|
|
|
elem.setAttribute('class', 'fa fa-copy clip-button');
|
|
|
|
}
|
|
|
|
|
2017-05-31 07:14:01 +08:00
|
|
|
function showTooltip(elem, msg) {
|
2017-06-01 03:07:30 +08:00
|
|
|
elem.firstChild.innerText=msg;
|
|
|
|
elem.setAttribute('class', 'fa fa-copy tooltipped');
|
2017-05-31 07:14:01 +08:00
|
|
|
}
|
2016-01-01 07:32:12 +08:00
|
|
|
|
2017-06-09 21:51:30 +08:00
|
|
|
function sidebarToggle() {
|
|
|
|
var html = $("html");
|
|
|
|
if ( html.hasClass("sidebar-hidden") ) {
|
|
|
|
html.removeClass("sidebar-hidden").addClass("sidebar-visible");
|
2017-09-23 01:58:45 +08:00
|
|
|
store.set('mdbook-sidebar', 'visible');
|
2017-06-09 21:51:30 +08:00
|
|
|
} else if ( html.hasClass("sidebar-visible") ) {
|
|
|
|
html.removeClass("sidebar-visible").addClass("sidebar-hidden");
|
2017-09-23 01:58:45 +08:00
|
|
|
store.set('mdbook-sidebar', 'hidden');
|
2017-06-09 21:51:30 +08:00
|
|
|
} else {
|
|
|
|
if($("#sidebar").position().left === 0){
|
|
|
|
html.addClass("sidebar-hidden");
|
2017-09-23 01:58:45 +08:00
|
|
|
store.set('mdbook-sidebar', 'hidden');
|
2017-06-09 21:51:30 +08:00
|
|
|
} else {
|
|
|
|
html.addClass("sidebar-visible");
|
2017-09-23 01:58:45 +08:00
|
|
|
store.set('mdbook-sidebar', 'visible');
|
2017-06-09 21:51:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-01 07:32:12 +08:00
|
|
|
function run_rust_code(code_block) {
|
|
|
|
var result_block = code_block.find(".result");
|
|
|
|
if(result_block.length === 0) {
|
|
|
|
code_block.append("<code class=\"result hljs language-bash\"></code>");
|
|
|
|
result_block = code_block.find(".result");
|
|
|
|
}
|
|
|
|
|
2017-09-21 11:24:47 +08:00
|
|
|
let text = playpen_text(code_block);
|
|
|
|
|
2017-06-10 02:59:29 +08:00
|
|
|
var params = {
|
2017-09-21 11:24:47 +08:00
|
|
|
channel: "stable",
|
|
|
|
mode: "debug",
|
|
|
|
crateType: "bin",
|
|
|
|
tests: false,
|
|
|
|
code: text,
|
|
|
|
}
|
2017-04-01 05:06:03 +08:00
|
|
|
|
2017-06-10 03:48:57 +08:00
|
|
|
if(text.indexOf("#![feature") !== -1) {
|
2017-09-21 11:24:47 +08:00
|
|
|
params.channel = "nightly";
|
2017-04-01 05:06:03 +08:00
|
|
|
}
|
|
|
|
|
2016-01-01 07:32:12 +08:00
|
|
|
result_block.text("Running...");
|
|
|
|
|
|
|
|
$.ajax({
|
2017-09-21 11:24:47 +08:00
|
|
|
url: "https://play.rust-lang.org/execute",
|
2016-01-01 07:32:12 +08:00
|
|
|
method: "POST",
|
|
|
|
crossDomain: true,
|
|
|
|
dataType: "json",
|
|
|
|
contentType: "application/json",
|
2017-04-01 05:06:03 +08:00
|
|
|
data: JSON.stringify(params),
|
2017-08-06 20:59:03 +08:00
|
|
|
timeout: 15000,
|
2016-01-01 07:32:12 +08:00
|
|
|
success: function(response){
|
2017-09-21 11:24:47 +08:00
|
|
|
result_block.text(response.success ? response.stdout : response.stderr);
|
2017-08-06 20:59:03 +08:00
|
|
|
},
|
|
|
|
error: function(qXHR, textStatus, errorThrown){
|
2017-08-06 23:10:52 +08:00
|
|
|
result_block.text("Playground communication " + textStatus);
|
2017-08-06 20:59:03 +08:00
|
|
|
},
|
2016-01-01 07:32:12 +08:00
|
|
|
});
|
|
|
|
}
|