diff --git a/assets/css/app.css b/assets/css/app.css index 8021b679..d9b9616c 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -165,7 +165,7 @@ showing the sidebar (on devices with md or higher) .toast-container { position: fixed; top: auto; - z-index: 1; + z-index: 3000; /* Over darkmode layer for correct colors! */ right: 25px; } @@ -347,7 +347,6 @@ btn-xs display: block; margin-left: auto; margin-right: auto; - } .hoverpic:hover { @@ -356,6 +355,10 @@ btn-xs box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); } +.darkmode--activated .hoverpic:hover { + background: black; +} + .thumbnail-sm { max-height: 100px; @@ -790,3 +793,11 @@ table.dataTable { font-size: 17.5px; border-left: 5px solid #eee; } + +.darkmode-layer { + z-index: 2020; +} + +.darkmode--activated img { + mix-blend-mode: difference; +} \ No newline at end of file diff --git a/assets/js/app.js b/assets/js/app.js index 535f0afc..9287e85d 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -88,6 +88,8 @@ require('../css/tagsinput.css'); //Tristate checkbox support require('./jquery.tristate.js'); +require('darkmode-js'); + require('../ts_src/ajax_ui'); import {ajaxUI} from "../ts_src/ajax_ui"; @@ -97,6 +99,26 @@ window.ajaxUI = ajaxUI; require('../ts_src/event_listeners'); + +//Register darkmode (we must do it here, TS does not support ES6 constructor... +try { + //The browser needs to support mix blend mode + if(typeof window.getComputedStyle(document.body).mixBlendMode !== 'undefined') { + const darkmode = new Darkmode(); + + $(document).on("ajaxUI:start ajaxUI:reload", function () { + //Show darkmode toggle to user + $('#toggleDarkmodeContainer, #toggleDarkmodeSeparator').removeAttr('hidden'); + $('#toggleDarkmode').prop('checked', darkmode.isActivated()); + $('#toggleDarkmode').change(function () { + darkmode.toggle(); + }); + }); + } +} catch (e) { + //Ignore all errors (for compatibiltiy with old browsers) +} + //Start AjaxUI AFTER all event has been registered $(document).ready(ajaxUI.start()); diff --git a/package.json b/package.json index ef8453b1..683a80ee 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "bootswatch": "^4.3.1", "copy-webpack-plugin": "^5.0.4", "corejs-typeahead": "^1.2.1", + "darkmode-js": "^1.5.3", "datatables.net-bs4": "^1.10.19", "datatables.net-buttons-bs4": "^1.5.4", "datatables.net-colreorder-bs4": "^1.5.1", diff --git a/templates/_navbar.html.twig b/templates/_navbar.html.twig index ef5401c0..40958da6 100644 --- a/templates/_navbar.html.twig +++ b/templates/_navbar.html.twig @@ -58,13 +58,13 @@ {% if true %}