Skip to content

Commit a08fd97

Browse files
committed
Add a JS function to toggle the dark mode
1 parent 27cb970 commit a08fd97

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

system/Debug/Toolbar/Views/toolbar.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var ciDebugBar = {
1616
ciDebugBar.createListeners();
1717
ciDebugBar.setToolbarState();
1818
ciDebugBar.setToolbarPosition();
19+
ciDebugBar.setToolbarTheme();
1920
ciDebugBar.toggleViewsHints();
2021

2122
document.getElementById('debug-bar-link').addEventListener('click', ciDebugBar.toggleToolbar, true);
@@ -504,6 +505,37 @@ var ciDebugBar = {
504505

505506
//--------------------------------------------------------------------
506507

508+
setToolbarTheme: function () {
509+
var btnTheme = document.getElementById('toolbar-theme');
510+
511+
if (ciDebugBar.readCookie('debug-bar-theme') === 'dark')
512+
{
513+
ciDebugBar.addClass(ciDebugBar.icon, 'dark');
514+
ciDebugBar.addClass(ciDebugBar.toolbar, 'dark');
515+
}
516+
517+
btnTheme.addEventListener('click', function () {
518+
var theme = ciDebugBar.readCookie('debug-bar-theme');
519+
520+
ciDebugBar.createCookie('debug-bar-theme', '', -1);
521+
522+
if (!theme || theme === 'light')
523+
{
524+
ciDebugBar.createCookie('debug-bar-theme', 'dark', 365);
525+
ciDebugBar.addClass(ciDebugBar.icon, 'dark');
526+
ciDebugBar.addClass(ciDebugBar.toolbar, 'dark');
527+
}
528+
else
529+
{
530+
ciDebugBar.createCookie('debug-bar-theme', 'light', 365);
531+
ciDebugBar.removeClass(ciDebugBar.icon, 'dark');
532+
ciDebugBar.removeClass(ciDebugBar.toolbar, 'dark');
533+
}
534+
}, true);
535+
},
536+
537+
//--------------------------------------------------------------------
538+
507539
/**
508540
* Helper to create a cookie.
509541
*

0 commit comments

Comments
 (0)