Current File : /home/itiffy/public_html/blog/wp-content/plugins/wp-invoice/static/scripts/wpi-checkout.js
!function($,w,d){w.wpi_spc=function(params){var self={};if(self.debug=function(error){return"undefined"!=typeof console&&"undefined"!=typeof console.log&&console.log(error),null},"string"==typeof params)try{var json=$.parseJSON(params);params=json}catch(e){return self.debug("WPI SPC Init error. Params can not be converted to object."),!1}var defaults={available_gateways:{},system_gateways:{},id:!1,total:0,total_before_filters:0,ga_event_tracking:{enabled:"false",events:{invoices:{}}}};if(self.params=$.extend(!0,defaults,params),!self.params.id||!self.params.id.length>0)return self.debug("WPI SPC Error. template ID is not set."),!1;if(self.instance=jQuery("#"+self.params.id),!self.instance.length>0)return self.debug("WPI SPC Error. template is not found."),!1;self.update_checkboxes=function(venue){$("input.wpi_checkout_toggle_item",self.instance).length&&($(".wpi_checkout_products",self.instance).removeAttr("checked"),$(".wpi_checkout_products",self.instance).attr("disabled","disabled")),$("input[paypal_item_name]",self.instance).length&&$("input[paypal_item_name]",self.instance).each(function(){$(this).attr("disabled","disabled")}),$("input.wpi_checkout_toggle_item",self.instance).length||$(".wpi_checkout_products",self.instance).each(function(){var checked,paypal_item_name;checked=$(this).is(":checked")?!0:!1,checked&&($(this).attr("paypal_item_name")&&(paypal_item_name=$(this).attr("paypal_item_name"),$("input[paypal_item_name="+paypal_item_name+"]",self.instance).removeAttr("disabled")),$(this).attr("checked","checked"),$(this).removeAttr("disabled"))}),$("input.wpi_checkout_toggle_item",self.instance).each(function(){var checked,this_element,paypal_item_name,item_name=$(this).attr("item_name");checked=$(this).is(":checked")?!0:!1,this_element=$('.wpi_checkout_products[item_name="'+item_name+'"]',self.instance),checked&&(1==this_element.length?this_element.each(function(){$(this).attr("paypal_item_name")&&(paypal_item_name=$(this).attr("paypal_item_name"),$("input[paypal_item_name="+paypal_item_name+"]",self.instance).removeAttr("disabled")),$(this).attr("checked","checked"),$(this).removeAttr("disabled")}):this_element.length>1&&this_element.each(function(){$(this).attr("paypal_item_name")&&(paypal_item_name=$(this).attr("paypal_item_name"),$("input[paypal_item_name="+paypal_item_name+"]",self.instance).removeAttr("disabled")),$(this).attr("checked","checked"),$(this).removeAttr("disabled")})),$("input[paypal_item_name^=item_name_].wpi_checkout_products:enabled",self.instance).each(function(key,value){$("input[paypal_item_name="+$(value).attr("paypal_item_name")+"]",self.instance).each(function(key_a,value_b){$(value_b).attr("name").match(/^item_name_(.*\d)$/)&&$(value_b).attr("name","item_name_"+(key+1)),$(value_b).attr("name").match(/^item_number_(.*\d)$/)&&$(value_b).attr("name","item_number_"+(key+1)),$(value_b).attr("name").match(/^amount_(.*\d)$/)&&$(value_b).attr("name","amount_"+(key+1)),$(value_b).attr("name").match(/^quantity_(.*\d)$/)&&$(value_b).attr("name","quantity_"+(key+1)),$(value_b).attr("name").match(/^tax_rate_(.*\d)$/)&&$(value_b).attr("name","tax_rate_"+(key+1))})})}),self.update_price(venue)},self.update_price=function(venue){$("form.wpi_checkout",self.instance).each(function(){venue.wpi_checkout_total=0;var wpi_checkout_fee=0;$(".wpi_checkout_products",$(this)).each(function(){"checked"==$(this).attr("checked")&&(venue.wpi_checkout_total=venue.wpi_checkout_total+parseFloat($(this).attr("item_price")))}),venue.wpi_checkout_total+=venue.amount,$(".wpi_checkout_fee",self.instance).length&&(wpi_checkout_fee=parseInt($(".wpi_checkout_fee",self.instance).val()),$(".wpi_fee_amount",self.instance).html(" ("+wpi_checkout_fee+"% fee)"),venue.wpi_checkout_total+=venue.wpi_checkout_total/100*wpi_checkout_fee),venue.wpi_checkout_total=isNaN(venue.wpi_checkout_total)?0:venue.wpi_checkout_total,$(".wpi_price",self.instance).text($().number_format(venue.wpi_checkout_total))})},self.change_payment_method=function(e){var selected_form_slug=$(e.target).val(),context=$(e.target).parents("div.wpi_checkout");$("form.wpi_checkout",context).animate({opacity:0},function(){$(this).hide().css({opacity:1}),$("form.wpi_checkout."+selected_form_slug,context).css({opacity:"0"}).show().animate({opacity:1})})},self.sync_input_data=function(e){var context=$(e.target,self.instance).parents("div.wpi_checkout"),full_class_path=".wpi_checkout_row ";$($(e.target).attr("class").split(" "),context).each(function(k,v){""!=v&&(full_class_path+="."+v)}),$(full_class_path,context).val($(e.target).val())};var _init=function(self){jQuery(".wpi_checkout_row input.text-input",self.instance).change(self.sync_input_data),jQuery(".wpi_checkout input",self.instance).change(function(){var parent_row=jQuery(this).parents(".wpi_checkout_row");jQuery("input",parent_row).removeClass("wpi_checkout_input_error"),jQuery("span.validation",parent_row).text("")}),"true"==self.params.ga_event_tracking.enabled&&"undefined"!=typeof w._gaq&&"object"==typeof w.wpi&&"undefined"!=typeof w.wpi.ga&&w.wpi.ga.tracking.init(self.params.ga_event_tracking.events.invoices),self.gateways={};for(var i in self.params.available_gateways)"function"!=typeof self.params.available_gateways[i]&&$(d).trigger("wpi_checkout_init-"+i,[self])};return _init(self)}}(jQuery,window,document);