result.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. OC.search.catagorizeResults=function(results){
  2. var types={};
  3. for(var i=0;i<results.length;i++){
  4. var type=results[i].type;
  5. if(!types[type]){
  6. types[type]=[];
  7. }
  8. types[type].push(results[i]);
  9. }
  10. return types;
  11. }
  12. OC.search.hide=function(){
  13. $('#searchresults').hide();
  14. if($('#searchbox').val().length>2){
  15. $('#searchbox').val('');
  16. };
  17. }
  18. OC.search.showResults=function(results){
  19. if(results.length==0){
  20. return;
  21. }
  22. if(!OC.search.showResults.loaded){
  23. var parent=$('<div/>');
  24. $('body').append(parent);
  25. parent.load(OC.filePath('search','templates','part.results.php'),function(){
  26. OC.search.showResults.loaded=true;
  27. $('#searchresults').click(function(event){
  28. OC.search.hide();
  29. event.stopPropagation();
  30. });
  31. $(window).click(function(event){
  32. OC.search.hide();
  33. });
  34. OC.search.lastResults=results;
  35. OC.search.showResults(results);
  36. });
  37. }else{
  38. var types=OC.search.catagorizeResults(results);
  39. $('#searchresults').show();
  40. $('#searchresults tr.result').remove();
  41. var index=0;
  42. for(var name in types){
  43. var type=types[name];
  44. if(type.length>0){
  45. for(var i=0;i<type.length;i++){
  46. var row=$('#searchresults tr.template').clone();
  47. row.removeClass('template');
  48. row.addClass('result');
  49. if (i == 0){
  50. row.children('td.type').text(name);
  51. }
  52. row.find('td.result a').attr('href',type[i].link);
  53. row.find('td.result div.name').text(type[i].name);
  54. row.find('td.result div.text').text(type[i].text);
  55. row.data('index',index);
  56. index++;
  57. if(OC.search.customResults[name]){//give plugins the ability to customize the entries in here
  58. OC.search.customResults[name](row,type[i]);
  59. }
  60. $('#searchresults tbody').append(row);
  61. }
  62. }
  63. }
  64. }
  65. }
  66. OC.search.showResults.loaded=false;
  67. OC.search.renderCurrent=function(){
  68. if($('#searchresults tr.result')[OC.search.currentResult]){
  69. var result=$('#searchresults tr.result')[OC.search.currentResult];
  70. $('#searchresults tr.result').removeClass('current');
  71. $(result).addClass('current');
  72. }
  73. }