PageSourceSearch

https://ponyexpress.kz/local/templates/ponyexpress_main/js/autocomplete.js?17660610798341

js ponyexpress.kz collected 2026-09-26 09:55:36 UTC 8,341 bytes, 266 lines download raw bytes

1var
2	url = 'https://search-pe-dd.ponyexpress.ru',
3	data = {},
4	city = '',
5	region = '',
6	street = '',
7	country = 'Казахстан';
8
9var config = {
10	headers:{
11		'Accept': '*/*',
12		'Authorization': '',
13	}
14};
15
16(function () {
17	return axios.get('https://integrationauth-service.ponyexpress.ru/api/v1/token?apikey=39A18951-636F-464E-B97D-0D6C7BF9573C', {
18		params: {},
19	}).then(function (response) {
20		config.headers.Authorization = 'Bearer ' + response.data.Token;
21		return response;
22	}).catch(function (error) {});
23})()
24
25$(function() {
26	$('[data-type="street"]').after('<ul class="autocomplete__list"></ul>');
27	$('[data-type="house"]').after('<ul class="autocomplete__list"></ul>');
28	$('[data-type="country"]').after('<ul class="autocomplete__list"></ul>');
29	$('[data-type="country"]').data('country', $('[data-type="country"]').val());
30
31	$(document).on('change', 'select[data-type="country"]' , function() {
32		country = $(this).val();
33	})
34
35	$(document).on('click', '.autocomplete__list li' , function() {
36		var $type = $(this).parent().parent().find('[data-type]');
37		var $correct = $(this).parent().next('input');
38		if ($type.attr('data-type') === 'country') {
39			country = $(this).attr('data-country');
40			$type.val($(this).html());
41		}
42		else if ($type.attr('data-type') === 'locality') {
43			region = $(this).attr('data-region');
44			city = $(this).attr('data-city');
45			$type.val($(this).html());
46			$correct.val(city + ', ' + region);
47		}
48		else if ($type.attr('data-type') === 'street') {
49			$type.val($(this).html());
50			street = $(this).html();
51		}
52		else if ($type.attr('data-type') === 'house') {
53			$type.val($(this).html());
54		}
55
56		triggerChoice();
57	});
58});
59
60var liSelected, li, focus, newFocus;
61
62$('[data-type="locality"]').on('focus', function () {
63	focus = $(this);
64	newFocus = true;
65})
66
67$(window).keydown(function(e) {
68	li = focus.next().find('li');
69
70	if (e.which === 40) {
71		if (newFocus && liSelected) {
72			newFocus = false;
73			liSelected.removeClass('selected');
74			liSelected = li.eq(0).addClass('selected');
75		} else if (liSelected) {
76			liSelected.removeClass('selected');
77			next = liSelected.next();
78			if (next.length > 0) {
79				liSelected = next.addClass('selected');
80			} else {
81				liSelected = li.eq(0).addClass('selected');
82			}
83		} else {
84			liSelected = li.eq(0).addClass('selected');
85		}
86
87	} else if (e.which === 38) {
88		if (liSelected) {
89			liSelected.removeClass('selected');
90			next = liSelected.prev();
91			if (next.length > 0) {
92				liSelected = next.addClass('selected');
93			} else {
94				liSelected = li.last().addClass('selected');
95			}
96		} else {
97			liSelected = li.last().addClass('selected');
98		}
99	}
100	if (e.keyCode === 13) {
101		$('.autocomplete__list li.selected').parent().parent().find('[data-type]').val($('.autocomplete__list li.selected').html());
102		triggerChoice();
103	}
104});
105
106function addressListItem(type, locality, region, district) {
107	var cityType;
108	if (type === '') {
109		cityType = '';
110	} else {
111		cityType = type + '. ';
112	}
113
114	if (region !== '' && region !== null) {
115		if(district !== '' && district !== null){
116			return cityType + locality + ', ' + region + ', ' + district;
117		}
118		return cityType + locality + ', ' + region;
119	} else if (district !== '' && district !== null) {
120		return cityType + locality + ', ' + district;
121	} else {
122		return cityType + locality;
123	}
124}
125
126function capitalizeFirstLetter(string) {
127	return string.charAt(0).toUpperCase() + string.slice(1);
128}
129
130function selfQuery($self, $selfType) {
131	var $selfVal = $self.val();
132	url = 'https://search-pe-dd.ponyexpress.ru/Autocomplete/' + capitalizeFirstLetter($selfType);
133
134	if ($selfType === 'country') {
135		data = {
136			"query": $selfVal,
137			"packSize": 10,
138			"language": "Ru"
139		}
140	} else if ($selfType === 'locality') {
141		if ($self.attr('data-direction') === 'to') {
142			country = $('[data-type="country"][data-direction="to"]').val()
143		} else if ($self.attr('data-direction') === 'from') {
144			country = $('[data-type="country"][data-direction="from"]').val()
145		}
146		data = {
147			"country": country,
148			"region": "",
149			"district": "",
150			"query": $selfVal,
151			"packSize": 10,
152			"language": "Ru"
153		}
154	} else if ($selfType === 'street') {
155		data = {
156			"country": country,
157			"region": region,
158			"district": "",
159			"locality": city,
160			"query": $selfVal,
161			"packSize": 10,
162			"language": "Ru"
163		}
164	} else if ($selfType === 'house') {
165		data = {
166			"country": country,
167			"region": region,
168			"district": "",
169			"locality": city,
170			"street": street,
171			"query": "5",
172			"packSize": 10,
173			"language": "Ru"
174		}
175	}
176}
177
178$('[data-type]').on('input', function () {
179	var $self = $(this),
180		$selfType = $self.attr('data-type');
181
182	selfQuery($self, $selfType);
183
184	if($(this).val().length > 2 && $selfType === 'locality') {
185
186		if ($self.attr('name') === 'parcel[from_city]') {
187			data.country = $('[name="parcel[from_country]"]').val();
188		} else if($self.attr('name') === 'parcel[to_city]') {
189			data.country = $('[name="parcel[to_country]"]').val();
190		}
191
192		axios.post(url, data, config)
193			.then(function (response) {
194				$self.parent().find('.autocomplete__list').html('');
195				$.each(response.data.suggestions , function(index, val) {
196					//$self.parent().find('.autocomplete__list').append('<li data-city="' + val.locality + ',' + '" data-region="' + val.region + ',' + '" data-district="' + val.district + ' ">'+ addressListItem(val.localityType, val.locality, val.region, val.district) +'</li>');
197					$self.parent().find('.autocomplete__list').append('<li data-city="' + val.locality + '" data-region="' + val.region + '" data-district="' + val.district + ' ">'+ addressListItem(val.localityType, val.locality, val.region, val.district) +'</li>');
198				});
199			})
200			.catch(function (error) {
201				console.log(error);
202			})
203			.finally(function () {});
204	} else if ($(this).val().length > 0 && $selfType !== 'locality') {
205		if (this.getAttribute('id') === 'senderStreet') {
206			data.locality = $('[name="order[sender][city]"]').val();
207			data.region = $('[name="order[sender][city]"]').attr('data-region');
208			data.country = $('[name="parcel[from_country]"]').val();
209		} else if (this.getAttribute('id') === 'courier-recipient-street') {
210			data.locality = $('[name="order[recipient][city]"]').val();
211			data.region = $('[name="order[recipient][city]"]').attr('data-region');
212			data.country = $('[name="parcel[to_country]"]').val();
213		}
214
215		if (this.getAttribute('id') === 'senderHouse') {
216			data.query = this.value;
217			data.locality = $('[name="order[sender][city]"]').val();
218			data.street = $('#senderStreet').val();
219			data.region = $('[name="order[sender][city]"]').attr('data-region');
220			data.country = $('[name="parcel[from_country]"]').val();
221		} else if (this.getAttribute('id') === 'courier-recipient-house') {
222			data.query = this.value;
223			data.locality = $('[name="order[recipient][city]"]').val();
224			data.street = $('#courier-recipient-street').val();
225			data.region = $('[name="order[recipient][city]"]').attr('data-region');
226			data.country = $('[name="parcel[to_country]"]').val();
227		}
228		axios.post(url, data, config)
229			.then(function (response) {
230				$self.parent().find('.autocomplete__list').html('');
231				if ($selfType === 'country') {
232					$.each(response.data.suggestions , function(index, val) {
233						$self.parent().find('.autocomplete__list').append('<li data-country="'+ val +'">'+ val +'</li>');
234					});
235				}
236				else if ($selfType === 'street') {
237					$.each(response.data.suggestions , function(index, val) {
238						$self.parent().find('.autocomplete__list').append('<li>'+ val.street + '</li>');
239					});
240				}
241				else if ($selfType === 'house') {
242					$.each(response.data.suggestions , function(index, val) {
243						$self.parent().find('.autocomplete__list').append('<li>'+ val.houseNumber + '</li>');
244						$self.closest('.b-oferta__row').find('input[data-type="postcode"]').val(val.postalCode);
245
246						if ($self.attr('id') === 'senderHouse') {
247							$('#senderpostcode').val(val.postalCode);
248						} else if ($self.attr('id') === 'courier-recipient-house') {
249							$('#recipientpostcode').val(val.postalCode);
250						}
251					});
252				}
253			})
254			.catch(function (error) {
255				console.log(error);
256			})
257			.finally(function () {});
258
259	} else {
260		$self.parent().find('.autocomplete__list').html('');
261	}
262})
263
264function triggerChoice() {
265	$(this).parent().parent().find('[data-type]').trigger('change');
266}

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.