PageSourceSearch

https://www.onegreenplanet.org/wp-content/plugins/woocommerce/assets/js/frontend/address-i18n.js?ver=11.1.2

js onegreenplanet.org collected 2026-09-24 08:39:06 UTC 5,085 bytes, 148 lines download raw bytes

1/*global wc_address_i18n_params */
2jQuery( function( $ ) {
3
4	// wc_address_i18n_params is required to continue, ensure the object exists
5	if ( typeof wc_address_i18n_params === 'undefined' ) {
6		return false;
7	}
8
9	var locale_json = wc_address_i18n_params.locale.replace( /"/g, '"' ), locale = JSON.parse( locale_json );
10
11	function field_is_required( field, is_required ) {
12		if ( is_required ) {
13			field.find( 'label .optional' ).remove();
14			field.addClass( 'validate-required' );
15
16			if ( field.find( 'label .required[aria-hidden="true"]' ).length === 0 ) {
17				field.find( 'label' ).append(
18					'&nbsp;<span class="required" aria-hidden="true">*</span>'
19				);
20			}
21		} else {
22			field.find( 'label .required' ).remove();
23			field.removeClass( 'validate-required woocommerce-invalid woocommerce-invalid-required-field' );
24
25			if ( field.find( 'label .optional' ).length === 0 ) {
26				field.find( 'label' ).append( '&nbsp;<span class="optional">(' + wc_address_i18n_params.i18n_optional_text + ')</span>' );
27			}
28		}
29	}
30
31	// Handle locale
32	$( document.body )
33		.on( 'country_to_state_changing', function( event, country, wrapper ) {
34			var thisform = wrapper, thislocale;
35
36			if ( typeof locale[ country ] !== 'undefined' ) {
37				thislocale = locale[ country ];
38			} else {
39				thislocale = locale['default'];
40			}
41
42			var $postcodefield = thisform.find( '#billing_postcode_field, #shipping_postcode_field, #calc_shipping_postcode_field' ),
43				$cityfield     = thisform.find( '#billing_city_field, #shipping_city_field, #calc_shipping_city_field' ),
44				$statefield    = thisform.find( '#billing_state_field, #shipping_state_field, #calc_shipping_state_field' );
45
46			if ( ! $postcodefield.attr( 'data-o_class' ) ) {
47				$postcodefield.attr( 'data-o_class', $postcodefield.attr( 'class' ) );
48				$cityfield.attr( 'data-o_class', $cityfield.attr( 'class' ) );
49				$statefield.attr( 'data-o_class', $statefield.attr( 'class' ) );
50			}
51
52			var locale_fields = JSON.parse( wc_address_i18n_params.locale_fields );
53
54			$.each( locale_fields, function( key, value ) {
55
56				var field       = thisform.find( value ),
57					fieldLocale = $.extend( true, {}, locale['default'][ key ], thislocale[ key ] );
58
59				// Labels.
60				if ( typeof fieldLocale.label !== 'undefined' ) {
61					field.find( 'label' ).html( fieldLocale.label );
62				}
63
64				// Placeholders.
65				if ( typeof fieldLocale.placeholder !== 'undefined' ) {
66					field.find( ':input' ).attr( 'placeholder', fieldLocale.placeholder );
67					field.find( ':input' ).attr( 'data-placeholder', fieldLocale.placeholder );
68					field.find( '.select2-selection__placeholder' ).text( fieldLocale.placeholder );
69				}
70
71				// Use the i18n label as a placeholder if there is no label element and no i18n placeholder.
72				if (
73					typeof fieldLocale.placeholder === 'undefined' &&
74					typeof fieldLocale.label !== 'undefined' &&
75					! field.find( 'label:not(.screen-reader-text)' ).length
76				) {
77					field.find( ':input' ).attr( 'placeholder', fieldLocale.label );
78					field.find( ':input' ).attr( 'data-placeholder', fieldLocale.label );
79					field.find( '.select2-selection__placeholder' ).text( fieldLocale.label );
80				}
81
82				// Required.
83				if ( typeof fieldLocale.required !== 'undefined' ) {
84					field_is_required( field, fieldLocale.required );
85				} else {
86					field_is_required( field, false );
87				}
88
89				// Priority.
90				if ( typeof fieldLocale.priority !== 'undefined' ) {
91					field.data( 'priority', fieldLocale.priority );
92				}
93
94				// Hidden fields. State visibility (show) is managed by
95				// country-select.js, but locale can still hide it.
96				if ( true === fieldLocale.hidden ) {
97					field.hide().find( ':input' ).val( '' );
98				} else if ( 'state' !== key ) {
99					field.show();
100				}
101
102				// Class changes.
103				if ( Array.isArray( fieldLocale.class ) ) {
104					field.removeClass( 'form-row-first form-row-last form-row-wide' );
105					field.addClass( fieldLocale.class.join( ' ' ) );
106				}
107			});
108
109			var fieldsets = $(
110				'.woocommerce-billing-fields__field-wrapper,' +
111				'.woocommerce-shipping-fields__field-wrapper,' +
112				'.woocommerce-address-fields__field-wrapper,' +
113				'.woocommerce-additional-fields__field-wrapper .woocommerce-account-fields'
114			);
115
116			fieldsets.each( function( index, fieldset ) {
117				var rows    = $( fieldset ).find( '.form-row' );
118				var wrapper = rows.first().parent();
119
120				// Before sorting, ensure all fields have a priority for bW compatibility.
121				var last_priority = 0;
122
123				rows.each( function() {
124					if ( ! $( this ).data( 'priority' ) ) {
125							$( this ).data( 'priority', last_priority + 1 );
126					}
127					last_priority = $( this ).data( 'priority' );
128				} );
129
130				// Sort the fields.
131				rows.sort( function( a, b ) {
132					var asort = parseInt( $( a ).data( 'priority' ), 10 ),
133						bsort = parseInt( $( b ).data( 'priority' ), 10 );
134
135					if ( asort > bsort ) {
136						return 1;
137					}
138					if ( asort < bsort ) {
139						return -1;
140					}
141					return 0;
142				});
143
144				rows.detach().appendTo( wrapper );
145			});
146		})
147		.trigger( 'wc_address_i18n_ready' );
148});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.