-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
74 lines (63 loc) · 2.66 KB
/
main.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
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
// function for changing year on word chart
function switchVis(chartId) {
document.querySelector('iframe').src = 'https://datawrapper.dwcdn.net/' + chartId;
}
// function for creating citation copy buttons
document.addEventListener('DOMContentLoaded', function() {
// Add a click event listener to the APA copy button
var copyButtonAPA = document.getElementById('copyButtonAPA');
copyButtonAPA.addEventListener('click', function() {
copyTextToClipboard('textToCopyAPA', copyButtonAPA);
});
// Add a click event listener to the Chicago copy button
var copyButtonChicago = document.getElementById('copyButtonChicago');
copyButtonChicago.addEventListener('click', function() {
copyTextToClipboard('textToCopyChicago', copyButtonChicago);
});
// Add a click event listener to the MLA copy button
var copyButtonMLA = document.getElementById('copyButtonMLA');
copyButtonMLA.addEventListener('click', function() {
copyTextToClipboard('textToCopyMLA', copyButtonMLA);
});
// Function to copy text to clipboard
function copyTextToClipboard(textElementId, copyButton) {
var textToCopy = document.getElementById(textElementId);
var textarea = document.createElement('textarea');
textarea.value = textToCopy.innerText;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
// Change button color and text
copyButton.style.backgroundColor = '#45a049'; // Change to the desired color
copyButton.style.borderColor = '#45a049'; // Add border color
copyButton.innerText = 'Copied!';
// Reset button after a delay (you can adjust the delay as needed)
setTimeout(function() {
copyButton.style.backgroundColor = ''; // Reset to the original color
copyButton.style.borderColor = ''; // Remove border color
copyButton.innerText = 'Copy Citation';
}, 2000); // Adjust the delay in milliseconds
}
});
/* Download Chart Button */
function downloadChart() {
// Get the selected year from the dropdown
var selectedValue = document.getElementById("yearSelector").value;
var selectedYear;
switch (selectedValue) {
case "Da5oL":
selectedYear = "2021";
break;
case "4ma8G":
selectedYear = "2022";
break;
case "Qjx9t":
selectedYear = "2023";
break;
}
// Construct the filename based on the selected year
var fileName = selectedYear + "_heat_chart.png";
document.getElementById("downloadLink").href = fileName;
document.getElementById("downloadLink").download = fileName;
}