PageSourceSearch

https://indrik.ru/wp-content/plugins/woocommerce-edostavka/assets/…/checkout-city-select.js?ver=2.2.5.5

js indrik.ru collected 2026-10-02 11:11:56 UTC 6,912 bytes, 201 lines download raw bytes

1( function( $, params ) {
2
3	const wc_edostavka_city_select = {
4		init: function() {
5			this.loadCityfield 			= this.loadCityfield.bind( this );
6			this.billingCountry 		= this.billingCountry.bind( this );
7			this.loadCityfieldForCart 	= this.loadCityfieldForCart.bind( this );
8			this.refreshAddressField 	= this.refreshAddressField.bind( this );
9			this.setCustomerLocation 	= this.setCustomerLocation.bind( this );
10			this.isBlocked				= this.isBlocked.bind( this );
11			this.blockNode				= this.blockNode.bind( this );
12			this.unBlock				= this.unBlock.bind( this );
13
14			$( document.body ).on( 'updated_checkout', this.loadCityfield );
15			//$( document.body ).on( 'country_to_state_changed', this.loadCityfield );
16			$( document.body ).on( 'change', '.country_to_state', this.loadCityfieldForCart );
17			$( document.body ).on( 'updated_checkout_city', this.refreshAddressField );
18
19			if( !!params.is_edit_address ) {
20				this.loadCityfield();
21			}
22		},
23		loadCityfield: function () {
24
25			const self 		= this;
26			const fields 	= self.cityFieldElements.join( ', ' );
27
28			if( params.enable_dropdown_city == 'enable' || ( params.enable_dropdown_city == 'zone' && $.inArray( this.billingCountry(), params.allowed_zone ) !== -1 ) ) {
29
30				$( fields ).off( 'select2:select' );
31
32				$( fields ).WCEdostavkaSelectCity( {
33					placeholder: params.i18n_strings.enter_city_name,
34					defaultValue: params.default_city,
35					countryCode: this.billingCountry(),
36					allowTags: params.enable_custom_city,
37					minimumInputLength: 0,
38					ajaxUrl: params.ajax_url,
39					customerLocation: params.customer_location
40				} );
41
42				$( fields ).on( 'select2:select', function( event ) {
43
44					const stateFields = self.stateFieldElements.join( ', ' );
45					const data = event.params.data;
46
47					if( $( stateFields ).length && $( stateFields ).is( 'input' ) ) {
48						const region = data.region ? data.region : null;
49						$( stateFields ).val( region ).change();
50					}
51
52					self.setCustomerLocation( data );
53
54					params.customer_location = $.extend( {}, params.customer_location, {
55						city: data?.id,
56						city_code: data?.code
57					}, data )
58
59					if( !!params.is_checkout ) {
60						//$( document.body ).trigger( 'update_checkout' );
61						$( document.body ).trigger( 'updated_checkout_city', [ data ] );
62					}
63				} );
64
65				$( fields ).on('select2:open', function() {
66					$('.select2-search__field').prop('placeholder', params.i18n_strings.enter_city_name );
67				} );
68
69			} else {
70
71				var $elements = $( fields ),
72					input_name    = $elements.attr( 'name' ),
73					input_id      = $elements.attr('id'),
74					input_classes = $elements.attr('data-input-classes'),
75					value         = $elements.val(),
76					placeholder   = $elements.attr( 'placeholder' ) || $elements.attr( 'data-placeholder' ) || '',
77					$newelements;
78
79				if ( $elements.is( 'select, input[type="hidden"]' ) ) {
80					$newelements = $( '<input type="text" />' )
81						.prop( 'id', input_id )
82						.prop( 'name', input_name )
83						.prop('placeholder', placeholder)
84						.attr('data-input-classes', input_classes )
85						.addClass( 'input-text  ' + input_classes );
86					$elements.filter( '.select2-hidden-accessible' ).selectWoo( 'destroy' );
87					$elements.replaceWith( $newelements );
88					$elements.off( 'select2:select' );
89				}
90			}
91		},
92		loadCityfieldForCart: function( event ) {
93			if( !!params.is_cart ) {
94				this.loadCityfield();
95			}
96		},
97		refreshAddressField: function () {
98			if( !!params.clean_address_field ) {
99				$( this.addressFields.join( ', ' ) ).val( null ).change();
100			}
101		},
102		setCustomerLocation: function( location ) {
103			const self = this;
104			if( location ) {
105				$.post( params.wc_ajax_url.toString().replace( '%%endpoint%%', 'edostavka_set_customer_location' ), {
106					customer_id: params.customer_id,
107					location,
108					beforeSend: function() {
109
110						if( !! params.is_cart ) {
111							self.blockNode( $( 'form.woocommerce-shipping-calculator' ) );
112							$( 'button[name="calc_shipping"]').prop( 'disabled', true );
113						}
114
115						if( !! params.is_checkout ) {
116							$( self.cityFieldElements.join( ', ' ) )
117								.prop( 'disabled', true )
118								.parent()
119								.find( '.select2-container' )
120								.css( { opacity: .65 } )
121								.find( '.select2-selection' )
122								.css( 'cursor', 'wait' );
123							self.blockNode( $( '.woocommerce-checkout-review-order-table' ) );
124						}
125					}
126				} ).done(function () {
127
128					if( !! params.is_cart ) {
129						self.unBlock( $('form.woocommerce-shipping-calculator') );
130						$( 'button[name="calc_shipping"]' ).prop('disabled', false);
131					}
132
133					if( !! params.is_checkout ) {
134						$( self.cityFieldElements.join( ', ' ) )
135							.prop( 'disabled', false )
136							.parent()
137							.find( '.select2-container' )
138							.css( { opacity: 1 } )
139							.find( '.select2-selection' )
140							.css( 'cursor', 'pointer' );
141						self.unBlock( $( '.woocommerce-checkout-review-order-table' ) );
142						$( document.body ).trigger( 'update_checkout' );
143					}
144				} );
145			}
146		},
147		countryFieldElements: [
148			'#billing_country',
149			'#shipping_country',
150			'#calc_shipping_country'
151		],
152		stateFieldElements: [
153			'#billing_state',
154			'#shipping_state',
155			'#calc_shipping_state'
156		],
157		addressFields: [
158			'#billing_address_1',
159			'#shipping_address_1'
160		],
161		cityFieldElements: [
162			'#billing_city',
163			'#shipping_city',
164			'#calc_shipping_city'
165		],
166		billingCountry: function () {
167			/**
168			 * Тут код может выглядеть немного запутанным.
169			 * Мы сначала получаем значение из поля "Страна", и если значение default или undefined то тогда возвращаем страну пользователя.
170			 * Страну пользователя получаем следующим алгоритмом, если значение country_value default, то используем страну магазина по умолчанию, иначе используем значение страны пользователя.
171			 */
172			const country_value = $( this.countryFieldElements.join( ',' ) ).val();
173			return $.inArray( country_value, [ 'default', 'undefined' ] ) !== -1 ?
174				( params.customer_country ?
175						( country_value == 'default' ? params.default_country : params.customer_country ) :
176						params.default_country
177				) :
178				country_value
179		},
180		isBlocked: function ( $node ) {
181			return $node.is( '.processing' ) || $node.parents( '.processing' ).length;
182		},
183		blockNode: function( $node, message = null ) {
184			if ( ! this.isBlocked( $node ) ) {
185				$node.addClass( 'processing' ).block( {
186					message: message,
187					overlayCSS: {
188						background: '#fff',
189						opacity: 0.6
190					}
191				} );
192			}
193		},
194		unBlock:function( $node ) {
195			$node.removeClass( 'processing' ).unblock();
196		}
197	};
198
199	wc_edostavka_city_select.init();
200
201} )( jQuery, edostavka_checkout_params );

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.