northriverfence's picture
Promote version 6d09658 to main
8b57d97 verified
Raw History Blame Contribute Delete
5.41 kB
// Initialize dark mode preference
function initDarkMode() {
const darkMode = localStorage.getItem('darkMode') === 'true' ||
(!localStorage.getItem('darkMode') && window.matchMedia('(prefers-color-scheme: dark)').matches);
if (darkMode) {
document.documentElement.classList.add('dark');
}
// Dispatch event for components to listen to
document.dispatchEvent(new CustomEvent('darkModeChange', { detail: darkMode }));
}
// Toggle dark mode
function toggleDarkMode() {
const isDark = document.documentElement.classList.toggle('dark');
localStorage.setItem('darkMode', isDark);
document.dispatchEvent(new CustomEvent('darkModeChange', { detail: isDark }));
}
// Collapsible Menu Functionality
function setupCollapsibleMenu() {
const menuSections = document.querySelectorAll('.menu-section');
menuSections.forEach(section => {
const header = section.querySelector('.menu-header');
const content = section.querySelector('.menu-content');
const chevron = header.querySelector('i[data-feather="chevron-down"]');
header.addEventListener('click', () => {
// Close all other sections
menuSections.forEach(s => {
if (s !== section) {
s.querySelector('.menu-content').classList.remove('active');
s.querySelector('.menu-header').classList.remove('active');
}
});
// Toggle current section
content.classList.toggle('active');
header.classList.toggle('active');
// Update chevron icon
if (content.classList.contains('active')) {
chevron.setAttribute('data-feather', 'chevron-up');
} else {
chevron.setAttribute('data-feather', 'chevron-down');
}
feather.replace();
});
});
}
// Connection Tabs Functionality
function setupConnectionTabs() {
const tabsContainer = document.querySelector('.connection-tabs');
if (!tabsContainer) return;
const tabs = tabsContainer.querySelectorAll('.connection-tab');
tabs.forEach(tab => {
tab.addEventListener('click', () => {
tabs.forEach(t => t.classList.remove('active'));
tab.classList.add('active');
// Here you would switch the terminal view to the selected connection
});
});
}
// Terminal simulation (simple demo)
function simulateTerminal() {
const terminal = document.querySelector('.terminal-container');
if (terminal) {
terminal.scrollTop = terminal.scrollHeight;
}
}
// Drag and drop file handling
function initFileDrop() {
const dropArea = document.querySelector('.border-dashed');
if (!dropArea) return;
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, preventDefaults, false);
});
function preventDefaults(e) {
e.preventDefault();
e.stopPropagation();
}
['dragenter', 'dragover'].forEach(eventName => {
dropArea.addEventListener(eventName, highlight, false);
});
['dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, unhighlight, false);
});
function highlight() {
dropArea.classList.add('border-primary-500', 'bg-primary-50', 'dark:bg-gray-700');
}
function unhighlight() {
dropArea.classList.remove('border-primary-500', 'bg-primary-50', 'dark:bg-gray-700');
}
dropArea.addEventListener('drop', handleDrop, false);
function handleDrop(e) {
const dt = e.dataTransfer;
const files = dt.files;
handleFiles(files);
}
function handleFiles(files) {
console.log('Files dropped:', files);
// Here you would handle the file upload
}
}
// Window controls functionality
function setupWindowControls() {
const minimizeBtn = document.querySelector('.window-control:nth-child(1)');
const maximizeBtn = document.querySelector('.window-control:nth-child(2)');
const closeBtn = document.querySelector('.window-control:nth-child(3)');
if (minimizeBtn) {
minimizeBtn.addEventListener('click', () => {
document.querySelector('.app-window').classList.add('minimized');
});
}
if (maximizeBtn) {
maximizeBtn.addEventListener('click', () => {
const window = document.querySelector('.app-window');
window.classList.toggle('maximized');
const icon = maximizeBtn.querySelector('i');
if (window.classList.contains('maximized')) {
icon.setAttribute('data-feather', 'minimize-2');
} else {
icon.setAttribute('data-feather', 'maximize-2');
}
feather.replace();
});
}
if (closeBtn) {
closeBtn.addEventListener('click', () => {
// In a real app, this would close the window
console.log('Window close requested');
});
}
}
// Initialize everything when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
initDarkMode();
setupCollapsibleMenu();
setupConnectionTabs();
simulateTerminal();
initFileDrop();
setupWindowControls();
});