поправлен предосмотр
This commit is contained in:
165
template.html
165
template.html
@@ -20,7 +20,7 @@
|
||||
<meta name="twitter:description" content="Моя личная помоечка" />
|
||||
<meta name="twitter:image" content="https://home.mashup.su/og.png" />
|
||||
<meta name="description" content="Моя личная помоечка" />
|
||||
<meta name="keywords" content="файлы, обмен, скачать, загрузить" />
|
||||
<meta name="keywords" content="RomkaZVO, mashup, mashup su, файлы, обмен, скачать, загрузить" />
|
||||
|
||||
<script>
|
||||
function getCookie(name) {
|
||||
@@ -58,7 +58,7 @@
|
||||
<div class="footer-content">
|
||||
<span>Навайбкодил с любовью ❤️</span>
|
||||
<a href="https://romkazvo.ru" target="_blank" class="footer-link">RomkaZVO</a><br>
|
||||
Сделано при помощи BusyBox httpd и nginx для SSL<br>
|
||||
Сделано при помощи BusyBox httpd и Nginx для SSL<br>
|
||||
Боже, храни Китай партия за DeepSeek
|
||||
</div>
|
||||
|
||||
@@ -80,7 +80,6 @@
|
||||
|
||||
<button class="scroll-top" onclick="scrollToTop()">↑</button>
|
||||
|
||||
<!-- Модальное окно предпросмотра -->
|
||||
<div id="previewModal" class="preview-modal">
|
||||
<div class="preview-content" id="previewContent">
|
||||
<div class="preview-header">
|
||||
@@ -123,18 +122,15 @@
|
||||
document.cookie = `theme=${newTheme}; expires=${date.toUTCString()}; path=/`;
|
||||
}
|
||||
|
||||
// Функции для предпросмотра файлов
|
||||
function openPreview(fileUrl) {
|
||||
const modal = document.getElementById('previewModal');
|
||||
const frame = document.getElementById('previewFrame');
|
||||
const content = document.getElementById('previewContent');
|
||||
const title = document.getElementById('previewTitle');
|
||||
|
||||
// Получаем имя файла из URL
|
||||
const fileName = fileUrl.split('/').pop();
|
||||
title.textContent = `Предпросмотр: ${fileName}`;
|
||||
|
||||
// Определяем тип файла для адаптивного масштабирования
|
||||
const fileExt = fileName.split('.').pop().toLowerCase();
|
||||
const imageTypes = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'svg', 'ico'];
|
||||
const textTypes = ['txt', 'md', 'html', 'htm', 'css', 'js', 'json', 'xml', 'csv'];
|
||||
@@ -142,81 +138,154 @@
|
||||
const videoTypes = ['mp4', 'webm', 'ogv', 'mov', 'avi', 'mkv'];
|
||||
const isPDF = fileExt === 'pdf';
|
||||
|
||||
// Устанавливаем размеры в зависимости от типа файла
|
||||
frame.style.display = 'block';
|
||||
frame.src = '';
|
||||
|
||||
let imgContainer = document.getElementById('previewImageContainer');
|
||||
if (!imgContainer) {
|
||||
imgContainer = document.createElement('div');
|
||||
imgContainer.id = 'previewImageContainer';
|
||||
imgContainer.className = 'preview-image-container';
|
||||
content.appendChild(imgContainer);
|
||||
}
|
||||
imgContainer.style.display = 'none';
|
||||
imgContainer.innerHTML = '';
|
||||
|
||||
if (imageTypes.includes(fileExt)) {
|
||||
// Для изображений - автоматический размер
|
||||
content.style.width = 'auto';
|
||||
content.style.height = 'auto';
|
||||
content.style.maxWidth = '90vw';
|
||||
content.style.maxHeight = '90vh';
|
||||
} else if (textTypes.includes(fileExt)) {
|
||||
// Для текстовых файлов - компактное окно
|
||||
content.style.width = '80vw';
|
||||
content.style.height = '70vh';
|
||||
content.style.maxWidth = '800px';
|
||||
content.style.maxHeight = '600px';
|
||||
} else if (audioTypes.includes(fileExt)) {
|
||||
// Для аудио - маленькое окно
|
||||
content.style.width = '500px';
|
||||
content.style.height = '300px';
|
||||
content.style.maxWidth = '90vw';
|
||||
content.style.maxHeight = '400px';
|
||||
} else if (videoTypes.includes(fileExt)) {
|
||||
// Для видео - большое окно
|
||||
content.style.width = '90vw';
|
||||
content.style.height = '80vh';
|
||||
content.style.maxWidth = '1200px';
|
||||
content.style.maxHeight = '800px';
|
||||
} else if (isPDF) {
|
||||
// Для PDF - большое окно
|
||||
frame.style.display = 'none';
|
||||
imgContainer.style.display = 'flex';
|
||||
|
||||
const img = document.createElement('img');
|
||||
img.src = fileUrl;
|
||||
img.alt = fileName;
|
||||
img.className = 'preview-image';
|
||||
|
||||
img.onload = function() {
|
||||
adjustModalForImage(this);
|
||||
};
|
||||
|
||||
img.onerror = function() {
|
||||
console.error('Failed to load image:', fileUrl);
|
||||
frame.style.display = 'block';
|
||||
imgContainer.style.display = 'none';
|
||||
frame.src = fileUrl;
|
||||
};
|
||||
|
||||
imgContainer.appendChild(img);
|
||||
|
||||
content.style.width = '90vw';
|
||||
content.style.height = '90vh';
|
||||
content.style.maxWidth = '1200px';
|
||||
content.style.maxHeight = '900px';
|
||||
frame.classList.add('pdf');
|
||||
content.style.maxWidth = 'none';
|
||||
content.style.maxHeight = 'none';
|
||||
|
||||
} else {
|
||||
// По умолчанию - средний размер
|
||||
content.style.width = '80vw';
|
||||
content.style.height = '80vh';
|
||||
content.style.maxWidth = '1000px';
|
||||
content.style.maxHeight = '800px';
|
||||
frame.style.display = 'block';
|
||||
imgContainer.style.display = 'none';
|
||||
|
||||
if (textTypes.includes(fileExt)) {
|
||||
content.style.width = '80vw';
|
||||
content.style.height = '70vh';
|
||||
content.style.maxWidth = '800px';
|
||||
content.style.maxHeight = '600px';
|
||||
} else if (audioTypes.includes(fileExt)) {
|
||||
content.style.width = '500px';
|
||||
content.style.height = '300px';
|
||||
content.style.maxWidth = '90vw';
|
||||
content.style.maxHeight = '400px';
|
||||
} else if (videoTypes.includes(fileExt)) {
|
||||
content.style.width = '90vw';
|
||||
content.style.height = '80vh';
|
||||
content.style.maxWidth = '1200px';
|
||||
content.style.maxHeight = '800px';
|
||||
} else if (isPDF) {
|
||||
content.style.width = '90vw';
|
||||
content.style.height = '90vh';
|
||||
content.style.maxWidth = '1200px';
|
||||
content.style.maxHeight = '900px';
|
||||
frame.classList.add('pdf');
|
||||
} else {
|
||||
content.style.width = '80vw';
|
||||
content.style.height = '80vh';
|
||||
content.style.maxWidth = '1000px';
|
||||
content.style.maxHeight = '800px';
|
||||
}
|
||||
|
||||
frame.src = fileUrl;
|
||||
}
|
||||
|
||||
// Просто открываем файл напрямую в iframe
|
||||
frame.src = fileUrl;
|
||||
|
||||
// Показываем модальное окно
|
||||
modal.style.display = 'block';
|
||||
document.body.style.overflow = 'hidden';
|
||||
}
|
||||
|
||||
|
||||
function adjustModalForImage(img) {
|
||||
const content = document.getElementById('previewContent');
|
||||
const maxWidth = window.innerWidth * 0.95;
|
||||
const maxHeight = window.innerHeight * 0.95;
|
||||
|
||||
const imgWidth = img.naturalWidth;
|
||||
const imgHeight = img.naturalHeight;
|
||||
|
||||
console.log(`Image size: ${imgWidth}x${imgHeight}, Screen limits: ${maxWidth}x${maxHeight}`);
|
||||
|
||||
let scale = 1;
|
||||
|
||||
if (imgWidth > maxWidth) {
|
||||
scale = Math.min(scale, maxWidth / imgWidth);
|
||||
}
|
||||
if (imgHeight > maxHeight) {
|
||||
scale = Math.min(scale, maxHeight / imgHeight);
|
||||
}
|
||||
|
||||
const displayWidth = imgWidth * scale;
|
||||
const displayHeight = imgHeight * scale;
|
||||
|
||||
console.log(`Display size: ${displayWidth}x${displayHeight}, Scale: ${scale}`);
|
||||
|
||||
content.style.width = (displayWidth + 20) + 'px';
|
||||
content.style.height = (displayHeight + 80) + 'px';
|
||||
|
||||
content.style.margin = 'auto';
|
||||
content.style.position = 'absolute';
|
||||
content.style.left = '50%';
|
||||
content.style.top = '50%';
|
||||
content.style.transform = 'translate(-50%, -50%)';
|
||||
}
|
||||
|
||||
function closePreview() {
|
||||
const modal = document.getElementById('previewModal');
|
||||
const frame = document.getElementById('previewFrame');
|
||||
const content = document.getElementById('previewContent');
|
||||
|
||||
// Скрываем модальное окно и сбрасываем iframe
|
||||
modal.style.display = 'none';
|
||||
frame.src = '';
|
||||
frame.classList.remove('pdf');
|
||||
|
||||
// Сбрасываем стили
|
||||
content.style.width = '';
|
||||
content.style.height = '';
|
||||
content.style.maxWidth = '';
|
||||
content.style.maxHeight = '';
|
||||
content.style.margin = '';
|
||||
content.style.position = '';
|
||||
content.style.left = '';
|
||||
content.style.top = '';
|
||||
content.style.transform = '';
|
||||
|
||||
const imgContainer = document.getElementById('previewImageContainer');
|
||||
if (imgContainer) {
|
||||
imgContainer.style.display = 'none';
|
||||
imgContainer.innerHTML = '';
|
||||
}
|
||||
|
||||
document.body.style.overflow = 'auto';
|
||||
}
|
||||
|
||||
// Закрытие модального окна по клику вне контента
|
||||
document.getElementById('previewModal').addEventListener('click', function(e) {
|
||||
if (e.target === this) {
|
||||
closePreview();
|
||||
}
|
||||
});
|
||||
|
||||
// Закрытие по ESC
|
||||
document.addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Escape') {
|
||||
closePreview();
|
||||
|
||||
Reference in New Issue
Block a user