function parse_query_string(query){for(var vars=query.split("&"),query_string={},i=0;i<vars.length;i++){var pair=vars[i].split("="),key=decodeURIComponent(pair.shift()),pair=decodeURIComponent(pair.join("="));void 0===query_string[key]?query_string[key]=pair:"string"==typeof query_string[key]?query_string[key]=[query_string[key],pair]:query_string[key].push(pair)}return query_string}void 0===window.WPBDP&&(window.WPBDP={}),void 0===window.wpbdp&&(window.wpbdp={}),jQuery(function($){$(".wpbdp-no-js").hide()}),jQuery(document).ready(function($){0<$(".wpbdp-js-select2").length&&$.fn.selectWoo&&($(".wpbdp-js-select2").selectWoo(),document.body.classList.add("wpbdp-has-select2"));var sticky=$(".wpbdp-listing-single .wpbdp-sticky-tag");sticky.length&&$("h1:first").append(sticky),wpbdp.main_box={init:function(){},sum_width:function($selector,prop){prop=void 0===prop?"width":prop;var sum=0;return $selector.each(function(){var w=0,w="initial"==prop?$(this).data("initial-width"):"outer"==prop?$(this).outerWidth():"inner"==prop?$(this).innerWidth():$(this).width();sum+=parseInt(w)}),sum},min_width:function(){return this.sum_width(this.$cols_fixed,"initial")},should_resize:function(){return this.$box.find("form").width()>this.min_width()},resize:function(){var available_width,flex_width;this.should_resize()&&(available_width=this.$box.find("form").innerWidth()-this.min_width(),flex_width=Math.floor(available_width/this.$cols_expanding.length)-2,this.$cols_expanding.each(function(){$(this).outerWidth(flex_width)}))}},0<$("#wpbdp-main-box").length&&wpbdp.main_box.init(),0==$(".wpbdp-bar").children().length&&""==$(".wpbdp-bar").text().trim()&&$(".wpbdp-bar").remove(),$(".wpbdp-listing-contact-form .send-message-button").on("click",function(){$(this).removeClass("wpbdp-show-on-mobile").hide(),$(".wpbdp-listing-contact-form .contact-form-wrapper").removeClass("wpbdp-hide-on-mobile")}),$(".wpbdp-listings-sort-options select").on("change",function(e){var selected=$(this).val();location.href=selected})}),jQuery(function($){({init:function(){var t=this;$(".wpbdp-form-field-type-date").each(function(i,v){t.configure_date_picker($(v).find("input"))}),$(window).on("wpbdp_submit_refresh",function(event,submit,section_id){"listing_fields"==section_id&&t.init()})},configure_date_picker:function($e){$e.datepicker({dateFormat:$e.attr("data-date-format"),defaultDate:$e.val(),beforeShow:function(){$("#ui-datepicker-div").addClass("wpbdp-datepicker")}})}}).init()}),WPBDP.fileUpload={resizeIFrame:function(element_id,height){var element_id=jQuery("#wpbdp-upload-iframe-"+element_id)[0],iframeWin=element_id.contentWindow||element_id.contentDocument.parentWindow;iframeWin.document.body&&(element_id.height=height||iframeWin.document.documentElement.scrollHeight||iframeWin.document.body.scrollHeight),0===jQuery(element_id).parents(".wpbdp-social-type-field").length||jQuery(element_id).parent().siblings(".wpbdp-inner-social-field-option-Other").find("input").is(":checked")||jQuery(element_id).parent().hide()},handleUpload:function(o){jQuery(o).parent("form").submit()},finishUpload:function(element_id,upload_id,element){element_id=jQuery("#wpbdp-upload-iframe-"+element_id),element=jQuery('input[name="'+element+'"]'),element.val(upload_id),upload_id=element.siblings(".preview");upload_id.find("img").remove(),upload_id.prepend(element_id.contents().find(".preview").html()),element_id.contents().find(".preview").remove(),element_id.hide(),upload_id.show()},deleteUpload:function(element_id,element){jQuery("#wpbdp-upload-iframe-"+element_id);element_id=jQuery('input[name="'+element+'"]'),element=element_id.siblings(".preview");return element_id.val(""),element.find("img").remove(),element.find("input").val(""),element.hide(),element.siblings().show(),!1}},($=>{var sb=wpbdp.listingSubmit={init:function(){0<$(".wpbdp-submit-listing-section-listing_images").length&&sb.images.init()},init_events:function(){$("#wpbdp-submit-listing").on("click",".wpbdp-inner-field-option-select_all",function(e){$(this).parent().find('input[type="checkbox"]').prop("checked",$(this).find("input").is(":checked"))}),$("#wpbdp-submit-listing").on("click",".wpbdp-inner-social-field-option input",function(e){var $icon_element=$(this).parents(".wpbdp-inner-social-field-option").siblings(".wpbdp-upload-widget");"Other"!==$(this).val()?$icon_element.hide():$icon_element.show()})}};sb.images=wpbdp.listingSubmit.images={_initialized:!1,_admin_nonce:"",_slots:0,_slotsRemaining:0,_working:!1,init:function(){this._initialized=!0,this._admin_nonce=$("#image-upload-dnd-area").attr("data-admin-nonce");var t=this;this._admin_nonce||(sb.images._slots=parseInt($("#image-slots-total").text()),sb.images._slotsRemaining=parseInt($("#image-slots-remaining").text())),$("#wpbdp-uploaded-images").on("click",".wpbdp-image-delete-link","click",function(e){e.preventDefault();e=$(this).attr("href");$.post(e,{},function(res){res.success&&$('#wpbdp-uploaded-images .wpbdp-image[data-imageid="'+res.data.imageId+'"]').fadeOut(function(){$(this).remove();var $no_count,n,thumbInput=$("#wpbdp-listing-fields-images input#_thumbnail_id");void 0!==thumbInput&&parseInt(thumbInput.val())===res.data.imageId&&thumbInput.val(""),t._admin_nonce||(t._slotsRemaining++,$("#image-slots-remaining").text(t._slotsRemaining),t._slotsRemaining<t._slots&&$("#image-upload-dnd-area").show()),(t._admin_nonce&&0==$("#wpbdp-uploaded-images .wpbdp-image").length||!t._admin_nonce&&t._slotsRemaining==t._slots)&&$("#current-images-header").show(),(t._admin_nonce||0<t._slotsRemaining)&&($("#image-upload-dnd-area .dnd-area-inside").show(),$("#noslots-message").hide(),$("#image-upload-dnd-area").removeClass("error"),$("#image-upload-dnd-area .dnd-area-inside-error").hide()),0<$("#wpbdp-listing-fields.postbox").length&&(thumbInput=$(".wpbdp-admin-tab-nav li a .with-image-count"),$no_count=$(".wpbdp-admin-tab-nav li a .no-image-count"),(n=$("#wpbdp-uploaded-images .wpbdp-image").length)?($no_count.addClass("hidden"),thumbInput.removeClass("hidden").find("span").text(n)):(thumbInput.addClass("hidden"),$no_count.removeClass("hidden")))})},"json")}),wpbdp.dnd.setup($("#image-upload-dnd-area"),{init:function(){t._admin_nonce||0<t._slotsRemaining||($("#image-upload-dnd-area .dnd-area-inside").hide(),$("#noslots-message").show(),$("#image-upload-dnd-area").addClass("error"),$("#image-upload-dnd-area .dnd-area-inside-error").show())},validate:function(data){return $(".image-upload-wrapper .error").remove(),t._admin_nonce||$(this).siblings(".wpbdp-msg").remove(),!0},done:function(res){var n,uploadErrors=!1;(uploadErrors=res.success?void 0!==res.data.uploadErrors&&res.data.uploadErrors:[res.error])?(uploadErrors=$("<div>").addClass("wpbdp-msg error").html(uploadErrors),$(uploadErrors).insertAfter($(".area-and-conditions")),$("#image-upload-dnd-area .dnd-area-inside").show()):($("#current-images-header").hide(),$("#wpbdp-uploaded-images").append(res.data.html),1==$("#wpbdp-uploaded-images .wpbdp-image").length&&$('#wpbdp-uploaded-images .wpbdp-image:first input[name="thumbnail_id"] ').attr("checked","checked"),t._admin_nonce||(t._slotsRemaining-=res.data.attachmentIds.length,$("#image-slots-remaining").text(t._slotsRemaining),0==t._slotsRemaining&&($("#image-upload-dnd-area .dnd-area-inside").hide(),$("#noslots-message").show(),$("#image-upload-dnd-area").addClass("error"),$("#image-upload-dnd-area .dnd-area-inside").hide(),$("#image-upload-dnd-area .dnd-area-inside-error").show())),0<$("#wpbdp-listing-fields.postbox").length&&(uploadErrors=$(".wpbdp-admin-tab-nav li a .with-image-count"),res=$(".wpbdp-admin-tab-nav li a .no-image-count"),(n=$("#wpbdp-uploaded-images .wpbdp-image").length)?(res.addClass("hidden"),uploadErrors.removeClass("hidden").find("span").text(n)):(uploadErrors.addClass("hidden"),res.removeClass("hidden"))))}}),$("input#wpbdp_media_manager").on("click",function(e){e.preventDefault();var url=$(this).attr("data-action"),image_frame=wp.media({title:"Select Media",multiple:!1,library:{type:"image"}});image_frame.on("close",function(){var selection=image_frame.state().get("selection"),gallery_ids=new Array,i=0,selection=(selection.each(function(attachment){gallery_ids[i]=attachment.id,i++}),gallery_ids.join(","));selection&&$.post(url,{image_ids:selection},function(res){var errorMsg;if(errors=res.success?void 0!==res.data.errors&&res.data.errors:[res.data.errors])errorMsg=$("<div>").addClass("wpbdp-msg error").html(errors),$(res.data.errorElement).prepend(errorMsg);else{if($(res.data.errorElement+" .wpbdp-msg.error").remove(),"listing_field"===res.data.source)return res.data.inputElement?((errorMsg=$('input[name="'+res.data.inputElement+'"]')).val(res.data.media_id),(errorMsg=errorMsg.siblings(".preview")).find("img").remove(),errorMsg.prepend(res.data.html),errorMsg.siblings().hide(),void errorMsg.show()):void 0;$("#current-images-header").hide(),$(res.data.previewElement).append(res.data.html)}})}),image_frame.open()}),$("#wpbdp-uploaded-images").sortable({axis:"y",cursor:"move",opacity:.9,update:function(ev,ui){var sorted=$(this).sortable("toArray",{attribute:"data-imageid"}),no_images=$(this).find(".wpbdp-image").length;$.each(sorted,function(i,v){$('input[name="images_meta['+v+'][order]"]').attr("value",no_images-i),0===i&&0<(i=$('input[name="_thumbnail_id"]')).length&&i.val(v)})}})}},$(document).ready(function(){0!=$("#wpbdp-submit-listing").length&&(sb.init_events(),0!=$(".wpbdp-submit-page").length)&&sb.init()})})(jQuery),($=>{$html=$("html"),$body=$("body"),$(".wpbdp-advanced-search-link").on("click",function(event){event.preventDefault(),0<($searchPage=$(".wpbdp-search-page.wpbdp-modal")).length?$html.toggleClass("wpbdp-has-modal"):($body.append('<div class="wpbdp-loader-wrapper"><span class="wpbdp-spinner"></span></div>'),(event=parse_query_string(location.search.substring(1))).action="wpbdp_ajax",event.handler="search__get_search_content",$.ajax(wpbdp_global.ajaxurl,{data:event,type:"POST",success:function(response){$(response.data).addClass("wpbdp-modal").appendTo($body);var data,showReset,response=document.getElementById("wpdbp-searched-terms");if(response){for(var key in data=response.getAttribute("data-search-terms"),data=JSON.parse(data))data.hasOwnProperty(key)&&0<$('[name="listingfields['+key+']"]').length&&(showReset=!0);showReset&&$(".wpbdp-modal .reset").show()}$html.addClass("wpbdp-has-modal"),$body.find(".wpbdp-loader-wrapper").remove()}}))}),$(document).on("click",".wpbdp-modal-close, .wpbdp-modal-overlay",function(){$html.removeClass("wpbdp-has-modal")}),$(document).on("click","#wpbdp-search-form .reset",function(e){e.preventDefault(),$('#wpbdp-search-form [name^="listingfields"][type!="radio"][type!="checkbox"]').val(""),$('#wpbdp-search-form [type="radio"]').attr("checked",!1),$('#wpbdp-search-form [type="checkbox"]').attr("checked",!1)})})(jQuery);
jQuery(function($){var wpbdp=window.wpbdp||{},$submit=(wpbdp.submit_listing=wpbdp.submit_listing||{},wpbdp.submit_listing.Fee_Selection_Helper=function($submit,editing){this.editing=!(void 0===editing||!editing),this.reset()},$.extend(wpbdp.submit_listing.Fee_Selection_Helper.prototype,{reset:function(){var self;this.field_wrapper=$(".wpbdp-submit-listing-section-plan_selection .wpbdp-form-field-association-category"),this.field_type="",this.plan_autoselect=!1,0<$(".wpbdp-js-select2",this.field_wrapper).length?this.field_type="select2":this.field_wrapper.hasClass("wpbdp-form-field-type-select")?this.field_type="select":this.field_wrapper.hasClass("wpbdp-form-field-type-checkbox")?this.field_type="checkbox":this.field_wrapper.hasClass("wpbdp-form-field-type-radio")&&(this.field_type="radio"),this.field=this.field_wrapper.find('select, input[type="checkbox"], input[type="radio"]'),this.field_type&&("select2"===this.field_type&&(this.field.find('option[disabled="disabled"]').data("keep_disabled",!0),self=this,setTimeout(function(){"select2"===this.field_type&&$.fn.selectWoo&&(self.field.selectWoo({placeholder:wpbdpSubmitListingL10n.categoriesPlaceholderTxt}),document.body.classList.add("wpbdp-has-select2"))})),this.editing||(this.skip_plan_selection=1===$('input[type="hidden"][name="skip_plan_selection"][value="1"]').length,this.skip_plan_selection)||(this.$plans_container=$(".wpbdp-plan-selection-wrapper"),this.$plan_selection=this.$plans_container.find(".wpbdp-plan-selection"),this.plans=this.$plan_selection.find(".wpbdp-plan"),this.$plan_selection.hide(),this.selected_categories=[],this.available_plans=this.plans.map(function(){return $(this).data("id")}).get(),this.field.change($.proxy(this.categories_changed,this)),this.maybe_limit_category_options(),this.field.first().trigger("change")))},categories_changed:function(){this.selected_categories=[],"select2"===this.field_type||"select"===this.field_type?this.selected_categories=this.field.val():"checkbox"===this.field_type?this.selected_categories=this.field.filter(":checked").map(function(){return $(this).val()}).get():"radio"===this.field_type&&(this.selected_categories=this.field.filter(":checked").val()),this.selected_categories||(this.selected_categories=[]),Array.isArray(this.selected_categories)||(this.selected_categories=[this.selected_categories]),this.selected_categories||(this.selected_categories=[]),this.selected_categories=$.map(this.selected_categories,function(x){return parseInt(x)}),this.update_plan_list(),this.update_plan_prices(),"checkbox"!==this.field_type&&!this.field.is("[multiple]")||this.maybe_limit_category_options(),0===this.selected_categories.length?this.plans.find('input[name="listing_plan"]').prop({disabled:0===this.selected_categories.length,checked:!1}):this.plans.find('input[name="listing_plan"]').prop("disabled",!1);var self=this;0<this.selected_categories.length?(this.$plans_container.show(),Reusables.Breakpoints.evaluate(),this.$plan_selection.fadeIn("fast")):this.$plans_container.fadeOut("fast",function(){self.$plan_selection.hide()}),1===this.available_plans.length&&this.plan_autoselect&&$("#wpbdp-plan-select-radio-"+this.available_plans[0]).trigger("click"),this.plan_autoselect||"checkbox"===this.field_type||$(this.field_wrapper).hasClass("wpbdp-form-field-type-multiselect")||(this.plan_autoselect=!0)},_enable_categories:function(categories){"none"!==categories&&"all"!==categories&&this._enable_categories("none"),"none"===categories||"all"===categories?"select2"===this.field_type?this.field.find("option").each(function(){!0!==$(this).data("keep_disabled")&&$(this).prop("disabled","all"!==categories)}):"all"===categories?this.field_wrapper.find(".wpbdp-form-field-checkbox-item, .wpbdp-form-field-radio-item").removeClass("disabled"):this.field_wrapper.find(".wpbdp-form-field-checkbox-item, .wpbdp-form-field-radio-item").addClass("disabled"):"select2"===this.field_type?this.field.find("option").each(function(i,v){!0!==$(this).data("keep_disabled")&&$(this).prop("disabled",-1===$.inArray(parseInt($(this).val()),categories))}):this.field.each(function(i,v){-1!==$.inArray(parseInt($(this).val()),categories)&&($(this).prop("disabled",!1),$(this).parents().filter(".wpbdp-form-field-checkbox-item, .wpbdp-form-field-radio-item").removeClass("disabled"))})},maybe_limit_category_options:function(){var all_cats=!1,cats=[],self=this;$.each(this.available_plans,function(i,v){all_cats||("all"===(v=self.plans.filter('[data-id="'+v+'"]').data("categories"))?all_cats=!0:(cats=$.unique(cats.concat(v.toString().split(","))),cats=$.map(cats,function(x){return parseInt(x)})))}),all_cats?this._enable_categories("all"):this._enable_categories(cats)},update_plan_list:function(){var self=this,plans=[];$.each(this.plans,function(i,v){var v=$(v),plan_cats=v.data("categories").toString(),plan_supports_selection=!0;"all"!==plan_cats&&self.selected_categories&&(plan_cats=$.map(plan_cats.split(","),function(x){return parseInt(x)}),$.each(self.selected_categories,function(j,c){plan_supports_selection&&-1===$.inArray(c,plan_cats)&&(plan_supports_selection=!1)})),plan_supports_selection?(plans.push(v.data("id")),v.show()):v.hide()}),self.available_plans=plans},update_plan_prices:function(){var self=this;$.each(self.available_plans,function(i,plan_id){var $plan=self.plans.filter('[data-id="'+plan_id+'"]'),pricing=$plan.data("pricing-details"),price=null;switch($plan.data("pricing-model")){case"variable":price=0,$.each(self.selected_categories,function(j,cat_id){price+=parseFloat(pricing[cat_id])});break;case"extra":price=parseFloat($plan.data("amount"))+parseFloat(pricing.extra)*self.selected_categories.length;break;default:price=parseFloat($plan.data("amount"))}$plan.find(".wpbdp-plan-price-amount").text(price?$plan.data("amount-format").replace("[amount]",price.toFixed(2)):$plan.data("free-text")),1===self.available_plans.length&&$plan.find("#wpbdp-plan-select-radio-"+plan_id).prop("checked",!0)})}}),wpbdp.submit_listing.Handler=function($submit){this.$submit=$submit,this.$form=this.$submit.find("form"),this.ajax_url=this.$form.attr("data-ajax-url"),this.doing_ajax=!1,0===this.$form.find('input[name="editing"]').length?(this.loadForm(),this.editing=!1):(this.editing="1"==this.$form.find('input[name="editing"]').val(),this.skip_plan_selection=1===$('input[type="hidden"][name="skip_plan_selection"][value="1"]').length),this.plan_handling();var self=this;this.$form.on("click","a.reset",function(e){e.preventDefault(),self.$form.find('input[name="save_listing"]').val(""),self.$form.find('input[name="reset"]').val("reset"),self.$form.submit()}),$(window).on("wpbdp_submit_refresh",function(event,submit,section_id){self.fee_helper.reset()}),$("#wpbdp-submit-listing").on("change","#wpbdp-submit-listing-create_account",function(e){$("#wpbdp-submit-listing-account-details").toggle()}),$("#wpbdp-submit-listing").on("keyup",'#wpbdp-submit-listing-account-details input[type="password"]',function(e){self.check_password_strength($(this))}),$("#wpbdp-submit-listing").on("click",".wpbdp-inner-field-option-select_all",function(e){$(this).parent().find('input[type="checkbox"]').prop("checked",$(this).find("input").is(":checked"))}),$("#wpbdp-submit-listing").on("click","button.submit-back-button",function(e){e.preventDefault();var current_section_id,current_section,e=$(this).attr("data-previous-section"),prev_section=self.$form.find(".wpbdp-submit-listing-section").filter('[data-section-id="'+e+'"]');prev_section.length&&(current_section_id=self.$form.find('input[name="current_section"]').val(),current_section=$(this).parents(".wpbdp-submit-listing-section"),self.$form.find('input[name="current_section"]').val(e),current_section.addClass("hidden").hide(),prev_section.removeClass("hidden").show(),self.$form.find(".wpbdp-submit-rootline .wpbdp-submit-section-"+current_section_id).removeClass("wpbdp-submit-checked wpbdp-submit-section-current"),self.$form.find(".wpbdp-submit-rootline .wpbdp-submit-section-"+e).addClass("wpbdp-submit-checked wpbdp-submit-section-current")),$("html, body").animate({scrollTop:self.$form.find(".wpbdp-submit-rootline").offset().top},500,function(){Reusables.Breakpoints.evaluate()})}),$(window).trigger("wpbdp_submit_init")},$.extend(wpbdp.submit_listing.Handler.prototype,{ajax:function(data,callback){var self;this.doing_ajax?alert(wpbdpSubmitListingL10n.waitAMoment):(this.doing_ajax=!0,$.post((self=this).ajax_url,data,function(res){res.success?(self.doing_ajax=!1,res.data&&res.data.redirect&&(window.location.href=res.data.redirect),callback.call(self,res.data)):alert(wpbdpSubmitListingL10n.somethingWentWrong)},"json"))},loadForm:function(){var self=this;self.ajax({action:"wpbdp_ajax",handler:"submit_listing__load_form"},function(res){void 0!==res.form&&(self.$submit.html(res.form),this.plan_handling(),0<(res=$(".wpbdp-js-select2")).length)&&$.fn.selectWoo&&(res.selectWoo(),document.body.classList.add("wpbdp-has-select2"))})},plan_handling:function(){var $plan,self;this.fee_helper=new wpbdp.submit_listing.Fee_Selection_Helper(this.$submit,this.editing),this.editing?"all"!==($plan=($plan=this.$form.find(this.skip_plan_selection?".wpbdp-plan-selection .wpbdp-plan":".wpbdp-current-plan .wpbdp-plan")).length?$plan.data("categories").toString():"")&&($plan=$.map($.unique($plan.split(",")),function(x){return parseInt(x)}),this.fee_helper._enable_categories($plan)):(self=this).$submit.on("click","#change-plan-link a",function(e){e.preventDefault(),self.$form.find('input[name="current_section"]').val("");e=self.$form.serialize();self.ajax(e+="&action=wpbdp_ajax&handler=submit_listing__reset_plan",function(res){self.refresh(res)})})},refresh:function(data){var data=data.sections,current_sections=this.$form.find(".wpbdp-submit-listing-section");current_sections.hide();var self=this;$.each(data,function(section_id,section_details){var $section=current_sections.filter('[data-section-id="'+section_id+'"]'),$new_html=$(section_details.html);$section.find(".wpbdp-editor-area").each(function(){wp.editor.remove($(this).attr("id"))}),$section.attr("class",$new_html.attr("class")),$section.find(".wpbdp-submit-listing-section-content").fadeOut("fast",function(){var $new_content=$new_html.find(".wpbdp-submit-listing-section-content");$(this).replaceWith($new_content),$section.find(".wpbdp-editor-area").each(function(){var id=$(this).attr("id");wp.editor.initialize(id,WPBDPTinyMCESettings[id])}),$(window).trigger("wpbdp_submit_refresh",[self,section_id,$section]),$section.hasClass("hidden")||(self.$form.find('input[name="current_section"]').val($section.attr("data-section-id")),$section.show()),Reusables.Breakpoints.scan($new_content)})})},check_password_strength:function($input){var pass=$input.val(),$input=$input.siblings(".wpbdp-password-strength-meter");if($input.removeClass("strength-0 strength-2 strength-3 strength-4").html(""),pass){var pass=wp.passwordStrength.meter(pass,wp.passwordStrength.userInputBlacklist(),""),strength_msg="";switch(pass){case 2:strength_msg=pwsL10n.bad;break;case 3:strength_msg=pwsL10n.good;break;case 4:strength_msg=pwsL10n.strong;break;case 5:strength_msg=pwsL10n.mismatch;break;default:strength_msg=pwsL10n.short}$input.addClass("strength-"+(pass<5&&2<=pass?pass:"0")),$input.html(strength_msg)}}}),$("#wpbdp-submit-listing"));$(window).on("wpbdp_submit_init",function(){$submit.find(".wpbdp-editor-area").each(function(){var id=$(this).attr("id");wp.editor.initialize(id,WPBDPTinyMCESettings[id])})}),0<$submit.length&&new wpbdp.submit_listing.Handler($submit)});
jQuery(function($){
var wpbdp_checkout={
init: function(){
var $form=$('form#wpbdp-checkout-form');
if(0==$form.length)
return;
var self=this;
this.$form=$form;
this.$container=this.$form.find('#wpbdp-checkout-form-fields');
this.payment_key=this.$form.find('input[name="payment"]').val();
this.nonce=this.$form.find('input[name="_wpnonce"]').val();
this.working=false;
this.$form.find('input[name="gateway"]').change(function(){
if(self.working)
return;
var gateway=self.$form.find('input[name="gateway"]:checked').val();
if(! gateway)
return;
self.load_gateway(gateway);
});
this.$form.find('input[name="gateway"]').trigger('change');
},
load_gateway: function(gateway_id){
var self=this;
self.$container.html('');
self.working=true;
var url=wpbdp_global.ajaxurl;
url    +=url.indexOf('?') > 0 ? '&':'?';
url    +='payment=' + self.payment_key + '&'
url    +='gateway=' + gateway_id;
$.post(url, { action: 'wpbdp_ajax', handler: 'checkout__load_gateway', _wpnonce: self.nonce }, function(res){
self.$container.removeClass().addClass('wpbdp-payment-gateway-' + gateway_id + '-form-fields');
self.$container.html(res);
self.working=false;
$(window).trigger('wpbdp-payment-gateway-loaded', gateway_id);
const submitButtonSelector=$('.wpbdp-checkout-submit input[type="submit"]:visible');
if('stripe'===gateway_id){
submitButtonSelector.on('click', self.sendToStripe);
}else{
submitButtonSelector.off('click', self.sendToStripe);
}});
},
sendToStripe: function(event){
if('stripe'!==$('form#wpbdp-checkout-form [name="gateway"]:checked').val()){
return false;
}
event.preventDefault();
const configurationElement=document.getElementById('wpbdp-stripe-checkout-configuration');
if(! configurationElement){
return false;
}
const configuration=$.parseJSON(configurationElement.dataset.configuration);
const stripe=Stripe(configuration.key, { stripeAccount: configuration.accountId });
stripe.redirectToCheckout({
sessionId: configuration.sessionId
}).then(function(result){
console.error('Error with Stripe checkout: ' + result.error.message);
});
return false;
}};
wpbdp_checkout.init();
$(document).on('click', '.wpbdp-payment-receipt-print', function(e){
e.preventDefault();
PrintElem($('.wpbdp-payment-receipt') );
});
function PrintElem(elem){
var mywindow=window.open('', 'PRINT', 'height=400,width=600');
mywindow.document.write('<html>');
mywindow.document.write($('head').html());
mywindow.document.write('</html><body >');
mywindow.document.write($(elem).wrap('<p/>').parent().html());
mywindow.document.write('</body></html>');
mywindow.document.close();
mywindow.focus(); // necessary for IE >=10*/
mywindow.onload=function(){
mywindow.print();
mywindow.close();
}
return true;
}});