style: format `book.js` with dprint to make diffing easier with upstream (#400)

Signed-off-by: simonsan <14062932+simonsan@users.noreply.github.com>
dependabot/github_actions/actions/configure-pages-5
simonsan 2 months ago committed by GitHub
parent 91d342c987
commit b714ff5ffb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -16,14 +16,18 @@
"includes": [ "includes": [
"**/*.{md}", "**/*.{md}",
"**/*.{toml}", "**/*.{toml}",
"**/*.{json}" "**/*.{json}",
"**/*.{js,ts,tsx,jsx}"
], ],
"excludes": [ "excludes": [
"book/**/book.js",
"theme/book.js",
"target/**/*" "target/**/*"
], ],
"plugins": [ "plugins": [
"https://plugins.dprint.dev/markdown-0.16.4.wasm", "https://plugins.dprint.dev/markdown-0.16.4.wasm",
"https://plugins.dprint.dev/toml-0.6.1.wasm", "https://plugins.dprint.dev/toml-0.6.1.wasm",
"https://plugins.dprint.dev/json-0.19.2.wasm" "https://plugins.dprint.dev/json-0.19.2.wasm",
"https://plugins.dprint.dev/typescript-0.89.3.wasm"
] ]
} }

@ -1,7 +1,7 @@
"use strict"; "use strict";
// Fix back button cache problem // Fix back button cache problem
window.onunload = function () {}; window.onunload = function() {};
function isPlaygroundModified(playground) { function isPlaygroundModified(playground) {
let code_block = playground.querySelector("code"); let code_block = playground.querySelector("code");
@ -65,7 +65,7 @@ function playground_text(playground, hidden = true) {
let code_block = playground_block.querySelector("code"); let code_block = playground_block.querySelector("code");
if (code_block.classList.contains("editable")) { if (code_block.classList.contains("editable")) {
let editor = window.ace.edit(code_block); let editor = window.ace.edit(code_block);
editor.addEventListener("change", function (e) { editor.addEventListener("change", function(e) {
update_play_button(playground_block, playground_crates); update_play_button(playground_block, playground_crates);
}); });
// add Ctrl-Enter command to execute rust code // add Ctrl-Enter command to execute rust code
@ -102,7 +102,7 @@ function playground_text(playground, hidden = true) {
} }
// check if all used crates are available on play.rust-lang.org // check if all used crates are available on play.rust-lang.org
var all_available = snippet_crates.every(function (elem) { var all_available = snippet_crates.every(function(elem) {
return playground_crates.indexOf(elem) > -1; return playground_crates.indexOf(elem) > -1;
}); });
@ -189,7 +189,7 @@ function playground_text(playground, hidden = true) {
let code_nodes = Array.from(document.querySelectorAll("code")) let code_nodes = Array.from(document.querySelectorAll("code"))
// Don't highlight `inline code` blocks in headers. // Don't highlight `inline code` blocks in headers.
.filter(function (node) { .filter(function(node) {
return !node.parentElement.classList.contains("header"); return !node.parentElement.classList.contains("header");
}); });
@ -197,33 +197,33 @@ function playground_text(playground, hidden = true) {
// language-rust class needs to be removed for editable // language-rust class needs to be removed for editable
// blocks or highlightjs will capture events // blocks or highlightjs will capture events
code_nodes code_nodes
.filter(function (node) { .filter(function(node) {
return node.classList.contains("editable"); return node.classList.contains("editable");
}) })
.forEach(function (block) { .forEach(function(block) {
block.classList.remove("language-rust"); block.classList.remove("language-rust");
}); });
code_nodes code_nodes
.filter(function (node) { .filter(function(node) {
return !node.classList.contains("editable"); return !node.classList.contains("editable");
}) })
.forEach(function (block) { .forEach(function(block) {
hljs.highlightBlock(block); hljs.highlightBlock(block);
}); });
} else { } else {
code_nodes.forEach(function (block) { code_nodes.forEach(function(block) {
hljs.highlightBlock(block); hljs.highlightBlock(block);
}); });
} }
// Adding the hljs class gives code blocks the color css // Adding the hljs class gives code blocks the color css
// even if highlighting doesn't apply // even if highlighting doesn't apply
code_nodes.forEach(function (block) { code_nodes.forEach(function(block) {
block.classList.add("hljs"); block.classList.add("hljs");
}); });
Array.from(document.querySelectorAll("code.hljs")).forEach(function (block) { Array.from(document.querySelectorAll("code.hljs")).forEach(function(block) {
var lines = Array.from(block.querySelectorAll(".boring")); var lines = Array.from(block.querySelectorAll(".boring"));
// If no lines were hidden, return // If no lines were hidden, return
if (!lines.length) { if (!lines.length) {
@ -234,13 +234,13 @@ function playground_text(playground, hidden = true) {
var buttons = document.createElement("div"); var buttons = document.createElement("div");
buttons.className = "buttons"; buttons.className = "buttons";
buttons.innerHTML = buttons.innerHTML =
'<button class="fa fa-eye" title="Show hidden lines" aria-label="Show hidden lines"></button>'; "<button class=\"fa fa-eye\" title=\"Show hidden lines\" aria-label=\"Show hidden lines\"></button>";
// add expand button // add expand button
var pre_block = block.parentNode; var pre_block = block.parentNode;
pre_block.insertBefore(buttons, pre_block.firstChild); pre_block.insertBefore(buttons, pre_block.firstChild);
pre_block.querySelector(".buttons").addEventListener("click", function (e) { pre_block.querySelector(".buttons").addEventListener("click", function(e) {
if (e.target.classList.contains("fa-eye")) { if (e.target.classList.contains("fa-eye")) {
e.target.classList.remove("fa-eye"); e.target.classList.remove("fa-eye");
e.target.classList.add("fa-eye-slash"); e.target.classList.add("fa-eye-slash");
@ -260,7 +260,7 @@ function playground_text(playground, hidden = true) {
}); });
if (window.playground_copyable) { if (window.playground_copyable) {
Array.from(document.querySelectorAll("pre code")).forEach(function (block) { Array.from(document.querySelectorAll("pre code")).forEach(function(block) {
var pre_block = block.parentNode; var pre_block = block.parentNode;
if (!pre_block.classList.contains("playground")) { if (!pre_block.classList.contains("playground")) {
var buttons = pre_block.querySelector(".buttons"); var buttons = pre_block.querySelector(".buttons");
@ -274,7 +274,7 @@ function playground_text(playground, hidden = true) {
clipButton.className = "fa fa-copy clip-button"; clipButton.className = "fa fa-copy clip-button";
clipButton.title = "Copy to clipboard"; clipButton.title = "Copy to clipboard";
clipButton.setAttribute("aria-label", clipButton.title); clipButton.setAttribute("aria-label", clipButton.title);
clipButton.innerHTML = '<i class="tooltiptext"></i>'; clipButton.innerHTML = "<i class=\"tooltiptext\"></i>";
buttons.insertBefore(clipButton, buttons.firstChild); buttons.insertBefore(clipButton, buttons.firstChild);
} }
@ -282,8 +282,8 @@ function playground_text(playground, hidden = true) {
} }
// Process playground code blocks // Process playground code blocks
Array.from(document.querySelectorAll(".playground")).forEach(function ( Array.from(document.querySelectorAll(".playground")).forEach(function(
pre_block pre_block,
) { ) {
// Add play button // Add play button
var buttons = pre_block.querySelector(".buttons"); var buttons = pre_block.querySelector(".buttons");
@ -300,18 +300,18 @@ function playground_text(playground, hidden = true) {
runCodeButton.setAttribute("aria-label", runCodeButton.title); runCodeButton.setAttribute("aria-label", runCodeButton.title);
buttons.insertBefore(runCodeButton, buttons.firstChild); buttons.insertBefore(runCodeButton, buttons.firstChild);
runCodeButton.addEventListener("click", function (e) { runCodeButton.addEventListener("click", function(e) {
run_rust_code(pre_block); run_rust_code(pre_block);
}); });
if (window.playground_copyable) { if (window.playground_copyable) {
var copyCodeClipboardButton = document.createElement("button"); var copyCodeClipboardButton = document.createElement("button");
copyCodeClipboardButton.className = "fa fa-copy clip-button"; copyCodeClipboardButton.className = "fa fa-copy clip-button";
copyCodeClipboardButton.innerHTML = '<i class="tooltiptext"></i>'; copyCodeClipboardButton.innerHTML = "<i class=\"tooltiptext\"></i>";
copyCodeClipboardButton.title = "Copy to clipboard"; copyCodeClipboardButton.title = "Copy to clipboard";
copyCodeClipboardButton.setAttribute( copyCodeClipboardButton.setAttribute(
"aria-label", "aria-label",
copyCodeClipboardButton.title copyCodeClipboardButton.title,
); );
buttons.insertBefore(copyCodeClipboardButton, buttons.firstChild); buttons.insertBefore(copyCodeClipboardButton, buttons.firstChild);
@ -326,7 +326,7 @@ function playground_text(playground, hidden = true) {
buttons.insertBefore(undoChangesButton, buttons.firstChild); buttons.insertBefore(undoChangesButton, buttons.firstChild);
undoChangesButton.addEventListener("click", function () { undoChangesButton.addEventListener("click", function() {
let editor = window.ace.edit(code_block); let editor = window.ace.edit(code_block);
editor.setValue(editor.originalCode); editor.setValue(editor.originalCode);
editor.clearSelection(); editor.clearSelection();
@ -339,7 +339,7 @@ function playground_text(playground, hidden = true) {
var html = document.querySelector("html"); var html = document.querySelector("html");
var themeToggleButton = document.getElementById("theme-toggle"); var themeToggleButton = document.getElementById("theme-toggle");
var themePopup = document.getElementById("theme-list"); var themePopup = document.getElementById("theme-list");
var themeColorMetaTag = document.querySelector('meta[name="theme-color"]'); var themeColorMetaTag = document.querySelector("meta[name=\"theme-color\"]");
var stylesheets = { var stylesheets = {
ayuHighlight: document.querySelector("[href$='ayu-highlight.css']"), ayuHighlight: document.querySelector("[href$='ayu-highlight.css']"),
tomorrowNight: document.querySelector("[href$='tomorrow-night.css']"), tomorrowNight: document.querySelector("[href$='tomorrow-night.css']"),
@ -353,7 +353,7 @@ function playground_text(playground, hidden = true) {
} }
function updateThemeSelected() { function updateThemeSelected() {
themePopup.querySelectorAll(".theme-selected").forEach(function (el) { themePopup.querySelectorAll(".theme-selected").forEach(function(el) {
el.classList.remove("theme-selected"); el.classList.remove("theme-selected");
}); });
themePopup themePopup
@ -400,14 +400,14 @@ function playground_text(playground, hidden = true) {
ace_theme = "ace/theme/dawn"; ace_theme = "ace/theme/dawn";
} }
setTimeout(function () { setTimeout(function() {
themeColorMetaTag.content = getComputedStyle( themeColorMetaTag.content = getComputedStyle(
document.documentElement document.documentElement,
).backgroundColor; ).backgroundColor;
}, 1); }, 1);
if (window.ace && window.editors) { if (window.ace && window.editors) {
window.editors.forEach(function (editor) { window.editors.forEach(function(editor) {
editor.setTheme(ace_theme); editor.setTheme(ace_theme);
}); });
} }
@ -430,7 +430,7 @@ function playground_text(playground, hidden = true) {
set_theme(theme, false); set_theme(theme, false);
themeToggleButton.addEventListener("click", function () { themeToggleButton.addEventListener("click", function() {
if (themePopup.style.display === "block") { if (themePopup.style.display === "block") {
hideThemes(); hideThemes();
} else { } else {
@ -438,7 +438,7 @@ function playground_text(playground, hidden = true) {
} }
}); });
themePopup.addEventListener("click", function (e) { themePopup.addEventListener("click", function(e) {
var theme; var theme;
if (e.target.className === "theme") { if (e.target.className === "theme") {
theme = e.target.id; theme = e.target.id;
@ -450,29 +450,29 @@ function playground_text(playground, hidden = true) {
set_theme(theme); set_theme(theme);
}); });
themePopup.addEventListener("focusout", function (e) { themePopup.addEventListener("focusout", function(e) {
// e.relatedTarget is null in Safari and Firefox on macOS (see workaround below) // e.relatedTarget is null in Safari and Firefox on macOS (see workaround below)
if ( if (
!!e.relatedTarget && !!e.relatedTarget
!themeToggleButton.contains(e.relatedTarget) && && !themeToggleButton.contains(e.relatedTarget)
!themePopup.contains(e.relatedTarget) && !themePopup.contains(e.relatedTarget)
) { ) {
hideThemes(); hideThemes();
} }
}); });
// Should not be needed, but it works around an issue on macOS & iOS: https://github.com/rust-lang/mdBook/issues/628 // Should not be needed, but it works around an issue on macOS & iOS: https://github.com/rust-lang/mdBook/issues/628
document.addEventListener("click", function (e) { document.addEventListener("click", function(e) {
if ( if (
themePopup.style.display === "block" && themePopup.style.display === "block"
!themeToggleButton.contains(e.target) && && !themeToggleButton.contains(e.target)
!themePopup.contains(e.target) && !themePopup.contains(e.target)
) { ) {
hideThemes(); hideThemes();
} }
}); });
document.addEventListener("keydown", function (e) { document.addEventListener("keydown", function(e) {
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) {
return; return;
} }
@ -522,7 +522,7 @@ function playground_text(playground, hidden = true) {
function showSidebar() { function showSidebar() {
html.classList.remove("sidebar-hidden"); html.classList.remove("sidebar-hidden");
html.classList.add("sidebar-visible"); html.classList.add("sidebar-visible");
Array.from(sidebarLinks).forEach(function (link) { Array.from(sidebarLinks).forEach(function(link) {
link.setAttribute("tabIndex", 0); link.setAttribute("tabIndex", 0);
}); });
sidebarToggleButton.setAttribute("aria-expanded", true); sidebarToggleButton.setAttribute("aria-expanded", true);
@ -538,14 +538,14 @@ function playground_text(playground, hidden = true) {
ev.currentTarget.parentElement.classList.toggle("expanded"); ev.currentTarget.parentElement.classList.toggle("expanded");
} }
Array.from(sidebarAnchorToggles).forEach(function (el) { Array.from(sidebarAnchorToggles).forEach(function(el) {
el.addEventListener("click", toggleSection); el.addEventListener("click", toggleSection);
}); });
function hideSidebar() { function hideSidebar() {
html.classList.remove("sidebar-visible"); html.classList.remove("sidebar-visible");
html.classList.add("sidebar-hidden"); html.classList.add("sidebar-hidden");
Array.from(sidebarLinks).forEach(function (link) { Array.from(sidebarLinks).forEach(function(link) {
link.setAttribute("tabIndex", -1); link.setAttribute("tabIndex", -1);
}); });
sidebarToggleButton.setAttribute("aria-expanded", false); sidebarToggleButton.setAttribute("aria-expanded", false);
@ -560,7 +560,7 @@ function playground_text(playground, hidden = true) {
if (html.classList.contains("sidebar-hidden")) { if (html.classList.contains("sidebar-hidden")) {
var current_width = parseInt( var current_width = parseInt(
document.documentElement.style.getPropertyValue("--sidebar-width"), document.documentElement.style.getPropertyValue("--sidebar-width"),
10 10,
); );
if (current_width < 150) { if (current_width < 150) {
document.documentElement.style.setProperty("--sidebar-width", "150px"); document.documentElement.style.setProperty("--sidebar-width", "150px");
@ -596,7 +596,7 @@ function playground_text(playground, hidden = true) {
document.documentElement.style.setProperty("--sidebar-width", pos + "px"); document.documentElement.style.setProperty("--sidebar-width", pos + "px");
} }
} }
//on mouseup remove windows functions mousemove & mouseup // on mouseup remove windows functions mousemove & mouseup
function stopResize(e) { function stopResize(e) {
html.classList.remove("sidebar-resizing"); html.classList.remove("sidebar-resizing");
window.removeEventListener("mousemove", resize, false); window.removeEventListener("mousemove", resize, false);
@ -605,18 +605,18 @@ function playground_text(playground, hidden = true) {
document.addEventListener( document.addEventListener(
"touchstart", "touchstart",
function (e) { function(e) {
firstContact = { firstContact = {
x: e.touches[0].clientX, x: e.touches[0].clientX,
time: Date.now(), time: Date.now(),
}; };
}, },
{ passive: true } { passive: true },
); );
document.addEventListener( document.addEventListener(
"touchmove", "touchmove",
function (e) { function(e) {
if (!firstContact) return; if (!firstContact) return;
var curX = e.touches[0].clientX; var curX = e.touches[0].clientX;
@ -625,21 +625,21 @@ function playground_text(playground, hidden = true) {
if (tDiff < 250 && Math.abs(xDiff) >= 150) { if (tDiff < 250 && Math.abs(xDiff) >= 150) {
if ( if (
xDiff >= 0 && xDiff >= 0
firstContact.x < Math.min(document.body.clientWidth * 0.25, 300) && firstContact.x < Math.min(document.body.clientWidth * 0.25, 300)
) ) {
showSidebar(); showSidebar();
else if (xDiff < 0 && curX < 300) hideSidebar(); } else if (xDiff < 0 && curX < 300) hideSidebar();
firstContact = null; firstContact = null;
} }
}, },
{ passive: true } { passive: true },
); );
})(); })();
(function chapterNavigation() { (function chapterNavigation() {
document.addEventListener("keydown", function (e) { document.addEventListener("keydown", function(e) {
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) {
return; return;
} }
@ -680,25 +680,25 @@ function playground_text(playground, hidden = true) {
} }
var clipboardSnippets = new ClipboardJS(".clip-button", { var clipboardSnippets = new ClipboardJS(".clip-button", {
text: function (trigger) { text: function(trigger) {
hideTooltip(trigger); hideTooltip(trigger);
let playground = trigger.closest("pre"); let playground = trigger.closest("pre");
return playground_text(playground, false); return playground_text(playground, false);
}, },
}); });
Array.from(clipButtons).forEach(function (clipButton) { Array.from(clipButtons).forEach(function(clipButton) {
clipButton.addEventListener("mouseout", function (e) { clipButton.addEventListener("mouseout", function(e) {
hideTooltip(e.currentTarget); hideTooltip(e.currentTarget);
}); });
}); });
clipboardSnippets.on("success", function (e) { clipboardSnippets.on("success", function(e) {
e.clearSelection(); e.clearSelection();
showTooltip(e.trigger, "Copied!"); showTooltip(e.trigger, "Copied!");
}); });
clipboardSnippets.on("error", function (e) { clipboardSnippets.on("error", function(e) {
showTooltip(e.trigger, "Clipboard error!"); showTooltip(e.trigger, "Clipboard error!");
}); });
})(); })();
@ -706,7 +706,7 @@ function playground_text(playground, hidden = true) {
(function scrollToTop() { (function scrollToTop() {
var menuTitle = document.querySelector(".menu-title"); var menuTitle = document.querySelector(".menu-title");
menuTitle.addEventListener("click", function () { menuTitle.addEventListener("click", function() {
document.scrollingElement.scrollTo({ top: 0, behavior: "smooth" }); document.scrollingElement.scrollTo({ top: 0, behavior: "smooth" });
}); });
})(); })();
@ -726,7 +726,7 @@ function playground_text(playground, hidden = true) {
var stickyCache = false; // Same as menu.classList.contains('sticky'), but faster var stickyCache = false; // Same as menu.classList.contains('sticky'), but faster
document.addEventListener( document.addEventListener(
"scroll", "scroll",
function () { function() {
scrollTop = Math.max(document.scrollingElement.scrollTop, 0); scrollTop = Math.max(document.scrollingElement.scrollTop, 0);
// `null` means that it doesn't need to be updated // `null` means that it doesn't need to be updated
var nextSticky = null; var nextSticky = null;
@ -758,7 +758,7 @@ function playground_text(playground, hidden = true) {
} }
prevScrollTop = scrollTop; prevScrollTop = scrollTop;
}, },
{ passive: true } { passive: true },
); );
})(); })();
(function controllBorder() { (function controllBorder() {

Loading…
Cancel
Save