diff options
Diffstat (limited to 'public/static/js/collapse.js')
-rw-r--r-- | public/static/js/collapse.js | 68 |
1 files changed, 62 insertions, 6 deletions
diff --git a/public/static/js/collapse.js b/public/static/js/collapse.js index 9763f26..d7d1e3b 100644 --- a/public/static/js/collapse.js +++ b/public/static/js/collapse.js @@ -1,9 +1,22 @@ /* - * Copyright (C) 2020 Daniel Friesel + * Copyright (C) 2020-2023 Birte Kristina Friesel * * SPDX-License-Identifier: AGPL-3.0-or-later */ +function setLang(lang) { + document.cookie = 'lang=' + lang + ';SameSite=None;Secure'; + location.reload(); +} + +function setTheme(theme) { + localStorage.setItem('theme', theme); + if (!otherTheme.hasOwnProperty(theme)) { + theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; + } + addStyleSheet(theme, 'theme'); +} + function reload_app() { // TODO use a variable instead of window.location.href, as // window.location.href may be /z/... @@ -29,7 +42,7 @@ function dbf_show_moreinfo(trainElem, keep_old) { $('.moreinfo').each(function() { const infoElem = $(this); if (!keep_old) { - $('.moreinfo .train-line').removeClass('bahn sbahn fern ext').addClass(trainElem.data('linetype')); + $('.moreinfo .train-line').removeClass('sbahn fern ext ubahn bus tram').addClass(trainElem.data('linetype')); $('.moreinfo .train-line').text(trainElem.data('line')); $('.moreinfo .train-no').text(trainElem.data('no')); $('.moreinfo .train-origin').text(trainElem.data('from')); @@ -80,7 +93,7 @@ function dbf_show_moreinfo(trainElem, keep_old) { } $('.moreinfo .mfooter').append('Fahrtverlauf: <ul class="mroute">' + routebuf + '</ul>'); } - $.get(window.location.href, {train: trainElem.data('train'), ajax: 1}, function(data) { + $.get(window.location.href, {train: trainElem.data('train'), jid: trainElem.data('jid'), ajax: 1}, function(data) { $('.moreinfo').html(data); }).fail(function() { $('.moreinfo .mfooter').append('Der Zug ist abgefahren (Zug nicht gefunden)'); @@ -94,17 +107,60 @@ function dbf_reg_handlers() { $('div.app > ul > li').click(function(event) { const trainElem = $(this); const station = $('div.app').data('station'); + const param = new URLSearchParams(window.location.search); event.preventDefault(); var suffix = '?'; - if (window.location.href.includes('detailed=1')) { + if (param.get('detailed')) { suffix += '&detailed=1'; } - if (window.location.href.includes('past=1')) { + if (param.get('hafas') && param.get('hafas') != '0') { + suffix += '&hafas=' + param.get('hafas') + '&highlight=' + trainElem.data('station'); + } + if (param.get('past')) { suffix += '&past=1'; } - history.pushState({'page':'traindetail','station':station,'train':trainElem.data('no')}, 'test', '/z/' + trainElem.data('train') + '/' + trainElem.data('station') + suffix); + if (param.get('rt') || param.get('show_realtime')) { + suffix += '&rt=1'; + } + if (param.get('hafas') && param.get('hafas') != '0') { + history.pushState({'page':'traindetail','jid':trainElem.data('jid')}, 'test', '/z/' + trainElem.data('jid') + suffix); + } else { + history.pushState({'page':'traindetail','station':station,'train':trainElem.data('no')}, 'test', '/z/' + trainElem.data('train') + '/' + trainElem.data('station') + suffix); + } dbf_show_moreinfo(trainElem, false); }); + const trainid = $(location).attr('hash').substr(1); + if (trainid) { + var found = false; + $('div.app > ul > li').each(function(index) { + if (found) { + return; + } + $(this).find('.anchor').each(function() { + if ($(this).attr('id') == trainid) { + found = true; + } + }); + }); + if (found) { + found = false; + $('div.app > ul > li').each(function(index) { + if (found) { + return; + } + $(this).find('.anchor').each(function() { + if ($(this).attr('id') == trainid) { + found = true; + } + }); + if (found) { + $(this).addClass('selected'); + } else { + $(this).addClass('past'); + } + }); + } + } } $(function() { |