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