PageSourceSearch

https://www.baden-baden.de/site/Baden-Baden/resourceCached/24.2.0.35/search-autocomplete/autocomplete.js

js baden-baden.de collected 2026-09-24 18:22:43 UTC 2,972 bytes, 87 lines download raw bytes

1/**
2 * overwrite of jquery-ui autocomplete plugin
3 * makes the input query term bold to difference from completed term part
4 */
5jQuery.ui.autocomplete.prototype._renderItem = function (ul, item) {
6    var t = item.label.replace(new RegExp('(' + this.term + ')', 'gi'), "<strong>$1</strong>");
7    return jQuery("<li></li>").data("item.autocomplete", item).append("<a>" + t + "</a>").appendTo(ul);
8};
9
10/**
11 * global cache for autocomplete in pbsearch
12 */
13var pbsearch = pbsearch || {};
14pbsearch.autocompleteCache = {};
15
16/**
17 * initialize jquery-ui autocomplete
18 * Performs ajax calls to "search-autocomplete" to get the autocompleted terms.
19 * Using the global autocompleteCache for caching requested terms.
20 */
21jQuery.widget("pbsearch.pbsearch_autocomplete", {
22    options: {
23        url: null,
24        minLength: 3,
25        delay: 300,
26        maxTerms: 5,
27        rows: 20,
28        avoidParallelRequests: true,
29        cache: function () {
30            return pbsearch.autocompleteCache;
31        },
32        select: function (event, ui) {
33            jQuery(this).val(ui.item.label);
34            jQuery(this).closest('form').submit();
35        },
36        messages: {
37            noResults: '',
38            results: function () {
39            }
40        },
41        afterSource: function (me) {
42            delete me.requestOngoing;
43            var term = me.latestTermWhileOngoing;
44            delete me.latestTermWhileOngoing;
45            if (term) {
46                me.search(term);
47            }
48        },
49        source: function (request, response) {
50            var me = this,
51                term = request.term.replace(new RegExp('AND', 'g'), '').replace(new RegExp('OR', 'g'), '').replace(/\s\s+/g, ' '),
52                cache = this.options.cache();
53            if (term in cache) {
54                response(cache[term]);
55                return;
56            }
57            if (this.options.maxTerms < term.split(' ').length) {
58                // we reached max terms, do not load new source
59                return;
60            }
61
62            if (me.options.avoidParallelRequests && me.requestOngoing) {
63                me.latestTermWhileOngoing = request.term;
64                return;
65            }
66
67            var matcher = new RegExp(jQuery.ui.autocomplete.escapeRegex(term), "i");
68            me.requestOngoing = true;
69            jQuery.ajax({
70                type: 'POST',
71                url: me.options.url,
72                data: {'query': jQuery(this.element[0]).val(), 'rows': me.options.rows},
73                success: function (data, textStatus, xhr) {
74                    cache[term] = data.searchResult;
75                    response(data.searchResult);
76                    me.options.afterSource(me);
77                },
78                failure: function () {
79                    me.options.afterSource(me);
80                }
81            });
82        }
83    },
84    _create: function () {
85        jQuery(this.element).autocomplete(this.options);
86    }
87});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.