Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedik committed Jan 28, 2024
1 parent 7b18960 commit 85c65c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 31 deletions.
2 changes: 1 addition & 1 deletion administrator/components/com_users/forms/user.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
filter="options"
>
<option value="">JOPTION_USE_DEFAULT</option>
<option value="0">COM_USERS_USER_COLORSCHEME_OPTION_FOLLOW_OS</option>
<option value="os">COM_USERS_USER_COLORSCHEME_OPTION_FOLLOW_OS</option>
<option value="light">COM_USERS_USER_COLORSCHEME_OPTION_LIGHT</option>
<option value="dark">COM_USERS_USER_COLORSCHEME_OPTION_DARK</option>
</field>
Expand Down
44 changes: 14 additions & 30 deletions build/media_source/mod_user/js/color-scheme.es6.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,26 @@
/**
* @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
* @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
/**
* Every quickicon with an ajax request url loads data and set them into the counter element
* Also the data name is set as singular or plural.
* A SR-only text is added
* The class pulse gets 'warning', 'success' or 'error', depending on the retrieved data.
*/
if (!Joomla) {
throw new Error('Joomla API was not properly initialized');
}

const initModUser = () => {
const buttons = [].slice.call(document.querySelectorAll('.mod_user-colorScheme'));

console.log(window.document);
const buttons = document.querySelectorAll('.mod_user-colorScheme');

buttons.forEach(button => {
button.addEventListener('click', e => {
e.preventDefault();
buttons.forEach((button) => {
button.addEventListener('click', (e) => {
e.preventDefault();

const docEl = document.documentElement
const colorScheme = docEl.dataset.colorScheme;
const docEl = document.documentElement;
const { colorScheme } = docEl.dataset;
const newScheme = colorScheme !== 'dark' ? 'dark' : 'light';

const newScheme = colorScheme !== 'dark' ? 'dark' : 'light';
docEl.dataset.colorScheme = newScheme;
docEl.dataset.bsTheme = newScheme;

docEl.dataset.colorScheme = newScheme;
docEl.dataset.bsTheme = newScheme;

const expires = new Date();
expires.setTime(expires.getTime() + 31536000000);
document.cookie = `colorScheme=${newScheme}; expires=${expires.toUTCString()};`;
document.dispatchEvent(new CustomEvent('joomla:color-scheme-change', { bubbles: true }));

});
document.cookie = `colorScheme=${newScheme};`;
document.dispatchEvent(new CustomEvent('joomla:color-scheme-change', { bubbles: true }));
});

});
};

document.addEventListener('DOMContentLoaded', initModUser);
initModUser();

0 comments on commit 85c65c0

Please sign in to comment.