MediaWiki:Common.js: відмінності між версіями
Wiki (обговорення | внесок) Немає опису редагування |
Wiki (обговорення | внесок) Немає опису редагування |
||
| Рядок 168: | Рядок 168: | ||
const maxScale = 3; | const maxScale = 3; | ||
const scaleStep = 0.25; | const scaleStep = 0.25; | ||
// Заборонити лупу в MediaViewer | |||
function disableMediaViewerZoom() { | |||
// Для стандартного MediaViewer | |||
const mediaViewerImages = document.querySelectorAll('.mw-mmv-image img, .mediaViewerOverlay img'); | |||
mediaViewerImages.forEach(img => { | |||
img.style.cursor = 'default'; | |||
img.style.transform = 'none'; | |||
img.addEventListener('click', (e) => { | |||
e.stopPropagation(); | |||
}); | |||
}); | |||
// Заборонити zoom по кліку в MediaViewer | |||
const mediaViewerOverlays = document.querySelectorAll('.mw-mmv-overlay, .mediaViewerOverlay'); | |||
mediaViewerOverlays.forEach(overlay => { | |||
overlay.addEventListener('click', (e) => { | |||
if (e.target.tagName === 'IMG') { | |||
e.stopPropagation(); | |||
} | |||
}); | |||
}); | |||
} | |||
// Створення оверлею в стилі MediaViewer | // Створення оверлею в стилі MediaViewer | ||
| Рядок 199: | Рядок 222: | ||
`; | `; | ||
// | // Кнопка закриття × | ||
const closeBtn = document.createElement('button'); | const closeBtn = document.createElement('button'); | ||
closeBtn.innerHTML = '×'; | closeBtn.innerHTML = '×'; | ||
| Рядок 249: | Рядок 264: | ||
border-radius: 8px; | border-radius: 8px; | ||
box-shadow: 0 10px 30px rgba(0,0,0,0.5); | box-shadow: 0 10px 30px rgba(0,0,0,0.5); | ||
cursor: default; | cursor: default !important; // Заборона лупи | ||
transition: transform 0.3s ease; | transition: transform 0.3s ease; | ||
`; | `; | ||
// Кнопки навігації | // Заборонити zoom по кліку на зображення | ||
img.addEventListener('click', (e) => { | |||
e.stopPropagation(); | |||
}); | |||
// Кнопки навігації | |||
const prevBtn = createNavButton('‹', 'Попереднє зображення (←)'); | const prevBtn = createNavButton('‹', 'Попереднє зображення (←)'); | ||
const nextBtn = createNavButton('›', 'Наступне зображення (→)'); | const nextBtn = createNavButton('›', 'Наступне зображення (→)'); | ||
| Рядок 259: | Рядок 279: | ||
nextBtn.style.right = '15px'; | nextBtn.style.right = '15px'; | ||
// Панель кнопок під зображенням | // Панель кнопок під зображенням | ||
const buttonPanel = document.createElement('div'); | const buttonPanel = document.createElement('div'); | ||
buttonPanel.style.cssText = ` | buttonPanel.style.cssText = ` | ||
| Рядок 269: | Рядок 289: | ||
`; | `; | ||
// Кнопки масштабування | // Кнопки масштабування | ||
const zoomOutBtn = createToolButton('−', 'Зменшити (Ctrl + -)'); | const zoomOutBtn = createToolButton('−', 'Зменшити (Ctrl + -)'); | ||
const resetZoomBtn = createToolButton('1:1', 'Скинути масштаб (Ctrl + 0)'); | const resetZoomBtn = createToolButton('1:1', 'Скинути масштаб (Ctrl + 0)'); | ||
| Рядок 299: | Рядок 319: | ||
buttonPanel.appendChild(zoomInBtn); | buttonPanel.appendChild(zoomInBtn); | ||
contentContainer.appendChild(closeBtn); | contentContainer.appendChild(closeBtn); | ||
contentContainer.appendChild(imageContainer); | contentContainer.appendChild(imageContainer); | ||
contentContainer.appendChild(buttonPanel); | contentContainer.appendChild(buttonPanel); | ||
| Рядок 385: | Рядок 405: | ||
break; | break; | ||
case 'i': | case 'i': | ||
case 'І': | case 'І': | ||
e.preventDefault(); | e.preventDefault(); | ||
toggleInfoPanel(); | toggleInfoPanel(); | ||
| Рядок 647: | Рядок 667: | ||
overlay.appendChild(closeBtn); | overlay.appendChild(closeBtn); | ||
// Заборонити лупу в MediaViewer | |||
disableMediaViewerZoom(); | |||
} | } | ||
// MutationObserver для MediaViewer | // MutationObserver для MediaViewer | ||
const observer = new MutationObserver(() => addCloseButtonToMediaViewer()); | const observer = new MutationObserver((mutations) => { | ||
for (let mutation of mutations) { | |||
if (mutation.type === 'childList') { | |||
for (let node of mutation.addedNodes) { | |||
if (node.nodeType === 1) { | |||
if (node.classList && | |||
(node.classList.contains('mediaViewerOverlay') || | |||
node.classList.contains('mwe-popups') || | |||
node.classList.contains('mw-mmv-overlay'))) { | |||
setTimeout(() => { | |||
addCloseButtonToMediaViewer(); | |||
disableMediaViewerZoom(); | |||
}, 100); | |||
} | |||
} | |||
} | |||
} | |||
} | |||
}); | |||
observer.observe(document.body, { childList: true, subtree: true }); | observer.observe(document.body, { childList: true, subtree: true }); | ||
// Стилі | // Також заборонити лупу при завантаженні сторінки | ||
document.addEventListener('DOMContentLoaded', disableMediaViewerZoom); | |||
setTimeout(disableMediaViewerZoom, 1000); | |||
// Стилі з забороною лупи | |||
const style = document.createElement('style'); | const style = document.createElement('style'); | ||
style.textContent = ` | style.textContent = ` | ||
| Рядок 672: | Рядок 718: | ||
.custom-media-viewer img { | .custom-media-viewer img { | ||
transition: transform 0.3s ease !important; | transition: transform 0.3s ease !important; | ||
cursor: default !important; | |||
} | |||
/* Заборонити лупу в MediaViewer */ | |||
.mw-mmv-image img, | |||
.mediaViewerOverlay img, | |||
.mw-mmv-overlay img { | |||
cursor: default !important; | |||
} | |||
.mw-mmv-image:hover img, | |||
.mediaViewerOverlay:hover img { | |||
cursor: default !important; | |||
transform: none !important; | |||
} | } | ||