summaryrefslogtreecommitdiff
path: root/public/static/js/collapse.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/static/js/collapse.js')
-rw-r--r--public/static/js/collapse.js77
1 files changed, 51 insertions, 26 deletions
diff --git a/public/static/js/collapse.js b/public/static/js/collapse.js
index 9fa2e89..0d4652b 100644
--- a/public/static/js/collapse.js
+++ b/public/static/js/collapse.js
@@ -4,6 +4,7 @@ function reload_app() {
// Until then, we guard it by only reloading whin moreinfo is not expanded.
if ($('.expanded-moreinfo').length == 0) {
$.get(window.location.href, {ajax: 1}, function(data) {
+ // TODO check expanded-moreinfo again here (until the issue itself has been resolved)
$('div.app > ul').html(data);
dbf_reg_handlers();
setTimeout(reload_app, 60000);
@@ -15,17 +16,13 @@ function reload_app() {
}
}
-function dbf_reg_handlers() {
- $('div.app > ul > li').click(function() {
- const trainElem = $(this);
- const routeprev = trainElem.data('routeprev').split('|');
- const routenext = trainElem.data('routenext').split('|');
- const moreinfo = trainElem.data('moreinfo').split('|');
- const this_href = window.location.href;
- const station = $('div.app').data('station');
- history.pushState({'page':'traindetail','train':trainElem.data('no')}, 'test', '/z/' + trainElem.data('train') + '/' + station);
- $('.moreinfo').each(function() {
- var infoElem = $(this);
+function dbf_show_moreinfo(trainElem, keep_old) {
+ const routeprev = trainElem.data('routeprev').split('|');
+ const routenext = trainElem.data('routenext').split('|');
+ const moreinfo = trainElem.data('moreinfo').split('|');
+ $('.moreinfo').each(function() {
+ const infoElem = $(this);
+ if (!keep_old) {
$('.moreinfo .train-line').removeClass('bahn sbahn fern ext').addClass(trainElem.data('linetype'));
$('.moreinfo .train-line').text(trainElem.data('line'));
$('.moreinfo .train-no').text(trainElem.data('no'));
@@ -76,14 +73,23 @@ function dbf_reg_handlers() {
}
}
$('.moreinfo .mfooter').append('Fahrtverlauf: <ul class="mroute">' + routebuf + '</ul>');
- $.get(this_href, {train: trainElem.data('train'), ajax: 1}, function(data) {
- $('.moreinfo').html(data);
- }).fail(function() {
- $('.moreinfo .mfooter').append('Der Zug ist abgefahren (Zug nicht gefunden)');
- });
- infoElem.removeClass('collapsed-moreinfo');
- infoElem.addClass('expanded-moreinfo');
+ }
+ $.get(window.location.href, {train: trainElem.data('train'), ajax: 1}, function(data) {
+ $('.moreinfo').html(data);
+ }).fail(function() {
+ $('.moreinfo .mfooter').append('Der Zug ist abgefahren (Zug nicht gefunden)');
});
+ infoElem.removeClass('collapsed-moreinfo');
+ infoElem.addClass('expanded-moreinfo');
+ });
+}
+
+function dbf_reg_handlers() {
+ $('div.app > ul > li').click(function() {
+ const trainElem = $(this);
+ const station = $('div.app').data('station');
+ history.pushState({'page':'traindetail','station':station,'train':trainElem.data('no')}, 'test', '/z/' + trainElem.data('train') + '/' + station);
+ dbf_show_moreinfo(trainElem, false);
});
}
@@ -128,14 +134,33 @@ $(function() {
history.replaceState({'page':'station'}, document.title, '');
}
window.onpopstate = function(event) {
- if ((event.state != null) && (event.state['page'] == 'station')) {
- $('.moreinfo').each(function() {
- $(this).removeClass('expanded-moreinfo');
- $(this).addClass('collapsed-moreinfo');
- });
- if (!$('div.app > ul').length) {
- $('div.app').append('<ul></ul>');
- reload_app();
+ if (event.state != null) {
+ if ((event.state['page'] == 'station')) {
+ $('.moreinfo').each(function() {
+ $(this).removeClass('expanded-moreinfo');
+ $(this).addClass('collapsed-moreinfo');
+ });
+ if (!$('div.app > ul').length) {
+ $('div.app').append('<ul></ul>');
+ reload_app();
+ }
+ } else if ((event.state['page'] == 'traindetail')) {
+ var success = false;
+ $('div.app > ul > li').each(function() {
+ const trainElem = $(this);
+ if (trainElem.data('no') == event.state['train']) {
+ dbf_show_moreinfo(trainElem, true);
+ success = true;
+ return;
+ }
+ });
+ if (!success) {
+ $('.moreinfo').each(function() {
+ $(this).removeClass('collapsed-moreinfo');
+ $(this).addClass('expanded-moreinfo');
+ });
+ $('.moreinfo .mfooter').append('Der Zug ist abgefahren (Zug nicht gefunden)');
+ }
}
} else {
console.log("unhandled popstate! " + document.location);