filemenager / index.html
Adityakumar12's picture
Add 2 files
9883e41 verified
Raw History Blame Contribute Delete
43.3 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Modern File Manager</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.file-icon {
color: #6b7280;
}
.file-icon.folder {
color: #f59e0b;
}
.file-icon.image {
color: #3b82f6;
}
.file-icon.document {
color: #10b981;
}
.file-icon.audio {
color: #8b5cf6;
}
.file-icon.video {
color: #ec4899;
}
.file-icon.archive {
color: #f97316;
}
.context-menu {
display: none;
position: absolute;
z-index: 1000;
}
.file-item:hover {
background-color: #f3f4f6;
}
.file-item.selected {
background-color: #e5e7eb;
}
.preview-container {
height: calc(100vh - 200px);
}
.breadcrumb-item:not(:last-child)::after {
content: '›';
margin: 0 8px;
color: #9ca3af;
}
.dropzone {
border: 2px dashed #d1d5db;
}
.dropzone.active {
border-color: #3b82f6;
background-color: #eff6ff;
}
#file-upload-progress {
transition: width 0.3s ease;
}
</style>
</head>
<body class="bg-gray-50 font-sans">
<div class="flex flex-col h-screen">
<!-- Header -->
<header class="bg-white shadow-sm py-3 px-6 flex items-center justify-between">
<div class="flex items-center space-x-4">
<h1 class="text-xl font-semibold text-gray-800">File Explorer</h1>
<div class="flex space-x-2">
<button class="p-2 rounded-full hover:bg-gray-100">
<i class="fas fa-sync-alt text-gray-600"></i>
</button>
<button class="p-2 rounded-full hover:bg-gray-100">
<i class="fas fa-cog text-gray-600"></i>
</button>
</div>
</div>
<div class="relative w-1/3">
<input type="text" placeholder="Search files..." class="w-full pl-10 pr-4 py-2 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent">
<i class="fas fa-search absolute left-3 top-3 text-gray-400"></i>
</div>
<div class="flex items-center space-x-3">
<button class="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 flex items-center space-x-2">
<i class="fas fa-plus"></i>
<span>New</span>
</button>
<div class="w-8 h-8 rounded-full bg-gray-300 flex items-center justify-center">
<i class="fas fa-user text-gray-600"></i>
</div>
</div>
</header>
<!-- Toolbar -->
<div class="bg-white border-b px-6 py-2 flex items-center justify-between">
<div class="flex items-center space-x-2">
<button id="back-btn" class="p-2 rounded hover:bg-gray-100 disabled:text-gray-400" disabled>
<i class="fas fa-arrow-left"></i>
</button>
<button id="forward-btn" class="p-2 rounded hover:bg-gray-100 disabled:text-gray-400" disabled>
<i class="fas fa-arrow-right"></i>
</button>
<button id="up-btn" class="p-2 rounded hover:bg-gray-100">
<i class="fas fa-arrow-up"></i>
</button>
<div class="h-6 border-l border-gray-300 mx-2"></div>
<button class="p-2 rounded hover:bg-gray-100">
<i class="fas fa-list"></i>
</button>
<button class="p-2 rounded hover:bg-gray-100">
<i class="fas fa-th-large"></i>
</button>
<div class="h-6 border-l border-gray-300 mx-2"></div>
<button id="new-folder-btn" class="p-2 rounded hover:bg-gray-100">
<i class="fas fa-folder-plus"></i>
</button>
<button id="upload-btn" class="p-2 rounded hover:bg-gray-100">
<i class="fas fa-upload"></i>
</button>
</div>
<div class="flex items-center space-x-4">
<div class="text-sm text-gray-500">
<span id="selected-count">0</span> selected
</div>
<div class="flex space-x-1">
<button id="delete-btn" class="p-2 rounded hover:bg-gray-100 text-red-500 disabled:text-gray-400" disabled>
<i class="fas fa-trash"></i>
</button>
<button id="download-btn" class="p-2 rounded hover:bg-gray-100 text-blue-500 disabled:text-gray-400" disabled>
<i class="fas fa-download"></i>
</button>
<button id="share-btn" class="p-2 rounded hover:bg-gray-100 text-green-500 disabled:text-gray-400" disabled>
<i class="fas fa-share-alt"></i>
</button>
</div>
</div>
</div>
<!-- Breadcrumbs -->
<div class="bg-white px-6 py-2 border-b flex items-center overflow-x-auto">
<div id="breadcrumbs" class="flex items-center text-sm">
<a href="#" class="text-blue-600 hover:underline">Home</a>
</div>
</div>
<!-- Main Content -->
<div class="flex flex-1 overflow-hidden">
<!-- Sidebar -->
<aside class="w-64 bg-white border-r p-4 overflow-y-auto">
<div class="space-y-1">
<div class="flex items-center space-x-3 p-2 rounded-lg bg-blue-50 text-blue-700">
<i class="fas fa-home"></i>
<span>Home</span>
</div>
<div class="flex items-center space-x-3 p-2 rounded-lg hover:bg-gray-100">
<i class="fas fa-star text-yellow-500"></i>
<span>Favorites</span>
</div>
<div class="flex items-center space-x-3 p-2 rounded-lg hover:bg-gray-100">
<i class="fas fa-clock"></i>
<span>Recent</span>
</div>
<div class="flex items-center space-x-3 p-2 rounded-lg hover:bg-gray-100">
<i class="fas fa-trash"></i>
<span>Trash</span>
</div>
</div>
<div class="mt-6">
<h3 class="text-xs font-semibold text-gray-500 uppercase tracking-wider mb-2">Storage</h3>
<div class="space-y-2">
<div>
<div class="flex justify-between text-sm mb-1">
<span>Used: 45%</span>
<span>45 GB of 100 GB</span>
</div>
<div class="w-full bg-gray-200 rounded-full h-2">
<div class="bg-blue-600 h-2 rounded-full" style="width: 45%"></div>
</div>
</div>
<div class="flex items-center space-x-3 p-2 rounded-lg hover:bg-gray-100">
<i class="fas fa-hdd"></i>
<span>Local Disk (C:)</span>
</div>
<div class="flex items-center space-x-3 p-2 rounded-lg hover:bg-gray-100">
<i class="fas fa-database"></i>
<span>Documents</span>
</div>
<div class="flex items-center space-x-3 p-2 rounded-lg hover:bg-gray-100">
<i class="fas fa-cloud"></i>
<span>Cloud Storage</span>
</div>
</div>
</div>
</aside>
<!-- File Browser -->
<main class="flex-1 overflow-auto p-6 bg-white">
<div id="dropzone" class="dropzone rounded-lg mb-4 p-8 text-center">
<i class="fas fa-cloud-upload-alt text-4xl text-gray-400 mb-2"></i>
<p class="text-gray-500">Drag and drop files here or click to upload</p>
<input type="file" id="file-input" class="hidden" multiple>
<button id="select-files-btn" class="mt-4 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700">
Select Files
</button>
</div>
<div class="mb-4 flex justify-between items-center">
<h2 class="text-lg font-semibold">Files</h2>
<div class="flex space-x-2">
<div class="relative">
<select class="appearance-none bg-gray-100 border border-gray-300 rounded-lg px-4 py-2 pr-8 focus:outline-none focus:ring-2 focus:ring-blue-500">
<option>Name (A-Z)</option>
<option>Name (Z-A)</option>
<option>Date (Newest)</option>
<option>Date (Oldest)</option>
<option>Size (Largest)</option>
<option>Size (Smallest)</option>
</select>
<i class="fas fa-chevron-down absolute right-3 top-3 text-gray-500 pointer-events-none"></i>
</div>
</div>
</div>
<div id="file-list" class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-4">
<!-- Files will be populated here by JavaScript -->
</div>
</main>
<!-- Preview Panel -->
<aside id="preview-panel" class="w-80 bg-white border-l p-4 overflow-y-auto hidden">
<div class="flex justify-between items-center mb-4">
<h3 class="font-semibold">Preview</h3>
<button id="close-preview" class="p-1 rounded-full hover:bg-gray-100">
<i class="fas fa-times"></i>
</button>
</div>
<div id="preview-content" class="preview-container flex flex-col items-center justify-center">
<i class="fas fa-file text-6xl text-gray-400 mb-4"></i>
<p class="text-gray-500">Select a file to preview</p>
</div>
<div id="file-info" class="mt-4 space-y-2">
<div class="flex justify-between">
<span class="text-gray-500">Name:</span>
<span id="info-name" class="font-medium">-</span>
</div>
<div class="flex justify-between">
<span class="text-gray-500">Type:</span>
<span id="info-type" class="font-medium">-</span>
</div>
<div class="flex justify-between">
<span class="text-gray-500">Size:</span>
<span id="info-size" class="font-medium">-</span>
</div>
<div class="flex justify-between">
<span class="text-gray-500">Modified:</span>
<span id="info-modified" class="font-medium">-</span>
</div>
<div class="flex justify-between">
<span class="text-gray-500">Created:</span>
<span id="info-created" class="font-medium">-</span>
</div>
</div>
<div class="mt-6 space-y-2">
<button id="preview-download-btn" class="w-full py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 flex items-center justify-center space-x-2">
<i class="fas fa-download"></i>
<span>Download</span>
</button>
<button id="preview-share-btn" class="w-full py-2 bg-gray-100 text-gray-800 rounded-lg hover:bg-gray-200 flex items-center justify-center space-x-2">
<i class="fas fa-share-alt"></i>
<span>Share</span>
</button>
<button id="preview-delete-btn" class="w-full py-2 bg-red-100 text-red-600 rounded-lg hover:bg-red-200 flex items-center justify-center space-x-2">
<i class="fas fa-trash"></i>
<span>Delete</span>
</button>
<div class="mt-4 border-t pt-4">
<h4 class="text-sm font-medium mb-2">Upload Files</h4>
<div id="preview-dropzone" class="dropzone rounded-lg p-4 text-center">
<i class="fas fa-cloud-upload-alt text-2xl text-gray-400 mb-2"></i>
<p class="text-xs text-gray-500 mb-2">Drag files here or click to select</p>
<input type="file" id="preview-file-input" class="hidden" multiple>
<button id="preview-select-files-btn" class="px-3 py-1 bg-blue-600 text-white rounded-lg hover:bg-blue-700 text-sm">
Select Files
</button>
</div>
<div id="upload-progress" class="mt-2 hidden">
<div class="flex justify-between text-xs mb-1">
<span>Uploading...</span>
<span id="upload-percentage">0%</span>
</div>
<div class="w-full bg-gray-200 rounded-full h-2">
<div id="file-upload-progress" class="bg-blue-600 h-2 rounded-full" style="width: 0%"></div>
</div>
</div>
</div>
</div>
</aside>
</div>
<!-- Status Bar -->
<footer class="bg-white border-t px-6 py-2 flex justify-between items-center text-sm text-gray-500">
<div id="status-message">Ready</div>
<div id="item-count">0 items</div>
</footer>
<!-- Context Menu -->
<div id="context-menu" class="context-menu bg-white shadow-lg rounded-md py-1 w-48 border border-gray-200">
<div class="px-4 py-2 hover:bg-gray-100 cursor-pointer flex items-center space-x-2">
<i class="fas fa-folder-open w-4"></i>
<span>Open</span>
</div>
<div class="px-4 py-2 hover:bg-gray-100 cursor-pointer flex items-center space-x-2">
<i class="fas fa-download w-4"></i>
<span>Download</span>
</div>
<div class="px-4 py-2 hover:bg-gray-100 cursor-pointer flex items-center space-x-2">
<i class="fas fa-share-alt w-4"></i>
<span>Share</span>
</div>
<div class="border-t border-gray-200 my-1"></div>
<div class="px-4 py-2 hover:bg-gray-100 cursor-pointer flex items-center space-x-2">
<i class="fas fa-copy w-4"></i>
<span>Copy</span>
</div>
<div class="px-4 py-2 hover:bg-gray-100 cursor-pointer flex items-center space-x-2">
<i class="fas fa-cut w-4"></i>
<span>Cut</span>
</div>
<div class="px-4 py-2 hover:bg-gray-100 cursor-pointer flex items-center space-x-2">
<i class="fas fa-paste w-4"></i>
<span>Paste</span>
</div>
<div class="border-t border-gray-200 my-1"></div>
<div class="px-4 py-2 hover:bg-gray-100 cursor-pointer flex items-center space-x-2 text-red-500">
<i class="fas fa-trash w-4"></i>
<span>Delete</span>
</div>
<div class="px-4 py-2 hover:bg-gray-100 cursor-pointer flex items-center space-x-2">
<i class="fas fa-info-circle w-4"></i>
<span>Properties</span>
</div>
</div>
<!-- Modal for new folder -->
<div id="new-folder-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden z-50">
<div class="bg-white rounded-lg shadow-xl w-96">
<div class="p-4 border-b">
<h3 class="text-lg font-semibold">Create New Folder</h3>
</div>
<div class="p-4">
<input type="text" id="folder-name" placeholder="Folder name" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div class="p-4 border-t flex justify-end space-x-2">
<button id="cancel-folder" class="px-4 py-2 text-gray-600 hover:bg-gray-100 rounded-lg">Cancel</button>
<button id="create-folder" class="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700">Create</button>
</div>
</div>
</div>
</div>
<script>
// Sample file data
const files = [
{ id: 1, name: 'Documents', type: 'folder', size: '-', modified: '2023-05-15', created: '2023-01-10' },
{ id: 2, name: 'Images', type: 'folder', size: '-', modified: '2023-06-20', created: '2023-01-10' },
{ id: 3, name: 'Project Files', type: 'folder', size: '-', modified: '2023-07-01', created: '2023-03-15' },
{ id: 4, name: 'report.pdf', type: 'document', size: '2.4 MB', modified: '2023-07-10', created: '2023-07-05' },
{ id: 5, name: 'presentation.pptx', type: 'document', size: '5.7 MB', modified: '2023-07-12', created: '2023-06-28' },
{ id: 6, name: 'vacation.jpg', type: 'image', size: '3.2 MB', modified: '2023-06-15', created: '2023-06-15' },
{ id: 7, name: 'meeting_notes.txt', type: 'document', size: '12 KB', modified: '2023-07-14', created: '2023-07-14' },
{ id: 8, name: 'project_backup.zip', type: 'archive', size: '45 MB', modified: '2023-07-01', created: '2023-07-01' },
{ id: 9, name: 'song.mp3', type: 'audio', size: '8.5 MB', modified: '2023-05-22', created: '2023-05-20' },
{ id: 10, name: 'tutorial.mp4', type: 'video', size: '156 MB', modified: '2023-06-30', created: '2023-06-25' },
];
// Current directory path
let currentPath = ['Home'];
let selectedFiles = [];
let history = [];
let historyIndex = -1;
let currentPreviewFile = null;
// DOM elements
const fileList = document.getElementById('file-list');
const breadcrumbs = document.getElementById('breadcrumbs');
const previewPanel = document.getElementById('preview-panel');
const previewContent = document.getElementById('preview-content');
const fileInfo = document.getElementById('file-info');
const closePreview = document.getElementById('close-preview');
const backBtn = document.getElementById('back-btn');
const forwardBtn = document.getElementById('forward-btn');
const upBtn = document.getElementById('up-btn');
const selectedCount = document.getElementById('selected-count');
const deleteBtn = document.getElementById('delete-btn');
const downloadBtn = document.getElementById('download-btn');
const shareBtn = document.getElementById('share-btn');
const newFolderBtn = document.getElementById('new-folder-btn');
const uploadBtn = document.getElementById('upload-btn');
const contextMenu = document.getElementById('context-menu');
const newFolderModal = document.getElementById('new-folder-modal');
const folderNameInput = document.getElementById('folder-name');
const createFolderBtn = document.getElementById('create-folder');
const cancelFolderBtn = document.getElementById('cancel-folder');
const dropzone = document.getElementById('dropzone');
const statusMessage = document.getElementById('status-message');
const itemCount = document.getElementById('item-count');
const fileInput = document.getElementById('file-input');
const selectFilesBtn = document.getElementById('select-files-btn');
const previewDownloadBtn = document.getElementById('preview-download-btn');
const previewShareBtn = document.getElementById('preview-share-btn');
const previewDeleteBtn = document.getElementById('preview-delete-btn');
const previewDropzone = document.getElementById('preview-dropzone');
const previewFileInput = document.getElementById('preview-file-input');
const previewSelectFilesBtn = document.getElementById('preview-select-files-btn');
const uploadProgress = document.getElementById('upload-progress');
const fileUploadProgress = document.getElementById('file-upload-progress');
const uploadPercentage = document.getElementById('upload-percentage');
// Initialize the file manager
function init() {
renderFiles();
updateBreadcrumbs();
updateStatusBar();
// Event listeners
closePreview.addEventListener('click', () => {
previewPanel.classList.add('hidden');
});
backBtn.addEventListener('click', navigateBack);
forwardBtn.addEventListener('click', navigateForward);
upBtn.addEventListener('click', navigateUp);
newFolderBtn.addEventListener('click', showNewFolderModal);
uploadBtn.addEventListener('click', () => {
fileInput.click();
});
createFolderBtn.addEventListener('click', createNewFolder);
cancelFolderBtn.addEventListener('click', () => {
newFolderModal.classList.add('hidden');
folderNameInput.value = '';
});
// File upload from main dropzone
selectFilesBtn.addEventListener('click', () => {
fileInput.click();
});
fileInput.addEventListener('change', handleFileUpload);
// Drag and drop for main dropzone
dropzone.addEventListener('dragover', (e) => {
e.preventDefault();
dropzone.classList.add('active');
});
dropzone.addEventListener('dragleave', () => {
dropzone.classList.remove('active');
});
dropzone.addEventListener('drop', (e) => {
e.preventDefault();
dropzone.classList.remove('active');
if (e.dataTransfer.files.length > 0) {
fileInput.files = e.dataTransfer.files;
handleFileUpload({ target: fileInput });
}
});
// File upload from preview panel
previewSelectFilesBtn.addEventListener('click', () => {
previewFileInput.click();
});
previewFileInput.addEventListener('change', handleFileUpload);
// Drag and drop for preview panel
previewDropzone.addEventListener('dragover', (e) => {
e.preventDefault();
previewDropzone.classList.add('active');
});
previewDropzone.addEventListener('dragleave', () => {
previewDropzone.classList.remove('active');
});
previewDropzone.addEventListener('drop', (e) => {
e.preventDefault();
previewDropzone.classList.remove('active');
if (e.dataTransfer.files.length > 0) {
previewFileInput.files = e.dataTransfer.files;
handleFileUpload({ target: previewFileInput });
}
});
// Preview panel buttons
previewDownloadBtn.addEventListener('click', () => {
if (currentPreviewFile) {
statusMessage.textContent = `Downloading ${currentPreviewFile.name}...`;
setTimeout(() => {
statusMessage.textContent = 'Ready';
}, 3000);
}
});
previewShareBtn.addEventListener('click', () => {
if (currentPreviewFile) {
statusMessage.textContent = `Sharing ${currentPreviewFile.name}...`;
setTimeout(() => {
statusMessage.textContent = 'Ready';
}, 3000);
}
});
previewDeleteBtn.addEventListener('click', () => {
if (currentPreviewFile) {
deleteFile(currentPreviewFile.id);
}
});
// Context menu
document.addEventListener('contextmenu', (e) => {
e.preventDefault();
const target = e.target.closest('.file-item');
if (target) {
showContextMenu(e, target.dataset.id);
}
});
document.addEventListener('click', () => {
contextMenu.style.display = 'none';
});
}
// Handle file upload
function handleFileUpload(e) {
const files = e.target.files;
if (files.length === 0) return;
uploadProgress.classList.remove('hidden');
fileUploadProgress.style.width = '0%';
uploadPercentage.textContent = '0%';
// Simulate upload progress
let progress = 0;
const interval = setInterval(() => {
progress += Math.random() * 10;
if (progress >= 100) {
progress = 100;
clearInterval(interval);
// Add the uploaded files to our file list
setTimeout(() => {
uploadProgress.classList.add('hidden');
for (let i = 0; i < files.length; i++) {
const file = files[i];
const fileType = getFileType(file.name);
const newFile = {
id: Date.now() + i,
name: file.name,
type: fileType,
size: formatFileSize(file.size),
modified: new Date().toISOString().split('T')[0],
created: new Date().toISOString().split('T')[0]
};
this.files.unshift(newFile);
}
renderFiles();
statusMessage.textContent = `Uploaded ${files.length} file(s)`;
setTimeout(() => {
statusMessage.textContent = 'Ready';
}, 3000);
}, 500);
}
fileUploadProgress.style.width = `${progress}%`;
uploadPercentage.textContent = `${Math.round(progress)}%`;
}, 200);
}
// Get file type based on extension
function getFileType(filename) {
const extension = filename.split('.').pop().toLowerCase();
const imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'];
const documentExtensions = ['pdf', 'doc', 'docx', 'txt', 'ppt', 'pptx', 'xls', 'xlsx'];
const audioExtensions = ['mp3', 'wav', 'ogg', 'aac'];
const videoExtensions = ['mp4', 'mov', 'avi', 'mkv', 'webm'];
const archiveExtensions = ['zip', 'rar', '7z', 'tar', 'gz'];
if (imageExtensions.includes(extension)) return 'image';
if (documentExtensions.includes(extension)) return 'document';
if (audioExtensions.includes(extension)) return 'audio';
if (videoExtensions.includes(extension)) return 'video';
if (archiveExtensions.includes(extension)) return 'archive';
return 'file';
}
// Format file size
function formatFileSize(bytes) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i];
}
// Render files in the current directory
function renderFiles() {
fileList.innerHTML = '';
files.forEach(file => {
const fileItem = document.createElement('div');
fileItem.className = 'file-item bg-white rounded-lg border border-gray-200 p-4 flex flex-col items-center cursor-pointer hover:shadow-md transition-shadow';
fileItem.dataset.id = file.id;
let iconClass = 'file-icon text-4xl mb-2 ';
let iconName = 'fa-file';
if (file.type === 'folder') {
iconClass += 'folder';
iconName = 'fa-folder';
} else if (file.type === 'image') {
iconClass += 'image';
iconName = 'fa-image';
} else if (file.type === 'document') {
iconClass += 'document';
iconName = 'fa-file-alt';
} else if (file.type === 'audio') {
iconClass += 'audio';
iconName = 'fa-file-audio';
} else if (file.type === 'video') {
iconClass += 'video';
iconName = 'fa-file-video';
} else if (file.type === 'archive') {
iconClass += 'archive';
iconName = 'fa-file-archive';
}
fileItem.innerHTML = `
<i class="${iconClass} fas ${iconName}"></i>
<span class="text-sm text-center font-medium text-gray-700 truncate w-full">${file.name}</span>
<span class="text-xs text-gray-500 mt-1">${file.size}</span>
`;
fileItem.addEventListener('click', (e) => {
if (e.ctrlKey || e.metaKey) {
// Multi-select with Ctrl/Cmd
toggleFileSelection(file.id);
} else {
// Single select
if (selectedFiles.includes(file.id)) {
clearSelection();
} else {
clearSelection();
selectFile(file.id);
}
}
if (file.type === 'folder') {
navigateToFolder(file.name);
} else {
showPreview(file);
}
});
fileItem.addEventListener('dblclick', () => {
if (file.type === 'folder') {
navigateToFolder(file.name);
}
});
fileList.appendChild(fileItem);
});
updateSelectionUI();
}
// Update breadcrumbs navigation
function updateBreadcrumbs() {
breadcrumbs.innerHTML = '';
currentPath.forEach((path, index) => {
const crumb = document.createElement('a');
crumb.href = '#';
crumb.className = 'text-blue-600 hover:underline';
crumb.textContent = path;
crumb.addEventListener('click', (e) => {
e.preventDefault();
currentPath = currentPath.slice(0, index + 1);
updateBreadcrumbs();
renderFiles();
});
breadcrumbs.appendChild(crumb);
if (index < currentPath.length - 1) {
const separator = document.createElement('span');
separator.className = 'breadcrumb-item';
breadcrumbs.appendChild(separator);
}
});
}
// Show file preview
function showPreview(file) {
currentPreviewFile = file;
previewPanel.classList.remove('hidden');
// Update file info
document.getElementById('info-name').textContent = file.name;
document.getElementById('info-type').textContent = file.type.charAt(0).toUpperCase() + file.type.slice(1);
document.getElementById('info-size').textContent = file.size;
document.getElementById('info-modified').textContent = file.modified;
document.getElementById('info-created').textContent = file.created;
// Show appropriate preview content
previewContent.innerHTML = '';
if (file.type === 'image') {
const img = document.createElement('div');
img.className = 'w-full h-full flex items-center justify-center';
img.innerHTML = `<i class="fas fa-image text-6xl text-gray-400"></i>`;
previewContent.appendChild(img);
} else if (file.type === 'document') {
const doc = document.createElement('div');
doc.className = 'w-full h-full flex flex-col items-center justify-center';
doc.innerHTML = `
<i class="fas fa-file-alt text-6xl text-gray-400 mb-4"></i>
<p class="text-gray-600">Document preview would appear here</p>
`;
previewContent.appendChild(doc);
} else if (file.type === 'video') {
const video = document.createElement('div');
video.className = 'w-full h-full flex flex-col items-center justify-center';
video.innerHTML = `
<i class="fas fa-film text-6xl text-gray-400 mb-4"></i>
<p class="text-gray-600">Video preview would appear here</p>
`;
previewContent.appendChild(video);
} else if (file.type === 'audio') {
const audio = document.createElement('div');
audio.className = 'w-full h-full flex flex-col items-center justify-center';
audio.innerHTML = `
<i class="fas fa-music text-6xl text-gray-400 mb-4"></i>
<p class="text-gray-600">Audio player would appear here</p>
`;
previewContent.appendChild(audio);
} else {
const defaultPreview = document.createElement('div');
defaultPreview.className = 'w-full h-full flex flex-col items-center justify-center';
defaultPreview.innerHTML = `
<i class="fas fa-file text-6xl text-gray-400 mb-4"></i>
<p class="text-gray-600">No preview available</p>
`;
previewContent.appendChild(defaultPreview);
}
}
// Delete a file
function deleteFile(fileId) {
const index = files.findIndex(file => file.id === fileId);
if (index !== -1) {
const fileName = files[index].name;
files.splice(index, 1);
renderFiles();
if (currentPreviewFile && currentPreviewFile.id === fileId) {
previewPanel.classList.add('hidden');
currentPreviewFile = null;
}
statusMessage.textContent = `Deleted ${fileName}`;
setTimeout(() => {
statusMessage.textContent = 'Ready';
}, 3000);
}
}
// Navigation functions
function navigateToFolder(folderName) {
history = history.slice(0, historyIndex + 1);
history.push([...currentPath]);
historyIndex++;
currentPath.push(folderName);
updateBreadcrumbs();
renderFiles();
updateNavigationButtons();
}
function navigateUp() {
if (currentPath.length > 1) {
history = history.slice(0, historyIndex + 1);
history.push([...currentPath]);
historyIndex++;
currentPath.pop();
updateBreadcrumbs();
renderFiles();
updateNavigationButtons();
}
}
function navigateBack() {
if (historyIndex > 0) {
historyIndex--;
currentPath = [...history[historyIndex]];
updateBreadcrumbs();
renderFiles();
updateNavigationButtons();
}
}
function navigateForward() {
if (historyIndex < history.length - 1) {
historyIndex++;
currentPath = [...history[historyIndex]];
updateBreadcrumbs();
renderFiles();
updateNavigationButtons();
}
}
function updateNavigationButtons() {
backBtn.disabled = historyIndex <= 0;
forwardBtn.disabled = historyIndex >= history.length - 1;
upBtn.disabled = currentPath.length <= 1;
}
// File selection functions
function selectFile(fileId) {
if (!selectedFiles.includes(fileId)) {
selectedFiles.push(fileId);
document.querySelector(`.file-item[data-id="${fileId}"]`).classList.add('selected');
updateSelectionUI();
}
}
function toggleFileSelection(fileId) {
const index = selectedFiles.indexOf(fileId);
const fileItem = document.querySelector(`.file-item[data-id="${fileId}"]`);
if (index === -1) {
selectedFiles.push(fileId);
fileItem.classList.add('selected');
} else {
selectedFiles.splice(index, 1);
fileItem.classList.remove('selected');
}
updateSelectionUI();
}
function clearSelection() {
selectedFiles.forEach(id => {
document.querySelector(`.file-item[data-id="${id}"]`)?.classList.remove('selected');
});
selectedFiles = [];
updateSelectionUI();
}
function updateSelectionUI() {
selectedCount.textContent = selectedFiles.length;
deleteBtn.disabled = selectedFiles.length === 0;
downloadBtn.disabled = selectedFiles.length === 0;
shareBtn.disabled = selectedFiles.length === 0;
}
// New folder functions
function showNewFolderModal() {
newFolderModal.classList.remove('hidden');
folderNameInput.focus();
}
function createNewFolder() {
const folderName = folderNameInput.value.trim();
if (folderName) {
// In a real app, this would create a folder on the server
statusMessage.textContent = `Folder "${folderName}" created`;
setTimeout(() => {
statusMessage.textContent = 'Ready';
}, 3000);
newFolderModal.classList.add('hidden');
folderNameInput.value = '';
// Add to our files array (simulated)
const newFolder = {
id: Date.now(),
name: folderName,
type: 'folder',
size: '-',
modified: new Date().toISOString().split('T')[0],
created: new Date().toISOString().split('T')[0]
};
files.unshift(newFolder);
renderFiles();
}
}
// Context menu functions
function showContextMenu(e, fileId) {
contextMenu.style.display = 'block';
contextMenu.style.left = `${e.pageX}px`;
contextMenu.style.top = `${e.pageY}px';
// Select the file if it's not already selected
if (!selectedFiles.includes(parseInt(fileId))) {
clearSelection();
selectFile(parseInt(fileId));
}
}
// Update status bar
function updateStatusBar() {
itemCount.textContent = `${files.length} items`;
}
// Initialize the file manager when the page loads
document.addEventListener('DOMContentLoaded', init);
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Adityakumar12/filemenager" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>