// mobilefancybox-compatibility.js // Hide element inside a iframe function controlIframeElement(elementId, action) { const iframe = $('.fancybox-iframe')[0]; if (iframe && iframe.contentDocument) { $(iframe.contentDocument).find('#' + elementId)[action](); } else { // PostMessage (cross-origin) iframe.contentWindow.postMessage({ action: 'control-element', elementId: elementId, method: action }, '*'); } } // This code makes .mobilefancybox work automatically with FancyBox 3.5.7 jQuery.fn.extend({ mobilefancybox: function (reloadOnClose, Width, Height) { // Detección más robusta de dispositivos móviles var isMobile = window.matchMedia("(max-width: 768px)").matches || ('ontouchstart' in window) || (navigator.maxTouchPoints > 0); if (isMobile) { $(this).attr('target', '_blank'); } else { $(this).fancybox({ type:'iframe', iframe: { css:{ width: Width, height: Height } }, buttons: [], infobar: false, toolbar: false, afterShow: function(instance, current) { currentFancyboxInstance = instance; controlIframeElement('fancybox-max', 'show'); controlIframeElement('fancybox-close', 'show'); console.log("✅ Iframe cloaded - ISaved instance"); }, afterClose: function(instance, current) { currentFancyboxInstance = null; console.log('✅ UClosed'); } }); } } });