address-il8n jshinted and standard coding fixes

This commit is contained in:
splashingpixels 2014-03-17 19:51:53 -07:00
parent d466d055ac
commit cbb5a2fb55
2 changed files with 81 additions and 79 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)}})})