-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ticket #4040 - Artificer: Allow to enable only one color scheme.
- Loading branch information
Showing
9 changed files
with
147 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,97 @@ | ||
//for custom JS | ||
$(document).ready(function() { | ||
bx_artificer_set_color_scheme_icon(); | ||
}); | ||
function BxArtificerUtils(oOptions) | ||
{ | ||
this._sActionUri = oOptions.sActionUri; | ||
this._sActionUrl = oOptions.sActionUrl; | ||
this._sObject = oOptions.sObject; | ||
this._aHtmlIds = undefined == oOptions.aHtmlIds ? {} : oOptions.aHtmlIds; | ||
this._sColorScheme = undefined == oOptions.sColorScheme ? 'auto' : oOptions.sColorScheme; | ||
|
||
function bx_artificer_set_color_scheme_html(){ | ||
if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) | ||
$('html').addClass('dark') | ||
else | ||
$('html').removeClass('dark') | ||
this.init(); | ||
} | ||
|
||
function bx_artificer_set_color_scheme_icon(){ | ||
if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) { | ||
$('.bx-sb-theme-switcher .sys-icon').addClass('moon').removeClass('sun'); | ||
} | ||
BxArtificerUtils.prototype.init = function() | ||
{ | ||
var $this = this; | ||
|
||
if (localStorage.theme === 'sun' || (!('theme' in localStorage) && !window.matchMedia('(prefers-color-scheme: dark)').matches)) { | ||
$('.bx-sb-theme-switcher .sys-icon').addClass('sun').removeClass('moon'); | ||
} | ||
} | ||
switch(this._sColorScheme) { | ||
case 'auto': | ||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => { | ||
$this.setColorSchemeIcon(); | ||
$this.setColorSchemeHtml(); | ||
}); | ||
break; | ||
|
||
case 'light_only': | ||
this.setColorScheme(1); | ||
break; | ||
|
||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => { | ||
bx_artificer_set_color_scheme_icon(); | ||
bx_artificer_set_color_scheme_html(); | ||
}); | ||
case 'dark_only': | ||
this.setColorScheme(2); | ||
break; | ||
} | ||
|
||
function bx_artificer_set_color_scheme(m){ | ||
switch (m) { | ||
this.setColorSchemeHtml(); | ||
|
||
$(document).ready(function() { | ||
$this.setColorSchemeIcon(); | ||
}); | ||
}; | ||
|
||
BxArtificerUtils.prototype.setColorScheme = function(iCode) | ||
{ | ||
switch(iCode) { | ||
case 0: | ||
localStorage.removeItem('theme'); | ||
break; | ||
|
||
case 1: | ||
localStorage.theme = 'sun' | ||
break; | ||
|
||
case 2: | ||
localStorage.theme = 'dark' | ||
break; | ||
} | ||
bx_artificer_set_color_scheme_icon(); | ||
bx_artificer_set_color_scheme_html(); | ||
} | ||
|
||
function bx_artificer_get_color_scheme_menu(){ | ||
this.setColorSchemeIcon(); | ||
this.setColorSchemeHtml(); | ||
}; | ||
|
||
BxArtificerUtils.prototype.setColorSchemeHtml = function() | ||
{ | ||
if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) | ||
$('html').addClass('dark') | ||
else | ||
$('html').removeClass('dark') | ||
}; | ||
|
||
BxArtificerUtils.prototype.setColorSchemeIcon = function() | ||
{ | ||
if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) { | ||
$('.bx-sb-theme-switcher .sys-icon').addClass('moon').removeClass('sun'); | ||
} | ||
|
||
if (localStorage.theme === 'sun' || (!('theme' in localStorage) && !window.matchMedia('(prefers-color-scheme: dark)').matches)) { | ||
$('.bx-sb-theme-switcher .sys-icon').addClass('sun').removeClass('moon'); | ||
} | ||
}; | ||
|
||
BxArtificerUtils.prototype.getColorSchemeMenu = function() { | ||
$('#bx-sb-theme-switcher-menu').dolPopup({ | ||
pointer: { | ||
el: $('.bx-sb-theme-switcher') | ||
}, | ||
moveToDocRoot: true, | ||
cssClass: 'bx-popup-menu' | ||
}); | ||
} | ||
}; | ||
|
||
function bx_artificer_add_content_panel(sMenu, e, sPosition) { | ||
BxArtificerUtils.prototype.getAddContentMenu = function(sMenu, e, sPosition) { | ||
$('.bx-popup-applied:visible').dolPopupHide(); | ||
|
||
var sSidebar = 'account'; | ||
if(bx_sidebar_active(sSidebar)) | ||
bx_sidebar_toggle(sSidebar); | ||
|
||
bx_menu_popup_inline(sMenu, e, {}); | ||
} | ||
|
||
bx_artificer_set_color_scheme_html(); | ||
}; |