fragment tweak

This commit is contained in:
Mike Jolley 2013-01-28 12:02:21 +00:00
parent fdfa0d6efb
commit c21ca1a68c
2 changed files with 14 additions and 9 deletions

View File

@ -8,7 +8,7 @@ jQuery(document).ready(function($) {
type: 'POST',
data: { action: 'woocommerce_get_refreshed_fragments' },
success: function( data ) {
if ( data.fragments ) {
if ( data && data.fragments ) {
$.each( data.fragments, function( key, value ) {
$(key).replaceWith(value);
@ -30,16 +30,21 @@ jQuery(document).ready(function($) {
localStorage.setItem( "wc_cart_hash", cart_hash );
});
var wc_fragments = $.parseJSON( localStorage.getItem( "wc_fragments" ) );
var cart_hash = localStorage.getItem( "wc_cart_hash" );
try {
var wc_fragments = $.parseJSON( localStorage.getItem( "wc_fragments" ) );
var cart_hash = localStorage.getItem( "wc_cart_hash" );
if ( wc_fragments && typeof wc_fragments == 'object' && wc_fragments['div.widget_shopping_cart_content'] && cart_hash == $.cookie( "woocommerce_cart_hash" ) ) {
if ( wc_fragments && wc_fragments['div.widget_shopping_cart_content'] && cart_hash == $.cookie( "woocommerce_cart_hash" ) ) {
$.each( wc_fragments, function( key, value ) {
$(key).replaceWith(value);
});
$.each( wc_fragments, function( key, value ) {
$(key).replaceWith(value);
});
} else {
} else {
throw "No fragment";
}
} catch(err) {
$.ajax( $fragment_refresh );
}

View File

@ -1 +1 @@
jQuery(document).ready(function(e){$supports_html5_storage="localStorage"in window&&window.localStorage!==null;$fragment_refresh={url:woocommerce_params.ajax_url,type:"POST",data:{action:"woocommerce_get_refreshed_fragments"},success:function(t){if(t.fragments){e.each(t.fragments,function(t,n){e(t).replaceWith(n)});if($supports_html5_storage){localStorage.setItem("wc_fragments",JSON.stringify(t.fragments));localStorage.setItem("wc_cart_hash",t.cart_hash)}}}};if($supports_html5_storage){e("body").bind("added_to_cart",function(e,t,n){localStorage.setItem("wc_fragments",JSON.stringify(t));localStorage.setItem("wc_cart_hash",n)});var t=e.parseJSON(localStorage.getItem("wc_fragments")),n=localStorage.getItem("wc_cart_hash");t&&typeof t=="object"&&t["div.widget_shopping_cart_content"]&&n==e.cookie("woocommerce_cart_hash")?e.each(t,function(t,n){e(t).replaceWith(n)}):e.ajax($fragment_refresh)}else e.ajax($fragment_refresh);e("select.orderby").change(function(){e(this).closest("form").submit()});e("div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)").addClass("buttons_added").append('<input type="button" value="+" class="plus" />').prepend('<input type="button" value="-" class="minus" />');e("input.qty:not(.product-quantity input.qty)").each(function(){var t=parseFloat(e(this).attr("min"));t&&t>0&&parseFloat(e(this).val())<t&&e(this).val(t)});e(document).on("click",".plus, .minus",function(){var t=e(this).closest(".quantity").find(".qty"),n=parseFloat(t.val()),r=parseFloat(t.attr("max")),i=parseFloat(t.attr("min")),s=t.attr("step");if(!n||n==""||n=="NaN")n=0;if(r==""||r=="NaN")r="";if(i==""||i=="NaN")i=0;if(s=="any"||s==""||s==undefined||parseFloat(s)=="NaN")s=1;e(this).is(".plus")?r&&(r==n||n>r)?t.val(r):t.val(n+parseFloat(s)):i&&(i==n||n<i)?t.val(i):n>0&&t.val(n-parseFloat(s));t.trigger("change")});var r=woocommerce_params.countries.replace(/&quot;/g,'"'),i=e.parseJSON(r);e("select.country_to_state").change(function(){var t=e(this).val(),n=e(this).closest("div").find("#billing_state, #shipping_state, #calc_shipping_state"),r=n.parent(),s=n.attr("name"),o=n.attr("id"),u=n.val(),a=n.attr("placeholder");if(i[t])if(i[t].length==0){n.parent().hide().find(".chzn-container").remove();n.replaceWith('<input type="hidden" class="hidden" name="'+s+'" id="'+o+'" value="" placeholder="'+a+'" />');e("body").trigger("country_to_state_changed",[t,e(this).closest("div")])}else{var f="",l=i[t];for(var c in l)f=f+'<option value="'+c+'">'+l[c]+"</option>";n.parent().show();if(n.is("input")){n.replaceWith('<select name="'+s+'" id="'+o+'" class="state_select" placeholder="'+a+'"></select>');n=e(this).closest("div").find("#billing_state, #shipping_state, #calc_shipping_state")}n.html('<option value="">'+woocommerce_params.i18n_select_state_text+"</option>"+f);n.val(u);e("body").trigger("country_to_state_changed",[t,e(this).closest("div")])}else if(n.is("select")){r.show().find(".chzn-container").remove();n.replaceWith('<input type="text" class="input-text" name="'+s+'" id="'+o+'" placeholder="'+a+'" />');e("body").trigger("country_to_state_changed",[t,e(this).closest("div")])}else if(n.is(".hidden")){r.show().find(".chzn-container").remove();n.replaceWith('<input type="text" class="input-text" name="'+s+'" id="'+o+'" placeholder="'+a+'" />');e("body").trigger("country_to_state_changed",[t,e(this).closest("div")])}e("body").trigger("country_to_state_changing",[t,e(this).closest("div")])})});
jQuery(document).ready(function(e){$supports_html5_storage="localStorage"in window&&window.localStorage!==null;$fragment_refresh={url:woocommerce_params.ajax_url,type:"POST",data:{action:"woocommerce_get_refreshed_fragments"},success:function(t){if(t&&t.fragments){e.each(t.fragments,function(t,n){e(t).replaceWith(n)});if($supports_html5_storage){localStorage.setItem("wc_fragments",JSON.stringify(t.fragments));localStorage.setItem("wc_cart_hash",t.cart_hash)}}}};if($supports_html5_storage){e("body").bind("added_to_cart",function(e,t,n){localStorage.setItem("wc_fragments",JSON.stringify(t));localStorage.setItem("wc_cart_hash",n)});try{var t=e.parseJSON(localStorage.getItem("wc_fragments")),n=localStorage.getItem("wc_cart_hash");if(!t||!t["div.widget_shopping_cart_content"]||n!=e.cookie("woocommerce_cart_hash"))throw"No fragment";e.each(t,function(t,n){e(t).replaceWith(n)})}catch(r){e.ajax($fragment_refresh)}}else e.ajax($fragment_refresh);e("select.orderby").change(function(){e(this).closest("form").submit()});e("div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)").addClass("buttons_added").append('<input type="button" value="+" class="plus" />').prepend('<input type="button" value="-" class="minus" />');e("input.qty:not(.product-quantity input.qty)").each(function(){var t=parseFloat(e(this).attr("min"));t&&t>0&&parseFloat(e(this).val())<t&&e(this).val(t)});e(document).on("click",".plus, .minus",function(){var t=e(this).closest(".quantity").find(".qty"),n=parseFloat(t.val()),r=parseFloat(t.attr("max")),i=parseFloat(t.attr("min")),s=t.attr("step");if(!n||n==""||n=="NaN")n=0;if(r==""||r=="NaN")r="";if(i==""||i=="NaN")i=0;if(s=="any"||s==""||s==undefined||parseFloat(s)=="NaN")s=1;e(this).is(".plus")?r&&(r==n||n>r)?t.val(r):t.val(n+parseFloat(s)):i&&(i==n||n<i)?t.val(i):n>0&&t.val(n-parseFloat(s));t.trigger("change")});var i=woocommerce_params.countries.replace(/&quot;/g,'"'),s=e.parseJSON(i);e("select.country_to_state").change(function(){var t=e(this).val(),n=e(this).closest("div").find("#billing_state, #shipping_state, #calc_shipping_state"),r=n.parent(),i=n.attr("name"),o=n.attr("id"),u=n.val(),a=n.attr("placeholder");if(s[t])if(s[t].length==0){n.parent().hide().find(".chzn-container").remove();n.replaceWith('<input type="hidden" class="hidden" name="'+i+'" id="'+o+'" value="" placeholder="'+a+'" />');e("body").trigger("country_to_state_changed",[t,e(this).closest("div")])}else{var f="",l=s[t];for(var c in l)f=f+'<option value="'+c+'">'+l[c]+"</option>";n.parent().show();if(n.is("input")){n.replaceWith('<select name="'+i+'" id="'+o+'" class="state_select" placeholder="'+a+'"></select>');n=e(this).closest("div").find("#billing_state, #shipping_state, #calc_shipping_state")}n.html('<option value="">'+woocommerce_params.i18n_select_state_text+"</option>"+f);n.val(u);e("body").trigger("country_to_state_changed",[t,e(this).closest("div")])}else if(n.is("select")){r.show().find(".chzn-container").remove();n.replaceWith('<input type="text" class="input-text" name="'+i+'" id="'+o+'" placeholder="'+a+'" />');e("body").trigger("country_to_state_changed",[t,e(this).closest("div")])}else if(n.is(".hidden")){r.show().find(".chzn-container").remove();n.replaceWith('<input type="text" class="input-text" name="'+i+'" id="'+o+'" placeholder="'+a+'" />');e("body").trigger("country_to_state_changed",[t,e(this).closest("div")])}e("body").trigger("country_to_state_changing",[t,e(this).closest("div")])})});