/** * Preview Module * Opens file preview in a separate popup window */ (function() { 'use strict'; let currentBlobUrl = null; let currentFile = null; let currentRowIndex = null; let previewWindow = null; // Use shared extension lists from window.zddc.preview where possible const IMAGE_EXTENSIONS = zddc.preview.IMAGE_EXTENSIONS; const TIFF_EXTENSIONS = zddc.preview.TIFF_EXTENSIONS; const TEXT_EXTENSIONS = zddc.preview.TEXT_EXTENSIONS; const PDF_EXTENSIONS = ['pdf']; const ZIP_EXTENSIONS = ['zip']; // Lazily load a script from CDN — delegates to shared cache. const loadLibrary = zddc.preview.loadLibrary; /** * Initialize preview module */ function init() { // Listen for row focused events from selection module document.addEventListener('rowfocused', handleRowFocused); // Set up toggle button to open/close preview window const toggleBtn = document.getElementById('togglePreviewBtn'); if (toggleBtn) { toggleBtn.addEventListener('click', () => { if (previewWindow && !previewWindow.closed) { // Close preview window previewWindow.close(); previewWindow = null; toggleBtn.classList.remove('preview-active'); } else if (currentFile) { openPreviewWindow(currentFile); toggleBtn.classList.add('preview-active'); } }); } } /** * Handle row focused event */ function handleRowFocused(e) { const { rowIndex, file } = e.detail; currentRowIndex = rowIndex; if (file && file !== currentFile) { currentFile = file; // Update preview window if open if (previewWindow && !previewWindow.closed) { openPreviewWindow(file); } } } /** * Open preview in a separate popup window */ async function openPreviewWindow(file) { if (!file) return; currentFile = file; try { const blob = await getFileBlob(file); // Clean up previous blob URL if (currentBlobUrl) { URL.revokeObjectURL(currentBlobUrl); } currentBlobUrl = URL.createObjectURL(blob); const fileName = zddc.joinExtension(file.originalFilename, file.extension); // Build preview HTML with toolbar const previewHtml = `