File size: 3,094 Bytes
1699200
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// javascript file that set the functionality of some of the components in the index.html file
// imported to the index.html file via the <script> tag in the end of the body part  


$(document).ready(function() {
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ scroll back to top button ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // javascript code was taken from https://mdbootstrap.com/docs/standard/extended/back-to-top/
    //Get the button
    let mybutton = document.getElementById("btn-back-to-top");
    // When the user scrolls down 20px from the top of the document, show the button
    window.onscroll = function () {
        scrollFunction();
        };
    function scrollFunction() {
        if (
            document.body.scrollTop > 20 ||
            document.documentElement.scrollTop > 20
        ) {
            mybutton.style.display = "block";
        } else {
            mybutton.style.display = "none";
        }
    }
    // When the user clicks on the button, scroll to the top of the document
    mybutton.addEventListener("click", backToTop);
    function backToTop() {
    document.body.scrollTop = 0;
    document.documentElement.scrollTop = 0;
    }
});


// ~~ Stop all other audios
// https://stackoverflow.com/questions/19790506/multiple-audio-html-auto-stop-other-when-current-is-playing-with-javascript
document.addEventListener('play', function(e){
    var audios = document.getElementsByTagName('audio');
    for(var i = 0, len = audios.length; i < len;i++){
        if(audios[i] != e.target){
            audios[i].pause();
        }
    }
}, true);

function toggleCollapseArrow(btnid) {
    a = $('#'+ btnid + ' i')[0];
    if (a.classList.contains('fa-chevron-down')) {
        a.classList.remove('fa-chevron-down');
        a.classList.add('fa-chevron-up');
    } else {
        a.classList.remove('fa-chevron-up');
        a.classList.add('fa-chevron-down');
    }
}

function copyBib() {
    let copyText = $("#citation")[0];
    navigator.clipboard.writeText(copyText.getInnerHTML());
}

function hearMore(btn, from, to) {
    let button = $('#'+btn)[0];
    let table = button.parentElement.parentElement.parentElement;
    for (let i = from; i <= to; i++) {
        table.rows[i].hidden = false;
    }
    button.parentElement.parentElement.hidden = true;
}

// Add a listener for when a toggle div is collapsed back
document.addEventListener('hidden.bs.collapse', function (e) {
    collapsed_div = e.target.id;
    tbody = $('#'+collapsed_div + ' tbody')[0];
    // if there's a show more button, hide all rows from the bottom to the first show more button
    if ($('#'+collapsed_div + ' button').length > 0) {
        btn_id = $('#'+collapsed_div + ' button')[0].id;

        for (let i = tbody.rows.length - 1; i >= 0; i--) {
            if (tbody.rows[i].getElementsByTagName('button').length > 0) {
                if (tbody.rows[i].getElementsByTagName('button')[0].id == btn_id) {
                    tbody.rows[i].hidden = false;
                    break;
                }
            }
            tbody.rows[i].hidden = true;
        }
    }
});