From 0f11d06782f3f2081538bd461bc9019b3c900e40 Mon Sep 17 00:00:00 2001 From: Jacek Kowalski <Jacek@jacekk.info> Date: Mon, 17 Apr 2017 15:51:41 +0000 Subject: [PATCH] Add vehicle info before schedule table --- index.js | 22 +++++++++++++++++++--- index.html | 2 ++ index.css | 7 ++++++- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/index.css b/index.css index bca5873..38820bd 100644 --- a/index.css +++ b/index.css @@ -35,9 +35,14 @@ } .vehicleInfo { + font-size: 21px; +} +#times-table .vehicleInfo { float: right; margin: -5px 0; - font-size: 21px; +} +#route-vehicle .vehicleInfo { + margin-right: .5em; } #vehicle-data { float: right; diff --git a/index.html b/index.html index 24f747d..f4e3a0e 100644 --- a/index.html +++ b/index.html @@ -98,6 +98,8 @@ <h3 id="route-line"></h3> + <p id="route-vehicle"></p> + <table class="table table-condensed"> <thead> <tr> diff --git a/index.js b/index.js index acdfb24..1e0d131 100644 --- a/index.js +++ b/index.js @@ -26,6 +26,7 @@ var route_xhr; var route_line = document.getElementById('route-line'); var route_table = document.getElementById('route-table'); +var route_vehicle = document.getElementById('route-vehicle'); var refresh_button = document.getElementById('refresh'); var refresh_text = document.getElementById('refresh-text'); @@ -189,7 +190,9 @@ addCellWithText(tr, ''); tr.className = 'active'; - tr.addEventListener('click', function(tripId){ return function(){ loadRoute(tripId); } }(data.old[i].tripId) ); + tr.addEventListener('click', function(tripId, vehicleInfo) { + return function(){ loadRoute(tripId, vehicleInfo); } + }(data.actual[i].tripId, vehicle)); times_table.appendChild(tr); } @@ -215,7 +218,9 @@ tr.className = 'warning'; } - tr.addEventListener('click', function(tripId){ return function(){ loadRoute(tripId); } }(data.actual[i].tripId) ); + tr.addEventListener('click', function(tripId, vehicleInfo) { + return function(){ loadRoute(tripId, vehicleInfo); } + }(data.actual[i].tripId, vehicle)); times_table.appendChild(tr); } @@ -236,12 +241,15 @@ }).fail(fail_ajax).always(loading_end); } -function loadRoute(tripId) { +function loadRoute(tripId, vehicleInfo) { if(!tripId) tripId = route_id; if(!tripId) return; + if(!vehicleInfo) vehicleInfo = route_vehicle_info; + console.log('loadRoute(' + tripId + ')'); route_id = tripId; + route_vehicle_info = vehicleInfo; if(route_xhr) route_xhr.abort(); route_xhr = $.get( @@ -255,6 +263,14 @@ } setText(route_line, data.routeName + ' ' + data.directionText); + + deleteChildren(route_vehicle); + if(vehicleInfo) { + var span = displayVehicle(vehicleInfo); + setText(route_vehicle, span.title); + route_vehicle.insertBefore(span, route_vehicle.firstChild); + } + deleteChildren(route_table); for(var i = 0, il = data.old.length; i < il; i++) { -- Gitblit v1.9.1