aboutsummaryrefslogtreecommitdiff
path: root/assets/js/ps-app.js
blob: 33f4f99edd7212a5975b79c0594cf1f3954dac09 (plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
(function($) {

    $(document).ready(function() {

	// Make each .media section clickable to reach ./<id>/
	[ 'gfx', 'txt', 'vdo' ].forEach(function(id) {
	    $('#' + id)
		.click(function(e) {
		    window.location = `/${id}/`;
		    return false
		})
		.mouseover(function(e) {
		    e.target.style.cursor = 'pointer'
		    return false
		})
		.mouseout(function(e) {
		    e.target.style.cursor = 'not-allowed'
		    return false
		})
	})
	$('.media').mouseout(function(e) {
	    e.target.style.cursor = 'auto'
	    return false
	})

	// EN/FR switch
	$('footer')
	    .append('<button id="lang-switch" title="Read in English">EN</button>')
	$('#lang-switch').click(function(e) {
	    var lang = $('html').attr('lang')
	    setLang(lang == 'fr' ? 'en' : 'fr')
	    return false
	})

	// Use ?lang=XX if available
	var URLParams = new URLSearchParams(window.location.search);
	if (URLParams.has('lang')) {
	    setLang(URLParams.get('lang'))
	}

	// Translate to target lang
	function setLang(lang) {
	    if (lang == 'fr') {
		$('html').attr('lang', 'fr')
		$('#lang-switch').html('EN').attr('title', 'Read in English')
	    } else {
		$('html').attr('lang', 'en')
		$('#lang-switch').html('FR').attr('title', 'Lire en français')
	    }
	}

    });

})($)