-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
49 lines (41 loc) · 1.8 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
document.addEventListener("DOMContentLoaded", function () {
const screenWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
const dropdownElement = document.querySelector(".dropdown");
const navElement = document.querySelector(".hide-on-small-screen ul");
if (screenWidth <= 760) {
const menuImgSrc = "../images/menu.png"; // Replace with the actual menu image source
const crossImgSrc = "../images/cross.png"; // Replace with the actual cross image source
const imgElement = document.createElement("img");
imgElement.src = menuImgSrc;
imgElement.alt = "Menu";
imgElement.style.height = "60px";
imgElement.style.width = "60px";
dropdownElement.appendChild(imgElement);
dropdownElement.addEventListener("click", function () {
navElement.classList.toggle("nav-hidden");
navElement.classList.toggle("nav-visible");
imgElement.src = navElement.classList.contains("nav-visible") ? crossImgSrc : menuImgSrc;
imgElement.alt = navElement.classList.contains("nav-visible") ? "Cross" : "Menu";
});
}
});
// Initialize Prism.js
Prism.highlightAll();
function copyCode() {
const codeBlock = document.getElementById("code-block");
navigator.clipboard.writeText(codeBlock.innerText)
.then(() => {
showNotification("Code Copied !!", "success");
})
.catch((error) => {
showNotification("Failed To Copy: " + error, "error");
});
}
function showNotification(message, type) {
const notification = document.getElementById("notification");
notification.textContent = message;
notification.classList.add(type, "show");
setTimeout(() => {
notification.classList.remove("show");
}, 3000);
}