1 line
12 KiB
JavaScript
1 line
12 KiB
JavaScript
jQuery.fn.animateHighlight=function(e,c){var d=e||"#FFFF9C";var a=c||1500;var b=this.css("backgroundColor");this.stop().css("background-color",d).animate({backgroundColor:b},a)};jQuery(document).ready(function(f){f(".add_to_cart_button").live("click",function(){var m=f(this);if(m.is(".product_type_simple")){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").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");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()});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("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");f.cookie("current_tab",m);return false});f("div.woocommerce_tabs").each(function(){if(f("ul.tabs li.active",f(this)).size()==0){f("ul.tabs li:first a",f(this)).click()}else{f("ul.tabs li.active 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(q){var m=f(".variations select").not("[disabled]").last();m.find("option:gt(0)").attr("disabled","disabled");var p=m.attr("name");for(num in q){var n=q[num].attributes;for(attr_name in n){var o=n[attr_name];if(attr_name==p){m.find('option[value="'+o+'"]').removeAttr("disabled")}}}}function g(o){var m=f("div.images img:eq(0)");var s=f("div.images a.zoom");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(".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()}function c(){f("form input[name=variation_id]").val("");f(".single_variation_wrap").hide();f(".single_variation").text("");var m=true;var o={};f(".variations select").each(function(){if(f(this).val().length==0){m=false}o[f(this).attr("name")]=f(this).val()});var p=l(o);if(m){var n=p.pop();f("form input[name=variation_id]").val(n.variation_id);g(n)}else{h(p)}}f(".variations select").change(function(){var m=f(this).data("index");if(f(this).val().length>0){m+=1}var n=f(".variations select");n.filter(":lt("+m+")").removeAttr("disabled");n.filter(":eq("+m+")").removeAttr("disabled").val("");n.filter(":gt("+m+")").attr("disabled","disabled").val("");c(f(this));if(f().uniform){f.uniform.update()}});f(".variations select:gt(0)").attr("disabled","disabled");f.each(f(".variations select"),function(m,n){f(n).data("index",m)});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};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()});f("#shipping_method").live("change",function(){clearTimeout(k);e()}).change();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").live("change",function(){clearTimeout(k);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})})}}); |