Refactor js

This commit is contained in:
2026-01-15 20:05:41 +01:00
parent 34ff7f1a7f
commit 8a97197f3e

View File

@@ -262,12 +262,9 @@
})();
// ============================================================
// Gallery Thumbnails
// Gallery Thumbnails Module
// ============================================================
function initGalleryThumbs() {
var imgs = document.querySelectorAll('div.luxtools-gallery img[data-thumb-src]');
if (!imgs || !imgs.length) return;
var GalleryThumbnails = (function () {
function loadThumb(img) {
var src = img.getAttribute('data-thumb-src') || '';
if (!src) return;
@@ -286,6 +283,10 @@
pre.src = src;
}
function init() {
var imgs = document.querySelectorAll('div.luxtools-gallery img[data-thumb-src]');
if (!imgs || !imgs.length) return;
if ('IntersectionObserver' in window) {
var io = new window.IntersectionObserver(function (entries) {
entries.forEach(function (entry) {
@@ -304,9 +305,15 @@
}
}
return {
init: init
};
})();
// ============================================================
// Open Service (file:// links)
// Open Service Module (file:// links)
// ============================================================
var OpenService = (function () {
function getServiceUrl(el) {
var url = el.getAttribute('data-service-url') || '';
url = (url || '').trim();
@@ -383,10 +390,17 @@
return path;
}
function initScratchpads() {
var pads = document.querySelectorAll('div.luxtools-scratchpad[data-luxtools-scratchpad="1"]');
if (!pads || !pads.length) return;
return {
openViaService: openViaService,
pingOpenViaImage: pingOpenViaImage,
normalizeToFileUrl: normalizeToFileUrl
};
})();
// ============================================================
// Scratchpads Module
// ============================================================
var Scratchpads = (function () {
function setEditMode(root, isEditing) {
if (!root || !root.classList) return;
@@ -511,7 +525,7 @@
setStatus(root, '');
}
document.addEventListener('click', function (e) {
function onClick(e) {
var t = e.target;
if (!t) return;
@@ -550,9 +564,19 @@
e.preventDefault();
closeEditor(rootC);
}
}, true);
}
function init() {
var pads = document.querySelectorAll('div.luxtools-scratchpad[data-luxtools-scratchpad="1"]');
if (!pads || !pads.length) return;
document.addEventListener('click', onClick, true);
}
return {
init: init
};
})();
// ============================================================
// Click Handlers
// ============================================================
@@ -598,14 +622,14 @@
if (!raw) return;
// Prefer local client service.
openViaService(el, raw)
OpenService.openViaService(el, raw)
.catch(function (err) {
// If the browser blocks the request before it reaches localhost (mixed-content,
// extensions, stricter CORS handling), fall back to a no-CORS GET ping.
pingOpenViaImage(el, raw);
OpenService.pingOpenViaImage(el, raw);
// Fallback to old behavior (often blocked in modern browsers).
var url = normalizeToFileUrl(raw);
var url = OpenService.normalizeToFileUrl(raw);
if (!url) return;
console.warn('Local client service failed, falling back to file:// navigation:', err);
try {
@@ -624,6 +648,6 @@
// Initialize
// ============================================================
document.addEventListener('click', onClick, false);
document.addEventListener('DOMContentLoaded', initGalleryThumbs, false);
document.addEventListener('DOMContentLoaded', initScratchpads, false);
document.addEventListener('DOMContentLoaded', GalleryThumbnails.init, false);
document.addEventListener('DOMContentLoaded', Scratchpads.init, false);
})();