From 1f5ee7fb1dab540e3ff22bf3b2f592e3c5611bde Mon Sep 17 00:00:00 2001 From: dalance Date: Mon, 25 Nov 2024 15:24:42 +0900 Subject: [PATCH] Update mdbook theme --- book/theme/book.js | 25 ++++++++------------- book/theme/index.hbs | 53 +++++++++++++------------------------------- 2 files changed, 25 insertions(+), 53 deletions(-) diff --git a/book/theme/book.js b/book/theme/book.js index 9a1083c9..b484940f 100644 --- a/book/theme/book.js +++ b/book/theme/book.js @@ -195,7 +195,7 @@ function playground_text(playground, hidden = true) { } var clipButton = document.createElement('button'); - clipButton.className = 'fa fa-copy clip-button'; + clipButton.className = 'clip-button'; clipButton.title = 'Copy to clipboard'; clipButton.setAttribute('aria-label', clipButton.title); clipButton.innerHTML = ''; @@ -228,7 +228,7 @@ function playground_text(playground, hidden = true) { if (window.playground_copyable) { var copyCodeClipboardButton = document.createElement('button'); - copyCodeClipboardButton.className = 'fa fa-copy clip-button'; + copyCodeClipboardButton.className = 'clip-button'; copyCodeClipboardButton.innerHTML = ''; copyCodeClipboardButton.title = 'Copy to clipboard'; copyCodeClipboardButton.setAttribute('aria-label', copyCodeClipboardButton.title); @@ -259,6 +259,10 @@ function playground_text(playground, hidden = true) { var themeToggleButton = document.getElementById('theme-toggle'); var themePopup = document.getElementById('theme-list'); var themeColorMetaTag = document.querySelector('meta[name="theme-color"]'); + var themeIds = []; + themePopup.querySelectorAll('button.theme').forEach(function (el) { + themeIds.push(el.id); + }); var stylesheets = { ayuHighlight: document.querySelector("[href$='ayu-highlight.css']"), tomorrowNight: document.querySelector("[href$='tomorrow-night.css']"), @@ -287,7 +291,7 @@ function playground_text(playground, hidden = true) { function get_theme() { var theme; try { theme = localStorage.getItem('mdbook-theme'); } catch (e) { } - if (theme === null || theme === undefined) { + if (theme === null || theme === undefined || !themeIds.includes(theme)) { return default_theme; } else { return theme; @@ -429,17 +433,6 @@ function playground_text(playground, hidden = true) { try { localStorage.setItem('mdbook-sidebar', 'visible'); } catch (e) { } } - - var sidebarAnchorToggles = document.querySelectorAll('#sidebar a.toggle'); - - function toggleSection(ev) { - ev.currentTarget.parentElement.classList.toggle('expanded'); - } - - Array.from(sidebarAnchorToggles).forEach(function (el) { - el.addEventListener('click', toggleSection); - }); - function hideSidebar() { body.classList.remove('sidebar-visible') body.classList.add('sidebar-hidden'); @@ -567,12 +560,12 @@ function playground_text(playground, hidden = true) { function hideTooltip(elem) { elem.firstChild.innerText = ""; - elem.className = 'fa fa-copy clip-button'; + elem.className = 'clip-button'; } function showTooltip(elem, msg) { elem.firstChild.innerText = msg; - elem.className = 'fa fa-copy tooltipped'; + elem.className = 'clip-button tooltipped'; } var clipboardSnippets = new ClipboardJS('.clip-button', { diff --git a/book/theme/index.hbs b/book/theme/index.hbs index 1f7e9b51..35e58ef3 100644 --- a/book/theme/index.hbs +++ b/book/theme/index.hbs @@ -1,5 +1,5 @@ - + @@ -52,15 +52,17 @@ {{/if}} - - -
+ - + + + + +
- - -