parent
59a0e6d286
commit
3ef514359e
@ -1,51 +1,58 @@ |
|||||||
var Storage = require('remix-lib').Storage |
var Storage = require('remix-lib').Storage |
||||||
var EventEmitter = require('events') |
var EventEmitter = require('events') |
||||||
|
|
||||||
// Boostrap themes
|
|
||||||
// TODO : Put it somewhere else
|
// TODO : Put it somewhere else
|
||||||
const themes = { |
const themes = [ |
||||||
dark: 'https://bootstrap.themes.guide/darkster/theme.min.css', |
{name: 'cerulean', quality: 'light', url: 'https://stackpath.bootstrapcdn.com/bootswatch/4.3.1/cerulean/bootstrap.min.css'}, |
||||||
light: 'https://bootstrap.themes.guide/herbie/theme.min.css', |
{name: 'materia', quality: 'light', url: 'https://bootswatch.com/4/materia/bootstrap.min.css'}, |
||||||
clean: 'https://bootstrap.themes.guide/fresca/theme.min.css' |
{name: 'litera', quality: 'light', url: 'https://bootswatch.com/4/litera/bootstrap.min.css'}, |
||||||
} |
{name: 'cosmo', quality: 'light', url: 'https://bootswatch.com/4/cosmo/bootstrap.min.css'}, |
||||||
// Used for the scroll color
|
{name: 'flatly', quality: 'light', url: 'https://bootswatch.com/4/flatly/bootstrap.min.css'}, |
||||||
const themeVariable = { |
{name: 'lux', quality: 'light', url: 'https://bootswatch.com/4/lux/bootstrap.min.css'}, |
||||||
dark: 'dark', |
{name: 'spacelab', quality: 'light', url: 'https://bootswatch.com/4/spacelab/bootstrap.min.css'}, |
||||||
light: 'light', |
{name: 'yeti', quality: 'light', url: 'https://bootswatch.com/4/yeti/bootstrap.min.css'}, |
||||||
clean: 'light' |
{name: 'darkly', quality: 'dark', url: 'https://stackpath.bootstrapcdn.com/bootswatch/4.3.1/darkly/bootstrap.min.css'}, |
||||||
} |
{name: 'slate', quality: 'dark', url: 'https://stackpath.bootstrapcdn.com/bootswatch/4.3.1/slate/bootstrap.min.css'} |
||||||
|
] |
||||||
|
|
||||||
|
const defaultTheme = themes[0].name |
||||||
|
|
||||||
module.exports = { |
module.exports = { |
||||||
event: new EventEmitter(), |
event: new EventEmitter(), |
||||||
chooser: function () { |
currentTheme: function () { |
||||||
const themeStorage = new Storage('style:') |
const themeStorage = new Storage('style:') |
||||||
if (themeStorage.exists('theme')) { |
if (themeStorage.exists('theme')) { |
||||||
if (themeStorage.get('theme') === 'dark') { |
const currThemeObj = this.isThere(themeStorage.get('theme')) |
||||||
document.getElementById('theme-link').setAttribute('href', themes['dark']) |
return currThemeObj ? currThemeObj.name : defaultTheme |
||||||
document.documentElement.style.setProperty('--theme', 'dark') |
|
||||||
} else if (themeStorage.get('theme') === 'clean') { |
|
||||||
document.getElementById('theme-link').setAttribute('href', themes['clean']) |
|
||||||
document.documentElement.style.setProperty('--theme', 'light') |
|
||||||
} else { |
|
||||||
document.getElementById('theme-link').setAttribute('href', themes['light']) |
|
||||||
document.documentElement.style.setProperty('--theme', 'light') |
|
||||||
} |
|
||||||
} else { |
} else { |
||||||
document.getElementById('theme-link').setAttribute('href', themes['light']) |
return defaultTheme |
||||||
document.documentElement.style.setProperty('--theme', 'light') |
|
||||||
} |
} |
||||||
}, |
}, |
||||||
|
isThere: function (themeName) { |
||||||
|
// returns an object
|
||||||
|
return themes.find(obj => { |
||||||
|
return obj.name === themeName |
||||||
|
}) |
||||||
|
}, |
||||||
|
getThemes: function () { |
||||||
|
return themes |
||||||
|
}, |
||||||
switchTheme: function (theme) { |
switchTheme: function (theme) { |
||||||
var themeStorage = new Storage('style:') |
let themeStorage = new Storage('style:') |
||||||
if (theme) themeStorage.set('theme', theme) |
if (theme) { |
||||||
else { |
themeStorage.set('theme', theme) |
||||||
theme = themeStorage.get('theme') |
} |
||||||
|
let theTheme |
||||||
|
if (theme) { |
||||||
|
theTheme = theme |
||||||
|
} else { |
||||||
|
theTheme = this.currentTheme() |
||||||
} |
} |
||||||
if (!theme) theme = 'light' |
let themeObj = this.isThere(theTheme) |
||||||
if (themes[theme]) { |
if (themeObj) { |
||||||
document.getElementById('theme-link').setAttribute('href', themes[theme]) |
document.getElementById('theme-link').setAttribute('href', themeObj.url) |
||||||
document.documentElement.style.setProperty('--theme', themeVariable[theme]) |
document.documentElement.style.setProperty('--theme', themeObj.quality) |
||||||
this.event.emit('switchTheme', themeVariable[theme]) |
this.event.emit('switchTheme', themeObj.quality) |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue