PageSourceSearch

https://laguna22.ru/hostcmsfiles/jquery/jquery.autocomplete.min.js?v=20260902d

js laguna22.ru collected 2026-09-28 22:45:37 UTC 16,005 bytes, 453 lines download raw bytes

1(function(a) {
2    if ("function" === typeof define && define.amd) {
3        define(["jquery"], a)
4    } else {
5        a(jQuery)
6    }
7})(function(c) {
8    function b(e, d) {
9        var f = function() {};
10        f = {
11            autoSelectFirst: false,
12            appendTo: "body",
13            serviceUrl: null,
14            lookup: null,
15            onSelect: null,
16            width: "auto",
17            minChars: 1,
18            maxHeight: 300,
19            deferRequestBy: 0,
20            params: {},
21            formatResult: b.formatResult,
22            delimiter: null,
23            zIndex: 9999,
24            type: "GET",
25            noCache: false,
26            onSearchStart: f,
27            onSearchComplete: f,
28            containerClass: "autocomplete-suggestions",
29            tabDisabled: false,
30            dataType: "text",
31            lookupFilter: function(h, g, i) {
32                return -1 !== h.value.toLowerCase().indexOf(i)
33            },
34            paramName: "query",
35            transformResult: function(g) {
36                return "string" === typeof g ? c.parseJSON(g) : g
37            }
38        };
39        this.element = e;
40        this.el = c(e);
41        this.suggestions = [];
42        this.badQueries = [];
43        this.selectedIndex = -1;
44        this.currentValue = this.element.value;
45        this.intervalId = 0;
46        this.cachedResponse = [];
47        this.onChange = this.onChangeInterval = null;
48        this.isLocal = this.ignoreValueChange = false;
49        this.suggestionsContainer = null;
50        this.options = c.extend({}, f, d);
51        this.classes = {
52            selected: "autocomplete-selected",
53            suggestion: "autocomplete-suggestion"
54        };
55        this.initialize();
56        this.setOptions(d)
57    }
58    var a = {
59        extend: function(d, e) {
60            return c.extend(d, e)
61        },
62        createNode: function(d) {
63            var e = document.createElement("div");
64            e.innerHTML = d;
65            return e.firstChild
66        }
67    };
68    b.utils = a;
69    c.Autocomplete = b;
70    b.formatResult = function(e, d) {
71        var f = "(" + d.replace(RegExp("(\\/|\\.|\\*|\\+|\\?|\\||\\(|\\)|\\[|\\]|\\{|\\}|\\\\)", "g"), "\\$1") + ")";
72        return e.value.replace(RegExp(f, "gi"), "<strong>$1</strong>")
73    };
74    b.prototype = {
75        killerFn: null,
76        initialize: function() {
77            var g = this;
78            var h = "." + g.classes.suggestion;
79            var f = g.classes.selected;
80            var e = g.options;
81            var d;
82            g.element.setAttribute("autocomplete", "off");
83            g.killerFn = function(i) {
84                if (0 === c(i.target).closest("." + g.options.containerClass).length) {
85                    g.killSuggestions();
86                    g.disableKillerFn()
87                }
88            };
89            if (!e.width || "auto" === e.width) {
90                e.width = g.el.outerWidth()
91            }
92            g.suggestionsContainer = b.utils.createNode('<div class="' + e.containerClass + '" style="position: absolute; display: none;"></div>');
93            d = c(g.suggestionsContainer);
94            d.appendTo(e.appendTo).width(e.width);
95            d.on("mouseover.autocomplete", h, function() {
96                g.activate(c(this).data("index"))
97            });
98            d.on("mouseout.autocomplete", function() {
99                g.selectedIndex = -1;
100                d.children("." + f).removeClass(f)
101            });
102            d.on("click.autocomplete", h, function() {
103                g.select(c(this).data("index"), false)
104            });
105            g.fixPosition();
106            if (window.opera) {
107                g.el.on("keypress.autocomplete", function(i) {
108                    g.onKeyPress(i)
109                })
110            } else {
111                g.el.on("keydown.autocomplete", function(i) {
112                    g.onKeyPress(i)
113                })
114            }
115            g.el.on("keyup.autocomplete", function(i) {
116                g.onKeyUp(i)
117            });
118            g.el.on("blur.autocomplete", function() {
119                g.onBlur()
120            });
121            g.el.on("focus.autocomplete", function() {
122                g.fixPosition()
123            })
124        },
125        onBlur: function() {
126            this.enableKillerFn()
127        },
128        setOptions: function(e) {
129            var d = this.options;
130            a.extend(d, e);
131            if (this.isLocal = c.isArray(d.lookup)) {
132                d.lookup = this.verifySuggestionsFormat(d.lookup)
133            }
134            c(this.suggestionsContainer).css({
135                "max-height": d.maxHeight + "px",
136                width: d.width + "px",
137                "z-index": d.zIndex
138            })
139        },
140        clearCache: function() {
141            this.cachedResponse = [];
142            this.badQueries = []
143        },
144        clear: function() {
145            this.clearCache();
146            this.currentValue = null;
147            this.suggestions = []
148        },
149        disable: function() {
150            this.disabled = true
151        },
152        enable: function() {
153            this.disabled = false
154        },
155        fixPosition: function() {
156            var d;
157            if ("body" === this.options.appendTo) {
158                d = this.el.offset();
159                c(this.suggestionsContainer).css({
160                    top: d.top + this.el.outerHeight() + "px",
161                    left: d.left + "px"
162                })
163            }
164        },
165        enableKillerFn: function() {
166            c(document).on("click.autocomplete", this.killerFn)
167        },
168        disableKillerFn: function() {
169            c(document).off("click.autocomplete", this.killerFn)
170        },
171        killSuggestions: function() {
172            var d = this;
173            d.stopKillSuggestions();
174            d.intervalId = window.setInterval(function() {
175                d.hide();
176                d.stopKillSuggestions()
177            }, 300)
178        },
179        stopKillSuggestions: function() {
180            window.clearInterval(this.intervalId)
181        },
182        onKeyPress: function(d) {
183            if (!this.disabled && (!this.visible && (40 === d.keyCode && this.currentValue))) {
184                this.suggest()
185            } else {
186                if (!this.disabled && this.visible) {
187                    switch (d.keyCode) {
188                        case 27:
189                            this.el.val(this.currentValue);
190                            this.hide();
191                            break;
192                        case 9:
193                        case 13:
194                            if (-1 === this.selectedIndex) {
195                                this.hide();
196                                return
197                            }
198                            this.select(this.selectedIndex, 13 === d.keyCode);
199                            if (9 === d.keyCode && false === this.options.tabDisabled) {
200                                return
201                            }
202                            break;
203                        case 38:
204                            this.moveUp();
205                            break;
206                        case 40:
207                            this.moveDown();
208                            break;
209                        default:
210                            return
211                    }
212                    d.stopImmediatePropagation();
213                    d.preventDefault()
214                }
215            }
216        },
217        onKeyUp: function(f) {
218            var d = this;
219            if (!d.disabled) {
220                switch (f.keyCode) {
221                    case 38:
222                    case 40:
223                        return
224                }
225                clearInterval(d.onChangeInterval);
226                if (d.currentValue !== d.el.val()) {
227                    if (0 < d.options.deferRequestBy) {
228                        d.onChangeInterval = setInterval(function() {
229                            d.onValueChange()
230                        }, d.options.deferRequestBy)
231                    } else {
232                        d.onValueChange()
233                    }
234                }
235            }
236        },
237        onValueChange: function() {
238            var d;
239            clearInterval(this.onChangeInterval);
240            this.currentValue = this.element.value;
241            d = this.getQuery(this.currentValue);
242            this.selectedIndex = -1;
243            if (this.ignoreValueChange) {
244                this.ignoreValueChange = false
245            } else {
246                if (d.length < this.options.minChars) {
247                    this.hide()
248                } else {
249                    this.getSuggestions(d)
250                }
251            }
252        },
253        getQuery: function(e) {
254            var d = this.options.delimiter;
255            if (!d) {
256                return c.trim(e)
257            }
258            e = e.split(d);
259            return c.trim(e[e.length - 1])
260        },
261        getSuggestionsLocal: function(f) {
262            var d = f.toLowerCase();
263            var e = this.options.lookupFilter;
264            return {
265                suggestions: c.grep(this.options.lookup, function(g) {
266                    return e(g, f, d)
267                })
268            }
269        },
270        getSuggestions: function(g) {
271            var d;
272            var f = this;
273            var e = f.options;
274            var h = e.serviceUrl;
275            if ((d = f.isLocal ? f.getSuggestionsLocal(g) : f.cachedResponse[g]) && c.isArray(d.suggestions)) {
276                f.suggestions = d.suggestions;
277                f.suggest()
278            } else {
279                if (!f.isBadQuery(g)) {
280                    e.params[e.paramName] = g;
281                    if (false !== e.onSearchStart.call(f.element, e.params)) {
282                        if (c.isFunction(e.serviceUrl)) {
283                            h = e.serviceUrl.call(f.element, g)
284                        }
285                        c.ajax({
286                            url: h,
287                            data: e.ignoreParams ? null : e.params,
288                            type: e.type,
289                            dataType: e.dataType
290                        }).done(function(i) {
291                            f.processResponse(i, g);
292                            e.onSearchComplete.call(f.element, g)
293                        })
294                    }
295                }
296            }
297        },
298        isBadQuery: function(e) {
299            var f = this.badQueries;
300            var d = f.length;
301            for (; d--;) {
302                if (0 === e.indexOf(f[d])) {
303                    return true
304                }
305            }
306            return false
307        },
308        hide: function() {
309            this.visible = false;
310            this.selectedIndex = -1;
311            c(this.suggestionsContainer).hide()
312        },
313        suggest: function() {
314            if (0 === this.suggestions.length) {
315                this.hide()
316            } else {
317                var i = this.options.formatResult;
318                var h = this.getQuery(this.currentValue);
319                var f = this.classes.suggestion;
320                var e = this.classes.selected;
321                var d = c(this.suggestionsContainer);
322                var g = "";
323                c.each(this.suggestions, function(k, j) {
324                    g += '<li class="' + f + '" data-index="' + k + '"><a href="' + j.href + '" >';
325                    if (j.image != "") {
326                        g += '<img src="' + j.image + '"/> '
327                    }
328                    g += i(j, h) + "</a></li>"
329                });
330                d.html(g).show();
331                this.visible = true;
332                if (this.options.autoSelectFirst) {
333                    this.selectedIndex = 0;
334                    d.children().first().addClass(e)
335                }
336            }
337        },
338        verifySuggestionsFormat: function(d) {
339            return d.length && "string" === typeof d[0] ? c.map(d, function(e) {
340                return {
341                    value: e,
342                    data: null
343                }
344            }) : d
345        },
346        processResponse: function(f, e) {
347            var g = this.options;
348            var d = g.transformResult(f, e);
349            d.suggestions = this.verifySuggestionsFormat(d.suggestions);
350            if (!g.noCache) {
351                this.cachedResponse[d[g.paramName]] = d;
352                if (0 === d.suggestions.length) {
353                    this.badQueries.push(d[g.paramName])
354                }
355            }
356            if (e === this.getQuery(this.currentValue)) {
357                this.suggestions = d.suggestions;
358                this.suggest()
359            }
360        },
361        activate: function(f) {
362            var g = this.classes.selected;
363            var d = c(this.suggestionsContainer);
364            var e = d.children();
365            d.children("." + g).removeClass(g);
366            this.selectedIndex = f;
367            return -1 !== this.selectedIndex && e.length > this.selectedIndex ? (f = e.get(this.selectedIndex), c(f).addClass(g), f) : null
368        },
369        select: function(d, f) {
370            var e = this.suggestions[d];
371            if (e) {
372                this.ignoreValueChange = f;
373                this.hide()
374            }
375        },
376        moveUp: function() {
377            if (-1 !== this.selectedIndex) {
378                if (0 === this.selectedIndex) {
379                    c(this.suggestionsContainer).children().first().removeClass(this.classes.selected);
380                    this.selectedIndex = -1;
381                    this.el.val(this.currentValue)
382                } else {
383                    this.adjustScroll(this.selectedIndex - 1)
384                }
385            }
386        },
387        moveDown: function() {
388            if (this.selectedIndex !== this.suggestions.length - 1) {
389                this.adjustScroll(this.selectedIndex + 1)
390            }
391        },
392        adjustScroll: function(d) {
393            var e = this.activate(d);
394            var g;
395            var f;
396            if (e) {
397                e = e.offsetTop;
398                g = c(this.suggestionsContainer).scrollTop();
399                f = g + this.options.maxHeight - 25;
400                if (e < g) {
401                    c(this.suggestionsContainer).scrollTop(e)
402                } else {
403                    if (e > f) {
404                        c(this.suggestionsContainer).scrollTop(e - this.options.maxHeight + 25)
405                    }
406                }
407                this.el.val(this.getValue(this.suggestions[d].value))
408            }
409        },
410        onSelect: function(d) {
411            var e = this.options.onSelect;
412            d = this.suggestions[d];
413            this.el.val(this.getValue(d.value));
414            if (c.isFunction(e)) {
415                e.call(this.element, d)
416            }
417        },
418        getValue: function(e) {
419            var g = this.options.delimiter;
420            var f;
421            if (!g) {
422                return e
423            }
424            f = this.currentValue;
425            g = f.split(g);
426            return 1 === g.length ? e : f.substr(0, f.length - g[g.length - 1].length) + e
427        },
428        dispose: function() {
429            this.el.off(".autocomplete").removeData("autocomplete");
430            this.disableKillerFn();
431            c(this.suggestionsContainer).remove()
432        }
433    };
434    c.fn.suggest = function(d, e) {
435        return 0 === arguments.length ? this.first().data("autocomplete") : this.each(function() {
436            var g = c(this);
437            var f = g.data("autocomplete");
438            if ("string" === typeof d) {
439                if (f && "function" === typeof f[d]) {
440                    f[d](e)
441                }
442            } else {
443                if (f) {
444                    if (f.dispose) {
445                        f.dispose()
446                    }
447                }
448                f = new b(this, d);
449                g.data("autocomplete", f)
450            }
451        })
452    }
453});

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.