R-Kentaren commited on
Commit
1699200
·
verified ·
1 Parent(s): ae82e4d

Create functionality.js

Browse files
Files changed (1) hide show
  1. functionality.js +87 -0
functionality.js ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // javascript file that set the functionality of some of the components in the index.html file
2
+ // imported to the index.html file via the <script> tag in the end of the body part
3
+
4
+
5
+ $(document).ready(function() {
6
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ scroll back to top button ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7
+ // javascript code was taken from https://mdbootstrap.com/docs/standard/extended/back-to-top/
8
+ //Get the button
9
+ let mybutton = document.getElementById("btn-back-to-top");
10
+ // When the user scrolls down 20px from the top of the document, show the button
11
+ window.onscroll = function () {
12
+ scrollFunction();
13
+ };
14
+ function scrollFunction() {
15
+ if (
16
+ document.body.scrollTop > 20 ||
17
+ document.documentElement.scrollTop > 20
18
+ ) {
19
+ mybutton.style.display = "block";
20
+ } else {
21
+ mybutton.style.display = "none";
22
+ }
23
+ }
24
+ // When the user clicks on the button, scroll to the top of the document
25
+ mybutton.addEventListener("click", backToTop);
26
+ function backToTop() {
27
+ document.body.scrollTop = 0;
28
+ document.documentElement.scrollTop = 0;
29
+ }
30
+ });
31
+
32
+
33
+ // ~~ Stop all other audios
34
+ // https://stackoverflow.com/questions/19790506/multiple-audio-html-auto-stop-other-when-current-is-playing-with-javascript
35
+ document.addEventListener('play', function(e){
36
+ var audios = document.getElementsByTagName('audio');
37
+ for(var i = 0, len = audios.length; i < len;i++){
38
+ if(audios[i] != e.target){
39
+ audios[i].pause();
40
+ }
41
+ }
42
+ }, true);
43
+
44
+ function toggleCollapseArrow(btnid) {
45
+ a = $('#'+ btnid + ' i')[0];
46
+ if (a.classList.contains('fa-chevron-down')) {
47
+ a.classList.remove('fa-chevron-down');
48
+ a.classList.add('fa-chevron-up');
49
+ } else {
50
+ a.classList.remove('fa-chevron-up');
51
+ a.classList.add('fa-chevron-down');
52
+ }
53
+ }
54
+
55
+ function copyBib() {
56
+ let copyText = $("#citation")[0];
57
+ navigator.clipboard.writeText(copyText.getInnerHTML());
58
+ }
59
+
60
+ function hearMore(btn, from, to) {
61
+ let button = $('#'+btn)[0];
62
+ let table = button.parentElement.parentElement.parentElement;
63
+ for (let i = from; i <= to; i++) {
64
+ table.rows[i].hidden = false;
65
+ }
66
+ button.parentElement.parentElement.hidden = true;
67
+ }
68
+
69
+ // Add a listener for when a toggle div is collapsed back
70
+ document.addEventListener('hidden.bs.collapse', function (e) {
71
+ collapsed_div = e.target.id;
72
+ tbody = $('#'+collapsed_div + ' tbody')[0];
73
+ // if there's a show more button, hide all rows from the bottom to the first show more button
74
+ if ($('#'+collapsed_div + ' button').length > 0) {
75
+ btn_id = $('#'+collapsed_div + ' button')[0].id;
76
+
77
+ for (let i = tbody.rows.length - 1; i >= 0; i--) {
78
+ if (tbody.rows[i].getElementsByTagName('button').length > 0) {
79
+ if (tbody.rows[i].getElementsByTagName('button')[0].id == btn_id) {
80
+ tbody.rows[i].hidden = false;
81
+ break;
82
+ }
83
+ }
84
+ tbody.rows[i].hidden = true;
85
+ }
86
+ }
87
+ });