You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
3.7 KiB
115 lines
3.7 KiB
jQuery(function(){
|
|
function build_ac_list() {
|
|
//Пример списка городов для автокомплита
|
|
var regionsListSample =
|
|
[
|
|
{"id": 9990, "label": "Россия", "value": "Россия" },
|
|
{"id": 9991, "label": "Москва", "value": "Москва" },
|
|
{"id": 9992, "label": "Владивосток", "value": "Владивосток" },
|
|
{"id": 9993, "label": "Краснодар", "value": "Краснодар" },
|
|
{"id": 9994, "label": "Санкт-Петербург", "value": "Санкт-Петербург" }
|
|
|
|
];
|
|
//Построение списка автокомплита из списка регионовв поп-ап окне
|
|
var regionsList=[];
|
|
var i=0;
|
|
$('.places-list').find('li').each(
|
|
function() {
|
|
i++;
|
|
if ($(this).find('a').text().length>0) {
|
|
regionsList.push({"id": 9990+i, "label": $(this).find('>a').text(), value: $(this).text() });
|
|
}
|
|
else {
|
|
regionsList.push({"id": 9990+i, "label": $(this).find('>label').text(), value: $(this).text() });
|
|
}
|
|
|
|
}
|
|
);
|
|
return regionsList;
|
|
}
|
|
function attach_ac_list() {
|
|
var ac_target=$('.c-select-box.places .csb-title input');
|
|
var ac_holder=ac_target.parent();
|
|
ac_target.parent().append('<input id="reg_ac_hidden" style="display:none;">');
|
|
var ac_list=build_ac_list();
|
|
ac_target.bind( "keydown", function( event ) {
|
|
if ( event.keyCode === $.ui.keyCode.TAB &&
|
|
$( this ).data( "ui-autocomplete" ).menu.active ) {
|
|
event.preventDefault();
|
|
}
|
|
})
|
|
.autocomplete({
|
|
appendTo: ac_holder,
|
|
minLength: 1,
|
|
source: function (request, response) {
|
|
var term = $.ui.autocomplete.escapeRegex(request.term)
|
|
, startsWithMatcher = new RegExp("^" + term, "i")
|
|
, startsWith = $.grep(ac_list, function(value) {
|
|
return startsWithMatcher.test(value.label || value.value || value);
|
|
})
|
|
, containsMatcher = new RegExp(term, "i")
|
|
, contains = $.grep(ac_list, function (value) {
|
|
return $.inArray(value, startsWith) < 0 &&
|
|
containsMatcher.test(value.label || value.value || value);
|
|
});
|
|
response(startsWith.concat(contains));
|
|
},
|
|
focus: function() {
|
|
return false;
|
|
},
|
|
select: function( event, ui){
|
|
var item_to_select=ui.item.label;
|
|
$('#reg_ac_hidden').val(ui.item.id);
|
|
$('li label:contains("'+item_to_select+'")').each(
|
|
function() {
|
|
if ($(this).hasClass('active')) {
|
|
$('#ac_animes').css({'opacity':0,'display':'block'}).animate({opacity:1}, 500, function() {
|
|
setTimeout(function() {
|
|
$('#ac_animes').stop().animate({opacity:0}, 500, function() {
|
|
$('#ac_animes').css({'display':'none'})
|
|
});
|
|
}, 1000);
|
|
});
|
|
} else {
|
|
|
|
}
|
|
$(this).not('.active').trigger('click');
|
|
}
|
|
);
|
|
$('.places-list ul li a').each(
|
|
function() {
|
|
if ($(this).text().indexOf(item_to_select)!=-1) {
|
|
$(this).parent().find('ul li label').each(
|
|
function() {
|
|
$(this).not('.active').trigger("click");
|
|
}
|
|
);
|
|
}
|
|
}
|
|
);
|
|
|
|
$(this).val('');
|
|
return false;
|
|
}
|
|
});
|
|
|
|
}
|
|
function init_regions() {
|
|
attach_ac_list();
|
|
}
|
|
init_regions();
|
|
$('.q-sel ul li a').click(function() {
|
|
if ($('.places-list').find('label:not(".active"):contains("'+$(this).text()+'")').length>0) {
|
|
$('.places-list').find('label:not(".active"):contains("'+$(this).text()+'")').trigger('click'); }
|
|
else {
|
|
$('#ac_animes').css({'opacity':0,'display':'block'}).animate({opacity:1}, 500, function() {
|
|
setTimeout(function() {
|
|
$('#ac_animes').stop().animate({opacity:0}, 500, function() {
|
|
$('#ac_animes').css({'display':'none'})
|
|
});
|
|
}, 1000);
|
|
});
|
|
}
|
|
return false;
|
|
});
|
|
}); |