Solução Popups Elementor v0
unknown
javascript
a month ago
2.0 kB
13
Indexable
<script>
(function () {
if (window.__ttElementorPopupFallback) return;
window.__ttElementorPopupFallback = true;
function decodeRepeated(value) {
value = String(value || '').replace(/&/g, '&');
for (var i = 0; i < 5; i++) {
try {
var decoded = decodeURIComponent(value);
if (decoded === value) break;
value = decoded;
} catch (e) {
break;
}
}
return value;
}
function isPopupLink(value) {
var text = decodeRepeated(value);
return text.indexOf('elementor-action:') !== -1 &&
text.indexOf('action=popup:open') !== -1 &&
text.indexOf('settings=') !== -1;
}
function getPopupId(value) {
var text = decodeRepeated(value);
var match = text.match(/settings=([^&#"'\s<>]+)/);
if (!match) return null;
try {
var base64 = decodeRepeated(match[1])
.replace(/ /g, '+')
.replace(/-/g, '+')
.replace(/_/g, '/');
while (base64.length % 4) base64 += '=';
var settings = JSON.parse(atob(base64));
return settings && settings.id ? String(settings.id) : null;
} catch (e) {
return null;
}
}
function openPopup(popupId) {
if (
window.elementorProFrontend &&
elementorProFrontend.modules &&
elementorProFrontend.modules.popup &&
typeof elementorProFrontend.modules.popup.showPopup === 'function'
) {
elementorProFrontend.modules.popup.showPopup({ id: popupId });
}
}
document.addEventListener('click', function (event) {
var link = event.target.closest && event.target.closest('a[href]');
if (!link) return;
var href = link.getAttribute('href') || link.href || '';
if (!isPopupLink(href)) return;
var popupId = getPopupId(href);
if (!popupId) return;
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();
link.removeAttribute('target');
link.removeAttribute('rel');
openPopup(popupId);
}, true);
})();
</script>Editor is loading...
Leave a Comment