author | bpatel |
Thu, 13 Oct 2016 10:48:09 -0700 | |
changeset 41523 | da4f500b886d |
parent 41032 | 32be25e34c38 |
child 43762 | 515fe48569fe |
permissions | -rw-r--r-- |
33920 | 1 |
/* |
40511 | 2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
33920 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
var noResult = {l: "No results found"}; |
|
27 |
var category = "category"; |
|
40511 | 28 |
var catModules = "Modules"; |
33920 | 29 |
var catPackages = "Packages"; |
30 |
var catTypes = "Types"; |
|
31 |
var catMembers = "Members"; |
|
32 |
var catSearchTags = "SearchTags"; |
|
41523
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
33 |
var highlight = "<span class=\"resultHighlight\">$&</span>"; |
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
34 |
var camelCaseRegexp = ""; |
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
35 |
var secondaryMatcher = ""; |
33920 | 36 |
function getName(name) { |
37 |
var anchor = ""; |
|
38 |
var ch = ''; |
|
39 |
for (i = 0; i < name.length; i++) { |
|
40 |
ch = name.charAt(i); |
|
41 |
switch (ch) { |
|
42 |
case '(': |
|
43 |
case ')': |
|
44 |
case '<': |
|
45 |
case '>': |
|
46 |
case ',': |
|
47 |
anchor += "-"; |
|
48 |
break; |
|
49 |
case ' ': |
|
50 |
case '[': |
|
51 |
break; |
|
52 |
case ']': |
|
53 |
anchor += ":A"; |
|
54 |
break; |
|
55 |
case '$': |
|
56 |
if (i == 0) |
|
57 |
anchor += "Z:Z"; |
|
58 |
anchor += ":D"; |
|
59 |
break; |
|
60 |
case '_': |
|
61 |
if (i == 0) |
|
62 |
anchor += "Z:Z"; |
|
63 |
anchor += ch; |
|
64 |
break; |
|
65 |
default: |
|
66 |
anchor += ch; |
|
67 |
} |
|
68 |
} |
|
69 |
return anchor; |
|
70 |
} |
|
41523
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
71 |
function getHighlightedText(item) { |
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
72 |
var ccMatcher = new RegExp(camelCaseRegexp); |
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
73 |
var label = item.replace(ccMatcher, highlight); |
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
74 |
if (label === item) { |
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
75 |
label = item.replace(secondaryMatcher, highlight); |
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
76 |
} |
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
77 |
return label; |
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
78 |
} |
33920 | 79 |
var watermark = 'Search'; |
80 |
$(function() { |
|
81 |
$("#search").prop("disabled", false); |
|
82 |
$("#reset").prop("disabled", false); |
|
83 |
$("#search").val(watermark).addClass('watermark'); |
|
41523
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
84 |
$("#search").blur(function() { |
33920 | 85 |
if ($(this).val().length == 0) { |
86 |
$(this).val(watermark).addClass('watermark'); |
|
87 |
} |
|
88 |
}); |
|
41523
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
89 |
$("#search").keydown(function() { |
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
90 |
if ($(this).val() == watermark) { |
33920 | 91 |
$(this).val('').removeClass('watermark'); |
92 |
} |
|
93 |
}); |
|
41523
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
94 |
$("#reset").click(function() { |
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
95 |
$("#search").val(''); |
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
96 |
$("#search").focus(); |
33920 | 97 |
}); |
98 |
$("#search").focus(); |
|
41523
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
99 |
$("#search")[0].setSelectionRange(0, 0); |
33920 | 100 |
}); |
101 |
$.widget("custom.catcomplete", $.ui.autocomplete, { |
|
102 |
_create: function() { |
|
103 |
this._super(); |
|
104 |
this.widget().menu("option", "items", "> :not(.ui-autocomplete-category)"); |
|
105 |
}, |
|
106 |
_renderMenu: function(ul, items) { |
|
107 |
var rMenu = this, |
|
108 |
currentCategory = ""; |
|
109 |
$.each(items, function(index, item) { |
|
110 |
var li; |
|
111 |
if (item.l !== noResult.l && item.category !== currentCategory) { |
|
112 |
ul.append("<li class=\"ui-autocomplete-category\">" + item.category + "</li>"); |
|
113 |
currentCategory = item.category; |
|
114 |
} |
|
115 |
li = rMenu._renderItemData(ul, item); |
|
116 |
if (item.category) { |
|
117 |
li.attr("aria-label", item.category + " : " + item.l); |
|
118 |
li.attr("class", "resultItem"); |
|
119 |
} else { |
|
120 |
li.attr("aria-label", item.l); |
|
121 |
li.attr("class", "resultItem"); |
|
122 |
} |
|
123 |
}); |
|
124 |
}, |
|
125 |
_renderItem: function(ul, item) { |
|
126 |
var label = ""; |
|
40511 | 127 |
if (item.category === catModules) { |
41523
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
128 |
label = getHighlightedText(item.l); |
40511 | 129 |
} else if (item.category === catPackages) { |
130 |
label = (item.m) |
|
41523
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
131 |
? getHighlightedText(item.m + "/" + item.l) |
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
132 |
: getHighlightedText(item.l); |
33920 | 133 |
} else if (item.category === catTypes) { |
41523
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
134 |
label = getHighlightedText(item.p + "." + item.l); |
33920 | 135 |
} else if (item.category === catMembers) { |
41523
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
136 |
label = getHighlightedText(item.p + "." + (item.c + "." + item.l)); |
33920 | 137 |
} else if (item.category === catSearchTags) { |
41523
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
138 |
label = getHighlightedText(item.l); |
33920 | 139 |
} else { |
140 |
label = item.l; |
|
141 |
} |
|
142 |
$li = $("<li/>").appendTo(ul); |
|
143 |
if (item.category === catSearchTags) { |
|
144 |
if (item.d) { |
|
145 |
$("<a/>").attr("href", "#") |
|
146 |
.html(label + "<span class=\"searchTagHolderResult\"> (" + item.h + ")</span><br><span class=\"searchTagDescResult\">" |
|
147 |
+ item.d + "</span><br>") |
|
148 |
.appendTo($li); |
|
149 |
} else { |
|
150 |
$("<a/>").attr("href", "#") |
|
151 |
.html(label + "<span class=\"searchTagHolderResult\"> (" + item.h + ")</span>") |
|
152 |
.appendTo($li); |
|
153 |
} |
|
154 |
} else { |
|
155 |
$("<a/>").attr("href", "#") |
|
156 |
.html(label) |
|
157 |
.appendTo($li); |
|
158 |
} |
|
159 |
return $li; |
|
160 |
} |
|
161 |
}); |
|
162 |
$(function() { |
|
163 |
$("#search").catcomplete({ |
|
164 |
minLength: 1, |
|
165 |
delay: 100, |
|
166 |
source: function(request, response) { |
|
167 |
var result = new Array(); |
|
40511 | 168 |
var presult = new Array(); |
33920 | 169 |
var tresult = new Array(); |
170 |
var mresult = new Array(); |
|
171 |
var tgresult = new Array(); |
|
172 |
var displayCount = 0; |
|
173 |
var exactMatcher = new RegExp("^" + $.ui.autocomplete.escapeRegex(request.term) + "$", "i"); |
|
41523
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
174 |
camelCaseRegexp = ($.ui.autocomplete.escapeRegex(request.term)).split(/(?=[A-Z])/).join("([a-z0-9_$]*?)"); |
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
175 |
var camelCaseMatcher = new RegExp("^" + camelCaseRegexp); |
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
176 |
secondaryMatcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i"); |
40511 | 177 |
if (moduleSearchIndex) { |
178 |
var mdleCount = 0; |
|
179 |
$.each(moduleSearchIndex, function(index, item) { |
|
180 |
item[category] = catModules; |
|
33920 | 181 |
if (exactMatcher.test(item.l)) { |
182 |
result.unshift(item); |
|
40511 | 183 |
mdleCount++; |
41523
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
184 |
} else if (camelCaseMatcher.test(item.l)) { |
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
185 |
result.unshift(item); |
33920 | 186 |
} else if (secondaryMatcher.test(item.l)) { |
187 |
result.push(item); |
|
188 |
} |
|
189 |
}); |
|
40511 | 190 |
displayCount = mdleCount; |
191 |
} |
|
192 |
if (packageSearchIndex) { |
|
193 |
var pCount = 0; |
|
194 |
var pkg = ""; |
|
195 |
$.each(packageSearchIndex, function(index, item) { |
|
196 |
item[category] = catPackages; |
|
197 |
pkg = (item.m) |
|
198 |
? (item.m + "/" + item.l) |
|
199 |
: item.l; |
|
200 |
if (exactMatcher.test(item.l)) { |
|
201 |
presult.unshift(item); |
|
202 |
pCount++; |
|
41523
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
203 |
} else if (camelCaseMatcher.test(pkg)) { |
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
204 |
presult.unshift(item); |
40511 | 205 |
} else if (secondaryMatcher.test(pkg)) { |
206 |
presult.push(item); |
|
207 |
} |
|
208 |
}); |
|
209 |
result = result.concat(presult); |
|
210 |
displayCount = (pCount > displayCount) ? pCount : displayCount; |
|
33920 | 211 |
} |
212 |
if (typeSearchIndex) { |
|
213 |
var tCount = 0; |
|
214 |
$.each(typeSearchIndex, function(index, item) { |
|
215 |
item[category] = catTypes; |
|
216 |
if (exactMatcher.test(item.l)) { |
|
217 |
tresult.unshift(item); |
|
218 |
tCount++; |
|
41523
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
219 |
} else if (camelCaseMatcher.test(item.l)) { |
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
220 |
tresult.unshift(item); |
33920 | 221 |
} else if (secondaryMatcher.test(item.p + "." + item.l)) { |
222 |
tresult.push(item); |
|
223 |
} |
|
224 |
}); |
|
225 |
result = result.concat(tresult); |
|
226 |
displayCount = (tCount > displayCount) ? tCount : displayCount; |
|
227 |
} |
|
228 |
if (memberSearchIndex) { |
|
229 |
var mCount = 0; |
|
230 |
$.each(memberSearchIndex, function(index, item) { |
|
231 |
item[category] = catMembers; |
|
232 |
if (exactMatcher.test(item.l)) { |
|
233 |
mresult.unshift(item); |
|
234 |
mCount++; |
|
41523
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
235 |
} else if (camelCaseMatcher.test(item.l)) { |
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
236 |
mresult.unshift(item); |
33920 | 237 |
} else if (secondaryMatcher.test(item.c + "." + item.l)) { |
238 |
mresult.push(item); |
|
239 |
} |
|
240 |
}); |
|
241 |
result = result.concat(mresult); |
|
242 |
displayCount = (mCount > displayCount) ? mCount : displayCount; |
|
243 |
} |
|
244 |
if (tagSearchIndex) { |
|
245 |
var tgCount = 0; |
|
246 |
$.each(tagSearchIndex, function(index, item) { |
|
247 |
item[category] = catSearchTags; |
|
248 |
if (exactMatcher.test(item.l)) { |
|
249 |
tgresult.unshift(item); |
|
250 |
tgCount++; |
|
251 |
} else if (secondaryMatcher.test(item.l)) { |
|
252 |
tgresult.push(item); |
|
253 |
} |
|
254 |
}); |
|
255 |
result = result.concat(tgresult); |
|
256 |
displayCount = (tgCount > displayCount) ? tgCount : displayCount; |
|
257 |
} |
|
258 |
displayCount = (displayCount > 500) ? displayCount : 500; |
|
259 |
var counter = function() { |
|
40511 | 260 |
var count = {Modules: 0, Packages: 0, Types: 0, Members: 0, SearchTags: 0}; |
33920 | 261 |
var f = function(item) { |
262 |
count[item.category] += 1; |
|
263 |
return (count[item.category] <= displayCount); |
|
264 |
}; |
|
265 |
return f; |
|
266 |
}(); |
|
267 |
response(result.filter(counter)); |
|
268 |
}, |
|
269 |
response: function(event, ui) { |
|
270 |
if (!ui.content.length) { |
|
271 |
ui.content.push(noResult); |
|
272 |
} else { |
|
273 |
$("#search").empty(); |
|
274 |
} |
|
275 |
}, |
|
276 |
autoFocus: true, |
|
277 |
position: { |
|
278 |
collision: "flip" |
|
279 |
}, |
|
280 |
select: function(event, ui) { |
|
281 |
if (ui.item.l !== noResult.l) { |
|
282 |
var url = ""; |
|
40511 | 283 |
if (ui.item.category === catModules) { |
41032
32be25e34c38
8166176: module search generates URLs with extra '/'
bpatel
parents:
40511
diff
changeset
|
284 |
url = ui.item.l + "-summary.html"; |
40511 | 285 |
} else if (ui.item.category === catPackages) { |
33920 | 286 |
url = ui.item.l.replace(/\./g, '/') + "/package-summary.html"; |
287 |
} else if (ui.item.category === catTypes) { |
|
288 |
if (ui.item.p === "<Unnamed>") { |
|
41032
32be25e34c38
8166176: module search generates URLs with extra '/'
bpatel
parents:
40511
diff
changeset
|
289 |
url = ui.item.l + ".html"; |
33920 | 290 |
} else { |
291 |
url = ui.item.p.replace(/\./g, '/') + "/" + ui.item.l + ".html"; |
|
292 |
} |
|
293 |
} else if (ui.item.category === catMembers) { |
|
294 |
if (ui.item.p === "<Unnamed>") { |
|
41032
32be25e34c38
8166176: module search generates URLs with extra '/'
bpatel
parents:
40511
diff
changeset
|
295 |
url = ui.item.c + ".html" + "#"; |
33920 | 296 |
} else { |
297 |
url = ui.item.p.replace(/\./g, '/') + "/" + ui.item.c + ".html" + "#"; |
|
298 |
} |
|
299 |
if (ui.item.url) { |
|
300 |
url += ui.item.url; |
|
301 |
} else { |
|
302 |
url += getName(ui.item.l); |
|
303 |
} |
|
304 |
} else if (ui.item.category === catSearchTags) { |
|
305 |
url += ui.item.u; |
|
306 |
} |
|
307 |
if (top !== window) { |
|
308 |
parent.classFrame.location = pathtoroot + url; |
|
309 |
} else { |
|
310 |
window.location.href = pathtoroot + url; |
|
311 |
} |
|
312 |
} |
|
313 |
} |
|
314 |
}); |
|
41523
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
315 |
}); |