{"version":3,"file":"../address-i18n-222.min.js","sources":["address-i18n-222.js"],"sourcesContent":["/**\n * Address Internationalization Script\n * \n * Replaces the original WooCommerce `address-i18n.js`.\n */\n\n/*global wc_address_i18n_params */\njQuery( function( $ ) {\n\n\t// wc_address_i18n_params is required to continue, ensure the object exists\n\tif ( typeof wc_address_i18n_params === 'undefined' ) {\n\t\treturn false;\n\t}\n\n\tvar locale_json = wc_address_i18n_params.locale.replace( /"/g, '\"' ), locale = JSON.parse( locale_json );\n\n\tfunction field_is_required( field, is_required ) {\n\t\tif ( is_required ) {\n\t\t\tfield.find( 'label .optional' ).remove();\n\t\t\tfield.addClass( 'validate-required' );\n\n\t\t\tif ( field.find( 'label .required' ).length === 0 ) {\n\t\t\t\tfield.find( 'label' ).append(\n\t\t\t\t\t' *'\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\tfield.find( 'label .required' ).remove();\n\t\t\tfield.removeClass( 'validate-required woocommerce-invalid woocommerce-invalid-required-field' );\n\n\t\t\tif ( field.find( 'label .optional' ).length === 0 ) {\n\t\t\t\tfield.find( 'label' ).append( ' (' + wc_address_i18n_params.i18n_optional_text + ')' );\n\t\t\t}\n\t\t}\n\t}\n\n\t// Handle locale\n\t$( document.body )\n\t\t.on( 'country_to_state_changing', function( event, country, wrapper ) {\n\t\t\tvar thisform = wrapper, thislocale;\n\n\t\t\tif ( typeof locale[ country ] !== 'undefined' ) {\n\t\t\t\tthislocale = locale[ country ];\n\t\t\t} else {\n\t\t\t\tthislocale = locale['default'];\n\t\t\t}\n\n\t\t\t// CHANGE: Add selector for address fields without prefix\n\t\t\tvar $postcodefield = thisform.find( '#postcode_field, #billing_postcode_field, #shipping_postcode_field' ),\n\t\t\t\t$cityfield = thisform.find( '#city_field, #billing_city_field, #shipping_city_field' ),\n\t\t\t\t$statefield = thisform.find( '#state_field, #billing_state_field, #shipping_state_field' );\n\n\t\t\tif ( ! $postcodefield.attr( 'data-o_class' ) ) {\n\t\t\t\t$postcodefield.attr( 'data-o_class', $postcodefield.attr( 'class' ) );\n\t\t\t\t$cityfield.attr( 'data-o_class', $cityfield.attr( 'class' ) );\n\t\t\t\t$statefield.attr( 'data-o_class', $statefield.attr( 'class' ) );\n\t\t\t}\n\n\t\t\tvar locale_fields = JSON.parse( wc_address_i18n_params.locale_fields );\n\n\t\t\t$.each( locale_fields, function( key, value ) {\n\n\t\t\t\tvar field = thisform.find( value ),\n\t\t\t\t\tfieldLocale = $.extend( true, {}, locale['default'][ key ], thislocale[ key ] );\n\n\t\t\t\t// Labels.\n\t\t\t\tif ( typeof fieldLocale.label !== 'undefined' ) {\n\t\t\t\t\tfield.find( 'label' ).html( fieldLocale.label );\n\t\t\t\t}\n\n\t\t\t\t// Placeholders.\n\t\t\t\tif ( typeof fieldLocale.placeholder !== 'undefined' ) {\n\t\t\t\t\tfield.find( ':input' ).attr( 'placeholder', fieldLocale.placeholder );\n\t\t\t\t\tfield.find( ':input' ).attr( 'data-placeholder', fieldLocale.placeholder );\n\t\t\t\t\tfield.find( '.select2-selection__placeholder' ).text( fieldLocale.placeholder );\n\t\t\t\t}\n\n\t\t\t\t// Use the i18n label as a placeholder if there is no label element and no i18n placeholder.\n\t\t\t\tif (\n\t\t\t\t\ttypeof fieldLocale.placeholder === 'undefined' &&\n\t\t\t\t\ttypeof fieldLocale.label !== 'undefined' &&\n\t\t\t\t\t! field.find( 'label' ).length\n\t\t\t\t) {\n\t\t\t\t\tfield.find( ':input' ).attr( 'placeholder', fieldLocale.label );\n\t\t\t\t\tfield.find( ':input' ).attr( 'data-placeholder', fieldLocale.label );\n\t\t\t\t\tfield.find( '.select2-selection__placeholder' ).text( fieldLocale.label );\n\t\t\t\t}\n\n\t\t\t\t// Required.\n\t\t\t\tif ( typeof fieldLocale.required !== 'undefined' ) {\n\t\t\t\t\tfield_is_required( field, fieldLocale.required );\n\t\t\t\t} else {\n\t\t\t\t\tfield_is_required( field, false );\n\t\t\t\t}\n\n\t\t\t\t// Priority.\n\t\t\t\tif ( typeof fieldLocale.priority !== 'undefined' ) {\n\t\t\t\t\tfield.data( 'priority', fieldLocale.priority );\n\t\t\t\t}\n\n\t\t\t\t// Hidden fields.\n\t\t\t\tif ( 'state' !== key ) {\n\t\t\t\t\tif ( typeof fieldLocale.hidden !== 'undefined' && true === fieldLocale.hidden ) {\n\t\t\t\t\t\tfield.hide().find( ':input' ).val( '' );\n\t\t\t\t\t} else {\n\t\t\t\t\t\tfield.show();\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Class changes.\n\t\t\t\tif ( Array.isArray( fieldLocale.class ) ) {\n\t\t\t\t\tfield.removeClass( 'form-row-first form-row-last form-row-wide' );\n\t\t\t\t\tfield.addClass( fieldLocale.class.join( ' ' ) );\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tvar fieldsets = $(\n\t\t\t\t'.woocommerce-billing-fields__field-wrapper,' +\n\t\t\t\t'.woocommerce-shipping-fields__field-wrapper,' +\n\t\t\t\t'.woocommerce-address-fields__field-wrapper,' +\n\t\t\t\t'.woocommerce-additional-fields__field-wrapper .woocommerce-account-fields'\n\t\t\t);\n\n\t\t\tfieldsets.each( function( index, fieldset ) {\n\t\t\t\t// CHANGE: Change form row selector to exclude nested `.form-row` elements (used for expansible form fields)\n\t\t\t\tvar rows = $( fieldset ).find( '.form-row:not( .form-row .form-row )' );\n\t\t\t\tvar wrapper = rows.first().parent();\n\n\t\t\t\t// Before sorting, ensure all fields have a priority for bW compatibility.\n\t\t\t\tvar last_priority = 0;\n\n\t\t\t\trows.each( function() {\n\t\t\t\t\tif ( ! $( this ).data( 'priority' ) ) {\n\t\t\t\t\t\t\t$( this ).data( 'priority', last_priority + 1 );\n\t\t\t\t\t}\n\t\t\t\t\tlast_priority = $( this ).data( 'priority' );\n\t\t\t\t} );\n\n\t\t\t\t// Sort the fields.\n\t\t\t\trows.sort( function( a, b ) {\n\t\t\t\t\tvar asort = parseInt( $( a ).data( 'priority' ), 10 ),\n\t\t\t\t\t\tbsort = parseInt( $( b ).data( 'priority' ), 10 );\n\n\t\t\t\t\tif ( asort > bsort ) {\n\t\t\t\t\t\treturn 1;\n\t\t\t\t\t}\n\t\t\t\t\tif ( asort < bsort ) {\n\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}\n\t\t\t\t\treturn 0;\n\t\t\t\t});\n\n\t\t\t\trows.detach().appendTo( wrapper );\n\t\t\t});\n\t\t})\n\t\t.trigger( 'wc_address_i18n_ready' );\n});\n"],"names":["jQuery","$","wc_address_i18n_params","locale_json","locale","replace","JSON","parse","field_is_required","field","is_required","find","remove","addClass","length","append","i18n_required_text","removeClass","i18n_optional_text","document","body","on","event","country","wrapper","thisform","thislocale","$postcodefield","$cityfield","$statefield","locale_fields","attr","each","key","value","fieldLocale","extend","label","html","placeholder","text","required","priority","data","hidden","hide","val","show","Array","isArray","class","join","index","fieldset","rows","first","parent","last_priority","this","sort","a","b","asort","parseInt","bsort","detach","appendTo","trigger"],"mappings":"AAOAA,OAAQ,SAAUC,GAGjB,GAAuC,oBAA3BC,uBACX,OAAO,EAGR,IAAIC,EAAcD,uBAAuBE,OAAOC,QAAS,UAAW,KAAOD,EAASE,KAAKC,MAAOJ,GAEhG,SAASK,EAAmBC,EAAOC,GAC7BA,GACJD,EAAME,KAAM,mBAAoBC,SAChCH,EAAMI,SAAU,qBAEgC,IAA3CJ,EAAME,KAAM,mBAAoBG,QACpCL,EAAME,KAAM,SAAUI,OACrB,uCACAb,uBAAuBc,mBACvB,gBAIFP,EAAME,KAAM,mBAAoBC,SAChCH,EAAMQ,YAAa,4EAE6B,IAA3CR,EAAME,KAAM,mBAAoBG,QACpCL,EAAME,KAAM,SAAUI,OAAQ,iCAAmCb,uBAAuBgB,mBAAqB,aAMhHjB,EAAGkB,SAASC,MACVC,GAAI,4BAA6B,SAAUC,EAAOC,EAASC,GAC3D,IAAIC,EAAWD,EAGdE,OADiC,IAAtBtB,EAAQmB,GACNnB,EAAQmB,GAERnB,EAAgB,QAI1BuB,EAAiBF,EAAS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