/* * Runs inside storefront pages when they are framed by embed.js. * Reports content height and the current path to the parent page. */ (function () { 'use strict'; if (window.self === window.top) return; // The theme pins html/body and a few wrappers to 100% height. Inside an auto-sized frame that // makes content height circular (the page is always exactly as tall as the frame), so undo it. var css = document.createElement('style'); css.id = 'rq-embed-css'; css.textContent = 'html,body,.container,#sidebar,#rightcontent,.side-nav{height:auto!important;min-height:0!important}'; document.head.appendChild(css); // Messages carry only height and path, and the parent checks source and origin, so '*' is safe here. function post(msg) { window.parent.postMessage(msg, '*'); } function measure() { var h = document.documentElement.getBoundingClientRect().height; var body = document.body; if (body) h = Math.max(h, body.getBoundingClientRect().bottom + window.scrollY); return Math.ceil(h); } var last = 0; var queued = false; function sendHeight() { queued = false; var h = measure(); if (h > 0 && h !== last) { last = h; post({ rq: 'height', frameHeight: h }); } } function schedule() { if (queued) return; queued = true; requestAnimationFrame(sendHeight); } var pathSent = false; function sendPath() { if (pathSent) return; pathSent = true; post({ rq: 'path', path: location.pathname + location.search }); } if (window.ResizeObserver) { var ro = new ResizeObserver(schedule); ro.observe(document.documentElement); if (document.body) ro.observe(document.body); } if (window.MutationObserver && document.body) { new MutationObserver(schedule).observe(document.body, { childList: true, subtree: true }); } window.addEventListener('load', schedule); window.addEventListener('resize', schedule); document.addEventListener('load', schedule, true); document.addEventListener('DOMContentLoaded', function () { sendPath(); schedule(); }); if (document.readyState !== 'loading') { sendPath(); schedule(); } })();