PageSourceSearch

https://afchub.org/custom/js/smart-search.js

js afchub.org collected 2026-10-02 12:01:05 UTC 1,740 bytes, 44 lines download raw bytes

1$(document).ready(function () {
2    var CSRF_TOKEN = $('meta[name="csrf-token"]').attr('content');
3    $('.smart-search').each(function name(i) {
4        let search_input = $(this);
5        var cache = {};
6        let data = $(this).data();
7        $(this).autocomplete({
8            source: function (request, response) {
9                let term = request.term;
10                if (term in cache) return response(cache[term]);
11                // Fetch data
12                $.ajax({
13                    url: data.url,
14                    type: 'post',
15                    dataType: "json",
16                    data: {
17                        _token: CSRF_TOKEN,
18                        search: request.term
19                    },
20                    success: function (data) {
21                        // cache[term] = data;
22                        response(data);
23                    },
24                    error: function (data) {
25                        console.log(data);
26                    }
27                });
28            },
29            minLength: 2,
30            select: function (event, ui) {
31                search_input.val(ui.item.title);
32                search_input.closest('form').trigger('submit')
33                return false;
34            }
35        }).autocomplete("instance")._renderItem = function (ul, item) {
36            var reg = new RegExp(search_input.val(), 'gi');
37            var label = item.title.replace(reg, '<span class="text-success">' + search_input.val() + '</span>');
38            return $(`<li class="text-nowrap text-truncate">`)
39                .append(`<span class="w-100 d-block">${label}</span>`)
40                .width(search_input.css('width'))
41                .appendTo(ul);
42        };
43    })
44});

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.