PageSourceSearch

https://www.vieuxboucau-surflodge.com/wp-content/plugins/woocommer…/js/frontend/address-i18n.js?ver=10.7.0

js vieuxboucau-surflodge.com collected 2026-10-10 02:04:16 UTC 5,053 bytes, 149 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.
95				if ( 'state' !== key ) {
96					if ( typeof fieldLocale.hidden !== 'undefined' && true === fieldLocale.hidden ) {
97						field.hide().find( ':input' ).val( '' );
98					} else {
99						field.show();
100					}
101				}
102
103				// Class changes.
104				if ( Array.isArray( fieldLocale.class ) ) {
105					field.removeClass( 'form-row-first form-row-last form-row-wide' );
106					field.addClass( fieldLocale.class.join( ' ' ) );
107				}
108			});
109
110			var fieldsets = $(
111				'.woocommerce-billing-fields__field-wrapper,' +
112				'.woocommerce-shipping-fields__field-wrapper,' +
113				'.woocommerce-address-fields__field-wrapper,' +
114				'.woocommerce-additional-fields__field-wrapper .woocommerce-account-fields'
115			);
116
117			fieldsets.each( function( index, fieldset ) {
118				var rows    = $( fieldset ).find( '.form-row' );
119				var wrapper = rows.first().parent();
120
121				// Before sorting, ensure all fields have a priority for bW compatibility.
122				var last_priority = 0;
123
124				rows.each( function() {
125					if ( ! $( this ).data( 'priority' ) ) {
126							$( this ).data( 'priority', last_priority + 1 );
127					}
128					last_priority = $( this ).data( 'priority' );
129				} );
130
131				// Sort the fields.
132				rows.sort( function( a, b ) {
133					var asort = parseInt( $( a ).data( 'priority' ), 10 ),
134						bsort = parseInt( $( b ).data( 'priority' ), 10 );
135
136					if ( asort > bsort ) {
137						return 1;
138					}
139					if ( asort < bsort ) {
140						return -1;
141					}
142					return 0;
143				});
144
145				rows.detach().appendTo( wrapper );
146			});
147		})
148		.trigger( 'wc_address_i18n_ready' );
149});

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.