Projekt

Obecné

Profil

Stáhnout (13.1 KB) Statistiky
| Větev: | Tag: | Revize:
1
/*
2
 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
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 catModules = "Modules";
28
var catPackages = "Packages";
29
var catTypes = "Types";
30
var catMembers = "Members";
31
var catSearchTags = "SearchTags";
32
var highlight = "<span class=\"resultHighlight\">$&</span>";
33
var camelCaseRegexp = "";
34
var secondaryMatcher = "";
35
function getHighlightedText(item) {
36
    var ccMatcher = new RegExp(camelCaseRegexp);
37
    var label = item.replace(ccMatcher, highlight);
38
    if (label === item) {
39
        label = item.replace(secondaryMatcher, highlight);
40
    }
41
    return label;
42
}
43
function getURLPrefix(ui) {
44
    var urlPrefix="";
45
    if (useModuleDirectories) {
46
        var slash = "/";
47
        if (ui.item.category === catModules) {
48
            return ui.item.l + slash;
49
        } else if (ui.item.category === catPackages && ui.item.m) {
50
            return ui.item.m + slash;
51
        } else if ((ui.item.category === catTypes && ui.item.p) || ui.item.category === catMembers) {
52
            $.each(packageSearchIndex, function(index, item) {
53
                if (ui.item.p == item.l) {
54
                    urlPrefix = item.m + slash;
55
                }
56
            });
57
            return urlPrefix;
58
        } else {
59
            return urlPrefix;
60
        }
61
    }
62
    return urlPrefix;
63
}
64
var watermark = 'Search';
65
$(function() {
66
    $("#search").val('');
67
    $("#search").prop("disabled", false);
68
    $("#reset").prop("disabled", false);
69
    $("#search").val(watermark).addClass('watermark');
70
    $("#search").blur(function() {
71
        if ($(this).val().length == 0) {
72
            $(this).val(watermark).addClass('watermark');
73
        }
74
    });
75
    $("#search").on('click keydown', function() {
76
        if ($(this).val() == watermark) {
77
            $(this).val('').removeClass('watermark');
78
        }
79
    });
80
    $("#reset").click(function() {
81
        $("#search").val('');
82
        $("#search").focus();
83
    });
84
    $("#search").focus();
85
    $("#search")[0].setSelectionRange(0, 0);
86
});
87
$.widget("custom.catcomplete", $.ui.autocomplete, {
88
    _create: function() {
89
        this._super();
90
        this.widget().menu("option", "items", "> :not(.ui-autocomplete-category)");
91
    },
92
    _renderMenu: function(ul, items) {
93
        var rMenu = this,
94
                currentCategory = "";
95
        $.each(items, function(index, item) {
96
            var li;
97
            if (item.l !== noResult.l && item.category !== currentCategory) {
98
                ul.append("<li class=\"ui-autocomplete-category\">" + item.category + "</li>");
99
                currentCategory = item.category;
100
            }
101
            li = rMenu._renderItemData(ul, item);
102
            if (item.category) {
103
                li.attr("aria-label", item.category + " : " + item.l);
104
                li.attr("class", "resultItem");
105
            } else {
106
                li.attr("aria-label", item.l);
107
                li.attr("class", "resultItem");
108
            }
109
        });
110
    },
111
    _renderItem: function(ul, item) {
112
        var label = "";
113
        if (item.category === catModules) {
114
            label = getHighlightedText(item.l);
115
        } else if (item.category === catPackages) {
116
            label = (item.m)
117
                    ? getHighlightedText(item.m + "/" + item.l)
118
                    : getHighlightedText(item.l);
119
        } else if (item.category === catTypes) {
120
            label = (item.p)
121
                    ? getHighlightedText(item.p + "." + item.l)
122
                    : getHighlightedText(item.l);
123
        } else if (item.category === catMembers) {
124
            label = getHighlightedText(item.p + "." + (item.c + "." + item.l));
125
        } else if (item.category === catSearchTags) {
126
            label = getHighlightedText(item.l);
127
        } else {
128
            label = item.l;
129
        }
130
        $li = $("<li/>").appendTo(ul);
131
        if (item.category === catSearchTags) {
132
            if (item.d) {
133
                $("<a/>").attr("href", "#")
134
                        .html(label + "<span class=\"searchTagHolderResult\"> (" + item.h + ")</span><br><span class=\"searchTagDescResult\">"
135
                                + item.d + "</span><br>")
136
                        .appendTo($li);
137
            } else {
138
                $("<a/>").attr("href", "#")
139
                        .html(label + "<span class=\"searchTagHolderResult\"> (" + item.h + ")</span>")
140
                        .appendTo($li);
141
            }
142
        } else {
143
            $("<a/>").attr("href", "#")
144
                    .html(label)
145
                    .appendTo($li);
146
        }
147
        return $li;
148
    }
149
});
150
$(function() {
151
    $("#search").catcomplete({
152
        minLength: 1,
153
        delay: 100,
154
        source: function(request, response) {
155
            var result = new Array();
156
            var presult = new Array();
157
            var tresult = new Array();
158
            var mresult = new Array();
159
            var tgresult = new Array();
160
            var secondaryresult = new Array();
161
            var displayCount = 0;
162
            var exactMatcher = new RegExp("^" + $.ui.autocomplete.escapeRegex(request.term) + "$", "i");
163
            camelCaseRegexp = ($.ui.autocomplete.escapeRegex(request.term)).split(/(?=[A-Z])/).join("([a-z0-9_$]*?)");
164
            var camelCaseMatcher = new RegExp("^" + camelCaseRegexp);
165
            secondaryMatcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
166

    
167
            // Return the nested innermost name from the specified object
168
            function nestedName(e) {
169
                return e.l.substring(e.l.lastIndexOf(".") + 1);
170
            }
171

    
172
            function concatResults(a1, a2) {
173
                a1 = a1.concat(a2);
174
                a2.length = 0;
175
                return a1;
176
            }
177

    
178
            if (moduleSearchIndex) {
179
                var mdleCount = 0;
180
                $.each(moduleSearchIndex, function(index, item) {
181
                    item.category = catModules;
182
                    if (exactMatcher.test(item.l)) {
183
                        result.push(item);
184
                        mdleCount++;
185
                    } else if (camelCaseMatcher.test(item.l)) {
186
                        result.push(item);
187
                    } else if (secondaryMatcher.test(item.l)) {
188
                        secondaryresult.push(item);
189
                    }
190
                });
191
                displayCount = mdleCount;
192
                result = concatResults(result, secondaryresult);
193
            }
194
            if (packageSearchIndex) {
195
                var pCount = 0;
196
                var pkg = "";
197
                $.each(packageSearchIndex, function(index, item) {
198
                    item.category = catPackages;
199
                    pkg = (item.m)
200
                            ? (item.m + "/" + item.l)
201
                            : item.l;
202
                    if (exactMatcher.test(item.l)) {
203
                        presult.push(item);
204
                        pCount++;
205
                    } else if (camelCaseMatcher.test(pkg)) {
206
                        presult.push(item);
207
                    } else if (secondaryMatcher.test(pkg)) {
208
                        secondaryresult.push(item);
209
                    }
210
                });
211
                result = result.concat(concatResults(presult, secondaryresult));
212
                displayCount = (pCount > displayCount) ? pCount : displayCount;
213
            }
214
            if (typeSearchIndex) {
215
                var tCount = 0;
216
                $.each(typeSearchIndex, function(index, item) {
217
                    item.category = catTypes;
218
                    var s = nestedName(item);
219
                    if (exactMatcher.test(s)) {
220
                        tresult.push(item);
221
                        tCount++;
222
                    } else if (camelCaseMatcher.test(s)) {
223
                        tresult.push(item);
224
                    } else if (secondaryMatcher.test(item.p + "." + item.l)) {
225
                        secondaryresult.push(item);
226
                    }
227
                });
228
                result = result.concat(concatResults(tresult, secondaryresult));
229
                displayCount = (tCount > displayCount) ? tCount : displayCount;
230
            }
231
            if (memberSearchIndex) {
232
                var mCount = 0;
233
                $.each(memberSearchIndex, function(index, item) {
234
                    item.category = catMembers;
235
                    var s = nestedName(item);
236
                    if (exactMatcher.test(s)) {
237
                        mresult.push(item);
238
                        mCount++;
239
                    } else if (camelCaseMatcher.test(s)) {
240
                        mresult.push(item);
241
                    } else if (secondaryMatcher.test(item.c + "." + item.l)) {
242
                        secondaryresult.push(item);
243
                    }
244
                });
245
                result = result.concat(concatResults(mresult, secondaryresult));
246
                displayCount = (mCount > displayCount) ? mCount : displayCount;
247
            }
248
            if (tagSearchIndex) {
249
                var tgCount = 0;
250
                $.each(tagSearchIndex, function(index, item) {
251
                    item.category = catSearchTags;
252
                    if (exactMatcher.test(item.l)) {
253
                        tgresult.push(item);
254
                        tgCount++;
255
                    } else if (secondaryMatcher.test(item.l)) {
256
                        secondaryresult.push(item);
257
                    }
258
                });
259
                result = result.concat(concatResults(tgresult, secondaryresult));
260
                displayCount = (tgCount > displayCount) ? tgCount : displayCount;
261
            }
262
            displayCount = (displayCount > 500) ? displayCount : 500;
263
            var counter = function() {
264
                var count = {Modules: 0, Packages: 0, Types: 0, Members: 0, SearchTags: 0};
265
                var f = function(item) {
266
                    count[item.category] += 1;
267
                    return (count[item.category] <= displayCount);
268
                };
269
                return f;
270
            }();
271
            response(result.filter(counter));
272
        },
273
        response: function(event, ui) {
274
            if (!ui.content.length) {
275
                ui.content.push(noResult);
276
            } else {
277
                $("#search").empty();
278
            }
279
        },
280
        autoFocus: true,
281
        position: {
282
            collision: "flip"
283
        },
284
        select: function(event, ui) {
285
            if (ui.item.l !== noResult.l) {
286
                var url = getURLPrefix(ui);
287
                if (ui.item.category === catModules) {
288
                    if (useModuleDirectories) {
289
                        url += "module-summary.html";
290
                    } else {
291
                        url = ui.item.l + "-summary.html";
292
                    }
293
                } else if (ui.item.category === catPackages) {
294
                    if (ui.item.url) {
295
                        url = ui.item.url;
296
                    } else {
297
                    url += ui.item.l.replace(/\./g, '/') + "/package-summary.html";
298
                    }
299
                } else if (ui.item.category === catTypes) {
300
                    if (ui.item.url) {
301
                        url = ui.item.url;
302
                    } else if (ui.item.p === "<Unnamed>") {
303
                        url += ui.item.l + ".html";
304
                    } else {
305
                        url += ui.item.p.replace(/\./g, '/') + "/" + ui.item.l + ".html";
306
                    }
307
                } else if (ui.item.category === catMembers) {
308
                    if (ui.item.p === "<Unnamed>") {
309
                        url += ui.item.c + ".html" + "#";
310
                    } else {
311
                        url += ui.item.p.replace(/\./g, '/') + "/" + ui.item.c + ".html" + "#";
312
                    }
313
                    if (ui.item.url) {
314
                        url += ui.item.url;
315
                    } else {
316
                        url += ui.item.l;
317
                    }
318
                } else if (ui.item.category === catSearchTags) {
319
                    url += ui.item.u;
320
                }
321
                if (top !== window) {
322
                    parent.classFrame.location = pathtoroot + url;
323
                } else {
324
                    window.location.href = pathtoroot + url;
325
                }
326
            }
327
        }
328
    });
329
});
(14-14/17)