woocommerce/assets/js/woocommerce.min.js

1 line
21 KiB
JavaScript
Raw Normal View History

2012-02-17 23:47:18 +00:00
jQuery(document).ready(function(a){function d(a,b){var c=!0;for(name in a){var d=a[name],e=b[name];d.length!=0&&e.length!=0&&d!=e&&(c=!1)}return c}function e(a){var b=[];for(var c=0;c<product_variations.length;c++){var e=product_variations[c],f=e.variation_id;d(e.attributes,a)&&b.push(e)}return b}function f(b){a(".variations select").each(function(c,d){current_attr_select=a(d);current_attr_select.find("option:gt(0)").attr("disabled","disabled");var e=current_attr_select.attr("name");for(num in b){var f=b[num].attributes;for(attr_name in f){var g=f[attr_name];if(attr_name==e)if(g){g=a("<div/>").html(g).text();g=g.replace(/'/g,"\\'");g=g.replace(/"/g,'\\"');current_attr_select.find('option[value="'+g+'"]').removeAttr("disabled")}else current_attr_select.find("option").removeAttr("disabled")}}})}function g(b){var c=a("div.images img:eq(0)"),d=a("div.images a.zoom:eq(0)"),e=a(c).attr("original-src"),f=a(d).attr("original-href"),g=b.image_src,h=b.image_link;a(".variations_button").show();a(".single_variation").html(b.price_html+b.availability_html);e||a(c).attr("original-src",a(c).attr("src"));f||a(d).attr("original-href",a(d).attr("href"));if(g&&g.length>1){a(c).attr("src",g);a(d).attr("href",h)}else{a(c).attr("src",e);a(d).attr("href",f)}b.sku?a(".product_meta").find(".sku").text(b.sku):a(".product_meta").find(".sku").text("");a(".single_variation_wrap").slideDown("200").trigger("variationWrapShown").trigger("show_variation")}function h(b){var c=!0,d={};a(".variations select").each(function(){if(b&&a(this).attr("name")==b){c=!1;d[a(this).attr("name")]=""}else{a(this).val().length==0&&(c=!1);value=a(this).val().replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&#039;").replace(/</g,"&lt;").replace(/>/g,"&gt;");d[a(this).attr("name")]=value}});var h=e(d);if(c){var i=h.pop();if(i){a("form input[name=variation_id]").val(i.variation_id).change();g(i)}else a(".variations select").val("")}else f(h)}woocommerce_params.option_ajax_add_to_cart=="yes"&&a(".add_to_cart_button").live("click",function(){var b=a(this);if(b.is(".product_type_simple, .product_type_downloadable, .product_type_virtual")){if(!b.attr("data-product_id"))return!0;b.removeClass("added");b.addClass("loading");var c={action:"woocommerce_add_to_cart",product_id:b.attr("data-product_id"),security:woocommerce_params.add_to_cart_nonce};a("body").trigger("adding_to_cart");a.post(woocommerce_params.ajax_url,c,function(d){b.removeClass("loading");c=a.parseJSON(d);if(c.error&&c.product_url){window.location=c.product_url;return}fragments=c;fragments&&a.each(fragments,function(b,c){a(b).addClass("updating")});a(".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:.6}});b.addClass("added");if(a(".widget_shopping_cart").size()>0)a(".widget_shopping_cart:eq(0)").load(window.location+" .widget_shopping_cart:eq(0) > *",function(){fragments&&a.each(fragments,function(b,c){a(b).replaceWith(c)});a(".widget_shopping_cart, .updating").css("opacity","1").unblock();a("body").trigger("cart_widget_refreshed")});else{fragments&&a.each(fragments,function(b,c){a(b).replaceWith(c)});a(".widget_shopping_cart, .updating").css("opacity","1").unblock()}a(".shop_table.cart").load(window.location+" .shop_table.cart:eq(0) > *",function(){a("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" />');a(".shop_table.cart").css("opacity","1").unblock();a("body").trigger("cart_page_refreshed")});a(".cart_totals").load(window.location+" .cart_totals:eq(0) > *",function(){a(".cart_totals").css("opacity","1").unblock()});a("body").trigger("added_to_cart")});return!1}return!0});a("select.orderby").change(function(){a(this).closest("form").submit()});a("#rating").hide().before('<p class="stars"><span><a class="star-1" href="#">1</a><a class="star-2