Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
darkmode
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
darkmode
Commits
9beb6d9b
Commit
9beb6d9b
authored
1 year ago
by
Bohdan Melnychuk
Committed by
Arthur Baghdasaryan
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3391071
: Add JS behavior for init.js
parent
84aa6785
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!3
Issue #3391071: Add JS behavior for init.js
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
darkmode.libraries.yml
+2
-0
2 additions, 0 deletions
darkmode.libraries.yml
js/init.js
+39
-18
39 additions, 18 deletions
js/init.js
with
41 additions
and
18 deletions
darkmode.libraries.yml
+
2
−
0
View file @
9beb6d9b
...
...
@@ -6,3 +6,5 @@ initiator:
js/init.js
:
{}
dependencies
:
-
darkmode/darkmodejs
-
core/drupal
-
core/once
This diff is collapsed.
Click to expand it.
js/init.js
+
39
−
18
View file @
9beb6d9b
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
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment