PageSourceSearch

https://legacyrecordings.it/wp-content/themes/sonylegacy-theme/js/zepto.autocomplete.js

js legacyrecordings.it collected 2026-10-02 03:40:12 UTC 4,007 bytes, 123 lines download raw bytes

1/*!
2 * ZeptoAutocomplete v0.0.1
3 * Stayzilla.com
4 * MIT license
5 * @preserve
6 */
7var ZeptoAutocomplete = {
8    init: function (limit, data) {
9        this.limit = limit;
10        this.data = data;
11        this.remoteTimeout = 3000;
12        this._setSelectionRange();
13    },
14    _clear: function () {
15        this.limit = 2;
16        this.data = '';
17        this.remoteTimeout = 3000;
18    },
19    _setSelectionRange: function () {
20        $('.autocomplete-input').click(function (event) {
21            this.setSelectionRange(0, this.value.length);
22        });
23    },
24    autocomplete: function (options) {
25        this._clear();
26        if (!this._isDataSourceDefined(options)) {
27            return;
28        }
29        if (this._isLocal(options)) {
30            this._initLocal(options.limit, options.data);
31            return;
32        }
33        if (this._isRemote(options)) {
34            this._initRemote(options.limit, options.data);
35        }
36    },
37    _isDataSourceDefined: function (options) {
38        return typeof options !== "undefined" &&
39            typeof options.datasource !== "undefined" &&
40            options.datasource !== "" &&
41            options.datasource;
42    },
43    _isRemote: function (options) {
44        return options.datasource === 'remote' && typeof options.data !== "undefined" && options.data;
45    },
46    _isLocal: function (options) {
47        return options.datasource === 'local' && typeof options.data !== "undefined" && $.isArray(options.data);
48    },
49    _initLocal: function (limit, data) {
50        this.init(limit, data);
51        var searchTextField = $('.autocomplete-input');
52        var _this = this;
53        searchTextField.bind("keyup", $.proxy(this._handleLocalSearch, _this));
54    },
55    _initRemote: function (limit, data) {
56        this.init(limit, data);
57        var searchTextField = $('.autocomplete-input');
58        var _this = this;
59        searchTextField.bind("keyup", $.proxy(this._handleRemoteSearch, _this));
60    },
61    _isWithinLimit: function (message) {
62        return message !== undefined && message.length > this.limit;
63    },
64    _handleLocalSearch: function () {
65        var message = $('.autocomplete-input').val();
66        if (!this._isWithinLimit(message)) {
67            this._clearResults();
68            return;
69        }
70        this._successHandler(this.data.filter(function (i) {
71            return i.indexOf(message) > -1;
72        }));
73    },
74    _handleRemoteSearch: function (evt) {
75        var message = $('.autocomplete-input').val();
76        var url = this.data + message;
77        if (!this._isWithinLimit(message)) {
78            this._clearResults();
79            return;
80        }
81        $.ajax({
82            type: 'GET',
83            url: url,
84            dataType: 'json',
85            success: $.proxy(this._successHandler, this),
86            error: function (err) {
87                alert('Request failed to load suggestions.');
88            },
89            timeout: this.remoteTimeout
90        });
91    },
92    _successHandler: function (data) {
93        if (data === undefined && data.length <= 0)
94            return;
95        var resultContainer = $('.autocomplete-result');
96        var autocompleteHTML = "<ol>";
97        $.map(data, function (listItem) {
98            autocompleteHTML += "<li>" + listItem + "</li>";
99        });
100        autocompleteHTML += "</ol>";
101        resultContainer.html(autocompleteHTML);
102        var _this = this;
103        $('.autocomplete-result li').on('click', function (evt) {
104            var selectedValue = $(this).text();
105            $('.autocomplete-input').val(selectedValue);
106
107            _this._clearResults();
108
109            
110            $('.autocomplete-input')[0].form.submit();
111        });
112        resultContainer.show();
113    },
114    _clearResults: function () {
115        var resultContainer = $('.autocomplete-result');
116        resultContainer.html('');
117        resultContainer.hide();
118    }
119};
120(function ($) {
121    $.extend($.fn, ZeptoAutocomplete);
122    $.autocomplete = $.fn.autocomplete;
123})(Zepto);

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.