PageSourceSearch

https://www.slavorum.org/wp-content/themes/bimber/js/ajax-search.js

js slavorum.org collected 2026-09-24 23:08:12 UTC 2,070 bytes, 76 lines download raw bytes

1/*****************
2 *
3 * Ajax search
4 *
5 *****************/
6
7(function ($) {
8
9    'use strict';
10
11    var selectors = {
12        'wrapper':  'div[role=search]',
13        'form':     'form.g1-searchform-ajax',
14        'input':    'form.g1-searchform-ajax input.search-field',
15        'results':  '.g1-searches-ajax',
16        'seeAll':   '.bimber-see-all-results'
17    };
18
19    g1.ajaxSearch = function () {
20        if (!$.fn.autocomplete) {
21            return;
22        }
23
24        var minLength = 2;
25
26        $( selectors.input).each(function() {
27            var $input   = $(this);
28            var $form    = $input.parents(selectors.form);
29            var $wrapper = $input.parents(selectors.wrapper);
30
31
32
33            $input.autocomplete({
34                'appendTo':   $form,
35                'delay':      500,
36                'minLength':  minLength,
37                'source': function(request) {
38                    var xhr = $.ajax({
39                        'type': 'GET',
40                        'url': g1.config.ajax_url,
41                        'dataType': 'json',
42                        'data': {
43                            'action':       'bimber_search',
44                            'bimber_term':  request.term
45                        }
46                    });
47
48                    xhr.done(function (res) {
49                        if (res.status === 'success') {
50                            $wrapper.find(selectors.results).html(res.html);
51                        }
52                    });
53                }
54            });
55
56            // Empty results.
57            $input.on('keyup search', function() {
58                if ($(this).val().length < minLength) {
59                    $wrapper.find(selectors.results).html('');
60                }
61            });
62
63            // See all results.
64            $wrapper.on('click', selectors.seeAll, function(e) {
65                e.preventDefault();
66
67                $form.submit();
68            });
69        });
70    };
71
72    // Fire it up.
73    $(document).ready(function () {
74        g1.ajaxSearch();
75    });
76})(jQuery);

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.