/******/ (() => { // webpackBootstrap /*!******************************************************************************!*\ !*** ./resources/js/templates/rebel-forms/riq-embedded-form-show-listing.js ***! \******************************************************************************/ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var RiQEmbeddedForm = /*#__PURE__*/function () { function RiQEmbeddedForm() { var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, _ref$selector = _ref.selector, selector = _ref$selector === void 0 ? 'a[data-action="embedded-form"]' : _ref$selector, _ref$enableCSS = _ref.enableCSS, enableCSS = _ref$enableCSS === void 0 ? true : _ref$enableCSS, _ref$debug = _ref.debug, debug = _ref$debug === void 0 ? false : _ref$debug, _ref$riqReferralSourc = _ref.riqReferralSource, riqReferralSource = _ref$riqReferralSourc === void 0 ? window.location.href : _ref$riqReferralSourc, _ref$singlePropertyWe = _ref.singlePropertyWebsitesId, singlePropertyWebsitesId = _ref$singlePropertyWe === void 0 ? null : _ref$singlePropertyWe; _classCallCheck(this, RiQEmbeddedForm); this.selector = selector; this.enableCSS = enableCSS; this.debug = debug; this.modalId = "riq-forms-modal"; this.modal = null; this.iframe = null; this.modalClose = null; this.riqReferralSource = riqReferralSource; this.singlePropertyWebsitesId = singlePropertyWebsitesId; this.init(); } // Function to log debug messages return _createClass(RiQEmbeddedForm, [{ key: "logger", value: function logger(message) { if (this.debug) console.log("[RiQEmbeddedForm] ".concat(message)); } // Function to inject CSS dynamically }, { key: "injectCSS", value: function injectCSS() { if (!this.enableCSS) { this.logger("CSS injection disabled."); return; } if (!document.getElementById("riq-embedded-form-modal-style")) { this.logger("Injecting CSS..."); var style = document.createElement("style"); style.id = "riq-embedded-form-modal-style"; style.textContent = "\n body.riq-modal-open {\n overflow: hidden;\n height: 100vh;\n width: 100vw;\n transition: background 0.8s ease-in-out;\n }\n\n body.riq-modal-open > *:not(.overlay-modal) {\n opacity: 0;\n visibility: hidden;\n transition: opacity 0.8s ease-in-out, visibility 0.8s ease-in-out;\n }\n\n body.riq-modal-open .overlay-modal {\n opacity: 1;\n visibility: visible;\n }\n\n .close.hidden {\n visibility: hidden !important;\n }\n\n #".concat(this.modalId, " iframe {\n display: none;\n }\n\n #").concat(this.modalId, " iframe.is-active {\n display: block;\n }\n\n .overlay-modal {\n display: none;\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 1);\n backdrop-filter: blur(15px);\n justify-content: center;\n align-items: center;\n z-index: 99999999999 !important;\n animation: fadeIn 1s;\n }\n\n .overlay-modal-content {\n position: relative;\n width: 100%;\n height: 100%;\n display: flex;\n justify-content: center;\n align-items: center;\n overflow: hidden;\n }\n\n iframe {\n width: 100%;\n height: 100%;\n border: none;\n background: white;\n }\n\n .overlay-modal-close {\n position: absolute;\n top: 30px;\n right: 50px;\n font-size: 24px;\n line-height: 38px;\n width: 40px;\n height: 40px;\n text-align: center;\n font-weight: 100;\n color: #fff;\n background: #0e0e0efc;\n border-radius: 500px;\n cursor: pointer;\n opacity: 1 !important;\n }\n\n @media (max-width: 480px) {\n .overlay-modal-close {\n top: 7px;\n right: 7px;\n }\n }\n\n .overlay-modal-close:hover {\n color: #fff !important;\n }\n "); document.head.appendChild(style); } } // Function to append modal if it doesn't exist }, { key: "appendModal", value: function appendModal() { this.modal = document.getElementById(this.modalId); if (this.modal) { this.logger("Modal already exists, skipping creation."); return; } this.logger("Appending modal to body..."); document.body.insertAdjacentHTML("beforeend", "\n
\n ")); this.modal = document.getElementById(this.modalId); this.iframe = null; this.modalClose = this.modal.querySelector(".overlay-modal-close"); this.attachEventListeners(); } // Function to create a new iframe }, { key: "createIframe", value: function createIframe(src) { this.logger("Creating iframe for: ".concat(src)); var iframe = document.createElement("iframe"); iframe.src = src; iframe.setAttribute("frameborder", 0); this.modal.querySelector(".overlay-modal-content").appendChild(iframe); return iframe; } // Function to open modal }, { key: "openModal", value: function openModal(url) { var _this = this; this.logger("Opening modal with URL: ".concat(url)); // Check if iframe exists or create a new one var iframe = this.modal.querySelector("iframe[src=\"".concat(url, "\"]")); if (!iframe) { iframe = this.createIframe(url); } iframe.classList.add("is-active"); this.modal.style.display = "flex"; document.body.classList.add("riq-modal-open"); setTimeout(function () { _this.modal.style.opacity = "1"; _this.modal.style.visibility = "visible"; // Send message to iframe once it's visible _this.sendMessageToIframe(iframe); // Add a console log specifically for tracking modal open with postMessage console.log("%c[RiQEmbeddedForm] Modal opened and postMessage sent", "background: #FF9800; color: white; padding: 2px 5px; border-radius: 3px;", { url: url, riqReferralSource: _this.riqReferralSource, singlePropertyWebsitesId: _this.singlePropertyWebsitesId }); }, 10); } // Function to send message to iframe using postMessage }, { key: "sendMessageToIframe", value: function sendMessageToIframe(iframe) { var _this2 = this; if (!iframe || !iframe.contentWindow) { this.logger("Cannot send message: no valid iframe found"); console.warn("[RiQEmbeddedForm] Cannot send postMessage: no valid iframe found"); return; } var message = { riqReferralSource: this.riqReferralSource, singlePropertyWebsitesId: this.singlePropertyWebsitesId }; // Function to actually send the message var sendMessage = function sendMessage() { _this2.logger("Sending postMessage to iframe: ".concat(JSON.stringify(message))); console.log("%c[RiQEmbeddedForm] SENDING POSTMESSAGE", "background: #4CAF50; color: white; padding: 2px 5px; border-radius: 3px;", { iframe: iframe.src, message: message }); // Send the actual postMessage iframe.contentWindow.postMessage(message, "*"); }; // If iframe is already loaded, send message immediately if (iframe.contentDocument && iframe.contentDocument.readyState === 'complete') { sendMessage(); } // Send message when iframe loads regardless of current state // This ensures the message is sent even if the load event hasn't fired yet iframe.onload = sendMessage; // Additionally, try sending the message after a short delay // This catches cases where the iframe might be in a state between loading and complete setTimeout(function () { if (iframe.contentWindow) { sendMessage(); } }, 500); } // Function to close modal }, { key: "closeModal", value: function closeModal() { var _this3 = this; this.logger("Closing modal with forced redraw..."); // Force browser to recognize the style change this.modal.style.display = "flex"; // Force a reflow/repaint void this.modal.offsetWidth; // Now apply the closing styles this.modal.style.opacity = "0"; this.modal.style.visibility = "hidden"; // Add a class that can be targeted by CSS this.modal.classList.add("closing"); document.body.classList.add("modal-closing"); setTimeout(function () { document.body.classList.remove("riq-modal-open"); document.body.classList.remove("modal-closing"); var activeIframe = _this3.modal.querySelector("iframe.is-active"); if (activeIframe) activeIframe.classList.remove("is-active"); _this3.modal.style.display = "none"; _this3.modal.classList.remove("closing"); // Dispatch a custom event that we can listen for var event = new CustomEvent('modalClosed'); document.dispatchEvent(event); }, 800); } // Attach event listeners // Attach event listeners }, { key: "attachEventListeners", value: function attachEventListeners() { this.logger("Attaching enhanced event listeners for dev tools compatibility..."); // Store a reference to the instance for use in event handlers var self = this; document.querySelectorAll(this.selector).forEach(function (alink) { alink.addEventListener("mouseover", function () { if (this.href && !self.modal.querySelector("iframe[src=\"".concat(this.href, "\"]"))) { self.logger("Preloading iframe for: ".concat(this.href)); self.createIframe(this.href); } }); alink.addEventListener("click", function (e) { e.preventDefault(); self.openModal(this.href); }); }); // Create a global click handler for the close button // This works better with dev tools emulation var closeHandler = function closeHandler(e) { // Check if click was on close button or its children if (e.target === self.modalClose || self.modalClose.contains(e.target)) { e.preventDefault(); e.stopPropagation(); self.logger("Close button clicked (global handler)"); // Call showParentClose() function if (typeof window.showParentClose === 'function') { window.showParentClose(); } self.closeModal(); return false; } }; // Add the global handler to document document.addEventListener("click", closeHandler, true); document.addEventListener("touchend", closeHandler, true); document.addEventListener("mouseup", closeHandler, true); // Also add direct handlers for maximum compatibility this.modalClose.onclick = function (e) { e.preventDefault(); e.stopPropagation(); self.logger("Close button direct onclick"); if (typeof window.showParentClose === 'function') { window.showParentClose(); } self.closeModal(); return false; }; // Try setting the button role for accessibility and dev tools this.modalClose.setAttribute("role", "button"); this.modalClose.setAttribute("tabindex", "0"); this.modalClose.setAttribute("aria-label", "Close modal"); // Make the close button more prominent in dev tools this.modalClose.style.zIndex = "999999999999"; this.modalClose.style.touchAction = "manipulation"; this.modalClose.style.cursor = "pointer"; // Add an additional close option: clicking outside content closes modal this.modal.addEventListener("click", function (e) { // Only close if clicking the backdrop, not the content if (e.target === this) { self.logger("Modal background clicked"); self.closeModal(); } }); // Close modal on Escape key press document.addEventListener("keydown", function (event) { if (event.key === "Escape" || event.code === "Escape") { self.closeModal(); } }); // Listen for messages from iframe window.addEventListener("message", function (event) { var iframes = Array.from(self.modal.querySelectorAll("iframe")); if (iframes.some(function (iframe) { return iframe.contentWindow === event.source; })) { self.logger("Received message from iframe: ".concat(JSON.stringify(event.data))); if (event.data.action === "closeModal") { self.closeModal(); } } }); // Add a backup close method that dev tools can access window.closeRiqModal = function () { self.logger("Modal closed via global window method"); self.closeModal(); }; // this.logger("Attaching event listeners..."); // // document.querySelectorAll(this.selector).forEach((alink) => { // // Preload iframe on mouseover // alink.addEventListener("mouseover", () => { // if (alink.href && !this.modal.querySelector(`iframe[src="${alink.href}"]`)) { // this.logger(`Preloading iframe for: ${alink.href}`); // this.createIframe(alink.href); // } // }); // // // Open modal on click // alink.addEventListener("click", (e) => { // e.preventDefault(); // this.openModal(alink.href); // }); // }); // // // Close modal on button click // // this.modalClose.addEventListener("click", () => this.closeModal()); // // // Enhanced close button event handling for both desktop and mobile // const closeButton = this.modalClose; // // // Add multiple event types for better cross-device compatibility // ['click', 'touchend'].forEach(eventType => { // closeButton.addEventListener(eventType, (e) => { // e.preventDefault(); // e.stopPropagation(); // Prevent event bubbling // this.logger(`Modal close triggered via ${eventType}`); // this.closeModal(); // }); // }); // // // Make sure the close button is clearly visible and accessible on mobile // closeButton.style.zIndex = "999999999999"; // closeButton.style.touchAction = "manipulation"; // Optimize for touch // // // Close modal on Escape key press // document.addEventListener("keydown", (event) => { // if (event.key === "Escape" || event.code === "Escape") { // this.closeModal(); // } // }); // // // Listen for messages from iframe // window.addEventListener("message", (event) => { // // Check if message is from our iframe // const iframes = Array.from(this.modal.querySelectorAll("iframe")); // if (iframes.some(iframe => iframe.contentWindow === event.source)) { // this.logger(`Received message from iframe: ${JSON.stringify(event.data)}`); // // Handle message from iframe if needed // if (event.data.action === "closeModal") { // this.closeModal(); // } // } // }); } // Function to preload iframes in the background }, { key: "preloadIframes", value: function preloadIframes() { this.logger("Preloading iframes..."); var links = Array.from(document.querySelectorAll(this.selector)).map(function (alink) { return alink.href; }); this.loadIframesSequentially(links); } // Function to load iframes sequentially }, { key: "loadIframesSequentially", value: function loadIframesSequentially(links) { var _this4 = this; var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; if (index < links.length) { if (!this.modal.querySelector("iframe[src=\"".concat(links[index], "\"]"))) { this.logger("Preloading iframe (".concat(index + 1, "/").concat(links.length, "): ").concat(links[index])); var iframe = this.createIframe(links[index]); iframe.onload = function () { // We don't send postMessage on preload anymore - only when opened // This prevents duplicate messages _this4.loadIframesSequentially(links, index + 1); }; } else { this.loadIframesSequentially(links, index + 1); } } } // Initialize plugin }, { key: "init", value: function init() { var _this5 = this; this.logger("Initializing RiQEmbeddedForm..."); this.injectCSS(); // Inject CSS if enabled this.appendModal(); // Append modal if not manually added if (document.readyState === "complete") { this.logger("Document already loaded, preloading iframes..."); this.preloadIframes(); } else { document.addEventListener("readystatechange", function () { if (document.readyState === "interactive") { setTimeout(function () { _this5.logger("Document interactive, delaying iframe preload..."); _this5.preloadIframes(); }, 5000); } }); } } }]); }(); window.RiQEmbeddedForm = RiQEmbeddedForm; function showParentClose() { console.log('showParentClose() called globally'); window.parent.postMessage({ action: 'showCloseButton' }, '*'); console.log('Sent showCloseButton message'); } // Also assign to window object for extra compatibility window.showParentClose = showParentClose; document.addEventListener("DOMContentLoaded", function () { function initializeRiQEmbeddedForm() { if (typeof RiQEmbeddedForm !== "undefined") { var _document$querySelect, _document$querySelect2; // Get the values from the window object or data attributes if they exist var clientSinglePropertyWebsitesId = window.clientSinglePropertyWebsitesId || ((_document$querySelect = document.querySelector('meta[name="client-spw-show-listings-websites-id"]')) === null || _document$querySelect === void 0 ? void 0 : _document$querySelect.content) || null; var referralSource = window.clientSinglePropertyWebsitesDomainName || ((_document$querySelect2 = document.querySelector('meta[name="client-spw-show-listings-websites-domain-name"]')) === null || _document$querySelect2 === void 0 ? void 0 : _document$querySelect2.content) || window.location.href; // Initialize with the values and make instance globally accessible for debugging window.riqEmbeddedFormInstance = new RiQEmbeddedForm({ debug: true, singlePropertyWebsitesId: clientSinglePropertyWebsitesId, riqReferralSource: referralSource }); console.log("%c[RiQEmbeddedForm] Initialized and accessible via window.riqEmbeddedFormInstance", "background: #2196F3; color: white; padding: 2px 5px; border-radius: 3px;", { singlePropertyWebsitesId: clientSinglePropertyWebsitesId, riqReferralSource: referralSource }); // Add debug method for manual testing window.sendTestMessage = function () { var customMessage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var activeIframe = window.riqEmbeddedFormInstance.modal.querySelector("iframe.is-active"); if (!activeIframe || !activeIframe.contentWindow) { console.error("[RiQEmbeddedForm] No active iframe found to debug postMessage"); return "No active iframe found"; } var message = _objectSpread({ riqReferralSource: window.riqEmbeddedFormInstance.riqReferralSource, singlePropertyWebsitesId: window.riqEmbeddedFormInstance.singlePropertyWebsitesId, debug: true }, customMessage); console.log("%c[RiQEmbeddedForm] MANUAL TEST - SENDING POSTMESSAGE", "background: #FF5722; color: white; padding: 2px 5px; border-radius: 3px;", message); activeIframe.contentWindow.postMessage(message, "*"); return "Test message sent to iframe!"; }; console.log("%c[RiQEmbeddedForm] Debug function available via window.sendTestMessage()", "background: #9C27B0; color: white; padding: 2px 5px; border-radius: 3px;"); } else { console.error("RiQEmbeddedForm is not defined."); } } initializeRiQEmbeddedForm(); }); /******/ })() ;