UNPKG

liftie

Version:

Clean, simple, easy to read, fast ski resort lift status

42 lines (41 loc) 1.4 kB
(() => { // lib/embed/index.js function el(attrs) { const attrStr = Object.keys(attrs).map((attr) => `${attr}="${attrs[attr]}"`).join(" "); return ["<iframe ", attrStr, "></iframe>"].join(""); } function addWidget(parent, resort, style) { const query = style ? `?style=${encodeURIComponent(style)}` : ""; let html = el({ class: `lift-status ${resort}`, src: `https://liftie.info/widget/resort/${resort}${query}`, scrolling: "no" }); html += '<p class="liftie-link">Lift status by <a href="https://liftie.info" target="_blank">Liftie</a></p>'; parent.insertAdjacentHTML("afterBegin", html); } function receiveMessage(event) { if (!/^https?:\/\/liftie.info$/.test(event.origin)) { return; } if (!event.data.height) { return; } const iframe = document.querySelector(`.liftie-widget[data-resort="${event.data.resort}"] iframe`); if (iframe) { iframe.style.height = `${event.data.height}px`; } } function embed() { let i; const els = document.querySelectorAll(".liftie-widget[data-resort]"); if (els.length) { window.addEventListener("message", receiveMessage, false); } for (i = 0; i < els.length; i++) { addWidget(els[i], els[i].getAttribute("data-resort"), els[i].getAttribute("data-style")); } } embed(); })(); //# sourceMappingURL=liftie-embed.js.map