summaryrefslogtreecommitdiffstats
path: root/src/extsearch_js.h
blob: dc72659e0cc82e95340c9aba3c0f93648ded691c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
"function SearchBox(name, resultsPath, inFrame, label)\n"
"{\n"
"  this.searchLabel = label;\n"
"  this.DOMSearchField = function()\n"
"  {  return document.getElementById(\"MSearchField\");  }\n"
"  this.DOMSearchBox = function()\n"
"  {  return document.getElementById(\"MSearchBox\");  }\n"
"  this.OnSearchFieldFocus = function(isActive)\n"
"  {\n"
"    if (isActive)\n"
"    {\n"
"      this.DOMSearchBox().className = 'MSearchBoxActive';\n"
"      var searchField = this.DOMSearchField();\n"
"      if (searchField.value == this.searchLabel) \n"
"      {\n"
"        searchField.value = '';\n"
"      }\n"
"    }\n"
"    else\n"
"    {\n"
"      this.DOMSearchBox().className = 'MSearchBoxInactive';\n"
"      this.DOMSearchField().value   = this.searchLabel;\n"
"    }\n"
"  }\n"
"}\n"
"\n"
"function trim(s) {\n"
"  return s?s.replace(/^\\s\\s*/, '').replace(/\\s\\s*$/, ''):'';\n"
"}\n"
"\n"
"function getURLParameter(name) {\n"
"  return decodeURIComponent((new RegExp('[?|&]'+name+\n"
"         '='+'([^&;]+?)(&|#|;|$)').exec(location.search)\n"
"         ||[,\"\"])[1].replace(/\\+/g, '%20'))||null;\n"
"}\n"
"\n"
"var entityMap = {\n"
"  \"&\": \"&\",\n"
"  \"<\": \"&lt;\",\n"
"  \">\": \"&gt;\",\n"
"  '\"': '&quot;',\n"
"  \"'\": '&#39;',\n"
"  \"/\": '&#x2F;'\n"
"};\n"
"\n"
"function escapeHtml(s) {\n"
"  return String(s).replace(/[&<>\"'\\/]/g, function (s) {\n"
"    return entityMap[s];\n"
"  });\n"
"}\n"
"\n"
"function searchFor(query,page,count) {\n"
"  $.getJSON(serverUrl+\"?cb=?\",\n"
"  {\n"
"    n:count,\n"
"    p:page,\n"
"    q:query\n"
"  },\n"
"  function(data) {\n"
"    var results = $('#searchresults');\n"
"    $('#MSearchField').val(query);\n"
"    if (data.hits>0) {\n"
"      if (data.hits==1) {\n"
"        results.html('<p>'+searchResultsText[1]+'</p>');\n"
"      } else {\n"
"        results.html('<p>'+searchResultsText[2].replace(/\\$num/,data.hits)+'</p>');\n"
"      }\n"
"      var r='<table>';\n"
"      $.each(data.items, function(i,item){\n"
"        var prefix = tagMap[item.tag];\n"
"        if (prefix) prefix+='/'; else prefix='';\n"
"        r+='<tr class=\"searchresult\">'+\n"
"           '<td align=\"right\">'+(data.first+i+1)+'.</td>'+\n"
"           '<td>'+escapeHtml(item.type)+'&#160;'+\n"
"                '<a href=\"'+escapeHtml(prefix+item.url)+\n"
"                '\">'+escapeHtml(item.name)+'</a>';\n"
"        if (item.type==\"source\") {\n"
"          var l=item.url.match(/[1-9][0-9]*$/);\n"
"          if (l) r+=' at line '+parseInt(l[0]);\n"
"        }\n"
"        r+='</td>';\n"
"        for (var i=0;i<item.fragments.length;i++)\n"
"        {\n"
"          r+='<tr><td></td><td>'+item.fragments[i]+'</td></tr>';\n"
"        }\n"
"        r+='</tr>';\n"
"      });\n"
"      r+='</table>';\n"
"      if (data.pages>1) // write multi page navigation bar\n"
"      {\n"
"        r+='<div class=\"searchpages\">';\n"
"        if (data.page>0)\n"
"        {\n"
"          r+='<span class=\"pages\"><a href=\"javascript:searchFor(\\''+escapeHtml(query)+'\\','+(page-1).toString()+','+count.toString()+')\">&laquo;</a></span>&nbsp;';\n"
"        }\n"
"        var firstPage = data.page-5;\n"
"        var lastPage  = data.page+5;\n"
"        if (firstPage<0)\n"
"        {\n"
"          lastPage-=firstPage;\n"
"          firstPage=0;\n"
"        }  \n"
"        if (lastPage>data.pages)\n"
"        {\n"
"          lastPage=data.pages;\n"
"        }\n"
"        for(var i=firstPage;i<lastPage;i++)\n"
"        {\n"
"          if (i==data.page)\n"
"          {\n"
"            r+='<span class=\"pages\"><b>'+(i+1).toString()+'</b></span>&nbsp;';\n"
"          }\n"
"          else\n"
"          {\n"
"            r+='<span class=\"pages\"><a href=\"javascript:searchFor(\\''+escapeHtml(query)+'\\','+i.toString()+','+count.toString()+')\">'+(i+1).toString()+'</a></span>&nbsp;';\n"
"          }\n"
"        }\n"
"        if (data.page+1<data.pages)\n"
"        {\n"
"          r+='<span class=\"pages\"><a href=\"javascript:searchFor(\\''+escapeHtml(query)+'\\','+(page+1).toString()+','+count.toString()+')\">&raquo;</a></span>';\n"
"        }\n"
"        r+='</div>';\n"
"      }\n"
"      results.append(r);\n"
"    } else {\n"
"      results.html('<p>'+searchResultsText[0]+'</p>');\n"
"    }\n"
"  });\n"
"}\n"