whoopsie forgot the darkmode js file

pull/27/head
Ondřej Hruška 6 years ago
parent 84103d6001
commit fa05d8c9d0
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 1
      resources/assets/js/app.js
  2. 35
      resources/assets/js/modules/dark-mode.js

@ -4,6 +4,7 @@ require('./base-setup')
require('./modules/block-collapse') require('./modules/block-collapse')
require('./modules/flash-messages') require('./modules/flash-messages')
require('./modules/form-autoalias') require('./modules/form-autoalias')
require('./modules/dark-mode')
require('./vue-init') require('./vue-init')
$(function () { $(function () {

@ -0,0 +1,35 @@
$(function () {
// theme switcher without reloading
let themeStyle = $('#theme-style');
const lightURL = themeStyle.data('light-url');
const darkURL = themeStyle.data('dark-url');
const navbar = $('.page-navbar');
const logo = $('#navbar-logo');
window.toggleDarkMode = function () {
let newStyle = document.createElement('link');
newStyle.rel = 'stylesheet';
if (themeStyle.attr('href') === lightURL) {
newStyle.href = darkURL;
navbar.removeClass('navbar-light');
navbar.addClass('navbar-dark');
logo.attr('src', logo.data('src-dark'));
document.cookie = "dark_mode=1";
} else {
newStyle.href = lightURL;
navbar.removeClass('navbar-dark');
navbar.addClass('navbar-light');
logo.attr('src', logo.data('src-light'));
document.cookie = "dark_mode=0;expires=" + new Date().toUTCString();
}
// remove old css after new css has loaded to prevent FOUC
let oldThemeStyle = themeStyle;
themeStyle = $(newStyle);
themeStyle.on('load', () => oldThemeStyle.remove());
$(document.head).append(themeStyle);
};
});
Loading…
Cancel
Save