summaryrefslogtreecommitdiff
path: root/public/static/collapse.js
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2019-05-07 17:32:02 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2019-05-07 17:33:15 +0200
commita5427163ced9f99044813058ddf62548debc673c (patch)
tree7bbd7efd42d497e1f6aff542d2c9284353620c3d /public/static/collapse.js
parent012169b095c2cb115cbf77707af4304a6e4a1f61 (diff)
app: Use AJAX, not HTTP Refresh for auto-reload2.0.2
Diffstat (limited to 'public/static/collapse.js')
-rw-r--r--public/static/collapse.js47
1 files changed, 32 insertions, 15 deletions
diff --git a/public/static/collapse.js b/public/static/collapse.js
index 3457d96..44d3048 100644
--- a/public/static/collapse.js
+++ b/public/static/collapse.js
@@ -1,13 +1,14 @@
-$(document).ready(function() {
- if (document.location.hash.length > 1) {
- var wanted = document.location.hash.replace('#', '');
- $('div.app > ul > li > .moreinfo, div.infoscreen > ul > li > .moreinfo').each(function() {
- if ($(this).data('train') == wanted) {
- $(this).removeClass('collapsed-moreinfo');
- $(this).addClass('expanded-moreinfo');
- }
- });
- }
+function reload_app() {
+ $.get(window.location.href, {ajax: 1}, function(data) {
+ $('div.app > ul').html(data);
+ dbf_reg_handlers();
+ setTimeout(reload_app, 30000);
+ }).fail(function() {
+ setTimeout(reload_app, 10000);
+ });
+}
+
+function dbf_reg_handlers() {
$('div.app > ul > li').click(function() {
var trainElem = $(this);
$('.moreinfo').each(function() {
@@ -22,7 +23,7 @@ $(document).ready(function() {
$('.moreinfo .verbose').html('');
$('.moreinfo .mroute').html('');
$('.moreinfo ul').html('');
- $.get(window.location.href, {train: trainElem.data('train')}, function(data) {
+ $.get(window.location.href, {train: trainElem.data('train'), ajax: 1}, function(data) {
$('.moreinfo').html(data);
}).fail(function() {
$('.moreinfo .mfooter').html('Der Zug ist abgefahren (Zug nicht gefunden)');
@@ -31,10 +32,18 @@ $(document).ready(function() {
infoElem.addClass('expanded-moreinfo');
});
});
- $('.moreinfo').click(function() {
- $(this).removeClass('expanded-moreinfo');
- $(this).addClass('collapsed-moreinfo');
- });
+}
+
+$(document).ready(function() {
+ if (document.location.hash.length > 1) {
+ var wanted = document.location.hash.replace('#', '');
+ $('div.app > ul > li > .moreinfo, div.infoscreen > ul > li > .moreinfo').each(function() {
+ if ($(this).data('train') == wanted) {
+ $(this).removeClass('collapsed-moreinfo');
+ $(this).addClass('expanded-moreinfo');
+ }
+ });
+ }
$('.moresettings-header').each(function() {
$(this).click(function() {
var moresettings = $('.moresettings');
@@ -69,4 +78,12 @@ $(document).ready(function() {
}
});
});
+ $('.moreinfo').click(function() {
+ $(this).removeClass('expanded-moreinfo');
+ $(this).addClass('collapsed-moreinfo');
+ });
+ dbf_reg_handlers();
+ if ($('.content .app').length) {
+ setTimeout(reload_app, 30000);
+ }
});