Merge pull request #709 from mattico/no-playpen-no-fetch

Only fetch crates list on pages with playpens
This commit is contained in:
Matt Ickstadt 2018-07-23 12:06:02 -05:00 committed by GitHub
commit 96b99472fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 18 deletions

View File

@ -18,13 +18,23 @@ function playpen_text(playpen) {
(function codeSnippets() {
// Hide Rust code lines prepended with a specific character
var hiding_character = "#";
var request = fetch("https://play.rust-lang.org/meta/crates", {
headers: {
'Content-Type': "application/json",
},
method: 'POST',
mode: 'cors',
});
var playpens = Array.from(document.querySelectorAll(".playpen"));
if (playpens.length > 0) {
fetch("https://play.rust-lang.org/meta/crates", {
headers: {
'Content-Type': "application/json",
},
method: 'POST',
mode: 'cors',
})
.then(response => response.json())
.then(response => {
// get list of crates available in the rust playground
let playground_crates = response.crates.map(item => item["id"]);
playpens.forEach(block => handle_crate_list_update(block, playground_crates));
});
}
function handle_crate_list_update(playpen_block, playground_crates) {
// update the play buttons after receiving the response
@ -274,17 +284,6 @@ function playpen_text(playpen) {
});
}
});
request
.then(function (response) { return response.json(); })
.then(function (response) {
// get list of crates available in the rust playground
let playground_crates = response.crates.map(function (item) { return item["id"]; });
Array.from(document.querySelectorAll(".playpen")).forEach(function (block) {
handle_crate_list_update(block, playground_crates);
});
});
})();
(function themes() {