62 lines
1.3 KiB
JavaScript
62 lines
1.3 KiB
JavaScript
$(document).ready(function() {
|
|
$("input[name=search-query]").typeahead({
|
|
minLength: 2,
|
|
source: function (query,process) {
|
|
if(query.length==0) return false;
|
|
|
|
search('u/search/ajaxlist',query,process);
|
|
},
|
|
|
|
matcher: function () { return true; },
|
|
|
|
updater: function (item) {
|
|
window.parent.location.href = site_url+users[item];
|
|
},
|
|
});
|
|
});
|
|
|
|
var c=0;
|
|
var search = _.debounce(function(url,query,process,icon){
|
|
$.ajax({
|
|
url : site_url+url,
|
|
type : 'GET',
|
|
data : 'term=' + query,
|
|
dataType : 'JSON',
|
|
async : true,
|
|
cache : false,
|
|
beforeSend : function() {
|
|
if (c++ == 0) {
|
|
if (icon)
|
|
$('i[name='+icon+']').addClass("fa-spin");
|
|
else
|
|
$('i[name=searching]').removeClass("hidden");
|
|
}
|
|
},
|
|
success : function(data) {
|
|
// if json is null, means no match, won't do again.
|
|
if(data==null || (data.length===0)) return;
|
|
|
|
users = {};
|
|
userLabels = [];
|
|
|
|
_.each(data,function(item,ix,list) {
|
|
if (_.contains(users,item.label))
|
|
item.label = item.label + ' #' + item.value;
|
|
|
|
userLabels.push(item.label);
|
|
users[item.label] = item.value;
|
|
});
|
|
|
|
process(userLabels);
|
|
},
|
|
complete : function() {
|
|
if (--c == 0) {
|
|
if (icon)
|
|
$('i[name='+icon+']').removeClass("fa-spin");
|
|
else
|
|
$('i[name=searching]').addClass("hidden");
|
|
}
|
|
}
|
|
})
|
|
}, 500);
|