PageSourceSearch

https://www.fpoe-noe.at/typo3conf/ext/solr/Resources/Public/JavaScript/suggest_controller.js?1539682566

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

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.