function var cityModalBodyRow var cityModalBody var defaultCityId var

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
(function(_, $) {
var cityModalBodyRow;
var cityModalBody;
var defaultCityId;
var defaultCityName;
var savedCityId = +$.cookie.get('_abumba_selected_city_id') || '';
var defaultIfNotFoundCityData = {
externalId : 757,
displayName: "Санкт-Петербург"
};
function onCityReceived(data) {
if (!data.externalId) data = defaultIfNotFoundCityData;
defaultCityId = data.externalId;
defaultCityName = data.displayName;
$('.city-selector-auto').html(data.displayName);
$abumba.cityId = data.externalId;
$abumba.onCityChange();
}
function onVeryTopCitiesReceived(data) {
var topCities = cityModalBody.find('.main-cities .cap-limiter');
for (var i = 0, city; city = data[i++];) {
topCities.append('<a href="#" class="capitals modal-city-select-city" data:city-id="' + city.externalId + '">' + city.displayName + '</a>');
}
}
function onTopReceived(data) {
var citiesInColumn = Math.ceil(data.length / 3);
for (var i = 0, city; city = data[i]; i++) {
if (i % citiesInColumn == 0) {
var column = $('<div class="col-md-3 col-sm-3 col-xs-3 other-cities"></div>');
cityModalBodyRow.append(column);
}
column.append('<div><a href="#" class="dotted modal-city-select-city" data:city-id="' + city.externalId + '">' + city.displayName + '</a></div>')
}
}
function selectCity(city) {
$('#modal-city').modal('hide');
$('.city-selector-auto').html(city.label);
$.cookie.set('_abumba_selected_city_id', city.externalId);
console.log('selecting city', city);
$abumba.cityId = city.externalId;
$abumba.onCityChange();
}
$(function() {
if (!savedCityId) {
$('#city-locator').show();
}
cityModalBody = $('#modal-city .modal-body');
cityModalBodyRow = $('#modal-city .modal-body .row');
var cityModal = $('#modal-city');
var autoCompleteInited = false;
$('#set-city .btn').click(function () {
$('#city-locator').hide();
selectCity({
externalId : defaultCityId,
label : defaultCityName
})
});
cityModal.on('shown.bs.modal', function() {
$('.search-city-auto-input').val('');
if (!autoCompleteInited) {
autoCompleteInited = true;
//TODO add loader
$.ajax({
url: 'http://tourit.ru/e-com/shipping/citiesInGroup?name=very_top_cities',
dataType: 'json',
success: function (data) {
onVeryTopCitiesReceived(data);
}
});
$.ajax({
url: 'http://tourit.ru/e-com/shipping/citiesInGroup?name=top_cities',
dataType: 'json',
success: function (data) {
onTopReceived(data);
}
});
cityModalBody.find('.search-city input').autocomplete({
appendTo: cityModalBody.find('.search-city'),
delay: 350,
minLength: 2,
select: function (event, ui) {
event.preventDefault();
selectCity(ui.item);
},
source: function (request, response) {
$.ajax({
url: 'http://tourit.ru/e-com/shipping/autocompleteCity?q=' + request.term,
dataType: 'json',
success: function (data) {
var output = [];
if (data && data.length) {
for (var i = 0, item; item = data[i++];) {
if (i > 20) {
break;
}
output.push({
label: item.displayName,
value: item.displayName,
externalId : item.externalId
});
}
}
response(output);
}
})
}
})
}
})
$('#city-locator-select-another, #my-city-main-text').click(function() {
$('#city-locator').hide();
cityModal.modal('show');
});
cityModalBody.on('click', function(event) {
var item = $(event.target);
if (item.is('.modal-city-select-city')) {
selectCity({
externalId : item.attr('data:city-id'),
label : item.html()
})
}
});
$.ajax({
url: 'http://tourit.ru/e-com/shipping/getCity?externalId=' + savedCityId,
dataType: 'json',
success: function (data) {
onCityReceived(data);
}
});
});
}(Tygh, Tygh.$));