Module: Daisy::ThemeHelper
- Defined in:
- app/helpers/daisy/theme_helper.rb
Instance Method Summary collapse
-
#theme_preload_script ⇒ String
Returns an inline script that preloads the saved theme from localStorage to prevent a flash of content when the page loads.
Instance Method Details
#theme_preload_script ⇒ String
Returns an inline script that preloads the saved theme from localStorage to prevent a flash of content when the page loads.
This script runs synchronously in the head section before the page renders, setting the ‘data-theme` attribute on the html element if a theme has been saved in localStorage.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/helpers/daisy/theme_helper.rb', line 23 def theme_preload_script <<~SCRIPT.html_safe <script> (function() { try { var savedTheme = localStorage.getItem('savedTheme'); if (savedTheme) { document.documentElement.setAttribute('data-theme', savedTheme); } } catch (e) { // localStorage not available (e.g., private browsing mode) } })(); </script> SCRIPT end |