!function(){"use strict";void 0===Element.prototype.getEventListeners&&(Element.prototype.__addEventListener=Element.prototype.addEventListener,Element.prototype.__removeEventListener=Element.prototype.removeEventListener,Element.prototype.addEventListener=function(e,t,n=!1){this.__addEventListener(e,t,n),this.eventListenerList||(this.eventListenerList={}),this.eventListenerList[e]||(this.eventListenerList[e]=[]),this.eventListenerList[e].push({type:e,listener:t,useCapture:n})},Element.prototype.removeEventListener=function(e,t,n=!1){this.__removeEventListener(e,t,n),this.eventListenerList||(this.eventListenerList={}),this.eventListenerList[e]||(this.eventListenerList[e]=[]);for(let o=0;o-1}))||""!==this.responseType&&"text"!==this.responseType||t(this.responseText)})),n.apply(this,arguments)}}(e,t),function(e,t){"undefined"!=typeof jQuery&&jQuery(document).ajaxSuccess((function(n,o,s){const i=s.url;e.some((function(e){return i.indexOf(e)>-1}))&&t(o.responseText)}))}(e,t),function(e,t){const n=window.fetch;window.fetch=function(){const e=n.apply(this,arguments);return e.then((function(e){const t=new CustomEvent("raleFetchEnd",{view:document,bubbles:!0,cancelable:!1,detail:{response:e.clone()}});document.dispatchEvent(t)})),e},document.addEventListener("raleFetchEnd",(function(n){const o=n.detail.response;if(200!==o.status)return;const s=o.url;e.some((function(e){return s.indexOf(e)>-1}))&&t(o.json())}))}(e,t)}function s(){const{selectors:t}=e;let n=!1;return document.querySelectorAll(t.checkbox).forEach((e=>{(function(e){const t=e.getBoundingClientRect(),n=window.innerWidth||document.documentElement.clientWidth,o=window.innerHeight||document.documentElement.clientHeight,s=function(e,t){return document.elementFromPoint(e,t)};return!(t.right<0||t.bottom<0||t.left>n||t.top>o)&&(e.contains(s(t.left,t.top))||e.contains(s(t.right,t.top))||e.contains(s(t.right,t.bottom))||e.contains(s(t.left,t.bottom))||e.parentNode.contains(s(t.left,t.top))||e.parentNode.contains(s(t.right,t.top))||e.parentNode.contains(s(t.right,t.bottom))||e.parentNode.contains(s(t.left,t.bottom)))})(e)&&(n=!0)})),n}function i(t){const{selectors:n}=e;let o=!1;if(s="/cart",window.location.href.indexOf(s)>-1){const e=t.closest("form");e&&e.querySelector(n.widget)&&(o=!0)}var s;return o}function r(t,n){const{classes:o,pointer:s}=e;if(n=n||window.event,void 0!==window.pageXOffset?(s.pageX=n.pageX-window.pageXOffset,s.pageY=n.pageY-window.pageYOffset):(s.pageX=n.pageX-document.documentElement.scrollLeft,s.pageY=n.pageY-document.documentElement.scrollTop),isNaN(s.pageX)||isNaN(s.pageY))s.target=t;else{const e=t.classList.contains(o.hidden);e&&t.classList.remove(o.hidden);const n=document.elementFromPoint(s.pageX,s.pageY);n&&(s.target=n),e&&t.classList.add(o.hidden)}}function l(t){const{id:n,classes:o,title:s,body:i,styles:r}=t;let l=document.getElementById(n);if(null!=l&&l.remove(),l=document.createElement("div"),l.id=n,l.classList="rale-modal",l.innerHTML=`
\n
${s}
\n
${i}
\n
`,o&&o.length>0&&l.classList.add(o),r&&Object.keys(r).length>0)for(const[e,t]of Object.entries(r))l.style.setProperty(e,t);return b(l),document.body.classList.add("rale-modal--opened"),document.body.appendChild(l),function(t){t.querySelectorAll(".rale-modal-close, .rale-modal-overlay").forEach((e=>{e.addEventListener("click",(e=>{a(e.currentTarget.closest(".rale-modal").getAttribute("id"))}))})),document.querySelectorAll(".rale-modal-button").forEach((t=>{t.addEventListener("click",(t=>{const n=t.currentTarget.closest(".rale-modal");n.classList.add("rale-modal--checked"),setTimeout((function(){const{pointer:{target:t}}=e;if(t)if("FORM"==t.tagName)t.submit();else try{t.click()}catch(e){const n=t.closest('[role="button"]');n&&n.click()}}),500),setTimeout((function(){a(n.getAttribute("id")),p()}),1e3)}))}))}(l),l}function a(e){const t=document.getElementById(e);if(null!=t&&t.remove(),0===document.querySelectorAll(".rale-modal").length){document.querySelector("body").classList.remove("rale-modal--opened")}}function c(t){const{selectors:n}=e;return!!t.closest(n.nopopup)}function d(t){const{classes:n,pointer:{target:o}}=e;let s=!0;if(t.classList.contains(n.hidden)&&(s=!1,o)){const e=o.getEventListeners("click"),t=o.closest("[class*=shopify-payment-button__]");(void 0!==e||t)&&(s=!0)}return s}function u(){const{settings:{param:t,popup:n,style:o}}=e,s=v();s.querySelector('input[type="checkbox"]').removeAttribute("checked");const i=s.querySelector(".rale-greeting");null!==i&&(i.classList.remove("rale-greeting--bottom"),i.classList.add("rale-greeting--top"));const r=n.title.length>0?n.title:"Terms and Conditions";let l=`${s.outerHTML}`;void 0!==t.force_enabled&&"1"===t.force_enabled?l+=`
${n.button.length>0?n.button:"Process to Checkout"}
`:l+=`
${t.error_message}
`;let a="",c={"--rale-size":`${o.message.size}px`,"--rale-popup-width":`${n.width}px`,"--rale-popup-icolor":n.icon_color},d="inherit";if("inherit"!==o.message.font){d=o.message.font.split(":")[0].replace(/\+/g," ")}return c["--rale-font"]=d,"1"===o.message.customized.enabled&&(a="rale-customized",c["--rale-color"]=o.message.customized.color,c["--rale-error"]=o.message.customized.error),{id:"rale-modal",classes:a,styles:c,title:r,body:l}}function p(){document.dispatchEvent(new CustomEvent("rale.shopifyCheckout"))}function m(t){const{selectors:n,settings:{param:o}}=e,a=t.currentTarget;if(function(t){const{settings:{param:n}}=e,o=t.closest("form");if(o&&0===o.querySelectorAll(".rale-time").length&&"0"!==n.time_enabled){const e=n.time_label.length>0?$(n.time_label):"Agreed to the Terms and Conditions on",t=document.createElement("input");t.type="hidden",t.name=`attributes[${e}]`,t.value=new Date,o.appendChild(t)}}(a),void 0!==o.force_enabled&&"1"===o.force_enabled){if(s()||i(a))p();else{if(r(a,t),!d(a))return!1;w(l(u())),t.preventDefault(),t.stopPropagation()}return!1}if(c(a))return p(),!1;if(function(){const{settings:{param:t}}=e;return(void 0===t.force_enabled||"1"!==t.force_enabled)&&void 0!==t.optional&&"1"===t.optional}())return o.optional_message_enabled&&"1"===o.optional_message_enabled&&o.optional_message_value.length>0&&alert(o.optional_message_value),p(),!1;if(r(a,t),s()||i(a))C()?(document.querySelectorAll(n.greeting).forEach((e=>{e.remove()})),p()):("dialog"===o.error_display?alert(o.error_message):(document.querySelectorAll(n.error).forEach((e=>{e.remove()})),document.querySelectorAll(n.widget).forEach((e=>{const t=document.createElement("div");t.classList="rale-error",t.innerHTML=o.error_message,"after"===o.error_display?e.appendChild(t):e.insertBefore(t,e.firstChild)}))),t.preventDefault(),t.stopPropagation());else{if(C())return!1;if(!d(a))return!1;w(l(u())),t.preventDefault(),t.stopPropagation()}}function g(){const{settings:t}=e;if("1"!==t.enabled)return!1;setTimeout((function(){!function(){const{classes:t,selectors:n}=e;document.querySelectorAll(n.checkout).forEach((e=>{C()||c(e)?e.classList.remove(t.invisible):e.classList.add(t.invisible)}))}(),function(){const{classes:t,selectors:n,settings:{param:o}}=e;"1"!==o.optional&&document.querySelectorAll(n.dynamic).forEach((e=>{("dynamic-checkout-cart"===e.dataset.shopify||"payment-button"===e.dataset.shopify)&&C()||c(e)?e.classList.remove(t.hidden):e.classList.add(t.hidden)}))}()}),100)}function h(){const{selectors:t,settings:n}=e;if("1"!==n.enabled)return!1;document.querySelectorAll(`${t.checkout}, ${t.dynamic}`).forEach((e=>{"a"===e.tagName.toLowerCase()&&(e.href.indexOf("/pages")>-1||e.href.indexOf("/blogs")>-1||e.href.indexOf("/collections")>-1||e.href.indexOf("/products")>-1)||(e.removeEventListener("click",m),e.addEventListener("click",m))})),document.querySelectorAll(t.form).forEach((e=>{e.removeEventListener("submit",m),e.addEventListener("submit",m)}))}function f(e){return("."+e.trim().replace(/ /g,".")).replace(/\.\.+/g,".").replace(/:+/g,"\\:")}function y(e){for(var t=[];e.parentNode;){var n=e.getAttribute("id"),o=e.tagName;if(n&&"BODY"!==o){t.unshift("#"+n);break}if(e===e.ownerDocument.documentElement||"BODY"===o)t.unshift(e.tagName);else{for(var s=1,i=e;i.previousElementSibling;i=i.previousElementSibling,s++);var r=e.className?f(e.className):"";r?t.unshift(""+e.tagName+r):t.unshift(""+e.tagName)}e=e.parentNode}return t.join(" ")}function v(t){const{fonts:n,settings:{param:o,style:s}}=e,i=`rale-${Date.now()+Math.random()}`,r=document.createElement("div");r.classList="rale-widget";let l="inherit";if("inherit"!==s.message.font){const e=s.message.font.split(":")[0];l=e.replace(/\+/g," "),n.includes(e)||(n.push(e),function(e,t){for(let t=0;t`}"1"===o.optional&&o.optional_message_enabled&&"1"===o.optional_message_enabled&&"1"===o.optional_checkbox_hidden&&r.classList.add("rale-widget--hidden");let c="";return!0===t&&(c='
'),r.innerHTML=`
${function(t){const{settings:{param:n,style:o}}=e;if(void 0!==n.force_enabled&&"1"===n.force_enabled)return``;{let e=`--rale-size:${o.checkbox.size}px;`,s="",i="",r="";if("0"!==n.checkbox&&(e+=`--rale-background:${o.checkbox.color};`,s=`${function(e){let t="";switch(e){case"1":t='';break;case"2":t='';break;case"3":t='';break;case"4":t='';break;case"5":t=''}return t}(n.checkbox)}`),void 0!==n.greeting&&"1"===n.greeting.enabled&&n.greeting.message.length>0){let e=parseInt(n.greeting.delay);e=e>0?e:0,r=`${n.greeting.message}`}return`${s}${r}`}}(i)+function(t){const{shop:n,editor:o,settings:{param:s}}=e,{message:i,links:r,link_order:l}=s;let a=i;return l&&l.forEach((function(e){const t=r[e];if(t){const{label:s,url:i,target:r,policy:l}=t,c=new RegExp(`{${e}}`,"g");if("popup"===r){let e=`/policies/${l}`;if(o.enabled&&(e=`https://${n}${e}`),s.length>0){let t=`${s}`;a=a.replace(c,t)}}else if(s.length>0){let e=s;i.length>0&&(e=`${s}`),a=a.replace(c,e)}}})),``}(i)+c}
${a}`,r}function b(t){const{settings:{param:n}}=e,o=t.querySelector(".rale-greeting");if(null!==o){let e=parseInt(n.greeting.delay);e=e>0?e:0,setTimeout((function(){o.classList.add("rale-greeting--open")}),1e3*e)}}function L(t,n,o=!1){const{selectors:s}=e,i=v(o);function r(e,t){const n=document.querySelector(e);if(null===n||n.parentNode.querySelector(s.widget)&&"append"!==t)return!1;switch(t){case"before":n.parentNode.insertBefore(i,n);break;case"after":n.parentNode.insertBefore(i,n.nextSibling);break;default:n.innerHTML="",n.appendChild(i)}b(i);const o=new CustomEvent("rale.widgetCreated",{detail:{selector:n}});return document.dispatchEvent(o),T(),w(i),!0}r(t,n)||setTimeout((function(){r(t,n)||setTimeout((function(){r(t,n)}),1e3)}),1e3)}function w(t){const{selectors:n}=e;t.querySelectorAll(n.checkbox).forEach((t=>{t.addEventListener("change",(t=>{const o=t.currentTarget,s=o.checked;if(document.querySelectorAll(n.checkbox).forEach((e=>{e.checked=s})),document.querySelectorAll(n.error).forEach((e=>{e.remove()})),document.querySelectorAll(n.greeting).forEach((e=>{e.classList.add("rale-greeting--close"),setTimeout((function(){e.remove()}),300)})),T(),g(),s&&o.closest(".rale-modal")){const t=o.closest(".rale-modal");t.classList.add("rale-modal--checked"),setTimeout((function(){const{pointer:{target:t}}=e;if(t)if("FORM"==t.tagName)t.submit();else{const e=t.closest('[role="button"]');if(e)e.click();else{const e=t.querySelector("button");e?e.click():t.click()}}}),500),setTimeout((function(){a(t.getAttribute("id")),p()}),1e3)}}))})),t.querySelectorAll(n.policy).forEach((t=>{t.addEventListener("click",(t=>{t.preventDefault();const{editor:n}=e,o=t.currentTarget,s=o.dataset.policy;l({id:"rale-modal--skeleton",classes:"rale-modal--skeleton",title:'
',body:'
'});let i=o.getAttribute("href");n.enabled&&(i=`${roarJsAdmin.Config.appUrl}/policies/${s}`),fetch(i).then((e=>e.text())).then((e=>{const t=(new DOMParser).parseFromString(e,"text/html");a("rale-modal--skeleton");let n="",o="";if(t.querySelector(".shopify-policy__body"))n=t.querySelector(".shopify-policy__title").textContent,o=t.querySelector(".shopify-policy__body").innerHTML;else{n={"refund-policy":"Refund policy","privacy-policy":"Privacy policy","terms-of-service":"Terms of service","shipping-policy":"Shipping policy"}[s],o='
\n

Unfortunately, your store policy has not been added yet!

\n
\n

Add or generate store policies

\n
    \n
  1. From your Shopify admin, go to Settings > Legal.

  2. \n
  3. \n

    Enter your store policies, or click Create from template to enter the default template. Use the rich text editor to add style and formatting to your policies, and to add links and images.

    \n
    The rich text editor consists of a multi-line text box with buttons above it for formatting the text, and for adding links and images.
    \n
  4. \n
  5. Review your policies and make any changes.

  6. \n
  7. Click Save to add your policies.

  8. \n
\n
\n
'}l({id:"rale-modal--policy",classes:"rale-modal--policy",title:n,body:o})})).catch((()=>{n.enabled?setTimeout((function(){a("rale-modal--skeleton"),l({id:"rale-modal--policy",classes:"rale-modal--policy",title:"That's all!",body:'
\n

In your real store, customers should see your store policies here.

\n
\n

Add or generate store policies

\n
    \n
  1. From your Shopify admin, go to Settings > Legal.

  2. \n
  3. \n

    Enter your store policies, or click Create from template to enter the default template. Use the rich text editor to add style and formatting to your policies, and to add links and images.

    \n
    The rich text editor consists of a multi-line text box with buttons above it for formatting the text, and for adding links and images.
    \n
  4. \n
  5. Review your policies and make any changes.

  6. \n
  7. Click Save to add your policies.

  8. \n
\n
\n
'})}),500):a("rale-modal--skeleton")}))}))}))}function k(){const{editor:t,installer:n,selectors:o,settings:s}=e;if("1"!==s.enabled)return document.querySelectorAll(o.widget).forEach((e=>{e.remove()})),!1;if(t.enabled)L(t.selector,"append");else if(n.enabled)L(n.selector,n.position,!0);else{let e={};if(Object.keys(s.installer).length>0&&(e=s.installer[Shopify.theme.id]),void 0!==e&&Object.keys(e).length>0){const{cart:t,minicart:n,product:o}=e;t&&t.selector.length>0&&t.position.length>0&&L(t.selector,t.position),n&&n.selector.length>0&&n.position.length>0&&L(n.selector,n.position),o&&o.selector.length>0&&o.position.length>0&&L(o.selector,o.position)}else{document.querySelectorAll(o.checkout).forEach((e=>{const t=e.closest("form");if(t&&0===t.querySelectorAll(o.widget).length){const t=e.parentNode;let n=e;t.querySelector(o.update)&&(n=t.querySelector(o.update)),L(y(n),"before")}}));const e=document.querySelector('#main-cart-footer [name="checkout"]');e&&L(y(e.parentNode),"before")}}document.querySelector(".rale-shortcode")&&L(".rale-shortcode","append")}function x(e){e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");const t=new RegExp("[\\?&]"+e+"=([^&#]*)").exec(window.location.search);return null===t?"":decodeURIComponent(t[1].replace(/\+/g," "))}function _(e){return new Promise((function(t,n){fetch("/cart.js").then((e=>e.json())).then((n=>{if(0==n.item_count){const n={items:[{quantity:1,id:e}]};fetch("/cart/add.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)}).then((e=>e.json())).then((e=>{t({reload:!0,url:e.items[0].url})}))}else t({reload:!1,url:n.items[0].url})}))}))}function E(){return e.installer.enabled=!0,t(),new Promise((function(t,n){!function(e,t){const n=document.getElementsByTagName("head")[0],o=document.createElement("script");o.type="text/javascript",o.readyState?o.onreadystatechange=function(){"loaded"!=o.readyState&&"complete"!=o.readyState||(o.onreadystatechange=null,t&&t())}:o.onload=function(){t&&t()},o.src=e,n.appendChild(o)}(e.installerUrl,(function(){t(!0)}))}))}function S(){window.location.href.indexOf("rale_helper=true")>-1&&(function(t){const{selectors:n}=e,{title:o,description:s}=t;let i=document.getElementById(n.modal);null!==i&&i.remove(),i=document.createElement("div"),i.id=n.modal,i.classList=n.modal,i.innerHTML=`
\n
\n

${o}

${s}

\n\n
`,document.body.classList.add("rale-modal--opened"),document.body.appendChild(i)}({title:"Click The Checkbox To Test The Function",description:'Open the product page and click the Add to cart button.
Go to the cart page. You will see the terms and conditions checkbox above the checkout button.

Then go back to app settings and click "Next".'}),function(){const{selectors:t}=e,n=document.getElementById(t.modal_close);null!==n&&n.addEventListener("click",(function(){const e=document.getElementById(t.modal);null!==e&&(e.remove(),document.body.classList.remove("rale-modal--opened"))}))}())}function C(){const{selectors:t}=e,n=document.querySelector(t.checkbox);return!!n&&n.checked}function T(t){if("undefined"==typeof roarJsAdmin){const{settings:{param:n}}=e,o=document.querySelector(".rale-time");if(null===o)return;void 0===t&&(t=void 0!==n.force_enabled&&"1"===n.force_enabled?o.value:void 0!==n.optional&&"1"===n.optional?C()?o.value:"NO":o.value);const s=o.getAttribute("name"),i={attributes:{[s.substring(s.lastIndexOf("[")+1,s.lastIndexOf("]"))]:t}};fetch("/cart/update.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)})}}function $(e){if(null===e||""===e)return"";e=e.toString();const t={"&":"&","<":"<",">":">",'"':""","'":"'"};return e.replace(/[&<>"']/g,(function(e){return t[e]}))}return{init:function(){S(),n()&&(e.editor.enabled||(function(){const e=x("rale_preview"),n=x("variant_id");e.length>0&&n.length>0&&(t(),_(n).then((function(e){e.reload&&window.location.reload()})))}(),function(){const e="raleInstaller";let t=window.sessionStorage.getItem(e);if(null!==t&&t.length>0)t=JSON.parse(t),void 0!==t.theme_id&&Shopify.theme.id!=t.theme_id&&(window.location.href=`${window.location.origin}?preview_theme_id=${t.theme_id}`),E();else{const t=x("ralei"),n=x("variant_id");t.length>0&&n.length>0&&(window.sessionStorage.setItem(e,JSON.stringify({access_token:t,step:1,theme_id:Shopify.theme.id,variant_id:n})),E())}}()),e.installer.enabled||(k(),h()),function(){const{classes:t,selectors:n}=e;if("1"!==e.settings.enabled)return!1;document.body.classList.remove(t.invisible),o(["/cart.js","/cart/add.js","/cart/change.js","/cart/change","/cart/clear.js"],(function(t){Promise.resolve(t).then((function(t){const{installer:n}=e;n.enabled||(k(),h(),g())}))}))}(),g())},refresh:function(){n()&&(k(),h(),g())},checked:C,manual:function(e){m(e)},install:function(t,o){n()&&(e.installer.selector=t,e.installer.position=o,k(),h())},initCart:_,updateTime:T,showMessage:function(){const{settings:{param:t},selectors:n}=e;C()||("dialog"===t.error_display?alert(t.error_message):(document.querySelectorAll(n.error).forEach((e=>{e.remove()})),document.querySelectorAll(n.widget).forEach((e=>{const n=document.createElement("div");n.classList="rale-error",n.innerHTML=t.error_message,"after"===t.error_display?e.appendChild(n):e.insertBefore(n,e.firstChild)}))))},bindCheckoutEvents:h}}(),roarJs.Legal.init();