Spaces:
Running
Running
Create script.js
Browse files
script.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ============================================
|
| 2 |
+
// Git для новачків - Інтерактивність дашборду
|
| 3 |
+
// ============================================
|
| 4 |
+
|
| 5 |
+
// Ініціалізація при завантаженні сторінки
|
| 6 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 7 |
+
initTabs();
|
| 8 |
+
initCopyButtons();
|
| 9 |
+
initSmoothScroll();
|
| 10 |
+
});
|
| 11 |
+
|
| 12 |
+
// ============================================
|
| 13 |
+
// ФУНКЦІЯ: Ініціалізація табів
|
| 14 |
+
// ============================================
|
| 15 |
+
function initTabs() {
|
| 16 |
+
const tabButtons = document.querySelectorAll('.tab-button');
|
| 17 |
+
const tabContents = document.querySelectorAll('.tab-content');
|
| 18 |
+
|
| 19 |
+
tabButtons.forEach(button => {
|
| 20 |
+
button.addEventListener('click', function() {
|
| 21 |
+
const tabName = this.getAttribute('data-tab');
|
| 22 |
+
|
| 23 |
+
// Видалення активного класу з усіх кнопок та контенту
|
| 24 |
+
tabButtons.forEach(btn => btn.classList.remove('active'));
|
| 25 |
+
tabContents.forEach(content => content.classList.remove('active'));
|
| 26 |
+
|
| 27 |
+
// Додавання активного класу до вибраного таба
|
| 28 |
+
this.classList.add('active');
|
| 29 |
+
document.getElementById(tabName).classList.add('active');
|
| 30 |
+
|
| 31 |
+
// Плавна прокрутка до контенту
|
| 32 |
+
smoothScrollToElement('#' + tabName);
|
| 33 |
+
});
|
| 34 |
+
});
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
// ============================================
|
| 38 |
+
// ФУНКЦІЯ: Копіювання коду в буфер обміну
|
| 39 |
+
// ============================================
|
| 40 |
+
function initCopyButtons() {
|
| 41 |
+
const codeBlocks = document.querySelectorAll('pre code');
|
| 42 |
+
|
| 43 |
+
codeBlocks.forEach(codeBlock => {
|
| 44 |
+
// Створення кнопки копіювання
|
| 45 |
+
const copyButton = document.createElement('button');
|
| 46 |
+
copyButton.textContent = '📋 Копіювати';
|
| 47 |
+
copyButton.className = 'copy-button';
|
| 48 |
+
copyButton.style.cssText = `
|
| 49 |
+
position: absolute;
|
| 50 |
+
top: 5px;
|
| 51 |
+
right: 5px;
|
| 52 |
+
padding: 5px 10px;
|
| 53 |
+
background: #f05033;
|
| 54 |
+
color: white;
|
| 55 |
+
border: none;
|
| 56 |
+
border-radius: 4px;
|
| 57 |
+
cursor: pointer;
|
| 58 |
+
font-size: 0.8rem;
|
| 59 |
+
opacity: 0;
|
| 60 |
+
transition: opacity 0.2s;
|
| 61 |
+
`;
|
| 62 |
+
|
| 63 |
+
// Огортання pre в контейнер з позицією
|
| 64 |
+
const preElement = codeBlock.parentElement;
|
| 65 |
+
preElement.style.position = 'relative';
|
| 66 |
+
preElement.appendChild(copyButton);
|
| 67 |
+
|
| 68 |
+
// Показ кнопки при наведенні
|
| 69 |
+
preElement.addEventListener('mouseenter', function() {
|
| 70 |
+
copyButton.style.opacity = '1';
|
| 71 |
+
});
|
| 72 |
+
|
| 73 |
+
preElement.addEventListener('mouseleave', function() {
|
| 74 |
+
copyButton.style.opacity = '0';
|
| 75 |
+
});
|
| 76 |
+
|
| 77 |
+
// Функція копіювання
|
| 78 |
+
copyButton.addEventListener('click', function() {
|
| 79 |
+
const text = codeBlock.textContent;
|
| 80 |
+
navigator.clipboard.writeText(text).then(function() {
|
| 81 |
+
copyButton.textContent = '✅ Скопійовано!';
|
| 82 |
+
setTimeout(function() {
|
| 83 |
+
copyButton.textContent = '📋 Копіювати';
|
| 84 |
+
}, 2000);
|
| 85 |
+
}).catch(function(err) {
|
| 86 |
+
console.error('Помилка копіювання:', err);
|
| 87 |
+
copyButton.textContent = '❌ Помилка';
|
| 88 |
+
setTimeout(function() {
|
| 89 |
+
copyButton.textContent = '📋 Копіювати';
|
| 90 |
+
}, 2000);
|
| 91 |
+
});
|
| 92 |
+
});
|
| 93 |
+
});
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
// ============================================
|
| 97 |
+
// ФУНКЦІЯ: Плавна прокрутка
|
| 98 |
+
// ============================================
|
| 99 |
+
function smoothScrollToElement(selector) {
|
| 100 |
+
const element = document.querySelector(selector);
|
| 101 |
+
if (element) {
|
| 102 |
+
const elementPosition = element.getBoundingClientRect().top + window.scrollY;
|
| 103 |
+
const offsetPosition = elementPosition - 100;
|
| 104 |
+
|
| 105 |
+
window.scrollBy({
|
| 106 |
+
top: offsetPosition - window.scrollY,
|
| 107 |
+
behavior: 'smooth'
|
| 108 |
+
});
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
function initSmoothScroll() {
|
| 113 |
+
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
|
| 114 |
+
anchor.addEventListener('click', function(e) {
|
| 115 |
+
e.preventDefault();
|
| 116 |
+
const target = document.querySelector(this.getAttribute('href'));
|
| 117 |
+
if (target) {
|
| 118 |
+
smoothScrollToElement(this.getAttribute('href'));
|
| 119 |
+
}
|
| 120 |
+
});
|
| 121 |
+
});
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
// ============================================
|
| 125 |
+
// ФУНКЦІЯ: Логування версії
|
| 126 |
+
// ============================================
|
| 127 |
+
console.log('%c🚀 Git для новачків', 'font-size: 20px; color: #f05033; font-weight: bold;');
|
| 128 |
+
console.log('%cДашборд успішно завантажено!', 'font-size: 14px; color: #244c5a;');
|
| 129 |
+
console.log('%cПочніть з вкладки "Базові команди"', 'font-size: 12px; color: #718096;');
|