22 lines
1.3 KiB
JavaScript
22 lines
1.3 KiB
JavaScript
(function(){
|
||
// Land at the top, even when the page is shown inside a frame (scrollIntoView also scrolls the parent page)
|
||
if('scrollRestoration' in history)history.scrollRestoration='manual';
|
||
function toTop(){window.scrollTo(0,0);var m=document.body;if(m&&m.scrollIntoView)m.scrollIntoView({block:'start',behavior:'instant'})}
|
||
window.addEventListener('load',function(){if(!/^#(en|fr)-/.test(location.hash))toTop()});
|
||
var arts={en:document.getElementById('en'),fr:document.getElementById('fr')};
|
||
var links=[].slice.call(document.querySelectorAll('.lang-switch a'));
|
||
function show(lang,top){
|
||
Object.keys(arts).forEach(function(k){arts[k].hidden=k!==lang});
|
||
links.forEach(function(a){a.setAttribute('aria-current',a.getAttribute('href')==='#'+lang)});
|
||
document.documentElement.lang=lang;
|
||
document.title=lang==='fr'?'Mentions légales – Nelson Thomas':'Legal notice – Nelson Thomas';
|
||
if(top)toTop();
|
||
}
|
||
links.forEach(function(a){a.addEventListener('click',function(e){
|
||
e.preventDefault(); var l=a.getAttribute('href').slice(1);
|
||
history.replaceState(null,'','#'+l); show(l,true);
|
||
})});
|
||
var h=location.hash.slice(1,3);
|
||
show(h==='fr'||h==='en'?h:(/^fr\b/i.test(navigator.language||'')?'fr':'en'),!/^#(en|fr)-/.test(location.hash));
|
||
})();
|