(function () { "use strict"; function qsa(root, sel) { return Array.prototype.slice.call(root.querySelectorAll(sel)); } function closest(el, sel) { while (el && el.nodeType === 1) { if (el.matches && el.matches(sel)) return el; el = el.parentElement; } return null; } function parseGalleryData(wrap) { var dataEl = wrap.querySelector("script.sn2-gallery-data"); if (!dataEl) { return []; } var urls = []; try { urls = JSON.parse(dataEl.textContent || "[]"); if (!Array.isArray(urls)) { urls = []; } } catch (e) { urls = []; } return urls.filter(Boolean); } function getVisibleUrls(grid) { return qsa(grid, '[data-sn2-item="1"]').map(function (node) { var href = node.getAttribute("data-sn2-href"); if (href) { return href; } if (node.tagName && node.tagName.toLowerCase() === "a") { return node.getAttribute("href"); } var img = node.querySelector("img"); if (img && img.src) { return img.src; } return null; }).filter(Boolean); } function getAllUrls(wrap, grid) { var visibleUrls = getVisibleUrls(grid); var hiddenUrls = parseGalleryData(wrap); var result = []; var seen = {}; visibleUrls.concat(hiddenUrls).forEach(function (url) { if (!url) return; if (seen[url]) return; seen[url] = true; result.push(url); }); return result; } function removeNode(node) { if (node && node.parentNode) { node.parentNode.removeChild(node); } } function appendGalleryItem(grid, url, lightboxEnabled) { if (!url) return; var img = document.createElement("img"); img.src = url; img.alt = ""; img.loading = "lazy"; img.decoding = "async"; if (lightboxEnabled) { var btn = document.createElement("button"); btn.type = "button"; btn.className = "sn-gallery-item sn2-open"; btn.setAttribute("data-sn2-item", "1"); btn.setAttribute("data-sn2-href", url); btn.appendChild(img); grid.appendChild(btn); } else { var div = document.createElement("div"); div.className = "sn-gallery-item"; div.setAttribute("data-sn2-item", "1"); div.appendChild(img); grid.appendChild(div); } } function showAllPhotos(moreBtn) { var wrap = closest(moreBtn, '.sn2-gallery-wrap[data-sn2-wrap="1"]'); if (!wrap) { return; } var grid = wrap.querySelector(".sn-gallery-lite"); if (!grid) { return; } var dataEl = wrap.querySelector("script.sn2-gallery-data"); var restUrls = parseGalleryData(wrap); if (!restUrls.length) { removeNode(moreBtn); removeNode(dataEl); return; } var lightboxEnabled = grid.getAttribute("data-sn2-lightbox") === "1"; var frag = document.createDocumentFragment(); restUrls.forEach(function (url) { if (!url) return; var img = document.createElement("img"); img.src = url; img.alt = ""; img.loading = "lazy"; img.decoding = "async"; if (lightboxEnabled) { var btn = document.createElement("button"); btn.type = "button"; btn.className = "sn-gallery-item sn2-open"; btn.setAttribute("data-sn2-item", "1"); btn.setAttribute("data-sn2-href", url); btn.appendChild(img); frag.appendChild(btn); } else { var div = document.createElement("div"); div.className = "sn-gallery-item"; div.setAttribute("data-sn2-item", "1"); div.appendChild(img); frag.appendChild(div); } }); grid.appendChild(frag); grid._sn2_allUrls = getVisibleUrls(grid); removeNode(moreBtn); removeNode(dataEl); } function createLightbox() { var overlay = document.createElement("div"); overlay.className = "sn2-lightbox"; var inner = document.createElement("div"); inner.className = "sn2-lightbox-inner"; var img = document.createElement("img"); img.className = "sn2-lightbox-img"; img.alt = ""; var close = document.createElement("button"); close.type = "button"; close.className = "sn2-lightbox-close"; close.textContent = "Закрыть"; var prev = document.createElement("button"); prev.type = "button"; prev.className = "sn2-lightbox-prev"; prev.textContent = "‹"; var next = document.createElement("button"); next.type = "button"; next.className = "sn2-lightbox-next"; next.textContent = "›"; var counter = document.createElement("div"); counter.className = "sn2-lightbox-counter"; inner.appendChild(img); overlay.appendChild(inner); var state = { opened: false, urls: [], index: 0, touchX: null }; function setImage(i) { if (!state.urls.length) return; if (i < 0) { i = 0; } if (i >= state.urls.length) { i = state.urls.length - 1; } state.index = i; img.src = state.urls[state.index]; counter.textContent = (state.index + 1) + " / " + state.urls.length; if (state.index <= 0) { prev.classList.add("sn2-lightbox-disabled"); } else { prev.classList.remove("sn2-lightbox-disabled"); } if (state.index >= state.urls.length - 1) { next.classList.add("sn2-lightbox-disabled"); } else { next.classList.remove("sn2-lightbox-disabled"); } } function onKey(e) { if (!state.opened) return; if (e.key === "Escape") { destroy(); } if (e.key === "ArrowLeft") { setImage(state.index - 1); } if (e.key === "ArrowRight") { setImage(state.index + 1); } } function destroy() { if (!state.opened) return; state.opened = false; document.removeEventListener("keydown", onKey); removeNode(overlay); removeNode(close); removeNode(prev); removeNode(next); removeNode(counter); document.documentElement.classList.remove("sn2-lightbox-opened"); document.body.classList.remove("sn2-lightbox-opened"); document.body.style.overflow = ""; } overlay.addEventListener("click", function (e) { if (e.target === overlay) { destroy(); } }); close.addEventListener("click", function (e) { e.preventDefault(); destroy(); }); prev.addEventListener("click", function (e) { e.preventDefault(); setImage(state.index - 1); }); next.addEventListener("click", function (e) { e.preventDefault(); setImage(state.index + 1); }); overlay.addEventListener("touchstart", function (e) { if (!e.touches || !e.touches[0]) return; state.touchX = e.touches[0].clientX; }, { passive: true }); overlay.addEventListener("touchend", function (e) { if (state.touchX === null) return; var endX = null; if (e.changedTouches && e.changedTouches[0]) { endX = e.changedTouches[0].clientX; } if (endX === null) { state.touchX = null; return; } var dx = endX - state.touchX; state.touchX = null; if (Math.abs(dx) < 45) { return; } if (dx > 0) { setImage(state.index - 1); } else { setImage(state.index + 1); } }, { passive: true }); function open(urls, index) { state.urls = Array.isArray(urls) ? urls.filter(Boolean) : []; state.index = index || 0; if (!state.urls.length) { return; } document.body.appendChild(overlay); document.body.appendChild(close); document.body.appendChild(prev); document.body.appendChild(next); document.body.appendChild(counter); document.addEventListener("keydown", onKey); document.documentElement.classList.add("sn2-lightbox-opened"); document.body.classList.add("sn2-lightbox-opened"); document.body.style.overflow = "hidden"; state.opened = true; setImage(state.index); } return { open: open, close: destroy }; } var LB = null; var booted = false; function boot() { if (booted) { return; } booted = true; if (!LB) { LB = createLightbox(); } document.addEventListener("click", function (e) { var moreBtn = closest(e.target, '[data-sn2-more="all"]'); if (moreBtn) { e.preventDefault(); e.stopPropagation(); showAllPhotos(moreBtn); return; } var openBtn = closest(e.target, 'button.sn2-open[data-sn2-item="1"]'); if (!openBtn) { return; } var grid = closest(openBtn, ".sn-gallery-lite"); if (!grid) { return; } if (grid.getAttribute("data-sn2-lightbox") !== "1") { return; } var wrap = closest(grid, '.sn2-gallery-wrap[data-sn2-wrap="1"]'); if (!wrap) { return; } e.preventDefault(); e.stopPropagation(); var href = openBtn.getAttribute("data-sn2-href"); if (!href) { return; } var urls = getAllUrls(wrap, grid); if (!urls.length) { return; } var idx = urls.indexOf(href); if (idx < 0) { idx = 0; } LB.open(urls, idx); }, true); } if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", boot); } else { boot(); } })(); Комментарии: Слив Валерия Федорович https://slivcam.com/valerija-fedorovich/ Слив фото и видео 18+ Mon, 17 Nov 2025 21:57:35 +0000 hourly 1 https://wordpress.org/?v=6.9.4