-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathscript.js
175 lines (144 loc) · 5.92 KB
/
script.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// script.js
const checkboxes = document.querySelectorAll('.checkbox');
// Add event listeners to checkboxes
checkboxes.forEach((checkbox) => {
checkbox.addEventListener('change', (event) => {
const checklistName = event.target.getAttribute('data-checklist');
const itemIndex = [...checkbox.parentElement.parentElement.children].indexOf(checkbox.parentElement);
// Save the completion status to local storage
localStorage.setItem(`${checklistName}_${itemIndex}`, event.target.checked);
});
// Retrieve the completion status from local storage
const checklistName = checkbox.getAttribute('data-checklist');
const itemIndex = [...checkbox.parentElement.parentElement.children].indexOf(checkbox.parentElement);
const isChecked = localStorage.getItem(`${checklistName}_${itemIndex}`);
if (isChecked === 'true') {
checkbox.checked = true;
}
});
// Hide the loading overlay when the page is fully loaded
window.addEventListener("load", function () {
const loadingOverlay = document.querySelector(".loading-overlay");
loadingOverlay.style.display = "none";
});
// Add click event listener to clicked-glow elements
const clickedGlowElements = document.querySelectorAll(".clicked-glow");
clickedGlowElements.forEach((element) => {
element.addEventListener("click", () => {
element.classList.add("clicked-glow");
setTimeout(() => {
element.classList.remove("clicked-glow");
}, 500); // Remove the glow class after 0.5 seconds (duration of glow animation)
});
});
// Code no longer user since clicking the section title does this action
// and section title encompasses the arrow
// drop down arrow
// const dropdownArrows = document.querySelectorAll(".dropdown-arrow");
// dropdownArrows.forEach((arrow) => {
// arrow.addEventListener("click", () => {
// const listItem = arrow.closest("li");
// const hiddenText = listItem.querySelector(".hidden-text");
// hiddenText.classList.toggle("show");
// arrow.classList.toggle("checked");
// });
// });
// Code no longer user since clicking the section title does this action
// and section title encompasses the arrow
// shifting of checklist item when arrow is activated
// document.addEventListener("DOMContentLoaded", function () {
// const dropdownArrows = document.querySelectorAll(".dropdown-arrow");
// dropdownArrows.forEach(function (arrow) {
// arrow.addEventListener("click", function () {
// const checklistItem = arrow.closest(".checklist-item");
// const hiddenText = checklistItem.querySelector(".hidden-text");
// const checkbox = checklistItem.querySelector(".checkbox");
// if (checkbox.checked) {
// hiddenText.style.display = "block";
// const hiddenTextHeight = hiddenText.clientHeight;
// checklistItem.style.marginBottom = hiddenTextHeight + "px";
// } else {
// hiddenText.style.display = "none";
// checklistItem.style.marginBottom = "0";
// }
// });
// });
// });
// Add click event listener to checklist section titles
const sectionTitles = document.querySelectorAll('.section-title-label');
sectionTitles.forEach((label) => {
label.addEventListener('click', (e) => {
// prevent the label from triggering default behavior of toggling the checkbox
e.preventDefault();
// Expand section and change the arrow icon
const arrow = label.querySelector('[class*="dropdown-arrow"]');
const listItem = arrow.closest("li");
arrow.classList.toggle("checked");
const hiddenText = listItem.querySelector(".hidden-text");
hiddenText.classList.toggle("show"); // show hidden text
const checklistItem = arrow.closest(".checklist-item");
if (arrow.className === "dropdown-arrow checked") {
hiddenText.style.display = "block";
const hiddenTextHeight = hiddenText.clientHeight;
checklistItem.style.marginBottom = hiddenTextHeight + "px";
} else {
hiddenText.style.display = "none";
checklistItem.style.marginBottom = "0";
}
}, false);
});
// New quote on Refresh
// const category = "happiness"
// $.ajax({
// method: 'GET',
// url: 'https://api.api-ninjas.com/v1/quotes?category=' + category,
// headers: { 'X-Api-Key': 'gv414CStL2w22HtsC4pp8A==fHW82xPwAxJPaUjU'},
// contentType: 'application/json',
// success: function(result) {
// console.log(result)
// },
// error: function ajaxError(jqXHR) {
// console.error('Error: ', jqXHR.responseText);
// }
// });
async function logMovies() {
const response = await fetch("https://api.api-ninjas.com/v1/quotes?category=happiness",
{ headers: { 'X-Api-Key': 'gv414CStL2w22HtsC4pp8A==fHW82xPwAxJPaUjU' }, });
const movies = await response.json();
document.getElementById("quoteContent").textContent = movies[0].quote;
document.getElementById("quoteTitle").textContent = "- " + movies[0].author;
}
logMovies();
// java basic
function copyToClipboard(exampleNumber) {
const codeBlock = document.querySelector(`.code-snippet[data-example="${exampleNumber}"]`);
if (codeBlock) {
const codeText = codeBlock.textContent;
const textArea = document.createElement('textarea');
textArea.value = codeText;
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
alert('Code copied to clipboard');
}
}
// var toggleButton = document.querySelector(".toggle-button");
let toggleButton = document.querySelector(".ham-mob");
var navbarLinks = document.querySelector(".hamburger");
toggleButton.addEventListener('click', () => {
navbarLinks.classList.toggle('active');
console.log(1)
})
const totop = document.querySelector('.to-top');
window.addEventListener("scroll", () => {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
totop.classList.add("active");
} else {
totop.classList.remove("active");
}
})
function f1() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}