theme enabled
This commit is contained in:
1 parent
178d3c7955
commit
13726d88b0
7 files changed
+73
-7
No files matched your search
+5
-1
@@ -20,6 +20,7 @@ import Article from './components/Article'
|
||||
import ArticlePageControl from './components/ArticlePageControl'
|
||||
import Album from './components/Album'
|
||||
import Parallax from './components/Parallax'
|
||||
import ThemeSelector from './components/ThemeSelector'
|
||||
|
||||
import Page from './components/CloudPage'
|
||||
import PageSchool from './components/PageSchool'
|
||||
@@ -48,6 +49,7 @@ import Ext from './filters/Ext'
|
||||
import IOService from './services/io'
|
||||
import MenuService from './services/menu'
|
||||
import API from './services/api'
|
||||
import Theme from './services/theme'
|
||||
|
||||
import {sortByPattern} from '../utils/sort'
|
||||
import {documentsSortPattern, collectiveSortPattern} from './config'
|
||||
@@ -260,6 +262,7 @@ app.run(($location, $rootScope, $http) => {
|
||||
API,
|
||||
IOService,
|
||||
MenuService,
|
||||
Theme,
|
||||
RemoveHashtags,
|
||||
RemoveNewline,
|
||||
Strip,
|
||||
@@ -301,5 +304,6 @@ app.run(($location, $rootScope, $http) => {
|
||||
ScheduleSlider,
|
||||
ScheduleSlide,
|
||||
ScheduleRecord,
|
||||
FooterLinks
|
||||
FooterLinks,
|
||||
ThemeSelector
|
||||
].map(i => i(app))
|
||||
@@ -0,0 +1,22 @@
|
||||
export default function (app) {
|
||||
app.component('themeSelector', {
|
||||
template: `
|
||||
<p ng-click="toggleTheme()">
|
||||
<span ng-hide="isMainTheme" title="Выключить версию для слабовидящих"><i class="fa fa-eye" aria-hidden="true"></i></span>
|
||||
<span ng-show="isMainTheme" title="Включить версию для слабовидящих"><i class="fa fa-eye-slash" aria-hidden="true"></i></span>
|
||||
</p>
|
||||
`,
|
||||
controller: ($scope, theme) => {
|
||||
const update = () => {
|
||||
$scope.isMainTheme = theme.currentTheme === theme.mainTheme
|
||||
}
|
||||
|
||||
$scope.toggleTheme = () => {
|
||||
theme.toggle()
|
||||
update()
|
||||
}
|
||||
|
||||
update()
|
||||
},
|
||||
})
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
const themes = {
|
||||
main: 'style.css',
|
||||
accessibility: 'style-accessibility.css',
|
||||
}
|
||||
|
||||
const defaultTheme = 'main'
|
||||
|
||||
class Theme {
|
||||
constructor($rootScope) {
|
||||
this.mainTheme = defaultTheme
|
||||
this.currentTheme = null
|
||||
|
||||
const getTheme = value => themes[value]
|
||||
const setTheme = value => {
|
||||
const theme = value in themes ? value : defaultTheme
|
||||
localStorage.setItem('theme', theme)
|
||||
this.currentTheme = theme
|
||||
$rootScope.theme = getTheme(theme)
|
||||
}
|
||||
|
||||
setTheme(localStorage.getItem('theme'))
|
||||
|
||||
this.toggle = () => {
|
||||
const t = this.currentTheme === 'main' ? 'accessibility' : 'main'
|
||||
setTheme(t)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default function (app) {
|
||||
app.service('theme', Theme)
|
||||
}
|
||||
Reference in new issue
Block a user