var EcommScripts = (function () { var defines = {}; var entry = [null]; function define(name, dependencies, factory) { defines[name] = { dependencies: dependencies, factory: factory }; entry[0] = name; } define("require", ["exports"], function (exports) { Object.defineProperty(exports, "__cjsModule", { value: true }); Object.defineProperty(exports, "default", { value: function (name) { return resolve(name); } }); }); define("buybox-modal", ["require", "exports"], function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BuyboxModal = void 0; var BuyboxModal = /** @class */ (function () { function BuyboxModal(modalID) { var _this = this; this.shiftKeyPressed = false; this.open = function () { document.documentElement.style.overflow = "hidden"; document.documentElement.style.height = "auto"; document.body.style.overflow = "hidden"; document.body.style.height = "100%"; _this.domEl.style.display = "flex"; siblings(_this.domEl).map(function (el) { return el.setAttribute("aria-hidden", "true"); }); _this.addKeyboardSupportCloseModal(); _this.addKeyboardSupportShiftDown(); _this.addKeyboardSupportShiftUp(); _this.addFocusTrap(); _this.focusFirst(); }; this.close = function () { document.documentElement.style.removeProperty("overflow"); document.documentElement.style.removeProperty("height"); document.body.style.removeProperty("overflow"); document.body.style.removeProperty("height"); _this.domEl.style.display = "none"; siblings(_this.domEl).map(function (el) { return el.removeAttribute("aria-hidden"); }); _this.removeKeyboardSupportCloseModal(); _this.removeKeyboardSupportShiftDown(); _this.removeKeyboardSupportShiftUp(); _this.removeFocusTrap(); _this.domEl.dispatchEvent(new Event("close")); }; this.trapFocus = function (event) { /* istanbul ignore next */ // as it's not possible to simulate with `user-event` atm if ((event.target instanceof HTMLElement) && !_this.domEl.contains(event.target)) { _this.focusNext(); } }; this.focusNext = function () { if (_this.shiftKeyPressed) { _this.focusLast(); } else { _this.focusFirst(); } }; this.focusFirst = function () { var focusable = _this.domEl.querySelectorAll(focusableElements); var firstFocusable = focusable[1]; if (firstFocusable instanceof HTMLElement) firstFocusable.focus(); }; this.focusLast = function () { var focusable = _this.domEl.querySelectorAll(focusableElements); var lastFocusable = focusable[focusable.length - 2]; if (lastFocusable instanceof HTMLElement) lastFocusable.focus(); }; this.updateShiftKeyDown = function (event) { if ((event instanceof KeyboardEvent) && contains("shift")(event.key.toLowerCase())) _this.shiftKeyPressed = true; }; this.updateShiftKeyUp = function (event) { if ((event instanceof KeyboardEvent) && contains("shift")(event.key.toLowerCase())) _this.shiftKeyPressed = false; }; this.closeModalViaESC = function (event) { if ((event instanceof KeyboardEvent) && contains("escape")(event.key.toLowerCase())) _this.close(); }; this.addFocusTrap = function () { document.addEventListener("focus", _this.trapFocus, true); }; this.removeFocusTrap = function () { document.removeEventListener("focus", _this.trapFocus, true); }; this.addKeyboardSupportShiftDown = function () { document.addEventListener("keydown", _this.updateShiftKeyDown, true); }; this.removeKeyboardSupportShiftDown = function () { document.removeEventListener("keydown", _this.updateShiftKeyDown, true); }; this.addKeyboardSupportShiftUp = function () { document.addEventListener("keyup", _this.updateShiftKeyUp, true); }; this.removeKeyboardSupportShiftUp = function () { document.removeEventListener("keyup", _this.updateShiftKeyUp, true); }; this.addKeyboardSupportCloseModal = function () { document.addEventListener("keyup", _this.closeModalViaESC, true); }; this.removeKeyboardSupportCloseModal = function () { document.removeEventListener("keyup", _this.closeModalViaESC, true); }; this.modalID = modalID; var modal = document.createElement("div"); var modalBody = document.createElement("div"); modalBody.setAttribute("style", "\n width: 500px;\n box-shadow: 0 4px 24px rgb(0 0 0 / 10%), 0px 6px 4px rgb(0 0 0 / 8%);\n "); modalBody.setAttribute("role", "alertdialog"); // modalBody.setAttribute("aria-modal", "true") // browsers and assistive tech currently lacking support this.modalLabelID = modalID + "_label"; modalBody.setAttribute("aria-labelledby", this.modalLabelID); modal.setAttribute("id", modalID); modal.setAttribute("style", "\n display: none;\n position: fixed;\n z-index: 9999;\n left: 0;\n top: 0;\n right: 0;\n bottom: 0;\n background-color: rgba(0,0,0,0.3);\n align-items: center;\n justify-content: center;\n "); modal.appendChild(modalBody); var focusGuardStart = document.createElement("div"); focusGuardStart.tabIndex = 0; modal.insertBefore(focusGuardStart, modalBody); focusGuardStart.addEventListener("focus", function () { _this.focusNext(); }, false); var focusGuardEnd = document.createElement("div"); focusGuardEnd.tabIndex = 0; modal.insertBefore(focusGuardEnd, modalBody.nextSibling); focusGuardEnd.addEventListener("focus", function () { _this.focusNext(); }, false); modal.addEventListener("click", function (event) { if (event.target === modal) { _this.close(); } }, false); this.domEl = modal; this.modalBodyEl = modalBody; } return BuyboxModal; }()); exports.BuyboxModal = BuyboxModal; var siblings = function (el) { if (!el.parentElement) throw Error("Element does not have a parent"); return Array.from(el.parentElement.children).filter(function (c) { return c != el; }); }; var contains = function (p) { return function (s) { return s.indexOf(p) !== -1; }; }; var focusableElements = "button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])"; }); define("buybox", ["require", "exports", "buybox-modal"], function (require, exports, buybox_modal_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Buybox = exports.Modal = void 0; exports.Modal = buybox_modal_1.BuyboxModal; var Buybox; (function (Buybox) { Buybox.interceptFormSubmit = function (task, onAddToCartSuccess, onAddToCartFailure) { return function (event) { var form = event.target; if (!(form instanceof HTMLFormElement)) throw Error("Not a form element"); var url = form.getAttribute("action") || "/"; event.preventDefault(); return task(url, form) .then(onAddToCartSuccess) .catch(onAddToCartFailure); }; }; Buybox.fetchFormAction = function (fetch) { return function (url, form) { return fetch(url, { method: "post", credentials: "include", body: Buybox.urlSearchParamsReimplementation(form) }).then(function (res) { return res.text(); }); }; }; Buybox.triggerModalAfterAddToCartSuccess = function (modal) { return function (responseBody) { Buybox.augmentModalBody(modal, responseBody); modal.open(); }; }; Buybox.augmentModalBody = function (modal, responseBody) { var modalBody = modal.modalBodyEl; var modalMessage = responseBody.split("")[1] || responseBody; // dangerously set innerHTML; `body` considered safe, no user input modalBody.innerHTML = modalMessage; var modalTitle = modalBody.querySelector(".message-title"); var modalCloseLink = modalBody.querySelector(".close-modal"); if ((modalTitle instanceof HTMLParagraphElement) && (modalCloseLink instanceof HTMLAnchorElement)) { modalTitle.setAttribute("id", modal.modalLabelID); modalCloseLink.addEventListener("click", function (event) { event.preventDefault(); modal.close(); }); } }; Buybox.urlSearchParamsReimplementation = function (form) { /** * Reimplementing the wheel here to compile the `requestBody` to retain * IE11 compatibility (accessibility, JAWS) for as long as possible. * * - only polyfill dependency: `Array.from` * - form data only consists of simple text input fields * * the preferred 2021 way would be: * `const requestBody = new URLSearchParams([...(new FormData(form))])` */ var formData = Array.from(form.elements).reduce(function (acc, el) { if (!(el instanceof HTMLInputElement)) return acc; return acc.concat([[el.name, el.value]]); }, []); var requestBody = formData.map(function (record) { return [encodeURIComponent(record[0]), encodeURIComponent(record[1])].join("="); }).join("&"); return requestBody; }; })(Buybox = exports.Buybox || (exports.Buybox = {})); }); 'marker:resolver'; function get_define(name) { if (defines[name]) { return defines[name]; } else if (defines[name + '/index']) { return defines[name + '/index']; } else { var dependencies = ['exports']; var factory = function (exports) { try { Object.defineProperty(exports, "__cjsModule", { value: true }); Object.defineProperty(exports, "default", { value: require(name) }); } catch (_a) { throw Error(['module "', name, '" not found.'].join('')); } }; return { dependencies: dependencies, factory: factory }; } } var instances = {}; function resolve(name) { if (instances[name]) { return instances[name]; } if (name === 'exports') { return {}; } var define = get_define(name); if (typeof define.factory !== 'function') { return define.factory; } instances[name] = {}; var dependencies = define.dependencies.map(function (name) { return resolve(name); }); define.factory.apply(define, dependencies); var exports = dependencies[define.dependencies.indexOf('exports')]; instances[name] = (exports['__cjsModule']) ? exports.default : exports; return instances[name]; } if (entry[0] !== null) { return resolve(entry[0]); } })();