[common] refactoring
This commit is contained in:
parent
04119e7fb8
commit
f8920bd84a
|
@ -8,21 +8,35 @@ define([
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
Common.UI.Themes = new (function() {
|
Common.UI.Themes = new (function() {
|
||||||
var sdk_themes_relation = {
|
var sdk_themes_alias = {
|
||||||
'theme-light': 'flat',
|
'theme-light': 'flat',
|
||||||
'theme-dark': 'flatDark'
|
'theme-dark': 'flatDark'
|
||||||
};
|
};
|
||||||
|
|
||||||
sdk_themes_relation.contains = function (name) {
|
sdk_themes_alias.contains = function (name) {
|
||||||
return !!this[name];
|
return !!this[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var refresh_sdk_colors = function () {
|
||||||
|
var style = getComputedStyle(document.body);
|
||||||
|
if ( !!window.DE ) {
|
||||||
|
var color_background_normal = style.getPropertyValue('--background-normal');
|
||||||
|
this.api.asc_setSkin({
|
||||||
|
"RulerOutline": style.getPropertyValue('--border-toolbar')
|
||||||
|
, "RulerMarkersFillColor": color_background_normal
|
||||||
|
, "RulerMarkersFillColorOld": color_background_normal
|
||||||
|
, "RulerTableColor1": color_background_normal
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
THEME_LIGHT_ID: 'theme-light',
|
THEME_LIGHT_ID: 'theme-light',
|
||||||
THEME_DARK_ID: 'theme-dark',
|
THEME_DARK_ID: 'theme-dark',
|
||||||
|
|
||||||
init: function (api) {
|
init: function (api) {
|
||||||
var me = this;
|
var me = this;
|
||||||
|
refresh_sdk_colors = refresh_sdk_colors.bind(this);
|
||||||
|
|
||||||
$(window).on('storage', function (e) {
|
$(window).on('storage', function (e) {
|
||||||
if ( e.key == 'ui-theme' ) {
|
if ( e.key == 'ui-theme' ) {
|
||||||
me.setTheme(e.originalEvent.newValue);
|
me.setTheme(e.originalEvent.newValue);
|
||||||
|
@ -31,12 +45,14 @@ define([
|
||||||
|
|
||||||
this.api = api;
|
this.api = api;
|
||||||
var theme_name = Common.localStorage.getItem('ui-theme', 'theme-light');
|
var theme_name = Common.localStorage.getItem('ui-theme', 'theme-light');
|
||||||
api.asc_setSkin(sdk_themes_relation[theme_name]);
|
api.asc_setSkin(sdk_themes_alias[theme_name]);
|
||||||
|
|
||||||
if ( !$('body').hasClass(theme_name) ) {
|
if ( !$('body').hasClass(theme_name) ) {
|
||||||
$('body').addClass(theme_name);
|
$('body').addClass(theme_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refresh_sdk_colors();
|
||||||
|
|
||||||
// app.eventbus.addListeners({
|
// app.eventbus.addListeners({
|
||||||
// 'FileMenu': {
|
// 'FileMenu': {
|
||||||
// 'settings:apply': function (menu) {
|
// 'settings:apply': function (menu) {
|
||||||
|
@ -60,23 +76,13 @@ define([
|
||||||
},
|
},
|
||||||
|
|
||||||
setTheme: function (name) {
|
setTheme: function (name) {
|
||||||
if ( sdk_themes_relation.contains(name) ) {
|
if ( sdk_themes_alias.contains(name) ) {
|
||||||
var classname = document.documentElement.className.replace(/theme-\w+\s?/, '');
|
var classname = document.documentElement.className.replace(/theme-\w+\s?/, '');
|
||||||
document.body.className = classname;
|
document.body.className = classname;
|
||||||
|
|
||||||
$('body').addClass(name);
|
$('body').addClass(name);
|
||||||
this.api.asc_setSkin(sdk_themes_relation[name]);
|
this.api.asc_setSkin(sdk_themes_alias[name]);
|
||||||
|
refresh_sdk_colors();
|
||||||
var style = getComputedStyle(document.body);
|
|
||||||
if ( !!window.DE ) {
|
|
||||||
var color_background_normal = style.getPropertyValue('--background-normal');
|
|
||||||
this.api.asc_setSkin({
|
|
||||||
"RulerOutline": style.getPropertyValue('--border-toolbar')
|
|
||||||
, "RulerMarkersFillColor": color_background_normal
|
|
||||||
, "RulerMarkersFillColorOld": color_background_normal
|
|
||||||
, "RulerTableColor1": color_background_normal
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Common.localStorage.setItem('ui-theme', name);
|
Common.localStorage.setItem('ui-theme', name);
|
||||||
Common.NotificationCenter.trigger('uitheme:changed', name);
|
Common.NotificationCenter.trigger('uitheme:changed', name);
|
||||||
|
|
Loading…
Reference in a new issue