2021-02-06 10:03:46 +00:00
|
|
|
/**
|
|
|
|
* Created by Maxim.Kadushkin on 2/5/2021.
|
|
|
|
*/
|
|
|
|
|
|
|
|
define([
|
|
|
|
'core'
|
|
|
|
], function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
Common.UI.Themes = new (function() {
|
2021-03-13 21:20:01 +00:00
|
|
|
var sdk_themes_alias = {
|
2021-02-06 10:03:46 +00:00
|
|
|
'theme-light': 'flat',
|
|
|
|
'theme-dark': 'flatDark'
|
|
|
|
};
|
|
|
|
|
2021-03-13 21:20:01 +00:00
|
|
|
sdk_themes_alias.contains = function (name) {
|
2021-02-06 10:03:46 +00:00
|
|
|
return !!this[name];
|
|
|
|
}
|
|
|
|
|
2021-03-13 21:20:01 +00:00
|
|
|
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({
|
2021-04-01 21:02:47 +00:00
|
|
|
"RulerOutline": style.getPropertyValue('--border-toolbar'),
|
|
|
|
"RulerMarkersFillColor": color_background_normal,
|
|
|
|
"RulerMarkersFillColorOld": color_background_normal,
|
|
|
|
"RulerTableColor1": color_background_normal,
|
|
|
|
"RulerLight": style.getPropertyValue("--canvas-ruler-background"),
|
|
|
|
"RulerDark": style.getPropertyValue("--canvas-ruler-margins-background"),
|
|
|
|
"RulerTextColor": style.getPropertyValue("--canvas-ruler-mark"),
|
|
|
|
"RulerTableColor2": style.getPropertyValue("--canvas-ruler-handle-border"),
|
|
|
|
"RulerTableColor2Old": style.getPropertyValue("--canvas-ruler-handle-border-disabled"),
|
|
|
|
"RulerTabsColor": style.getPropertyValue("--canvas-high-contrast"),
|
|
|
|
"RulerTabsColorOld": style.getPropertyValue("--canvas-high-contrast-disabled"),
|
2021-03-13 21:20:01 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2021-02-06 10:03:46 +00:00
|
|
|
return {
|
2021-03-11 21:16:19 +00:00
|
|
|
THEME_LIGHT_ID: 'theme-light',
|
|
|
|
THEME_DARK_ID: 'theme-dark',
|
|
|
|
|
2021-02-06 10:03:46 +00:00
|
|
|
init: function (api) {
|
|
|
|
var me = this;
|
2021-03-13 21:20:01 +00:00
|
|
|
refresh_sdk_colors = refresh_sdk_colors.bind(this);
|
|
|
|
|
2021-02-06 10:03:46 +00:00
|
|
|
$(window).on('storage', function (e) {
|
|
|
|
if ( e.key == 'ui-theme' ) {
|
|
|
|
me.setTheme(e.originalEvent.newValue);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
this.api = api;
|
2021-02-17 21:25:27 +00:00
|
|
|
var theme_name = Common.localStorage.getItem('ui-theme', 'theme-light');
|
2021-03-13 21:20:01 +00:00
|
|
|
api.asc_setSkin(sdk_themes_alias[theme_name]);
|
2021-02-17 21:25:27 +00:00
|
|
|
|
|
|
|
if ( !$('body').hasClass(theme_name) ) {
|
|
|
|
$('body').addClass(theme_name);
|
|
|
|
}
|
2021-02-06 10:03:46 +00:00
|
|
|
|
2021-03-13 21:20:01 +00:00
|
|
|
refresh_sdk_colors();
|
|
|
|
|
2021-02-06 10:03:46 +00:00
|
|
|
// app.eventbus.addListeners({
|
|
|
|
// 'FileMenu': {
|
|
|
|
// 'settings:apply': function (menu) {
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }, {id: 'Themes'});
|
|
|
|
|
|
|
|
// getComputedStyle(document.documentElement).getPropertyValue('--background-normal');
|
|
|
|
},
|
|
|
|
|
2021-02-16 12:08:39 +00:00
|
|
|
available: function () {
|
|
|
|
return !Common.Utils.isIE;
|
|
|
|
},
|
|
|
|
|
2021-02-06 10:03:46 +00:00
|
|
|
current: function () {
|
2021-03-11 21:16:19 +00:00
|
|
|
return Common.localStorage.getItem('ui-theme') || 'theme-light';
|
2021-02-06 10:03:46 +00:00
|
|
|
},
|
|
|
|
|
2021-02-13 21:43:51 +00:00
|
|
|
isDarkTheme: function () {
|
|
|
|
return this.current() == 'theme-dark';
|
|
|
|
},
|
|
|
|
|
2021-02-06 10:03:46 +00:00
|
|
|
setTheme: function (name) {
|
2021-03-13 21:20:01 +00:00
|
|
|
if ( sdk_themes_alias.contains(name) ) {
|
2021-02-06 10:03:46 +00:00
|
|
|
var classname = document.documentElement.className.replace(/theme-\w+\s?/, '');
|
2021-02-17 15:58:24 +00:00
|
|
|
document.body.className = classname;
|
2021-02-06 10:03:46 +00:00
|
|
|
|
2021-02-17 15:58:24 +00:00
|
|
|
$('body').addClass(name);
|
2021-03-13 21:20:01 +00:00
|
|
|
this.api.asc_setSkin(sdk_themes_alias[name]);
|
|
|
|
refresh_sdk_colors();
|
2021-02-17 21:27:58 +00:00
|
|
|
|
2021-02-06 10:03:46 +00:00
|
|
|
Common.localStorage.setItem('ui-theme', name);
|
2021-02-24 20:34:05 +00:00
|
|
|
Common.NotificationCenter.trigger('uitheme:changed', name);
|
2021-02-06 10:03:46 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
toggleTheme: function () {
|
|
|
|
this.setTheme(this.current() == 'theme-dark' ? 'theme-light' : 'theme-dark');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
});
|