woocommerce/assets/js/woocommerce.min.js

1 line
9.9 KiB
JavaScript

jQuery(document).ready(function(e){if(woocommerce_params.option_ajax_add_to_cart=="yes"){e(".add_to_cart_button").live("click",function(){var l=e(this);if(l.is(".product_type_simple, .product_type_downloadable, .product_type_virtual")){if(!e(l).attr("data-product_id")){return true}e(l).addClass("loading");var m={action:"woocommerce_add_to_cart",product_id:e(l).attr("data-product_id"),security:woocommerce_params.add_to_cart_nonce};e("body").trigger("adding_to_cart");e.post(woocommerce_params.ajax_url,m,function(n){e(l).removeClass("loading");m=e.parseJSON(n);if(m.error){alert(m.error);return}fragments=m;if(fragments){e.each(fragments,function(o,p){e(o).addClass("updating")})}e(".widget_shopping_cart, .shop_table.cart, .updating, .cart_totals").fadeTo("400","0.6").block({message:null,overlayCSS:{background:"transparent url("+woocommerce_params.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:0.6}});e(l).addClass("added");if(e(".widget_shopping_cart").size()>0){e(".widget_shopping_cart:eq(0)").load(window.location+" .widget_shopping_cart:eq(0) > *",function(){if(fragments){e.each(fragments,function(o,p){e(o).replaceWith(p)})}e(".widget_shopping_cart, .updating").css("opacity","1").unblock()})}else{if(fragments){e.each(fragments,function(o,p){e(o).replaceWith(p)})}e(".widget_shopping_cart, .updating").css("opacity","1").unblock()}e(".shop_table.cart").load(window.location+" .shop_table.cart:eq(0) > *",function(){e("div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)").addClass("buttons_added").append('<input type="button" value="+" id="add1" class="plus" />').prepend('<input type="button" value="-" id="minus1" class="minus" />');e(".shop_table.cart").css("opacity","1").unblock()});e(".cart_totals").load(window.location+" .cart_totals:eq(0) > *",function(){e(".cart_totals").css("opacity","1").unblock()});e("body").trigger("added_to_cart")});return false}else{return true}})}e("select.orderby").change(function(){e(this).closest("form").submit()});e("#rating").hide().before('<p class="stars"><span><a class="star-1" href="#">1</a><a class="star-2" href="#">2</a><a class="star-3" href="#">3</a><a class="star-4" href="#">4</a><a class="star-5" href="#">5</a></span></p>');e("p.stars a").click(function(){var l=e(this);e("#rating").val(l.text());e("p.stars a").removeClass("active");l.addClass("active");return false});e("div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)").addClass("buttons_added").append('<input type="button" value="+" id="add1" class="plus" />').prepend('<input type="button" value="-" id="minus1" class="minus" />');e(".plus").live("click",function(){var l=parseInt(e(this).prev(".qty").val());if(!l||l==""||l=="NaN"){l=0}e(this).prev(".qty").val(l+1)});e(".minus").live("click",function(){var l=parseInt(e(this).next(".qty").val());if(!l||l==""||l=="NaN"){l=1}if(l>0){e(this).next(".qty").val(l-1)}});var b=woocommerce_params.countries.replace(/&quot;/g,'"');var i=e.parseJSON(b);e("select.country_to_state").change(function(){var r=e(this).val();var o=e("#"+e(this).attr("rel"));var s=e(o).attr("name");var n=e(o).attr("id");var q=e(o).val();if(i[r]){var m="";var p=i[r];for(var l in p){m=m+'<option value="'+l+'">'+p[l]+"</option>"}if(e(o).is("input")){e(o).replaceWith('<select name="'+s+'" id="'+n+'"></select>');o=e("#"+e(this).attr("rel"))}e(o).html('<option value="">'+woocommerce_params.select_state_text+"</option>"+m);e(o).val(q)}else{if(e(o).is("select")){e(o).replaceWith('<input type="text" class="input-text" placeholder="'+woocommerce_params.state_text+'" name="'+s+'" id="'+n+'" />')}}}).change();e("div.woocommerce_tabs .panel").hide();e("div.woocommerce_tabs ul.tabs li a").click(function(){var m=e(this);var l=m.closest("div.woocommerce_tabs");e("ul.tabs li",l).removeClass("active");e("div.panel",l).hide();e("div"+m.attr("href")).show();m.parent().addClass("active");return false});e("div.woocommerce_tabs").each(function(){var l=window.location.hash;if(l.toLowerCase().indexOf("comment-")>=0){e("ul.tabs li.reviews_tab a",e(this)).click()}else{e("ul.tabs li:first a",e(this)).click()}});e(".shipping-calculator-form").hide();e(".shipping-calculator-button").click(function(){e(".shipping-calculator-form").slideToggle("slow");return false});function a(p,o){var l=true;for(name in p){var n=p[name];var m=o[name];if(n.length!=0&&m.length!=0&&n!=m){l=false}}return l}function k(n){var p=[];for(var m=0;m<product_variations.length;m++){var l=product_variations[m];var o=l.variation_id;if(a(l.attributes,n)){p.push(l)}}return p}function g(l){e(".variations select").each(function(p,q){current_attr_select=e(q);current_attr_select.find("option:gt(0)").attr("disabled","disabled");var o=current_attr_select.attr("name");for(num in l){var m=l[num].attributes;for(attr_name in m){var n=m[attr_name];if(attr_name==o){if(n){n=e("<div/>").html(n).text();n=n.replace(/'/g,"\\'");n=n.replace(/"/g,'\\"');current_attr_select.find('option[value="'+n+'"]').removeAttr("disabled")}else{current_attr_select.find("option").removeAttr("disabled")}}}}})}function f(n){var l=e("div.images img:eq(0)");var r=e("div.images a.zoom:eq(0)");var q=e(l).attr("original-src");var p=e(r).attr("original-href");var o=n.image_src;var m=n.image_link;e(".variations_button").show();e(".single_variation").html(n.price_html+n.availability_html);if(!q){e(l).attr("original-src",e(l).attr("src"))}if(!p){e(r).attr("original-href",e(r).attr("href"))}if(o&&o.length>1){e(l).attr("src",o);e(r).attr("href",m)}else{e(l).attr("src",q);e(r).attr("href",p)}e(".single_variation_wrap").slideDown("200").trigger("variationWrapShown")}function c(m){var l=true;var o={};e(".variations select").each(function(){if(m&&e(this).attr("name")==m){l=false;o[e(this).attr("name")]=""}else{if(e(this).val().length==0){l=false}value=e(this).val().replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&#039;").replace(/</g,"&lt;").replace(/>/g,"&gt;");o[e(this).attr("name")]=value}});var p=k(o);if(l){var n=p.pop();if(n){e("form input[name=variation_id]").val(n.variation_id);f(n)}else{e(".variations select").val("")}}else{g(p)}}e(".variations select").change(function(){e("form input[name=variation_id]").val("");e(".single_variation_wrap").hide();e(".single_variation").text("");c();e(this).blur();if(e().uniform&&e.isFunction(e.uniform.update)){e.uniform.update()}}).focus(function(){c(e(this).attr("name"))}).change();if(woocommerce_params.is_cart==1){e("select#shipping_method").live("change",function(){var m=e("#shipping_method").val();e("div.cart_totals").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_params.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:0.6}});var l={action:"woocommerce_update_shipping_method",security:woocommerce_params.update_shipping_method_nonce,shipping_method:m};e.post(woocommerce_params.ajax_url,l,function(n){e("div.cart_totals").replaceWith(n)})})}if(woocommerce_params.is_checkout==1||woocommerce_params.is_pay_page==1){var j;var h;function d(){if(h){h.abort()}var s=e("#shipping_method").val();var r=e("#billing_country").val();var p=e("#billing_state").val();var l=e("input#billing_postcode").val();if(e("#shiptobilling input").is(":checked")||e("#shiptobilling input").size()==0){var m=e("#billing_country").val();var o=e("#billing_state").val();var q=e("input#billing_postcode").val()}else{var m=e("#shipping_country").val();var o=e("#shipping_state").val();var q=e("input#shipping_postcode").val()}e("#order_methods, #order_review").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_params.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:0.6}});var n={action:"woocommerce_update_order_review",security:woocommerce_params.update_order_review_nonce,shipping_method:s,country:r,state:p,postcode:l,s_country:m,s_state:o,s_postcode:q,post_data:e("form.checkout").serialize()};h=e.ajax({type:"POST",url:woocommerce_params.ajax_url,data:n,success:function(t){e("#order_methods, #order_review").remove();e("#order_review_heading").after(t);e("#order_review input[name=payment_method]:checked").click()}})}e("p.password, form.login, div.shipping_address").hide();e("input.show_password").change(function(){e("p.password").slideToggle()});e("a.showlogin").click(function(){e("form.login").slideToggle();return false});e("#shiptobilling input").change(function(){e("div.shipping_address").hide();if(!e(this).is(":checked")){e("div.shipping_address").slideDown()}}).change();if(woocommerce_params.option_guest_checkout=="yes"){e("div.create-account").hide();e("input#createaccount").change(function(){e("div.create-account").hide();if(e(this).is(":checked")){e("div.create-account").slideDown()}}).change()}e(".payment_methods input.input-radio").live("click",function(){e("div.payment_box").hide();if(e(this).is(":checked")){e("div.payment_box."+e(this).attr("ID")).slideDown()}});e("#order_review input[name=payment_method]:checked").click();e("#shipping_method").live("change",function(){clearTimeout(j);d()});e("input#billing_country, input#billing_state, #billing_postcode, input#shipping_country, input#shipping_state, #shipping_postcode").live("keydown",function(){clearTimeout(j);j=setTimeout("update_checkout()","1000")});e("select#billing_country, select#billing_state, select#shipping_country, select#shipping_state, #shiptobilling input, .update_totals_on_change").live("change",function(){clearTimeout(j);d()});if(woocommerce_params.is_checkout==1){d()}e("form.checkout").submit(function(){var l=e(this);if(l.is(".processing")){return false}l.addClass("processing").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_params.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:0.6}});e.ajax({type:"POST",url:woocommerce_params.checkout_url,data:l.serialize(),success:function(n){e(".woocommerce_error, .woocommerce_message").remove();try{success=e.parseJSON(n);window.location=decodeURI(success.redirect)}catch(m){l.prepend(n);l.removeClass("processing").unblock();e("html, body").animate({scrollTop:(e("form.checkout").offset().top-100)},1000)}},dataType:"html"});return false})}});