Merge branch 'theme3-body-class' into 'develop'
Add theme3 body class helper See merge request pleroma/pleroma-fe!1966
This commit is contained in:
commit
8c28133c72
3 changed files with 39 additions and 2 deletions
1
changelog.d/theme3-body-class.add
Normal file
1
changelog.d/theme3-body-class.add
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Indicate currently active V3 theme as a body element class
|
||||||
34
src/App.js
34
src/App.js
|
|
@ -52,6 +52,9 @@ export default {
|
||||||
themeApplied () {
|
themeApplied () {
|
||||||
this.removeSplash()
|
this.removeSplash()
|
||||||
},
|
},
|
||||||
|
currentTheme () {
|
||||||
|
this.setThemeBodyClass()
|
||||||
|
},
|
||||||
layoutType () {
|
layoutType () {
|
||||||
document.getElementById('modal').classList = ['-' + this.layoutType]
|
document.getElementById('modal').classList = ['-' + this.layoutType]
|
||||||
}
|
}
|
||||||
|
|
@ -71,6 +74,7 @@ export default {
|
||||||
this.scrollParent.addEventListener('scroll', this.updateScrollState)
|
this.scrollParent.addEventListener('scroll', this.updateScrollState)
|
||||||
|
|
||||||
if (useInterfaceStore().themeApplied) {
|
if (useInterfaceStore().themeApplied) {
|
||||||
|
this.setThemeBodyClass()
|
||||||
this.removeSplash()
|
this.removeSplash()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -82,6 +86,17 @@ export default {
|
||||||
themeApplied () {
|
themeApplied () {
|
||||||
return useInterfaceStore().themeApplied
|
return useInterfaceStore().themeApplied
|
||||||
},
|
},
|
||||||
|
currentTheme () {
|
||||||
|
if (useInterfaceStore().styleDataUsed) {
|
||||||
|
const styleMeta = useInterfaceStore().styleDataUsed.find(x => x.component === '@meta')
|
||||||
|
|
||||||
|
if (styleMeta !== undefined) {
|
||||||
|
return styleMeta.directives.name.replaceAll(" ", "-").toLowerCase()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'stock'
|
||||||
|
},
|
||||||
layoutModalClass () {
|
layoutModalClass () {
|
||||||
return '-' + this.layoutType
|
return '-' + this.layoutType
|
||||||
},
|
},
|
||||||
|
|
@ -172,6 +187,25 @@ export default {
|
||||||
this.$refs.appContentRef.classList.remove(['-scrolled'])
|
this.$refs.appContentRef.classList.remove(['-scrolled'])
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
setThemeBodyClass () {
|
||||||
|
const themeName = this.currentTheme
|
||||||
|
const classList = Array.from(document.body.classList)
|
||||||
|
const oldTheme = classList.filter(c => c.startsWith('theme-'))
|
||||||
|
|
||||||
|
if (themeName !== null && themeName !== '') {
|
||||||
|
const newTheme = `theme-${themeName.toLowerCase()}`
|
||||||
|
|
||||||
|
// remove old theme reference if there are any
|
||||||
|
if (oldTheme.length) {
|
||||||
|
document.body.classList.replace(oldTheme[0], newTheme)
|
||||||
|
} else {
|
||||||
|
document.body.classList.add(newTheme)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// remove theme reference if non-V3 theme is used
|
||||||
|
document.body.classList.remove(...oldTheme)
|
||||||
|
}
|
||||||
|
},
|
||||||
removeSplash () {
|
removeSplash () {
|
||||||
document.querySelector('#status').textContent = this.$t('splash.fun_' + Math.ceil(Math.random() * 4))
|
document.querySelector('#status').textContent = this.$t('splash.fun_' + Math.ceil(Math.random() * 4))
|
||||||
const splashscreenRoot = document.querySelector('#splash')
|
const splashscreenRoot = document.querySelector('#splash')
|
||||||
|
|
|
||||||
|
|
@ -521,16 +521,18 @@ export const useInterfaceStore = defineStore('interface', {
|
||||||
theme3hacks
|
theme3hacks
|
||||||
} = window.vuex.state.config
|
} = window.vuex.state.config
|
||||||
this.themeChangeInProgress = true
|
this.themeChangeInProgress = true
|
||||||
// If we're not not forced to recompile try using
|
// If we're not forced to recompile try using
|
||||||
// cache (tryLoadCache return true if load successful)
|
// cache (tryLoadCache return true if load successful)
|
||||||
|
|
||||||
const forceRecompile = forceThemeRecompilation || recompile
|
const forceRecompile = forceThemeRecompilation || recompile
|
||||||
|
|
||||||
|
await this.getThemeData()
|
||||||
|
|
||||||
if (!forceRecompile && !themeDebug && await tryLoadCache()) {
|
if (!forceRecompile && !themeDebug && await tryLoadCache()) {
|
||||||
this.themeChangeInProgress = false
|
this.themeChangeInProgress = false
|
||||||
return this.setThemeApplied()
|
return this.setThemeApplied()
|
||||||
}
|
}
|
||||||
window.splashUpdate('splash.theme')
|
window.splashUpdate('splash.theme')
|
||||||
await this.getThemeData()
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const paletteIss = (() => {
|
const paletteIss = (() => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue