Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/_includes/base.njk
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@
</details>
</nav>



{% block header %}
{% include 'breadcrumbs.njk' %}
<h1 class="title">{{ title }}</h1>
Expand Down
18 changes: 7 additions & 11 deletions docs/_includes/head.njk
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,15 @@

<script type="module" src="/assets/scripts/theme-picker.js"></script>
{# Preset Theme #}
<link id="theme-stylesheet" rel="stylesheet" id="theme-stylesheet" href="/dist/styles/themes/{{ forceTheme or 'default' }}.css" render="blocking" fetchpriority="high" />
{% if not forceTheme %}
{% if forceTheme %}
<link id="theme-stylesheet" rel="stylesheet" id="theme-stylesheet" href="/dist/styles/themes/{{ forceTheme }}.css" render="blocking" fetchpriority="high" />
{% else %}
<noscript><link id="theme-stylesheet" rel="stylesheet" id="theme-stylesheet" href="/dist/styles/themes/default.css" render="blocking" fetchpriority="high" /></noscript>
<script>
if (localStorage.presetTheme) {
let preset = localStorage.presetTheme;
{
let preset = localStorage.presetTheme ?? 'default';
let script = document.currentScript;
let link = script.previousElementSibling;
let newLink = link.cloneNode();
newLink.href = link.href.replace("/default.css", `/${preset}.css`);
newLink.addEventListener('load', () => {
link.remove();
});
link.after(newLink);
script.insertAdjacentHTML('beforebegin', `<link id="theme-stylesheet" rel="stylesheet" id="theme-stylesheet" href="/dist/styles/themes/${ preset }.css" render="blocking" fetchpriority="high" />`);
}
</script>
<script type="module" src="/assets/scripts/preset-theme-picker.js"></script>
Expand Down
8 changes: 6 additions & 2 deletions docs/assets/scripts/preset-theme-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const presetTheme = new ThemeAspect({
key: 'presetTheme',
picker: 'wa-select.preset-theme-selector',

applyChange() {
applyChange(options = {}) {
const oldStylesheets = [...document.querySelectorAll('#theme-stylesheet')];
const oldStylesheet = oldStylesheets.pop();

Expand Down Expand Up @@ -38,7 +38,7 @@ const presetTheme = new ThemeAspect({

oldStylesheet.remove();
},
{ behavior: 'smooth' },
{ behavior: 'smooth', ...options },
);
},
{ once: true },
Expand All @@ -61,4 +61,8 @@ function updateSelectionBeforeTurboLoad(e) {
document.addEventListener(eventName, updateSelectionBeforeTurboLoad);
});

window.addEventListener('turbo:render', e => {
presetTheme.applyChange({ behavior: 'instant' });
});

window.presetTheme = presetTheme;
Loading