1 line
1.5 KiB
JavaScript
1 line
1.5 KiB
JavaScript
!function(e){var t={loading:!1,init:function(){var t=e("a[data-embed-checkout]");if(t.length){var o=this;e(document).on("click","a[data-embed-checkout]",function(t){t.preventDefault(),o.modal.open(e(this))})}},modal:{open:function(t){this.$target=t,(!this.product_url||this.product_url&&this.product_url!=t.data("embed-checkout"))&&(this.product_url=t.data("embed-checkout"),this.setup()),this.show_checkout(),e("body").addClass("udp-modal-is-opened"),this.$el.removeClass("iframe-is-opened"),this.$el.appendTo("body").show(),window.scrollTo(0,0)},setup:function(){this.$el&&(this.$el.remove(),this.$el=null);var t=e("#udp-modal-template").html();this.$el=e(t),window.addEventListener("message",function(t){var o=t.data;if(o&&o.action)switch(o.action){case"domready":this.$el.removeClass("loading");break;case"closemodal":e(document).trigger("udp/checkout/close",o.data,this.$target),this.close();break;case"ordercomplete":console.log("Order complete:",o.data),e(document).trigger("udp/checkout/done",o.data,this.$target)}}.bind(this))},close:function(t){t&&t.preventDefault(),e("body").removeClass("udp-modal-is-opened"),this.$iframe&&(this.$iframe.remove(),this.$iframe_container.remove()),this.$el.hide()},show_checkout:function(){this.$el.addClass("loading iframe-is-opened"),this.$iframe=e('<iframe src="'+this.product_url+'"/>'),this.$iframe_container=e('<div class="udp-modal__iframe"/>').appendTo(this.$el.find(".udp-modal__modal")).append(this.$iframe)}}};e(document).ready(function(e){t.init()})}(jQuery); |