diff options
author | Daniel Friesel <derf@finalrewind.org> | 2020-04-20 20:20:52 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2020-04-20 20:20:52 +0200 |
commit | eeedb40bdc0510dec0e2ddca149e82bff7495d0a (patch) | |
tree | b80eb0f9908016382e8a36d9dd9f321cdd44473f /templates | |
parent | 375f02ad634c10030f47af94f0530dda0d2d044d (diff) |
switch to a proper dark theme using javascript and sass3.1.0
The dark=1 option is still supported, but no longer visible in the UI.
Diffstat (limited to 'templates')
-rw-r--r-- | templates/app.html.ep | 7 | ||||
-rw-r--r-- | templates/layouts/app.html.ep | 45 | ||||
-rw-r--r-- | templates/wagenreihung.html.ep | 4 |
3 files changed, 38 insertions, 18 deletions
diff --git a/templates/app.html.ep b/templates/app.html.ep index fd7c1f1..5ceec12 100644 --- a/templates/app.html.ep +++ b/templates/app.html.ep @@ -1,12 +1,7 @@ % if (@{$departures}) { % if (not param('ajax')) { -% if (param('dark')) { -<div class="app appdark"> -% } -% else { -<div class="app applight"> -% } +<div class="app"> <div class="moreinfo collapsed-moreinfo"> <div class="mheader"> <div> diff --git a/templates/layouts/app.html.ep b/templates/layouts/app.html.ep index 258c6fd..6485a22 100644 --- a/templates/layouts/app.html.ep +++ b/templates/layouts/app.html.ep @@ -19,7 +19,37 @@ % } % my $av = 'v28'; # asset version - %= stylesheet "/static/${av}/css/app.css" + % if (session('theme') and session('theme') eq 'dark' or param('dark')) { + %= stylesheet "/static/${av}/css/dark.min.css", id => 'theme' + % } + % else { + %= stylesheet "/static/${av}/css/light.min.css", id => 'theme' + % } + <script> + function addStyleSheet(name, id) { + var path = '/static/<%=$av%>/css/' + name + '.min.css'; + var old = document.getElementById(id); + if (old && (old.href != path)) { + old.href = path; + document.cookie = 'theme=' + name; + } + } + var otherTheme = { + 'dark': 'light', + 'light': 'dark', + }; + var currentTheme = localStorage.getItem('theme'); + if (!otherTheme.hasOwnProperty(currentTheme)) { + currentTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; + } + addStyleSheet(currentTheme, 'theme'); + + function toggleTheme() { + currentTheme = otherTheme[currentTheme] || 'light'; + localStorage.setItem('theme', currentTheme); + addStyleSheet(currentTheme, 'theme'); + } + </script> %= stylesheet "/static/${av}/css/material-icons.css" %= stylesheet "/static/${av}/css/jquery-ui.min.css" %= javascript '/static/js/jquery-3.4.1.min.js', defer => undef @@ -33,7 +63,7 @@ %= javascript "/static/${av}/leaflet/leaflet.js" % } </head> -<body style="<%= (param('dark') ? 'background-color: #000000; color: #ffffff;' : q{}) %>"> +<body> <div class="navbar-fixed"> <nav style="color: #ffffff; background-color: #00838f;"> @@ -42,6 +72,9 @@ %= stash('title') || 'DBF' </span> <ul id="nav-mobile" style="float: right;"> + <li class="waves-effect waves-light"> + <a onClick="javascript:toggleTheme()"><i class="material-icons" aria-label="Farbschema invertieren">invert_colors</i></a> + </li> % if (stash('hide_opts')) { <li><a href="/"><i class="material-icons">edit</i></a></li> % } @@ -139,14 +172,6 @@ Bitte eine Station aus der Liste auswählen</div> </div> <div class="field"> <div class="desc"> - %= check_box 'dark' => 1, id => 'id_dark' - <label for="id_dark"> - Dunkles Layout (experimentell) - </label> - </div> - </div> - <div class="field"> - <div class="desc"> %= check_box 'hide_opts' => 1, id => 'id_hide_opts' <label for="id_hide_opts"> Formular verstecken (für Infoscreens) diff --git a/templates/wagenreihung.html.ep b/templates/wagenreihung.html.ep index 53be3a1..c4fade8 100644 --- a/templates/wagenreihung.html.ep +++ b/templates/wagenreihung.html.ep @@ -64,10 +64,10 @@ % my $bg = ''; % my $extra_class = ''; % if ($wagon->is_first_class) { -% $bg = 'background-color: #ffff99;'; +% $extra_class .= ' firstclass'; % } % if ($wagon->is_locomotive or $wagon->is_powercar) { -% $bg = 'background-color: #cccccc;'; +% $extra_class .= ' powercar'; % } % if ($wagon->train_no ne $train_no) { % $extra_class .= ' nondestwagon'; |