mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
40 lines
889 B
TypeScript
40 lines
889 B
TypeScript
import { EventEmitter, Injectable } from '@angular/core';
|
|
|
|
export interface DocsSiteTheme {
|
|
href: string;
|
|
name: string;
|
|
accent: string;
|
|
primary: string;
|
|
isDark?: boolean;
|
|
isDefault?: boolean;
|
|
}
|
|
|
|
@Injectable()
|
|
export class ThemeStorage {
|
|
static storageKey = 'docs-theme-storage-current';
|
|
|
|
public onThemeUpdate: EventEmitter<DocsSiteTheme> = new EventEmitter<DocsSiteTheme>();
|
|
|
|
public storeTheme(theme: DocsSiteTheme) {
|
|
try {
|
|
window.localStorage[ThemeStorage.storageKey] = JSON.stringify(theme);
|
|
} catch (e) { }
|
|
|
|
this.onThemeUpdate.emit(theme);
|
|
}
|
|
|
|
public getStoredTheme(): DocsSiteTheme {
|
|
try {
|
|
return JSON.parse(window.localStorage[ThemeStorage.storageKey] || null);
|
|
} catch (e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public clearStorage() {
|
|
try {
|
|
window.localStorage.removeItem(ThemeStorage.storageKey);
|
|
} catch (e) { }
|
|
}
|
|
}
|