Skip to content
Snippets Groups Projects
Commit 9beb6d9b authored by Bohdan Melnychuk's avatar Bohdan Melnychuk Committed by Arthur Baghdasaryan
Browse files

Issue #3391071: Add JS behavior for init.js

parent 84aa6785
No related branches found
No related tags found
1 merge request!3Issue #3391071: Add JS behavior for init.js
......@@ -6,3 +6,5 @@ initiator:
js/init.js: {}
dependencies:
- darkmode/darkmodejs
- core/drupal
- core/once
function addDarkmodeWidget() {
const options = {
bottom: '64px', // default: '32px'
right: 'unset', // default: '32px'
left: '32px', // default: 'unset'
time: '0.5s', // default: '0.3s'
mixColor: '#fff', // default: '#fff'
backgroundColor: '#fff', // default: '#fff'
buttonColorDark: '#100f2c', // default: '#100f2c'
buttonColorLight: '#fff', // default: '#fff'
saveInCookies: false, // default: true,
label: '🌓', // default: ''
autoMatchOsTheme: true // default: true
}
/**
* @file
* Provides base JS for darkmode.
*/
(function (Drupal, once) {
/**
* Enables the dark mode widget.
*/
Drupal.behaviors.darkModeWidget = {
attach: function (context) {
// Check if the Darkmode library is available.
if (typeof Darkmode !== 'undefined') {
return;
}
const darkmode = new Darkmode(options);
darkmode.showWidget();
}
window.addEventListener('load', addDarkmodeWidget);
once('darkmode', 'body', context).forEach(() => {
const options = {
bottom: '64px',
right: '32px',
left: 'unset',
time: '0.5s',
mixColor: '#fff',
backgroundColor: '#fff',
buttonColorDark: '#100f2c',
buttonColorLight: '#fff',
saveInCookies: false,
label: '🌓',
autoMatchOsTheme: true
};
// Initialize the dark mode widget.
const darkmode = new Darkmode(options);
darkmode.showWidget();
})
}
}
})(Drupal, once);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment