From ead2ca2cfa3774af733c613ea03d9b4f3d10fbdf Mon Sep 17 00:00:00 2001 From: johannst Date: Wed, 21 Dec 2022 22:24:31 +0000 Subject: deploy: 4a8c8c7520419cbaa01b26353ef35e357c5d1ecf --- book.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'book.js') diff --git a/book.js b/book.js index d40440c..e303ebb 100644 --- a/book.js +++ b/book.js @@ -4,14 +4,16 @@ window.onunload = function () { }; // Global variable, shared between modules -function playground_text(playground) { +function playground_text(playground, hidden = true) { let code_block = playground.querySelector("code"); if (window.ace && code_block.classList.contains("editable")) { let editor = window.ace.edit(code_block); return editor.getValue(); - } else { + } else if (hidden) { return code_block.textContent; + } else { + return code_block.innerText; } } @@ -166,7 +168,6 @@ function playground_text(playground) { .filter(function (node) {return node.classList.contains("editable"); }) .forEach(function (block) { block.classList.remove('language-rust'); }); - Array code_nodes .filter(function (node) {return !node.classList.contains("editable"); }) .forEach(function (block) { hljs.highlightBlock(block); }); @@ -300,6 +301,13 @@ function playground_text(playground) { themePopup.querySelector("button#" + get_theme()).focus(); } + function updateThemeSelected() { + themePopup.querySelectorAll('.theme-selected').forEach(function (el) { + el.classList.remove('theme-selected'); + }); + themePopup.querySelector("button#" + get_theme()).classList.add('theme-selected'); + } + function hideThemes() { themePopup.style.display = 'none'; themeToggleButton.setAttribute('aria-expanded', false); @@ -355,6 +363,7 @@ function playground_text(playground) { html.classList.remove(previousTheme); html.classList.add(theme); + updateThemeSelected(); } // Set theme @@ -592,7 +601,7 @@ function playground_text(playground) { text: function (trigger) { hideTooltip(trigger); let playground = trigger.closest("pre"); - return playground_text(playground); + return playground_text(playground, false); } }); -- cgit v1.2.3