2020-05-22 21:02:17 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<b-nav-item-dropdown
|
|
|
|
id="my-nav-dropdown"
|
|
|
|
text="Theme"
|
|
|
|
toggle-class="nav-link-custom"
|
|
|
|
right
|
|
|
|
lazy
|
|
|
|
>
|
2020-05-23 12:05:59 +00:00
|
|
|
<b-dropdown-item v-if="themes.length === 0">
|
2020-05-24 09:19:45 +00:00
|
|
|
<b-spinner small></b-spinner> Loading Themes...
|
2020-05-23 12:05:59 +00:00
|
|
|
</b-dropdown-item>
|
|
|
|
|
2020-05-24 09:19:45 +00:00
|
|
|
<!-- TODO Add v-b-tooltip.hover.right=="{ variant: 'className' }" for tooltip class rendered from bootswatch-->
|
2020-05-22 21:02:17 +00:00
|
|
|
<b-dropdown-item-button
|
|
|
|
v-for="(theme, key) in themes"
|
|
|
|
:key="key"
|
|
|
|
@click="handleClick"
|
2020-05-23 12:05:59 +00:00
|
|
|
:active="activeTheme === theme.name"
|
|
|
|
v-b-tooltip.hover.right
|
|
|
|
:title="theme.description"
|
2020-05-24 09:19:45 +00:00
|
|
|
>{{ theme.name }}</b-dropdown-item-button
|
|
|
|
>
|
2020-05-22 21:02:17 +00:00
|
|
|
</b-nav-item-dropdown>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import axios from 'axios';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
activeTheme: '',
|
2020-05-24 09:19:45 +00:00
|
|
|
themes: [
|
2020-07-26 09:16:40 +00:00
|
|
|
{
|
|
|
|
name: 'Bootstrap',
|
|
|
|
description: 'Plain bootstrap default theme',
|
|
|
|
},
|
2020-05-24 09:19:45 +00:00
|
|
|
{
|
|
|
|
name: 'Cerulean',
|
|
|
|
description: 'A calm blue sky',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Cosmo',
|
|
|
|
description: 'An ode to Metro',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Cyborg',
|
|
|
|
description: 'Jet black and electric blue',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Darkly',
|
|
|
|
description: 'Flatly in night mode',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Flatly',
|
|
|
|
description: 'Flat and modern',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Journal',
|
|
|
|
description: 'Crisp like a new sheet of paper',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Litera',
|
|
|
|
description: 'The medium is the message',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Lumen',
|
|
|
|
description: 'Light and shadow',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Lux',
|
|
|
|
description: 'A touch of class',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Materia',
|
|
|
|
description: 'Material is the metaphor',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Minty',
|
|
|
|
description: 'A fresh feel',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Pulse',
|
|
|
|
description: 'A trace of purple',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Sandstone',
|
|
|
|
description: 'A touch of warmth',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Simplex',
|
|
|
|
description: 'Mini and minimalist',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Sketchy',
|
|
|
|
description: 'A hand-drawn look for mockups and mirth',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Slate',
|
|
|
|
description: 'Shades of gunmetal gray',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Solar',
|
|
|
|
description: 'A spin on Solarized',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Spacelab',
|
|
|
|
description: 'Silvery and sleek',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Superhero',
|
|
|
|
description: 'The brave and the blue',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'United',
|
|
|
|
description: 'Ubuntu orange and unique font',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Yeti',
|
|
|
|
description: 'A friendly foundation',
|
|
|
|
},
|
|
|
|
],
|
2020-05-22 21:02:17 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
name: 'BootswatchThemeSelect',
|
|
|
|
mounted() {
|
2020-05-24 09:19:45 +00:00
|
|
|
// If a theme has been stored in localstorage, the theme will be set.
|
|
|
|
if (window.localStorage.theme) this.setTheme(window.localStorage.theme);
|
2020-05-22 21:02:17 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
handleClick(e) {
|
2020-05-23 12:05:59 +00:00
|
|
|
this.setTheme(e.target.innerText.trim());
|
2020-05-22 21:02:17 +00:00
|
|
|
},
|
2020-05-23 12:05:59 +00:00
|
|
|
setTheme(themeName) {
|
2020-05-24 09:19:45 +00:00
|
|
|
// If theme is already active, do nothing.
|
2020-05-23 12:05:59 +00:00
|
|
|
if (this.activeTheme === themeName) {
|
2020-05-22 21:02:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-07-26 09:16:40 +00:00
|
|
|
if (themeName.toLowerCase() === 'bootstrap') {
|
|
|
|
console.log('bootstrap');
|
2020-05-23 12:05:59 +00:00
|
|
|
const styles = document.getElementsByTagName('style');
|
|
|
|
const bw = Array.from(styles).filter((w) => w.textContent.includes('bootswatch'));
|
2020-07-26 09:16:40 +00:00
|
|
|
// Reset all bootswatch styles
|
2020-05-23 12:05:59 +00:00
|
|
|
bw.forEach((style, index) => {
|
2020-07-26 09:16:40 +00:00
|
|
|
bw[index].disabled = true;
|
2020-05-23 12:05:59 +00:00
|
|
|
});
|
2020-07-26 09:16:40 +00:00
|
|
|
} else {
|
|
|
|
// Dynamic import for a different theme, to avoid loading ALL themes.
|
|
|
|
import(`bootswatch/dist/${themeName.toLowerCase()}/bootstrap.min.css`).then(() => {
|
|
|
|
const styles = document.getElementsByTagName('style');
|
|
|
|
const bw = Array.from(styles).filter((w) => w.textContent.includes('bootswatch'));
|
|
|
|
bw.forEach((style, index) => {
|
|
|
|
if (!style.id) {
|
|
|
|
// If its a style that was just imported and hasn't been assigned an id.
|
|
|
|
bw[index].id = themeName;
|
|
|
|
} else if (style.id === themeName) {
|
|
|
|
// If it's a style that has been imported already.
|
|
|
|
bw[index].disabled = false;
|
|
|
|
} else {
|
|
|
|
// All other style themes should be disabled.
|
|
|
|
bw[index].disabled = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2020-05-22 21:02:17 +00:00
|
|
|
// Save the theme as localstorage
|
2020-05-24 09:19:45 +00:00
|
|
|
console.log('Setting theme as', themeName);
|
|
|
|
window.localStorage.theme = themeName;
|
2020-05-23 12:05:59 +00:00
|
|
|
this.activeTheme = themeName;
|
|
|
|
},
|
2020-05-22 21:02:17 +00:00
|
|
|
fetchApi() {
|
2020-05-23 12:05:59 +00:00
|
|
|
// Fetches boostswatch api and dynamically sets themes.
|
2020-05-24 09:19:45 +00:00
|
|
|
// Not used, but useful for updating the static array of themes if bootswatch dependency is outdated.
|
2020-05-22 21:02:17 +00:00
|
|
|
axios
|
|
|
|
.get('https://bootswatch.com/api/4.json')
|
|
|
|
.then((res) => {
|
|
|
|
const { themes } = res.data;
|
|
|
|
this.themes = themes;
|
2020-05-24 09:19:45 +00:00
|
|
|
|
|
|
|
// Use this code in the browser console and copy and paste the filteredThemes into this.themes
|
2020-05-23 12:05:59 +00:00
|
|
|
// console.log(themes);
|
2020-05-24 09:19:45 +00:00
|
|
|
// const filteredThemes = [];
|
|
|
|
// themes.forEach((item) =>
|
|
|
|
// filteredThemes.push({ name: item.name, description: item.description }),
|
|
|
|
// );
|
2020-05-22 21:02:17 +00:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.log(error);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
2020-07-26 08:48:07 +00:00
|
|
|
<style scoped></style>
|