f1vis/js/main.js

88 lines
2.7 KiB
JavaScript
Raw Normal View History

"use strict";
2017-11-16 23:08:14 +01:00
/*
* This file contains the main control flow.
*/
var slyelement = {
obj: {},
2017-12-22 13:57:42 +01:00
curRaces: {},
curRaceId: 0,
el: '.frame',
options: {
horizontal: 1,
itemNav: 'basic',
smart: 1,
2017-12-29 17:11:02 +01:00
//activateOn: 'click',
//activatePageOn: 'click',
mouseDragging: 0,
touchDragging: 1,
2017-12-29 17:11:02 +01:00
releaseSwing: 0,
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,
}
};
preprocessor.load(function(data) {
slyelement.obj = new Sly($(slyelement.el), slyelement.options);
slyelement.obj.init();
// Some sample code for a year selector - TODO: Improve a lot and move somewhere else
var yearSelector = $("#seasonByYearSelector");
var seasons = processor.getSeasonsWithLapData();
for(var season in seasons){ yearSelector.append("<option>" + seasons[season].year + "</option>"); }
// 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);
$("#courseSelection").empty();
2017-12-29 17:28:30 +01:00
// Add all the races to the selector
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-29 21:28:05 +01:00
"<div class=\"courseimagecontainer\"></div>" + raceD.raceInfo.date.toLocaleDateString("de-DE") + "</li>");
2017-12-29 17:28:30 +01:00
$("#courseSelection li").click(function(event) {
var raceI = event.currentTarget.attributes.data.value;
if(slyelement.curRaceId == raceI){ return; }
slyelement.curRaceId = raceI;
var rdata = slyelement.curRaces.filter(r => r.raceInfo.raceId == raceI)[0];
$("#lineGraphBox").empty();
createLineGraph("#lineGraphBox", rdata);
});
slyelement.obj.reload();
}
slyelement.obj.reload();
// 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];
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);
});
}
});
$(window).resize(function(e) {
slyelement.obj.reload();
});
2017-12-29 22:16:16 +01:00
$("#seasonByYearSelector").trigger("change");
});