Merge pull request #5158 from splashingpixels/jshint

Jshint
This commit is contained in:
Mike Jolley 2014-03-18 09:21:43 +00:00
commit 2d0903a476
6 changed files with 127 additions and 119 deletions

View File

@ -1,93 +1,95 @@
jQuery(function($) {
jQuery( function( $ ) {
var locale_json = wc_address_i18n_params.locale.replace(/"/g, '"');
var locale = $.parseJSON( locale_json );
var required = ' <abbr class="required" title="' + wc_address_i18n_params.i18n_required_text + '">*</abbr>';
var locale_json = wc_address_i18n_params.locale.replace( /&quot;/g, '"' ),
locale = $.parseJSON( locale_json ),
required = ' <abbr class="required" title="' + wc_address_i18n_params.i18n_required_text + '">*</abbr>';
$('body')
$( 'body' )
// Handle locale
.bind('country_to_state_changing', function( event, country, wrapper ){
// Handle locale
.bind( 'country_to_state_changing', function( event, country, wrapper ) {
var thisform = wrapper;
var thisform = wrapper,
thislocale;
if ( typeof locale[country] != 'undefined' ) {
var thislocale = locale[country];
} else {
var thislocale = locale['default'];
}
// Handle locale fields
var locale_fields = $.parseJSON( wc_address_i18n_params.locale_fields );
$.each( locale_fields, function( key, value ) {
var field = thisform.find( value );
if ( thislocale[key] ) {
if ( thislocale[key]['label'] ) {
field.find('label').html( thislocale[key]['label'] );
}
if ( thislocale[key]['placeholder'] ) {
field.find('input').attr( 'placeholder', thislocale[key]['placeholder'] );
}
field.find('label abbr').remove();
if ( typeof thislocale[key]['required'] == 'undefined' && locale['default'][key]['required'] == true ) {
field.find('label').append( required );
} else if ( thislocale[key]['required'] == true ) {
field.find('label').append( required );
}
if ( key !== 'state' ) {
if ( thislocale[key]['hidden'] == true ) {
field.hide().find('input').val('');
} else {
field.show();
}
}
} else if ( locale['default'][key] ) {
if ( locale['default'][key]['required'] == true ) {
if (field.find('label abbr').size()==0) field.find('label').append( required );
}
if ( key !== 'state' ) {
if ( typeof locale['default'][key]['hidden'] == 'undefined' || locale['default'][key]['hidden'] == false ) {
field.show();
} else if ( locale['default'][key]['hidden'] == true ) {
field.hide().find('input').val('');
}
}
if ( typeof locale[ country ] !== 'undefined' ) {
thislocale = locale[ country ];
} else {
thislocale = locale['default'];
}
});
// Handle locale fields
var locale_fields = $.parseJSON( wc_address_i18n_params.locale_fields );
var $postcodefield = thisform.find('#billing_postcode_field, #shipping_postcode_field');
var $cityfield = thisform.find('#billing_city_field, #shipping_city_field');
var $statefield = thisform.find('#billing_state_field, #shipping_state_field');
$.each( locale_fields, function( key, value ) {
if ( ! $postcodefield.attr('data-o_class') ) {
$postcodefield.attr('data-o_class', $postcodefield.attr('class'));
$cityfield.attr('data-o_class', $cityfield.attr('class'));
$statefield.attr('data-o_class', $statefield.attr('class'));
}
var field = thisform.find( value );
// Re-order postcode/city
if ( thislocale['postcode_before_city'] ) {
if ( thislocale[ key ] ) {
$postcodefield.add( $cityfield ).add( $statefield ).removeClass('form-row-first form-row-last').addClass('form-row-wide');
$postcodefield.insertBefore( $cityfield );
if ( thislocale[ key ].label ) {
field.find( 'label' ).html( thislocale[ key ].label );
}
} else {
// Default
$postcodefield.attr('class', $postcodefield.attr('data-o_class'));
$cityfield.attr('class', $cityfield.attr('data-o_class'));
$statefield.attr('class', $statefield.attr('data-o_class'));
$postcodefield.insertAfter( $statefield );
}
if ( thislocale[ key ].placeholder ) {
field.find( 'input' ).attr( 'placeholder', thislocale[ key ].placeholder );
}
field.find( 'label abbr' ).remove();
if ( typeof thislocale[ key ].required === 'undefined' && locale['default'][ key ].required === true ) {
field.find( 'label' ).append( required );
} else if ( thislocale[ key ].required === true ) {
field.find( 'label' ).append( required );
}
if ( key !== 'state' ) {
if ( thislocale[ key ].hidden === true ) {
field.hide().find( 'input' ).val( '' );
} else {
field.show();
}
}
} else if ( locale['default'][ key ] ) {
if ( locale['default'][ key ].required === true ) {
if ( field.find( 'label abbr' ).size() === 0 ) field.find( 'label' ).append( required );
}
if ( key !== 'state' ) {
if ( typeof locale['default'][ key ].hidden === 'undefined' || locale['default'][ key ].hidden === false ) {
field.show();
} else if ( locale['default'][ key ].hidden === true ) {
field.hide().find( 'input' ).val( '' );
}
}
}
});
var $postcodefield = thisform.find( '#billing_postcode_field, #shipping_postcode_field' ),
$cityfield = thisform.find( '#billing_city_field, #shipping_city_field' ),
$statefield = thisform.find( '#billing_state_field, #shipping_state_field' );
if ( ! $postcodefield.attr( 'data-o_class' ) ) {
$postcodefield.attr( 'data-o_class', $postcodefield.attr( 'class' ) );
$cityfield.attr( 'data-o_class', $cityfield.attr( 'class' ) );
$statefield.attr( 'data-o_class', $statefield.attr( 'class' ) );
}
// Re-order postcode/city
if ( thislocale.postcode_before_city ) {
$postcodefield.add( $cityfield ).add( $statefield ).removeClass( 'form-row-first form-row-last' ).addClass( 'form-row-wide' );
$postcodefield.insertBefore( $cityfield );
} else {
// Default
$postcodefield.attr( 'class', $postcodefield.attr( 'data-o_class' ) );
$cityfield.attr( 'class', $cityfield.attr( 'data-o_class' ) );
$statefield.attr( 'class', $statefield.attr( 'data-o_class' ) );
$postcodefield.insertAfter( $statefield );
}
});

View File

@ -1 +1 @@
jQuery(function(a){var b=wc_address_i18n_params.locale.replace(/&quot;/g,'"'),c=a.parseJSON(b),d=' <abbr class="required" title="'+wc_address_i18n_params.i18n_required_text+'">*</abbr>';a("body").bind("country_to_state_changing",function(b,e,f){var g=f;if("undefined"!=typeof c[e])var h=c[e];else var h=c["default"];var i=a.parseJSON(wc_address_i18n_params.locale_fields);a.each(i,function(a,b){var e=g.find(b);h[a]?(h[a].label&&e.find("label").html(h[a].label),h[a].placeholder&&e.find("input").attr("placeholder",h[a].placeholder),e.find("label abbr").remove(),"undefined"==typeof h[a].required&&1==c["default"][a].required?e.find("label").append(d):1==h[a].required&&e.find("label").append(d),"state"!==a&&(1==h[a].hidden?e.hide().find("input").val(""):e.show())):c["default"][a]&&(1==c["default"][a].required&&0==e.find("label abbr").size()&&e.find("label").append(d),"state"!==a&&("undefined"==typeof c["default"][a].hidden||0==c["default"][a].hidden?e.show():1==c["default"][a].hidden&&e.hide().find("input").val("")))});var j=g.find("#billing_postcode_field, #shipping_postcode_field"),k=g.find("#billing_city_field, #shipping_city_field"),l=g.find("#billing_state_field, #shipping_state_field");j.attr("data-o_class")||(j.attr("data-o_class",j.attr("class")),k.attr("data-o_class",k.attr("class")),l.attr("data-o_class",l.attr("class"))),h.postcode_before_city?(j.add(k).add(l).removeClass("form-row-first form-row-last").addClass("form-row-wide"),j.insertBefore(k)):(j.attr("class",j.attr("data-o_class")),k.attr("class",k.attr("data-o_class")),l.attr("class",l.attr("data-o_class")),j.insertAfter(l))})});
jQuery(function(e){var t=wc_address_i18n_params.locale.replace(/&quot;/g,'"'),n=e.parseJSON(t),r=' <abbr class="required" title="'+wc_address_i18n_params.i18n_required_text+'">*</abbr>';e("body").bind("country_to_state_changing",function(t,i,s){var o=s,u;if(typeof n[i]!=="undefined"){u=n[i]}else{u=n["default"]}var a=e.parseJSON(wc_address_i18n_params.locale_fields);e.each(a,function(e,t){var i=o.find(t);if(u[e]){if(u[e].label){i.find("label").html(u[e].label)}if(u[e].placeholder){i.find("input").attr("placeholder",u[e].placeholder)}i.find("label abbr").remove();if(typeof u[e].required==="undefined"&&n["default"][e].required===true){i.find("label").append(r)}else if(u[e].required===true){i.find("label").append(r)}if(e!=="state"){if(u[e].hidden===true){i.hide().find("input").val("")}else{i.show()}}}else if(n["default"][e]){if(n["default"][e].required===true){if(i.find("label abbr").size()===0)i.find("label").append(r)}if(e!=="state"){if(typeof n["default"][e].hidden==="undefined"||n["default"][e].hidden===false){i.show()}else if(n["default"][e].hidden===true){i.hide().find("input").val("")}}}});var f=o.find("#billing_postcode_field, #shipping_postcode_field"),l=o.find("#billing_city_field, #shipping_city_field"),c=o.find("#billing_state_field, #shipping_state_field");if(!f.attr("data-o_class")){f.attr("data-o_class",f.attr("class"));l.attr("data-o_class",l.attr("class"));c.attr("data-o_class",c.attr("class"))}if(u.postcode_before_city){f.add(l).add(c).removeClass("form-row-first form-row-last").addClass("form-row-wide");f.insertBefore(l)}else{f.attr("class",f.attr("data-o_class"));l.attr("class",l.attr("data-o_class"));c.attr("class",c.attr("data-o_class"));f.insertAfter(c)}})})

View File

@ -1,11 +1,12 @@
jQuery(function($) {
jQuery( function( $ ) {
// wc_cart_fragments_params is required to continue, ensure the object exists
if (typeof wc_cart_fragments_params === "undefined")
if ( typeof wc_cart_fragments_params === 'undefined' ) {
return false;
}
/** Cart Handling */
$supports_html5_storage = ( 'sessionStorage' in window && window['sessionStorage'] !== null );
$supports_html5_storage = ( 'sessionStorage' in window && window.sessionStorage !== null );
$fragment_refresh = {
url: wc_cart_fragments_params.ajax_url,
@ -15,50 +16,52 @@ jQuery(function($) {
if ( data && data.fragments ) {
$.each( data.fragments, function( key, value ) {
$(key).replaceWith(value);
$( key ).replaceWith( value );
});
if ( $supports_html5_storage ) {
sessionStorage.setItem( wc_cart_fragments_params.fragment_name, JSON.stringify( data.fragments ) );
sessionStorage.setItem( "wc_cart_hash", data.cart_hash );
sessionStorage.setItem( 'wc_cart_hash', data.cart_hash );
}
$('body').trigger( 'wc_fragments_refreshed' );
$( 'body' ).trigger( 'wc_fragments_refreshed' );
}
}
};
if ( $supports_html5_storage ) {
$('body').bind( 'added_to_cart', function( event, fragments, cart_hash ) {
$( 'body' ).bind( 'added_to_cart', function( event, fragments, cart_hash ) {
sessionStorage.setItem( wc_cart_fragments_params.fragment_name, JSON.stringify( fragments ) );
sessionStorage.setItem( "wc_cart_hash", cart_hash );
sessionStorage.setItem( 'wc_cart_hash', cart_hash );
});
try {
var wc_fragments = $.parseJSON( sessionStorage.getItem( wc_cart_fragments_params.fragment_name ) );
var cart_hash = sessionStorage.getItem( "wc_cart_hash" );
var cookie_hash = $.cookie( "woocommerce_cart_hash" );
var wc_fragments = $.parseJSON( sessionStorage.getItem( wc_cart_fragments_params.fragment_name ) ),
cart_hash = sessionStorage.getItem( 'wc_cart_hash' ),
cookie_hash = $.cookie( 'woocommerce_cart_hash' );
if ( cart_hash == null || cart_hash == undefined || cart_hash == '' )
if ( cart_hash === null || cart_hash === undefined || cart_hash === '' ) {
cart_hash = '';
}
if ( cookie_hash == null || cookie_hash == undefined || cookie_hash == '' )
if ( cookie_hash === null || cookie_hash === undefined || cookie_hash === '' ) {
cookie_hash = '';
}
if ( wc_fragments && wc_fragments['div.widget_shopping_cart_content'] && cart_hash == cookie_hash ) {
$.each( wc_fragments, function( key, value ) {
$(key).replaceWith(value);
$( key ).replaceWith(value);
});
$('body').trigger( 'wc_fragments_loaded' );
$( 'body' ).trigger( 'wc_fragments_loaded' );
} else {
throw "No fragment";
throw 'No fragment';
}
} catch(err) {
} catch( err ) {
$.ajax( $fragment_refresh );
}
@ -67,13 +70,14 @@ jQuery(function($) {
}
/* Cart hiding */
if ( $.cookie( "woocommerce_items_in_cart" ) > 0 )
$('.hide_cart_widget_if_empty').closest('.widget_shopping_cart').show();
else
$('.hide_cart_widget_if_empty').closest('.widget_shopping_cart').hide();
if ( $.cookie( 'woocommerce_items_in_cart' ) > 0 ) {
$( '.hide_cart_widget_if_empty' ).closest( '.widget_shopping_cart' ).show();
} else {
$( '.hide_cart_widget_if_empty' ).closest( '.widget_shopping_cart' ).hide();
}
$('body').bind( 'adding_to_cart', function() {
$('.hide_cart_widget_if_empty').closest('.widget_shopping_cart').show();
$( 'body' ).bind( 'adding_to_cart', function() {
$( '.hide_cart_widget_if_empty' ).closest( '.widget_shopping_cart' ).show();
} );
});

View File

@ -1 +1 @@
jQuery(function(a){if("undefined"==typeof wc_cart_fragments_params)return!1;if($supports_html5_storage="sessionStorage"in window&&null!==window.sessionStorage,$fragment_refresh={url:wc_cart_fragments_params.ajax_url,type:"POST",data:{action:"woocommerce_get_refreshed_fragments"},success:function(b){b&&b.fragments&&(a.each(b.fragments,function(b,c){a(b).replaceWith(c)}),$supports_html5_storage&&(sessionStorage.setItem(wc_cart_fragments_params.fragment_name,JSON.stringify(b.fragments)),sessionStorage.setItem("wc_cart_hash",b.cart_hash)),a("body").trigger("wc_fragments_refreshed"))}},$supports_html5_storage){a("body").bind("added_to_cart",function(a,b,c){sessionStorage.setItem(wc_cart_fragments_params.fragment_name,JSON.stringify(b)),sessionStorage.setItem("wc_cart_hash",c)});try{var b=a.parseJSON(sessionStorage.getItem(wc_cart_fragments_params.fragment_name)),c=sessionStorage.getItem("wc_cart_hash"),d=a.cookie("woocommerce_cart_hash");if((null==c||void 0==c||""==c)&&(c=""),(null==d||void 0==d||""==d)&&(d=""),!b||!b["div.widget_shopping_cart_content"]||c!=d)throw"No fragment";a.each(b,function(b,c){a(b).replaceWith(c)}),a("body").trigger("wc_fragments_loaded")}catch(e){a.ajax($fragment_refresh)}}else a.ajax($fragment_refresh);a.cookie("woocommerce_items_in_cart")>0?a(".hide_cart_widget_if_empty").closest(".widget_shopping_cart").show():a(".hide_cart_widget_if_empty").closest(".widget_shopping_cart").hide(),a("body").bind("adding_to_cart",function(){a(".hide_cart_widget_if_empty").closest(".widget_shopping_cart").show()})});
jQuery(function(e){if(typeof wc_cart_fragments_params==="undefined"){return false}$supports_html5_storage="sessionStorage"in window&&window.sessionStorage!==null;$fragment_refresh={url:wc_cart_fragments_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){sessionStorage.setItem(wc_cart_fragments_params.fragment_name,JSON.stringify(t.fragments));sessionStorage.setItem("wc_cart_hash",t.cart_hash)}e("body").trigger("wc_fragments_refreshed")}}};if($supports_html5_storage){e("body").bind("added_to_cart",function(e,t,n){sessionStorage.setItem(wc_cart_fragments_params.fragment_name,JSON.stringify(t));sessionStorage.setItem("wc_cart_hash",n)});try{var t=e.parseJSON(sessionStorage.getItem(wc_cart_fragments_params.fragment_name)),n=sessionStorage.getItem("wc_cart_hash"),r=e.cookie("woocommerce_cart_hash");if(n===null||n===undefined||n===""){n=""}if(r===null||r===undefined||r===""){r=""}if(t&&t["div.widget_shopping_cart_content"]&&n==r){e.each(t,function(t,n){e(t).replaceWith(n)});e("body").trigger("wc_fragments_loaded")}else{throw"No fragment"}}catch(i){e.ajax($fragment_refresh)}}else{e.ajax($fragment_refresh)}if(e.cookie("woocommerce_items_in_cart")>0){e(".hide_cart_widget_if_empty").closest(".widget_shopping_cart").show()}else{e(".hide_cart_widget_if_empty").closest(".widget_shopping_cart").hide()}e("body").bind("adding_to_cart",function(){e(".hide_cart_widget_if_empty").closest(".widget_shopping_cart").show()})})

View File

@ -1,37 +1,39 @@
jQuery(function($) {
jQuery( function( $ ) {
// wc_cart_params is required to continue, ensure the object exists
if (typeof wc_cart_params === "undefined")
if ( typeof wc_cart_params === 'undefined' ) {
return false;
}
// Shipping calculator
$(document).on( 'click', '.shipping-calculator-button', function() {
$('.shipping-calculator-form').slideToggle('slow');
$( document ).on( 'click', '.shipping-calculator-button', function() {
$( '.shipping-calculator-form' ).slideToggle( 'slow' );
return false;
}).on( 'change', 'select.shipping_method, input[name^=shipping_method]', function() {
var shipping_methods = [];
$('select.shipping_method, input[name^=shipping_method][type=radio]:checked, input[name^=shipping_method][type=hidden]').each( function( index, input ) {
shipping_methods[ $(this).data( 'index' ) ] = $(this).val();
$( 'select.shipping_method, input[name^=shipping_method][type=radio]:checked, input[name^=shipping_method][type=hidden]' ).each( function( index, input ) {
shipping_methods[ $( this ).data( 'index' ) ] = $( this ).val();
} );
$('div.cart_totals').block({message: null, overlayCSS: {background: '#fff url(' + wc_cart_params.ajax_loader_url + ') no-repeat center', backgroundSize: '16px 16px', opacity: 0.6}});
$( 'div.cart_totals' ).block({ message: null, overlayCSS: { background: '#fff url(' + wc_cart_params.ajax_loader_url + ') no-repeat center', backgroundSize: '16px 16px', opacity: 0.6 } });
var data = {
action: 'woocommerce_update_shipping_method',
security: wc_cart_params.update_shipping_method_nonce,
shipping_method: shipping_methods
action: 'woocommerce_update_shipping_method',
security: wc_cart_params.update_shipping_method_nonce,
shipping_method: shipping_methods
};
$.post( wc_cart_params.ajax_url, data, function(response) {
$.post( wc_cart_params.ajax_url, data, function( response ) {
$('div.cart_totals').replaceWith( response );
$('body').trigger('updated_shipping_method');
$( 'div.cart_totals' ).replaceWith( response );
$( 'body' ).trigger( 'updated_shipping_method' );
});
})
});
$('.shipping-calculator-form').hide();
$( '.shipping-calculator-form' ).hide();
});

View File

@ -1 +1 @@
jQuery(function(a){return"undefined"==typeof wc_cart_params?!1:(a(document).on("click",".shipping-calculator-button",function(){return a(".shipping-calculator-form").slideToggle("slow"),!1}).on("change","select.shipping_method, input[name^=shipping_method]",function(){var b=[];a("select.shipping_method, input[name^=shipping_method][type=radio]:checked, input[name^=shipping_method][type=hidden]").each(function(){b[a(this).data("index")]=a(this).val()}),a("div.cart_totals").block({message:null,overlayCSS:{background:"#fff url("+wc_cart_params.ajax_loader_url+") no-repeat center",backgroundSize:"16px 16px",opacity:.6}});var c={action:"woocommerce_update_shipping_method",security:wc_cart_params.update_shipping_method_nonce,shipping_method:b};a.post(wc_cart_params.ajax_url,c,function(b){a("div.cart_totals").replaceWith(b),a("body").trigger("updated_shipping_method")})}),void a(".shipping-calculator-form").hide())});
jQuery(function(e){if(typeof wc_cart_params==="undefined"){return false}e(document).on("click",".shipping-calculator-button",function(){e(".shipping-calculator-form").slideToggle("slow");return false}).on("change","select.shipping_method, input[name^=shipping_method]",function(){var t=[];e("select.shipping_method, input[name^=shipping_method][type=radio]:checked, input[name^=shipping_method][type=hidden]").each(function(n,r){t[e(this).data("index")]=e(this).val()});e("div.cart_totals").block({message:null,overlayCSS:{background:"#fff url("+wc_cart_params.ajax_loader_url+") no-repeat center",backgroundSize:"16px 16px",opacity:.6}});var n={action:"woocommerce_update_shipping_method",security:wc_cart_params.update_shipping_method_nonce,shipping_method:t};e.post(wc_cart_params.ajax_url,n,function(t){e("div.cart_totals").replaceWith(t);e("body").trigger("updated_shipping_method")})});e(".shipping-calculator-form").hide()})