-
Notifications
You must be signed in to change notification settings - Fork 1
/
the.min.js
28 lines (27 loc) · 3.52 KB
/
the.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var DEFAULT_LOCALE='fr';var localStorageLocale='';var HEMISPHERE_GREEN='#8ACDA3';var currentLocale='';var urlParamsHM={};var NO_LOCAL_STRG=false;$("document").ready(function(){start();});function start(){if(!Modernizr.canvas){console.log('no canvas');}
if(!Modernizr.localstorage){console.log('no localStorage');NO_LOCAL_STRG=true;}
var localStorageLocale=localStorage.getItem('hemisp_lng');if((localStorageLocale===undefined)||(localStorageLocale===null))
$('#menu_opts').load('menu_'+DEFAULT_LOCALE+'.html');else
$('#menu_opts').load('menu_'+localStorageLocale+'.html');$(window).bind('hashchange',onHashChange);$(window).hashchange();}
function menuClick(event){event.preventDefault();trimUSCandSCParams();var urlParamsString=urlParamsHMToString();if(urlParamsString!='')
urlParamsString='?'+urlParamsString;if(window.location.href.indexOf("#!")!=-1)
window.location.hash='!'+event.currentTarget.href.substring(window.location.href.indexOf("#!"))+urlParamsString;else
window.location.hash='!'+event.currentTarget.href.substring(window.location.href.length)+urlParamsString;}
function langToggleClick(event){event.preventDefault();switch(event.currentTarget.id){case'langToggle_fr':setLocale('fr');break;case'langToggle_en':setLocale('en');break;default:console.log('err#1 unexpected langToggle id');break;}}
function setLocale(value){if(!NO_LOCAL_STRG){localStorage.hemisp_lng=value;}
urlParamsHM['lng']=value;updateParamsInURL();}
function updateParamsInURL(){var paramsIndex=window.location.href.indexOf('?')+1;var paramsString=urlParamsHMToString();if(paramsIndex!=0){window.location.href=window.location.href.substring(0,paramsIndex)+paramsString;}else{var hashIndex=window.location.href.indexOf('#!');if(hashIndex!=-1){window.location.href+='?'+paramsString;}else{window.location.href+='#!?'+paramsString;}}}
function urlParamsHMToString(){var string='';for(var param in urlParamsHM){string+=param+'='+urlParamsHM[param]+'&';}
string=string.substring(0,string.length-1);return string;}
function onHashChange(){urlParamsHM=extractUrlParams();updateLangIfRequiered();loadContent(window.location.href);}
function trimUSCandSCParams(){if(urlParamsHM['usc']){delete urlParamsHM['usc'];}
if(urlParamsHM['sc']){delete urlParamsHM['sc'];}}
function loadContent(url){var hashPos=url.indexOf('#!');if(hashPos!=-1){if((url.indexOf('?')!=-1&&url.indexOf('?')==hashPos+2)||url.length<=hashPos+2){$("#content").html('');return;}
var newUrl=url.substring(0,hashPos)+url.substring(hashPos+2);url=newUrl;}else{$("#content").html('');return;}
if(!NO_LOCAL_STRG&&!urlParamsHM['lng']&&localStorage.hemisp_lng){if(url.indexOf('?')!=-1){url+='&lng='+localStorage.hemisp_lng;}else{url+='?lng='+localStorage.hemisp_lng;}}
$("#content").load(url);}
function updateLangIfRequiered(){if(urlParamsHM['lng']){if(currentLocale!=urlParamsHM['lng']){currentLocale=urlParamsHM['lng'];$('#menu_opts').load('menu_'+currentLocale+'.html');switch(currentLocale){case'en':$('#langToggle_en').css('color',HEMISPHERE_GREEN);$('#langToggle_fr').css('color','');break;case'fr':$('#langToggle_fr').css('color',HEMISPHERE_GREEN);$('#langToggle_en').css('color','');break;default:console.log('err#2 locale not supported');}}}else{$('#langToggle_fr').css('color','');$('#langToggle_en').css('color','');}}
function toggleFold(elmnt){$(elmnt).next(".subcontent").slideToggle(300,function(){});}
function extractUrlParams(){var t=[];if(window.location.href.indexOf('?')!=-1)
t=window.location.href.substring(window.location.href.indexOf('?')+1).split('&');var f={};for(var i=0;i<t.length;i++){var x=t[i].split('=');f[x[0]]=x[1];}
return f;}