PageSourceSearch

https://fein.com/_assets/ede6549c31ea16e83d41b339ddaa64bd/JavaScript/suggest_controller.1790160281.js

js fein.com collected 2026-09-24 19:30:43 UTC 8,984 bytes, 189 lines download raw bytes

1/**
2  * @see: https://github.com/devbridge/jQuery-Autocomplete
3 */
4function SuggestController()
5{
6
7    this.init = function (formId) {
8        formId = formId || 'none';
9
10        // close dropdown on srolling
11        jQuery(window).scroll(function () {
12            jQuery('.autocomplete-suggestions').hide();
13        });
14
15        var formSelector = ('none' != formId) ? 'form[data-suggest]#' + formId : 'form[data-suggest]';
16
17        jQuery(formSelector).each(function () {
18            var $form = $(this), $searchBox = $form.find('.tx-solr-suggest');
19
20            // $form.find('.tx-solr-suggest-focus').focus();
21
22            jQuery.ajaxSetup({jsonp: "tx_solr[callback]"})
23
24            // when no specific container found, use the form as container
25            if ($searchBox.length === 0) {
26                $searchBox = $form;
27            }
28            $searchBox.css('position', 'relative');
29
30            // Prevent submit of empty search form
31            $form.on('submit', function (e) {
32                if ($form.find('.tx-solr-suggest').val() === '') {
33                    e.preventDefault();
34                    $form.find('.tx-solr-suggest').focus();
35                }
36            });
37
38            $form.find('.tx-solr-suggest').devbridgeAutocomplete({
39                serviceUrl: $form.data('suggest'),
40                dataType: 'json',
41                paramName: 'tx_solr[queryString]',
42                groupBy: 'category',
43                maxHeight: 500,
44                autoSelectFirst: false,
45                minChars: 3,
46                deferRequestBy: 400,
47// ----- RSL: set box to 100% width ---------------------------------------------------------
48                // width: $searchBox.outerWidth() * 0.66,
49// ----- RSL: set box to 100% width ---------------------------------------------------------
50                onSelect: function (suggestion) {
51                    // go to link when selecting found result
52                    if (suggestion.data.link) {
53                        // Open youtube in overlay
54                        if (suggestion.data.link.indexOf('https://www.youtube.com') === 0) {
55                            openVideoOverlay(suggestion.data.link);
56                        } else {
57                            location.href = suggestion.data.link;
58                        }
59                        // else trigger form submit (do search)
60                    } else {
61                        $form.trigger('submit');
62                    }
63                },
64                transformResult: function (response) {
65                    if (!response.suggestions) return {suggestions: []};
66                    var firstSuggestion = '', result = {
67                        suggestions: []
68                    };
69
70                    $.each(response.documents, function (key, value) {
71                        var dataObject = value;
72
73                        var defaultGroup = $form.data('suggest-header') ? $form.data('suggest-header') : 'Top results';
74                        dataObject.category = defaultGroup;
75
76                        // if a group is set we try to get a label
77                        if (dataObject.group) {
78                            dataObject.category = $form.data('suggest-header-' + dataObject.group) ? $form.data('suggest-header-' + dataObject.group) : dataObject.group;
79                        }
80
81                        result.suggestions.push(
82                            {
83                                value: firstSuggestion,
84                                data: dataObject
85                            }
86                        );
87                    });
88
89                    var suggestions = $.map(response.suggestions, function (count, suggestion) {
90                        if (!firstSuggestion) {
91                            firstSuggestion = suggestion;
92                        }
93                            var groupHeadline = $form.data('suggest-header-suggestions') ? $form.data('suggest-header-suggestions') : 'suggestion';
94                            return {value: suggestion, data: {category: groupHeadline, count: count, suggestions: 1}};
95                    });
96
97                    result.suggestions = result.suggestions.concat(suggestions);
98
99                    // 1 result means not result for given input; then we don't show is as suggestion
100                    // also prevents autosubmit when selecting input box
101                    if (result.suggestions.length <= 1) {
102                        result.suggestions = [];
103                    } else if (result.suggestions.length > 10) {
104                        // only allow max. 10 entries within dropdown!
105                        result.suggestions = result.suggestions.slice(0,10);
106                    }
107
108                    return result;
109                },
110                beforeRender: function (container) {
111                    // remove first group header
112                    container.find('.autocomplete-group:first').remove();
113                    container.addClass('tx-solr-autosuggest');
114
115                    // add active class to container
116                    $searchBox.parent().addClass('autocomplete-active').fadeIn();
117                },
118                formatResult: function (suggestion, currentValue) {
119                    // Do not replace anything if there current value is empty
120                    if (!currentValue) {
121                        return suggestion.value;
122                    }
123                    var pattern = '(' + $.Autocomplete.utils.escapeRegExChars(currentValue.trim()) + ')';
124                    // normal suggestion
125                    if (suggestion.data.suggestions === 1) {
126                        var content = suggestion.value
127                            .replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>')
128                            .replace(/&/g, '&amp;')
129                            .replace(/</g, '&lt;')
130                            .replace(/>/g, '&gt;')
131                            .replace(/"/g, '&quot;')
132                            .replace(/&lt;(\/?strong)&gt;/g, '<$1>');
133
134                        return '<div class="suggestion keyword"><div class="keyword">' + content + '</div></div>';
135                        // results
136                    } else {
137                        var type = (suggestion.data.type) ? suggestion.data.type : 'none';
138
139                        var title = (suggestion.data.title) ? suggestion.data.title
140                            .replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>')
141                            .replace(/&/g, '&amp;')
142                            .replace(/</g, '&lt;')
143                            .replace(/>/g, '&gt;')
144                            .replace(/"/g, '&quot;')
145                            .replace(/&lt;(\/?strong)&gt;/g, '<$1>') : '';
146
147                        var content = (suggestion.data.content) ? suggestion.data.content
148                            .replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>')
149                            .replace(/&/g, '&amp;')
150                            .replace(/</g, '&lt;')
151                            .replace(/>/g, '&gt;')
152                            .replace(/"/g, '&quot;')
153                            .replace(/&lt;(\/?strong)&gt;/g, '<$1>') : '';
154
155                        if (content && title && type != 'tx_mqkbacustom_domain_model_kba') {
156                            return '<div class="suggestion"><div class="' + suggestion.data.type + '">' +
157                                (!!suggestion.data.image_stringS ? '<figure ' + (!!suggestion.data.hasVideo ? 'class="hasVideo"' : '') + '><img src="' + suggestion.data.image_stringS + '" /></figure>' : '') +
158                                '<a href="' + suggestion.data.link + '" class="internal-link">' + title + '<br>' + content + '</a>' +
159                                '</div></div>';
160                        }
161
162                        if (title) {
163                            return '<div class="suggestion"><div class="' + suggestion.data.type + '">' +
164                                (!!suggestion.data.image_stringS ? '<figure ' + (!!suggestion.data.hasVideo ? 'class="hasVideo"' : '') + '><img src="' + suggestion.data.image_stringS + '" /></figure>' : '') +
165                                '<a href="' + suggestion.data.link + '" class="internal-link">' + title + '</a>' +
166                                '</div></div>';
167                        }
168
169                        return '';
170                    }
171
172                }
173            }).on('blur', function () {
174                $searchBox.parent().removeClass('autocomplete-active');
175                var $box = $(this);
176                setTimeout(function () {
177                    $box.devbridgeAutocomplete('hide');
178                }, 200);
179            });
180        });
181    };
182}
183
184jQuery(document).ready(function () {
185    /** solr search autocomplete **/
186    var solrSuggestController = new SuggestController();
187    solrSuggestController.init();
188});
189

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.