Skip to content

Commit

Permalink
Update theme-loader.js
Browse files Browse the repository at this point in the history
  • Loading branch information
janfaracik committed May 6, 2024
1 parent 5ef527f commit f8fc7b6
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/main/webapp/js/theme-loader.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// We wait till the DOM is loaded to make sure theme manager has loaded
document.addEventListener('DOMContentLoaded', () => {
const defaultTheme = 'default.css'
const head = document.getElementsByTagName('head')[0]
const resUrl = head.dataset.resurl

function setTheme() {
const themeElement = document.getElementById('prism-theme-loader')
let themeCss = themeElement.dataset.selectedTheme || "default.css"
let themeCss = themeElement.dataset.selectedTheme || defaultTheme

// if default theme is in use then use theme manager API to get light / dark version
if (themeCss === 'prism.css' && window.getThemeManagerProperty) {
if (themeCss === defaultTheme && window.getThemeManagerProperty) {
const themeName = window.getThemeManagerProperty('prism-api', 'theme')

if (themeName) {
Expand All @@ -23,13 +24,13 @@ document.addEventListener('DOMContentLoaded', () => {

let baseUrl = `${resUrl}/plugin/prism-api/css/`

if (themeCss !== 'default.css') {
if (themeCss !== defaultTheme) {
baseUrl += 'prism/'
}

head.insertAdjacentHTML(
'beforeend',
`<link id="prism-active-theme" rel="stylesheet" href="${baseUrl}/${themeCss}.css" />`)
`<link id="prism-active-theme" rel="stylesheet" href="${baseUrl}/${themeCss}" />`)
}

if (window.getThemeManagerProperty && window.isSystemRespectingTheme) {
Expand Down

0 comments on commit f8fc7b6

Please sign in to comment.