-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathcopy.js
More file actions
45 lines (43 loc) · 1.63 KB
/
copy.js
File metadata and controls
45 lines (43 loc) · 1.63 KB
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
// Navbar toggle for mobile
// Hide loading screen after page load
// Enable copy button functionality for all .copy-button elements
document.addEventListener('DOMContentLoaded', function () {
const navToggle = document.querySelector('.nav-toggle');
const navLinks = document.querySelector('.nav-links');
if (navToggle && navLinks) {
navToggle.addEventListener('click', function () {
navLinks.classList.toggle('open');
});
}
// Hide loading screen after page load
const loadingScreen = document.querySelector('.loading-screen');
if (loadingScreen) {
loadingScreen.style.opacity = '0';
setTimeout(() => {
loadingScreen.style.display = 'none';
}, 600);
}
});
function copyCode(btn, codeId) {
var codeElem = document.getElementById(codeId);
var code = codeElem ? codeElem.textContent : '';
if (!navigator.clipboard) {
alert('Clipboard not supported. Please copy manually.');
return;
}
navigator.clipboard.writeText(code).then(function() {
var original = btn.querySelector('span').textContent;
btn.querySelector('span').textContent = 'Copied';
btn.classList.add('copied');
// Show confirmation message
var msg = document.createElement('div');
msg.className = 'copy-confirmation';
msg.textContent = 'Installation script copied';
btn.parentNode.insertBefore(msg, btn.nextSibling);
setTimeout(function() {
btn.querySelector('span').textContent = original;
btn.classList.remove('copied');
msg.remove();
}, 1800);
});
}