nextcloud/search/js/result.js

75 lines
2.0 KiB
JavaScript
Raw Normal View History

2011-07-30 23:18:54 +04:00
OC.search.catagorizeResults=function(results){
var types={};
for(var i=0;i<results.length;i++){
var type=results[i].type;
if(!types[type]){
types[type]=[];
}
types[type].push(results[i]);
}
return types;
}
OC.search.hide=function(){
$('#searchresults').hide();
if($('#searchbox').val().length>2){
$('#searchbox').val('');
};
}
OC.search.showResults=function(results){
if(results.length==0){
return;
}
2011-07-30 23:18:54 +04:00
if(!OC.search.showResults.loaded){
var parent=$('<div/>');
$('body').append(parent);
parent.load(OC.filePath('search','templates','part.results.php'),function(){
OC.search.showResults.loaded=true;
$('#searchresults').click(function(event){
OC.search.hide();
2011-07-30 23:18:54 +04:00
event.stopPropagation();
});
$(window).click(function(event){
OC.search.hide();
});
2011-07-31 06:03:48 +04:00
OC.search.lastResults=results;
2011-07-30 23:18:54 +04:00
OC.search.showResults(results);
});
}else{
var types=OC.search.catagorizeResults(results);
$('#searchresults').show();
$('#searchresults tr.result').remove();
2011-07-31 06:03:48 +04:00
var index=0;
2011-07-30 23:18:54 +04:00
for(var name in types){
var type=types[name];
if(type.length>0){
2012-06-22 19:43:57 +04:00
for(var i=0;i<type.length;i++){
2011-07-30 23:18:54 +04:00
var row=$('#searchresults tr.template').clone();
row.removeClass('template');
row.addClass('result');
if (i == 0){
2012-06-22 19:43:57 +04:00
row.children('td.type').text(name);
}
2011-07-30 23:18:54 +04:00
row.find('td.result a').attr('href',type[i].link);
row.find('td.result div.name').text(type[i].name);
row.find('td.result div.text').text(type[i].text);
2011-07-31 06:03:48 +04:00
row.data('index',index);
index++;
if(OC.search.customResults[name]){//give plugins the ability to customize the entries in here
OC.search.customResults[name](row,type[i]);
}
2011-07-30 23:18:54 +04:00
$('#searchresults tbody').append(row);
}
}
}
}
}
OC.search.showResults.loaded=false;
2011-07-31 06:03:48 +04:00
OC.search.renderCurrent=function(){
if($('#searchresults tr.result')[OC.search.currentResult]){
var result=$('#searchresults tr.result')[OC.search.currentResult];
$('#searchresults tr.result').removeClass('current');
$(result).addClass('current');
}
}