//open / close
var anthologyOpen = 0
$('#buttonAnthology').on('click',function(){
//hiding navbar
$('.navbar-collapse').collapse('hide');
if (anthologyOpen > 0){
$('#anthology').css('visibility','hidden');
$('#anthology').css('opacity','0')
$('#backToMap').css('visibility','hidden');
$('#backToMap').css('opacity','0')
anthologyOpen = 0
}
else{
$('#anthology').css('visibility','visible')
$('#anthology').css('opacity','1')
$('#backToMap').css('visibility','visible');
$('#backToMap').css('opacity','1')
anthologyOpen = 1
displayAnthology()
}
//closing about
$('#about').css('visibility','hidden');
$('#about').css('opacity','0')
aboutOpen = 0
})
$('#closeAnthologyAbout').on('click',function(){
$('#anthology').css('opacity','0')
$('#anthology').css('visibility','hidden')
$('#backToMap').css('opacity','0')
$('#backToMap').css('visibility','hidden')
anthologyOpen = 0
})
$('#navTitle').on('click',function(){
$('#anthology').css('opacity','0')
$('#anthology').css('visibility','hidden')
$('#backToMap').css('opacity','0')
$('#backToMap').css('visibility','hidden')
$('#about').css('opacity','0')
$('#about').css('visibility','hidden')
aboutOpen = 0
anthologyOpen = 0
})
function flightTime(a,b){
var days = Math.round((b-a)/86400 * 100) / 100
var months = Math.round(days/30)
var years = Math.round(months/12)
if (days < 30){
return ""+days+" "+dictionnary.jours
}
else if (days >= 30 && days < 365){
if(months>1){
return ""+months+" "+dictionnary.mois_pluriel
}
else{
return ""+months+" "+dictionnary.mois
}
}
else if (days >= 365){
if(years>1){
return ""+years+" "+dictionnary.ans
}
else{
return ""+years+" "+dictionnary.an
}
}
}
//load
var nPages;
var nPagesLoaded = 1
$.post( "getAnthology.php", function(pages) {
pages = $.parseJSON(pages)
nPages = Number(pages.nPages)
})
function displayAnthology(){ // clean and display first page
$("#anthologyItems").html('')
nPagesLoaded = 1
$.post( "getAnthology.php?page=1", function(result) {
results = $.parseJSON(result)
var momentLocale = lang;
if (momentLocale == 'zh'){momentLocale = 'zh-cn'} //troubleshot for chinese
moment.locale(momentLocale)
for (var i in results){
addAnthologyLine(results[i])
}
})
}
$( "#anthology" ).scroll(function() {
if($("#anthology").scrollTop() + 700 > $("#anthologyItems").height()){
if (nPagesLoaded < nPages){
nPagesLoaded++
console.log('Loading anthology page '+nPagesLoaded+'/'+nPages)
$.post( "getAnthology.php?page="+nPagesLoaded+"", function(result) {
results = $.parseJSON(result)
var momentLocale = lang;
if (momentLocale == 'zh'){momentLocale = 'zh-cn'} //troubleshot for chinese
moment.locale(momentLocale)
for (var i in results){
addAnthologyLine(results[i])
}
})
}
}
});
function addAnthologyLine(results){
if (lang == 'ar'){ // arabic : rtl + add
$("#anthologyItems").append(
''+dictionnary.origine+': '+results.startName+' • '+dictionnary.destination+': '+results.destName+' • '+dictionnary.date_arrivee+': '+moment(Number(results.deliveryTime)*1000).format('LL')+' • '+dictionnary.temps_de_vol+': '+flightTime(Number(results.startTime),Number(results.deliveryTime))+'
'+results.message+'