diff --git a/apps/common/main/lib/controller/Themes.js b/apps/common/main/lib/controller/Themes.js index 863594e41..0c6610f14 100644 --- a/apps/common/main/lib/controller/Themes.js +++ b/apps/common/main/lib/controller/Themes.js @@ -8,21 +8,35 @@ define([ 'use strict'; Common.UI.Themes = new (function() { - var sdk_themes_relation = { + var sdk_themes_alias = { 'theme-light': 'flat', 'theme-dark': 'flatDark' }; - sdk_themes_relation.contains = function (name) { + sdk_themes_alias.contains = function (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 { THEME_LIGHT_ID: 'theme-light', THEME_DARK_ID: 'theme-dark', init: function (api) { var me = this; + refresh_sdk_colors = refresh_sdk_colors.bind(this); + $(window).on('storage', function (e) { if ( e.key == 'ui-theme' ) { me.setTheme(e.originalEvent.newValue); @@ -31,12 +45,14 @@ define([ this.api = api; 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) ) { $('body').addClass(theme_name); } + refresh_sdk_colors(); + // app.eventbus.addListeners({ // 'FileMenu': { // 'settings:apply': function (menu) { @@ -60,23 +76,13 @@ define([ }, setTheme: function (name) { - if ( sdk_themes_relation.contains(name) ) { + if ( sdk_themes_alias.contains(name) ) { var classname = document.documentElement.className.replace(/theme-\w+\s?/, ''); document.body.className = classname; $('body').addClass(name); - this.api.asc_setSkin(sdk_themes_relation[name]); - - 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 - }); - } + this.api.asc_setSkin(sdk_themes_alias[name]); + refresh_sdk_colors(); Common.localStorage.setItem('ui-theme', name); Common.NotificationCenter.trigger('uitheme:changed', name);