This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
lnapp/media/js/search.js

54 lines
1.1 KiB
JavaScript
Raw Normal View History

2014-02-17 00:29:11 +00:00
$(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){
$.ajax({
url : site_url+url,
type : 'GET',
data : 'term=' + query,
dataType : 'JSON',
async : true,
cache : false,
beforeSend : function() {
if (c++ == 0)
$('i[name=searching]').removeClass("hidden");
2014-02-17 00:29:11 +00:00
},
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)
$('i[name=searching]').addClass("hidden");
2014-02-17 00:29:11 +00:00
}
})
}, 500);