-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from bembelimen/Fedir/dark-mode/switch
Dark Mode switch module
- Loading branch information
Showing
18 changed files
with
191 additions
and
31 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
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"$schema": "https://developer.joomla.org/schemas/json-schema/web_assets.json", | ||
"name": "mod_user", | ||
"version": "5.0.0", | ||
"description": "Joomla CMS", | ||
"license": "GPL-2.0-or-later", | ||
"assets": [ | ||
{ | ||
"name": "mod_user.color-scheme", | ||
"type": "style", | ||
"uri": "mod_user/color-scheme.min.css" | ||
}, | ||
{ | ||
"name": "mod_user.color-scheme", | ||
"type": "script", | ||
"uri": "mod_user/color-scheme.min.js", | ||
"dependencies": [ | ||
"core" | ||
], | ||
"attributes": { | ||
"type": "module" | ||
} | ||
}, | ||
{ | ||
"name": "mod_user.color-scheme", | ||
"type": "preset", | ||
"dependencies": [ | ||
"mod_user.color-scheme#style", | ||
"mod_user.color-scheme#script" | ||
] | ||
} | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* @copyright (C) 2019 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); | ||
|
||
buttons.forEach(button => { | ||
button.addEventListener('click', e => { | ||
e.preventDefault(); | ||
|
||
const docEl = document.documentElement | ||
const colorScheme = docEl.dataset.colorScheme; | ||
|
||
const newScheme = colorScheme !== 'dark' ? 'dark' : 'light'; | ||
|
||
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.addEventListener('DOMContentLoaded', initModUser); |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.mod_user-colorScheme { | ||
> span { | ||
&.mod_user-colorScheme-dark { | ||
display: none; | ||
} | ||
&.mod_user-colorScheme-light { | ||
display: inline; | ||
} | ||
} | ||
} | ||
|
||
[data-color-scheme="dark"] { | ||
.mod_user-colorScheme { | ||
> span { | ||
&.mod_user-colorScheme-dark { | ||
display: inline; | ||
} | ||
&.mod_user-colorScheme-light { | ||
display: none; | ||
} | ||
} | ||
} | ||
} |
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