Commit 8abf8294 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

fix forward button when navigating back to train details

parent 951581a9
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -648,6 +648,10 @@ sub train_details {
	my $train_no = $self->stash('train');
	my $station  = $self->stash('station');

	if ( $self->param('ajax') ) {
		delete $self->stash->{layout};
	}

	my %opt = (
		cache_hafas     => $self->app->cache_hafas,
		cache_iris_main => $self->app->cache_iris_main,
@@ -739,9 +743,11 @@ sub train_details {
	$self->stash( title => $data->{station_name} // $self->stash('station') );
	$self->stash( hide_opts => 1 );

	$self->render_train( $result, $result_info,
	$self->render_train(
		$result, $result_info,
		$data->{station_name} // $self->stash('station'),
		'train_details' );
		$self->param('ajax') ? '_train_details' : 'train_details'
	);
}

sub handle_result {
+4 −4
Original line number Diff line number Diff line
@@ -2,12 +2,12 @@
  font-family: 'Material Icons';
  font-style: normal;
  font-weight: 400;
  src: url(/static/v35/fonts/MaterialIcons-Regular.eot); /* For IE6-8 */
  src: url(/static/v36/fonts/MaterialIcons-Regular.eot); /* For IE6-8 */
  src: local('Material Icons'),
       local('MaterialIcons-Regular'),
       url(/static/v35/fonts/MaterialIcons-Regular.woff2) format('woff2'),
       url(/static/v35/fonts/MaterialIcons-Regular.woff) format('woff'),
       url(/static/v35/fonts/MaterialIcons-Regular.ttf) format('truetype');
       url(/static/v36/fonts/MaterialIcons-Regular.woff2) format('woff2'),
       url(/static/v36/fonts/MaterialIcons-Regular.woff) format('woff'),
       url(/static/v36/fonts/MaterialIcons-Regular.ttf) format('truetype');
}

.material-icons {
+51 −26
Original line number Diff line number Diff line
@@ -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);
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('|');
		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);
		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,7 +73,8 @@ function dbf_reg_handlers() {
				}
			}
			$('.moreinfo .mfooter').append('Fahrtverlauf: <ul class="mroute">' + routebuf + '</ul>');
			$.get(this_href, {train: trainElem.data('train'), ajax: 1}, function(data) {
		}
		$.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)');
@@ -84,6 +82,14 @@ function dbf_reg_handlers() {
		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,7 +134,8 @@ $(function() {
		history.replaceState({'page':'station'}, document.title, '');
	}
	window.onpopstate = function(event) {
		if ((event.state != null) && (event.state['page'] == 'station')) {
		if (event.state != null) {
			if ((event.state['page'] == 'station')) {
				$('.moreinfo').each(function() {
					$(this).removeClass('expanded-moreinfo');
					$(this).addClass('collapsed-moreinfo');
@@ -137,6 +144,24 @@ $(function() {
					$('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);
		}
+2 −2

File changed.

Preview size limit exceeded, changes collapsed.

+0 −0

File moved.

Loading