2017-11-15 19:46:47 +01:00
|
|
|
"use strict";
|
2017-11-15 20:19:15 +01:00
|
|
|
|
2017-11-16 23:08:14 +01:00
|
|
|
/*
|
|
|
|
* This file contains the main control flow.
|
|
|
|
*/
|
|
|
|
|
2017-12-22 13:13:52 +01:00
|
|
|
var slyelement = {
|
|
|
|
obj: {},
|
2017-12-22 13:57:42 +01:00
|
|
|
curRaces: {},
|
2017-12-29 17:17:21 +01:00
|
|
|
curRaceId: 0,
|
2017-12-22 13:13:52 +01:00
|
|
|
el: '.frame',
|
|
|
|
options: {
|
|
|
|
horizontal: 1,
|
|
|
|
itemNav: 'basic',
|
|
|
|
smart: 1,
|
2017-12-29 17:11:02 +01:00
|
|
|
//activateOn: 'click',
|
|
|
|
//activatePageOn: 'click',
|
|
|
|
mouseDragging: 0,
|
2017-12-22 13:13:52 +01:00
|
|
|
touchDragging: 1,
|
2017-12-29 17:11:02 +01:00
|
|
|
releaseSwing: 0,
|
2017-12-22 13:13:52 +01:00
|
|
|
startAt: 3,
|
|
|
|
scrollBar: $('.strecken-selector').parent().find('.scrollbar'),
|
|
|
|
scrollBy: 1,
|
|
|
|
pagesBar: $('.strecken-selector').parent().find('.pages'),
|
|
|
|
speed: 300,
|
|
|
|
elasticBounds: 1,
|
|
|
|
dragHandle: 1,
|
|
|
|
dynamicHandle: 1,
|
|
|
|
clickBar: 1,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-12-29 23:45:10 +01:00
|
|
|
preprocessor.load(function(data) {
|
|
|
|
slyelement.obj = new Sly($(slyelement.el), slyelement.options);
|
2017-12-22 13:13:52 +01:00
|
|
|
slyelement.obj.init();
|
2017-12-22 09:40:26 +01:00
|
|
|
|
2017-12-30 00:02:06 +01:00
|
|
|
// Create list of available years in descending order
|
2017-12-08 13:50:41 +01:00
|
|
|
var yearSelector = $("#seasonByYearSelector");
|
2017-12-17 10:38:48 +01:00
|
|
|
var seasons = processor.getSeasonsWithLapData();
|
2017-12-30 00:02:06 +01:00
|
|
|
for(var season in seasons){ yearSelector.prepend("<option>" + seasons[season].year + "</option>"); }
|
2017-12-29 23:45:10 +01:00
|
|
|
|
2017-12-22 13:13:52 +01:00
|
|
|
// Someone chose a year
|
|
|
|
yearSelector.change(function(event) {
|
|
|
|
var selectedYear = $(event.target).val();
|
2017-12-22 13:57:42 +01:00
|
|
|
slyelement.curRaces = processor.getRacesByYear(selectedYear);
|
2017-12-30 00:15:53 +01:00
|
|
|
// Empty the course selector
|
2017-12-22 13:13:52 +01:00
|
|
|
$("#courseSelection").empty();
|
2017-12-30 00:15:53 +01:00
|
|
|
// ... and fill it with fresh races to choose from
|
2017-12-29 17:28:30 +01:00
|
|
|
for(var race in slyelement.curRaces) {
|
|
|
|
var raceD = slyelement.curRaces[race];
|
|
|
|
$("#courseSelection").append("<li data=\"" + raceD.raceInfo.raceId + "\">" +
|
|
|
|
"<span class=\"coursename\">" + raceD.raceInfo.name +"</span>"+
|
2017-12-30 12:08:53 +01:00
|
|
|
"<div class=\"courseimagecontainer\"></div>" + germanDateString(raceD.raceInfo.date) + "</li>");
|
2017-12-29 17:28:30 +01:00
|
|
|
|
|
|
|
$("#courseSelection li").click(function(event) {
|
2017-12-30 00:35:25 +01:00
|
|
|
var raceI = event.currentTarget.attributes.data.value;
|
|
|
|
// Internal check if element was already selected
|
|
|
|
if(slyelement.curRaceId == raceI){ return true; }
|
|
|
|
slyelement.curRaceId = raceI;
|
2017-12-30 00:15:53 +01:00
|
|
|
// Clear previously selected courses
|
|
|
|
$("#courseSelection .selected").removeClass("selected");
|
|
|
|
// Mark selected course
|
|
|
|
$(event.currentTarget).addClass("selected");
|
2017-12-30 00:35:25 +01:00
|
|
|
// Fetch race data
|
2017-12-29 17:28:30 +01:00
|
|
|
var rdata = slyelement.curRaces.filter(r => r.raceInfo.raceId == raceI)[0];
|
2017-12-30 01:16:47 +01:00
|
|
|
// Put information about race into race info box
|
2017-12-30 00:46:43 +01:00
|
|
|
$("#race-infobox").html(renderRaceInfoBox(rdata)); // See util.js
|
2017-12-30 01:16:47 +01:00
|
|
|
// Put information about drivers into driver info box
|
|
|
|
$("#driver-infobox").html(renderDriverInfoBox(rdata)); // See util.js
|
2017-12-30 01:48:44 +01:00
|
|
|
$('#driver-infobox table').DataTable({paging: false});
|
2017-12-30 01:16:47 +01:00
|
|
|
// Hand off to diagram rendering
|
2017-12-29 17:28:30 +01:00
|
|
|
$("#lineGraphBox").empty();
|
|
|
|
createLineGraph("#lineGraphBox", rdata);
|
|
|
|
});
|
2017-12-29 23:45:10 +01:00
|
|
|
slyelement.obj.reload();
|
2017-12-29 17:28:30 +01:00
|
|
|
}
|
2017-12-30 00:15:53 +01:00
|
|
|
// Refresh carousell after building the selector
|
2017-12-29 17:28:30 +01:00
|
|
|
slyelement.obj.reload();
|
2017-12-30 00:15:53 +01:00
|
|
|
// Register hover event
|
|
|
|
$("#courseSelection li").hover(function(event){
|
|
|
|
// handlerIn
|
|
|
|
$(event.currentTarget).addClass("hover");
|
|
|
|
}, function(event) {
|
|
|
|
// handlerOut
|
|
|
|
$(event.currentTarget).removeClass("hover");
|
|
|
|
});
|
2017-12-29 17:28:30 +01:00
|
|
|
|
|
|
|
// TODO: Now add all the images without disturbing the user
|
2017-12-22 13:57:42 +01:00
|
|
|
for(var race in slyelement.curRaces) {
|
|
|
|
var raceD = slyelement.curRaces[race];
|
2017-12-29 16:55:54 +01:00
|
|
|
var url = raceD.raceInfo.url;
|
|
|
|
var pathName = url.substring(url.lastIndexOf("/")+1);
|
|
|
|
getImageFromWikipedia(raceD,pathName,100,(raceD1,imageURL) => {
|
2017-12-29 17:28:30 +01:00
|
|
|
var imageTag = "<img src=\"" + imageURL + "\"class=\"courseimage\"/> ";
|
|
|
|
$("#courseSelection li[data="+raceD1.raceInfo.raceId+"] .courseimagecontainer").append(imageTag);
|
2017-12-29 16:55:54 +01:00
|
|
|
});
|
2017-12-22 13:13:52 +01:00
|
|
|
}
|
2017-12-31 17:04:58 +01:00
|
|
|
// Show first race by default
|
|
|
|
$("#courseSelection li").first().click();
|
2017-12-22 13:13:52 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
$(window).resize(function(e) {
|
|
|
|
slyelement.obj.reload();
|
|
|
|
});
|
2017-11-16 23:57:21 +01:00
|
|
|
|
2017-12-31 13:44:46 +01:00
|
|
|
$( "#toggle-btn-selection" ).click(function() {
|
2017-12-29 23:45:10 +01:00
|
|
|
if ( $( "#selector-card .card-body" ).is( ":hidden" ) ) {
|
|
|
|
$( "#selector-card .card-body" ).slideDown();
|
2017-12-31 13:44:46 +01:00
|
|
|
$('#icon-up-arrow-selection').animate({ borderSpacing: 0 - 90 }, {
|
2017-12-29 23:45:10 +01:00
|
|
|
step: function(now,fx) {
|
|
|
|
$(this).css('-webkit-transform','rotate('+now+'deg)');
|
|
|
|
$(this).css('-moz-transform','rotate('+now+'deg)');
|
|
|
|
$(this).css('transform','rotate('+now+'deg)');
|
|
|
|
},
|
|
|
|
duration: 150
|
|
|
|
},'linear');
|
|
|
|
} else {
|
|
|
|
$( "#selector-card .card-body" ).slideUp();
|
2017-12-31 13:44:46 +01:00
|
|
|
$('#icon-up-arrow-selection').animate({ borderSpacing: 180 - 90 }, {
|
|
|
|
step: function(now,fx) {
|
|
|
|
$(this).css('-webkit-transform','rotate('+now+'deg)');
|
|
|
|
$(this).css('-moz-transform','rotate('+now+'deg)');
|
|
|
|
$(this).css('transform','rotate('+now+'deg)');
|
|
|
|
},
|
|
|
|
duration: 150
|
|
|
|
},'linear');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$( "#toggle-btn-driverinfo" ).click(function() {
|
|
|
|
if ( $( "#driver-card .card-body" ).is( ":hidden" ) ) {
|
|
|
|
$( "#driver-card .card-body" ).slideDown();
|
|
|
|
$('#icon-up-arrow-driverinfo').animate({ borderSpacing: 0 - 90 }, {
|
|
|
|
step: function(now,fx) {
|
|
|
|
$(this).css('-webkit-transform','rotate('+now+'deg)');
|
|
|
|
$(this).css('-moz-transform','rotate('+now+'deg)');
|
|
|
|
$(this).css('transform','rotate('+now+'deg)');
|
|
|
|
},
|
|
|
|
duration: 150
|
|
|
|
},'linear');
|
|
|
|
} else {
|
|
|
|
$( "#driver-card .card-body" ).slideUp();
|
|
|
|
$('#icon-up-arrow-driverinfo').animate({ borderSpacing: 180 - 90 }, {
|
2017-12-29 23:45:10 +01:00
|
|
|
step: function(now,fx) {
|
|
|
|
$(this).css('-webkit-transform','rotate('+now+'deg)');
|
|
|
|
$(this).css('-moz-transform','rotate('+now+'deg)');
|
|
|
|
$(this).css('transform','rotate('+now+'deg)');
|
|
|
|
},
|
|
|
|
duration: 150
|
|
|
|
},'linear');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-12-30 00:02:06 +01:00
|
|
|
// Select most recent year by default
|
|
|
|
$("#seasonByYearSelector").val($("#seasonByYearSelector option").first().val()).change();
|
2017-12-29 22:16:16 +01:00
|
|
|
|
2017-12-30 00:46:43 +01:00
|
|
|
// Enable tooltips
|
|
|
|
$('[data-toggle="tooltip"]').tooltip()
|
2017-11-16 23:57:21 +01:00
|
|
|
});
|