-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch fonts with a toggle in the lefthand nav. (#193)
* Adds basic logic and styling for font toggler. * Attempting to import open-dyslexic font. * Toggle now works but doesn't persist. * Toggling font persists across page loads now. * Something funky is going on with this css file... * Attempting to fix this weird static folder bug. * Saves font choice to localStorage.
- Loading branch information
1 parent
0a82afe
commit 4586751
Showing
8 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
var contentElements = document.querySelectorAll('body'); | ||
var preElements = document.querySelectorAll('pre'); | ||
|
||
function toggleFont() { | ||
var currentFont = localStorage.getItem('currentFont') || 'default'; | ||
|
||
if (currentFont === 'default') { | ||
setDyslexicFonts(); | ||
localStorage.setItem('currentFont', 'dyslexic'); | ||
} else { | ||
setDefaultFonts(); | ||
localStorage.setItem('currentFont', 'default'); | ||
} | ||
} | ||
|
||
function setDyslexicFonts() { | ||
contentElements.forEach(function(element) { | ||
element.style.fontFamily = 'Open-Dyslexic'; | ||
}); | ||
preElements.forEach(function(element) { | ||
element.style.fontFamily = 'Open-Dyslexic-Mono'; | ||
}); | ||
console.log("Switch to Open-Dyslexic and Open-Dyslexic-Mono for pre tags."); | ||
} | ||
|
||
function setDefaultFonts() { | ||
contentElements.forEach(function(element) { | ||
element.style.fontFamily = 'sans-serif'; | ||
}); | ||
preElements.forEach(function(element) { | ||
element.style.fontFamily = 'monospace'; | ||
}); | ||
console.log("Switch to sans-serif and monospace for pre tags."); | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', function() { | ||
var savedFont = localStorage.getItem('currentFont'); | ||
if (savedFont === 'dyslexic') { | ||
setDyslexicFonts(); | ||
} else { | ||
setDefaultFonts(); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{{- $hideLabel := .hideLabel | default false -}} | ||
{{- $changeFont := (T "changeFont") | default "Change font" -}} | ||
{{- $light := (T "light") | default "Light" -}} | ||
{{- $dark := (T "dark") | default "Dark" -}} | ||
|
||
|
||
<button | ||
title="{{ $changeFont }}" | ||
data-theme="light" | ||
class=" hx-group hx-h-7 hx-rounded-md hx-px-2 hx-text-left hx-text-xs hx-font-medium hx-text-gray-600 hx-transition-colors dark:hx-text-gray-400 hover:hx-bg-gray-100 hover:hx-text-gray-900 dark:hover:hx-bg-primary-100/5 dark:hover:hx-text-gray-50" | ||
type="button" | ||
aria-label="{{ $changeFont }}" | ||
onclick="toggleFont()" | ||
> | ||
<div class="hx-flex hx-items-center hx-gap-2 hx-capitalize"> | ||
{{- partial "utils/icon.html" (dict "name" "translate" "attributes" "height=12 class=\"group-data-[theme=light]:hx-hidden\"") -}} | ||
{{- if not $hideLabel }}<span class="group-data-[theme=light]:hx-hidden">Toggle font</span>{{ end -}} | ||
{{- partial "utils/icon.html" (dict "name" "translate" "attributes" "height=12 class=\"group-data-[theme=dark]:hx-hidden\"") -}} | ||
{{- if not $hideLabel }}<span class="group-data-[theme=dark]:hx-hidden">Toggle font</span>{{ end -}} | ||
</div> | ||
</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.