result.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. event.stopPropagation();
  29. });
  30. $(window).click(function(event){
  31. OC.search.hide();
  32. });
  33. OC.search.lastResults=results;
  34. OC.search.showResults(results);
  35. });
  36. }else{
  37. var types=OC.search.catagorizeResults(results);
  38. $('#searchresults').show();
  39. $('#searchresults tr.result').remove();
  40. var index=0;
  41. for(var name in types){
  42. var type=types[name];
  43. if(type.length>0){
  44. var row=$('#searchresults tr.template').clone();
  45. row.removeClass('template');
  46. row.addClass('result');
  47. row.children('td.type').text(name);
  48. row.find('td.result a').attr('href',type[0].link);
  49. row.find('td.result div.name').text(type[0].name);
  50. row.find('td.result div.text').text(type[0].text);
  51. row.data('index',index);
  52. index++;
  53. if(OC.search.customResults[name]){//give plugins the ability to customize the entries in here
  54. OC.search.customResults[name](row,type[0]);
  55. }
  56. $('#searchresults tbody').append(row);
  57. for(var i=1;i<type.length;i++){
  58. var row=$('#searchresults tr.template').clone();
  59. row.removeClass('template');
  60. row.addClass('result');
  61. row.find('td.result a').attr('href',type[i].link);
  62. row.find('td.result div.name').text(type[i].name);
  63. row.find('td.result div.text').text(type[i].text);
  64. row.data('index',index);
  65. index++;
  66. if(OC.search.customResults[name]){//give plugins the ability to customize the entries in here
  67. OC.search.customResults[name](row,type[i]);
  68. }
  69. $('#searchresults tbody').append(row);
  70. }
  71. }
  72. }
  73. }
  74. }
  75. OC.search.showResults.loaded=false;
  76. OC.search.renderCurrent=function(){
  77. if($('#searchresults tr.result')[OC.search.currentResult]){
  78. var result=$('#searchresults tr.result')[OC.search.currentResult];
  79. $('#searchresults tr.result').removeClass('current');
  80. $(result).addClass('current');
  81. }
  82. }