PageSourceSearch

https://www.fva-bw.de/_assets/15aaf13420dff842b1d0c1d22b3081eb/JavaScript/suggest_controller.js?1758113062

js fva-bw.de collected 2026-10-02 04:50:18 UTC 6,564 bytes, 145 lines download raw bytes

1function SuggestController() {
2
3    this.init = function () {
4
5        jQuery('form[data-suggest]').each(function () {
6            var $form = $(this), $searchBox = $form.find('.tx-solr-suggest');
7
8            jQuery.ajaxSetup({json: "tx_solr[callback]"})
9
10            // when no specific container found, use the form as container
11
12            if ($searchBox.length === 0) {
13                $searchBox = $form;
14            }
15            $searchBox.css('position', 'relative');
16
17            $form.find('.tx-solr-suggest-focus').focus();
18
19            // Prevent submit of empty search form
20            $form.on('submit', function (e) {
21                if ($form.find('.tx-solr-suggest-focus').val() === '') {
22                    e.preventDefault();
23                    $form.find('.tx-solr-suggest-focus').focus();
24                }
25            });
26
27            $form.find('.tx-solr-suggest').devbridgeAutocomplete({
28                serviceUrl: $form.data('suggest'),
29                dataType: 'json',
30                paramName: 'tx_solr[queryString]',
31                groupBy: 'category',
32                maxHeight: 1000,
33                autoSelectFirst: false,
34                triggerSelectOnValidInput: false,
35                appendTo: '.gd-solr-autosuggest',
36                forceFixPosition: true,
37                onSelect: function (suggestion) {
38                    // go to link when selecting found result
39                    if (suggestion.data.link) {
40                        // Open youtube in overlay
41                        if (suggestion.data.link.indexOf('https://www.youtube.com') === 0) {
42                            openVideoOverlay(suggestion.data.link);
43                        } else {
44                            location.href = suggestion.data.link;
45                        }
46                        // else trigger form submit (do search)
47                    } else {
48                        $form.trigger('submit');
49                    }
50                },
51                transformResult: function (response) {
52                    if (!response.suggestions) return {suggestions: []};
53                    var firstSuggestion, result = {
54                        suggestions: $.map(response.suggestions, function (count, suggestion) {
55                            if (!firstSuggestion) firstSuggestion = suggestion;
56                            return {value: suggestion, data: {category: 'suggestion', count: count}};
57                        })
58                    };
59
60                    $.each(response.documents, function (key, value) {
61                        var dataObject = value;
62
63                        dataObject.category = $form.data('suggest-header') ? $form.data('suggest-header') : 'Top results';
64
65                        // if a group is set we try to get a label
66                        if (dataObject.group) {
67                            dataObject.category = $form.data('suggest-header-' + dataObject.group) ? $form.data('suggest-header-' + dataObject.group) : dataObject.group;
68                        }
69
70                        result.suggestions.push(
71                            {
72                                value: firstSuggestion,
73                                data: dataObject
74                            }
75                        );
76                    });
77
78                    return result;
79                },
80                beforeRender: function (container) {
81                    // remove first group header
82                    container.find('.autocomplete-group:first').remove();
83                    container.addClass('tx-solr-autosuggest');
84                    container.css('position', '');
85                    container.parent().removeAttr('hidden');
86                    // add active class to container
87                    $searchBox.parent().addClass('autocomplete-active').fadeIn();
88                },
89                onHide: function (container) {
90                    container.parent().attr('hidden', 'hidden');
91                },
92                formatResult: function (suggestion, currentValue) {
93                    // Do not replace anything if there current value is empty
94                    if (!currentValue) {
95                        return suggestion.value;
96                    }
97                    var pattern = '(' + $.Autocomplete.utils.escapeRegExChars(currentValue.trim()) + ')';
98                    // normal suggestion
99                    if (suggestion.data.category === 'suggestion') {
100                        return suggestion.value
101                            .replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>')
102                            .replace(/&/g, '&amp;')
103                            .replace(/</g, '&lt;')
104                            .replace(/>/g, '&gt;')
105                            .replace(/"/g, '&quot;')
106                            .replace(/&lt;(\/?strong)&gt;/g, '<$1>');
107
108                        // results
109                    } else {
110                        var title = suggestion.data.title
111                            .replace(new RegExp(pattern, 'gi'), '<em>$1<\/em>')
112                            .replace(/&/g, '&amp;')
113                            .replace(/</g, '&lt;')
114                            .replace(/>/g, '&gt;')
115                            .replace(/"/g, '&quot;')
116                            .replace(/&lt;(\/?em)&gt;/g, '<$1>');
117
118                        return '<div class="' + suggestion.data.type + '">' +
119                            (!!suggestion.data.previewImage ? '<figure ' + (!!suggestion.data.hasVideo ? 'class="hasVideo"' : '') + '>
119<img src="' + suggestion.data.previewImage + '" /></figure>' : '') +
120                            '<a href="' + suggestion.data.link + '" class="internal-link">' + title + '</a>' +
121                            '</div>';
122                    }
123
124                }
125            }).on('blur', function () {
126                $searchBox.parent().removeClass('autocomplete-active');
127                var $box = $(this);
128                setTimeout(function () {
129                    $box.devbridgeAutocomplete('hide');
130                }, 200);
131            });
132        });
133    };
134}
135
136jQuery(document).ready(function () {
137    /** solr search autocomplete **/
138    var solrSuggestController = new SuggestController();
139    solrSuggestController.init();
140
141    jQuery("body").on("tx_solr_updated", function () {
142        solrSuggestController.init();
143    });
144});
145

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.