PageSourceSearch

https://www.bazashop.ru/design/user/baza23/assets/libs/jquery.autocomplete.js

js bazashop.ru collected 2026-09-28 08:06:56 UTC 19,301 bytes, 509 lines download raw bytes

1// Limit scope pollution from any deprecated API
2var fcatal = false;
3(function() {
4
5    var matched, browser;
6
7    // Use of jQuery.browser is frowned upon.
8    // More details: http://api.jquery.com/jQuery.browser
9    // jQuery.uaMatch maintained for back-compat
10    jQuery.uaMatch = function(ua) {
11        ua = ua.toLowerCase();
12
13        var match = /(chrome)[ \/]([\w.]+)/.exec(ua) ||
14            /(webkit)[ \/]([\w.]+)/.exec(ua) ||
15            /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) ||
16            /(msie) ([\w.]+)/.exec(ua) ||
17            ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || [];
18
19        return {
20            browser: match[1] || "",
21            version: match[2] || "0"
22        };
23    };
24
25    matched = jQuery.uaMatch(navigator.userAgent);
26    browser = {};
27
28    if (matched.browser) {
29        browser[matched.browser] = true;
30        browser.version = matched.version;
31    }
32
33    // Chrome is Webkit, but Webkit is also Safari.
34    if (browser.chrome) {
35        browser.webkit = true;
36    } else if (browser.webkit) {
37        browser.safari = true;
38    }
39
40    jQuery.browser = browser;
41
42    jQuery.sub = function() {
43        function jQuerySub(selector, context) {
44            return new jQuerySub.fn.init(selector, context);
45        }
46        jQuery.extend(true, jQuerySub, this);
47        jQuerySub.superclass = this;
48        jQuerySub.fn = jQuerySub.prototype = this();
49        jQuerySub.fn.constructor = jQuerySub;
50        jQuerySub.sub = this.sub;
51        jQuerySub.fn.init = function init(selector, context) {
52            if (context && context instanceof jQuery && !(context instanceof jQuerySub)) {
53                context = jQuerySub(context);
54            }
55
56            return jQuery.fn.init.call(this, selector, context, rootjQuerySub);
57        };
58        jQuerySub.fn.init.prototype = jQuerySub.fn;
59        var rootjQuerySub = jQuerySub(document);
60        return jQuerySub;
61    };
62
63})();
64! function(a) {
65    a.fn.extend({
66        autocomplete: function(b, c) {
67            var d = "string" == typeof b;
68            return c = a.extend({}, a.Autocompleter.defaults, {
69                url: d ? b : null,
70                data: d ? null : b,
71                delay: d ? a.Autocompleter.defaults.delay : 10,
72                max: c && !c.scroll ? 10 : 150
73            }, c), c.highlight = c.highlight || function(a) {
74                return a
75            }, c.formatMatch = c.formatMatch || c.formatItem, this.each(function() {
76                new a.Autocompleter(this, c)
77            })
78        },
79        result: function(a) {
80            return this.bind("result", a)
81        },
82        search: function(a) {
83            return this.trigger("search", [a])
84        },
85        flushCache: function() {
86            return this.trigger("flushCache")
87        },
88        setOptions: function(a) {
89            return this.trigger("setOptions", [a])
90        },
91        unautocomplete: function() {
92            return this.trigger("unautocomplete")
93        }
94    }), a.Autocompleter = function(b, c) {
95        function n() {
96            var d = l.selected();
97            if (!d) return !1;
98            var f = d.result;
99            if (g = f, c.multiple) {
100                var h = p(e.val());
101                if (h.length > 1) {
102                    var k, i = c.multipleSeparator.length,
103                        j = a(b).selection().start,
104                        m = 0;
105                    a.each(h, function(a, b) {
106                        return m += b.length, j <= m ? (k = a, !1) : void(m += i)
107                    }), h[k] = f, f = h.join(c.multipleSeparator)
108                }
109                f += c.multipleSeparator
110            }
111            return e.val(f), t(), e.trigger("result", [d.data, d.value]), !0
112        }
113
114        function o(a, b) {
115            if (j == d.DEL) return void l.hide();
116            var f = e.val();
117            (b || f != g) && (g = f, f = q(f), f.length >= c.minChars ? (e.addClass(c.loadingClass), c.matchCase || (f = f.toLowerCase()), v(f, u, t)) : (x(), l.hide()))
118        }
119
120        function p(b) {
121            return b ? c.multiple ? a.map(b.split(c.multipleSeparator), function(c) {
122                return a.trim(b).length ? a.trim(c) : null
123            }) : [a.trim(b)] : [""]
124        }
125
126        function q(d) {
127            if (!c.multiple) return d;
128            var e = p(d);
129            if (1 == e.length) return e[0];
130            var f = a(b).selection().start;
131            return e = p(f == d.length ? d : d.replace(d.substring(f), "")), e[e.length - 1]
132        }
133
134        function r(f, h) {
135            c.autoFill && q(e.val()).toLowerCase() == f.toLowerCase() && j != d.BACKSPACE && (e.val(e.val() + h.substring(q(g).length)), a(b).selection(g.length, g.length + h.length))
136        }
137
138        function s() {
139            clearTimeout(f), f = setTimeout(t, 200)
140        }
141
142        function t() {
143            l.visible();
144            l.hide(), clearTimeout(f), x(), c.mustMatch && e.search(function(a) {
145                if (!a)
146                    if (c.multiple) {
147                        var b = p(e.val()).slice(0, -1);
148                        e.val(b.join(c.multipleSeparator) + (b.length ? c.multipleSeparator : ""))
149                    } else e.val(""), e.trigger("result", null)
150            })
151        }
152
153        function u(a, b) {
154            b && b.length && i ? (x(), l.display(b, a), r(a, b[0].value), l.show()) : t()
155        }
156
157        function v(d, e, f) {
158            c.matchCase || (d = d.toLowerCase());
159            var g = h.load(d);
160            if (g && g.length) e(d, g);
161            else if ("string" == typeof c.url && c.url.length > 0) {
162                var i = {
163                    timestamp: +new Date
164                };
165                a.each(c.extraParams, function(a, b) {
166                    i[a] = "function" == typeof b ? b() : b
167                }), a.ajax({
168                    mode: "abort",
169                    port: "autocomplete" + b.name,
170                    dataType: c.dataType,
171                    url: c.url,
172                    data: a.extend({
173                        q: q(d),
174                        limit: c.max
175                    }, i),
176                    success: function(a) {
177                        var b = c.parse && c.parse(a) || w(a);
178                        h.add(d, b), e(d, b)
179                    }
180                })
181            } else l.emptyList(), f(d)
182        }
183
184        function w(b) {
185            for (var d = [], e = b.split("\n"), f = 0; f < e.length; f++) {
186                var g = a.trim(e[f]);
187                g && (g = g.split("|"), d[d.length] = {
188                    data: g,
189                    value: g[0],
190                    result: c.formatResult && c.formatResult(g, g[0]) || g[0]
191                })
192            }
193            return d
194        }
195
196        function x() {
197            e.removeClass(c.loadingClass)
198        }
199        var f, j, m, d = {
200                UP: 38,
201                DOWN: 40,
202                DEL: 46,
203                TAB: 9,
204                RETURN: 13,
205                ESC: 27,
206                COMMA: 188,
207                PAGEUP: 33,
208                PAGEDOWN: 34,
209                BACKSPACE: 8
210            },
211            e = a(b).attr("autocomplete", "off").addClass(c.inputClass),
212            g = "",
213            h = a.Autocompleter.Cache(c),
214            i = 0,
215            k = {
216                mouseDownOnSelect: !1
217            },
218            l = a.Autocompleter.Select(c, b, n, k);
219        a.browser.opera && a(b.form).bind("submit.autocomplete", function() {
220            if (m) return m = !1, !1
221        }), e.bind((a.browser.opera ? "keypress" : "keydown") + ".autocomplete", function(b) {
222            switch (i = 1, j = b.keyCode, b.keyCode) {
223                case d.UP:
224                    b.preventDefault(), l.visible() ? l.prev() : o(0, !0);
225                    break;
226                case d.DOWN:
227                    b.preventDefault(), l.visible() ? l.next() : o(0, !0);
228                    break;
229                case d.PAGEUP:
230                    b.preventDefault(), l.visible() ? l.pageUp() : o(0, !0);
231                    break;
232                case d.PAGEDOWN:
233                    b.preventDefault(), l.visible() ? l.pageDown() : o(0, !0);
234                    break;
235                case c.multiple && "," == a.trim(c.multipleSeparator) && d.COMMA:
236                case d.TAB:
237                case d.RETURN:
238                    if (n()) return b.preventDefault(), m = !0, !1;
239                    break;
240                case d.ESC:
241                    l.hide();
242                    break;
243                default:
244                    clearTimeout(f), f = setTimeout(o, c.delay)
245            }
246        }).focus(function() {
247            i++
248        }).blur(function() {
249            i = 0, k.mouseDownOnSelect || s()
250        }).click(function() {
251            i++ > 1 && !l.visible() && o(0, !0)
252        }).bind("search", function() {
253            function c(a, c) {
254                var d;
255                if (c && c.length)
256                    for (var f = 0; f < c.length; f++)
257                        if (c[f].result.toLowerCase() == a.toLowerCase()) {
258                            d = c[f];
259                            break
260                        }
261                "function" == typeof b ? b(d) : e.trigger("result", d && [d.data, d.value])
262            }
263            var b = arguments.length > 1 ? arguments[1] : null;
264            a.each(p(e.val()), function(a, b) {
265                v(b, c, c)
266            })
267        }).bind("flushCache", function() {
268            h.flush()
269        }).bind("setOptions", function() {
270            a.extend(c, arguments[1]), "data" in arguments[1] && h.populate()
271        }).bind("unautocomplete", function() {
272            l.unbind(), e.unbind(), a(b.form).unbind(".autocomplete")
273        })
274    }, a.Autocompleter.defaults = {
275        inputClass: "ac_input",
276        resultsClass: "ac_results",
277        loadingClass: "ac_loading",
278        minChars: 1,
279        delay: 400,
280        matchCase: !1,
281        matchSubset: !0,
282        matchContains: !1,
283        cacheLength: 10,
284        max: 100,
285        mustMatch: !1,
286        extraParams: {},
287        selectFirst: !0,
288        formatItem: function(a) {
289            return a[0]
290        },
291        formatMatch: null,
292        autoFill: !1,
293        width: 0,
294        multiple: !1,
295        multipleSeparator: ", ",
296        highlight: function(a, b) {
297            return a.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + b.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>")
298        },
299        scroll: !0,
300        scrollHeight: 180
301    }, a.Autocompleter.Cache = function(b) {
302        function e(a, c) {
303            b.matchCase || (a = a.toLowerCase());
304            var d = a.indexOf(c);
305            return "word" == b.matchContains && (d = a.toLowerCase().search("\\b" + c.toLowerCase())), d != -1 && (0 == d || b.matchContains)
306        }
307
308        function f(a, e) {
309            d > b.cacheLength && h(), c[a] || d++, c[a] = e
310        }
311
312        function g() {
313            if (!b.data) return !1;
314            var c = {},
315                d = 0;
316            b.url || (b.cacheLength = 1), c[""] = [];
317            for (var e = 0, g = b.data.length; e < g; e++) {
318                var h = b.data[e];
319                h = "string" == typeof h ? [h] : h;
320                var i = b.formatMatch(h, e + 1, b.data.length);
321                if (i !== !1) {
322                    var j = i.charAt(0).toLowerCase();
323                    c[j] || (c[j] = []);
324                    var k = {
325                        value: i,
326                        data: h,
327                        result: b.formatResult && b.formatResult(h) || i
328                    };
329                    c[j].push(k), d++ < b.max && c[""].push(k)
330                }
331            }
332            a.each(c, function(a, c) {
333                b.cacheLength++, f(a, c)
334            })
335        }
336
337        function h() {
338            c = {}, d = 0
339        }
340        var c = {},
341            d = 0;
342        return setTimeout(g, 25), {
343            flush: h,
344            add: f,
345            populate: g,
346            load: function(f) {
347                if (!b.cacheLength || !d) return null;
348                if (!b.url && b.matchContains) {
349                    var g = [];
350                    for (var h in c)
351                        if (h.length > 0) {
352                            var i = c[h];
353                            a.each(i, function(a, b) {
354                                e(b.value, f) && g.push(b)
355                            })
356                        } return g
357                }
358                if (c[f]) return c[f];
359                if (b.matchSubset)
360                    for (var j = f.length - 1; j >= b.minChars; j--) {
361                        var i = c[f.substr(0, j)];
362                        if (i) {
363                            var g = [];
364                            return a.each(i, function(a, b) {
365                                e(b.value, f) && (g[g.length] = b)
366                            }), g
367                        }
368                    }
369                return null
370            }
371        }
372    }, a.Autocompleter.Select = function(b, c, d, e) {
373        function n() {
374            k && (l = a("<div/>").hide().addClass(b.resultsClass).css("position", "absolute").appendTo(document.body), m = a("<ul/>").appendTo(l).mouseover(function(b) {
375                o(b).nodeName && "LI" == o(b).nodeName.toUpperCase() && (h = a("li", m).removeClass(f.ACTIVE).index(o(b)), a(o(b)).addClass(f.ACTIVE))
376            }) /*.click(function(b){return a(o(b)).addClass(f.ACTIVE),d(),c.focus(),!1})*/ .mousedown(function() {
377                e.mouseDownOnSelect = !0
378            }).mouseup(function() {
379                e.mouseDownOnSelect = !1
380            }), b.width > 0 && l.css("width", b.width), k = !1)
381        }
382
383        function o(a) {
384            for (var b = a.target; b && "LI" != b.tagName;) b = b.parentNode;
385            return b ? b : []
386        }
387
388        function p(a) {
389            g.slice(h, h + 1).removeClass(f.ACTIVE), q(a);
390            var c = g.slice(h, h + 1).addClass(f.ACTIVE);
391            if (b.scroll) {
392                var d = 0;
393                g.slice(0, h).each(function() {
394                    d += this.offsetHeight
395                }), d + c[0].offsetHeight - m.scrollTop() > m[0].clientHeight ? m.scrollTop(d + c[0].offsetHeight - m.innerHeight()) : d < m.scrollTop() && m.scrollTop(d)
396            }
397        }
398
399        function q(a) {
400            h += a, h < 0 ? h = g.size() - 1 : h >= g.size() && (h = 0)
401        }
402
403        function r(a) {
404            return b.max && b.max < a ? b.max : a
405        }
406
407        function s() {
408            m.empty();
409            for (var c = r(i.length), d = 0; d < c; d++)
410                if (i[d]) {
411                    var e = b.formatItem(i[d].data, d + 1, c, i[d].value, j);
412					
413					
414                    if (e !== !1) {
415						if(i[d].data[0] == 'cat') {
416							var k = a("<li/>").html(b.highlight(e, j)).addClass(d % 2 == 0 ? "ac_even" : "ac_odd").addClass('cat').appendTo(m)[0];
417						} else {
418							var k = a("<li/>").html(b.highlight(e, j)).addClass(d % 2 == 0 ? "ac_even" : "ac_odd").appendTo(m)[0];
419						}
420                        a.data(k, "ac_data", i[d])
421                    }
422                } g = m.find("li"), b.selectFirst && (g.slice(0, 1).addClass(f.ACTIVE), h = 0), a.fn.bg
422iframe && m.bgiframe()
423        }
424        var g, i, l, m, f = {
425                ACTIVE: "ac_over"
426            },
427            h = -1,
428            j = "",
429            k = !0;
430        return {
431            display: function(a, b) {
432                n(), i = a, j = b, s()
433            },
434            next: function() {
435                p(1)
436            },
437            prev: function() {
438                p(-1)
439            },
440            pageUp: function() {
441                p(0 != h && h - 8 < 0 ? -h : -8)
442            },
443            pageDown: function() {
444                p(h != g.size() - 1 && h + 8 > g.size() ? g.size() - 1 - h : 8)
445            },
446            hide: function() {
447                l && l.hide(), g && g.removeClass(f.ACTIVE), h = -1
448            },
449            visible: function() {
450                return l && l.is(":visible")
451            },
452            current: function() {
453                return this.visible() && (g.filter("." + f.ACTIVE)[0] || b.selectFirst && g[0])
454            },
455            show: function() {
456                var d = a(c).offset();
457                if (l.css({
458                        width: "string" == typeof b.width || b.width > 0 ? b.width : a(c).width(),
459                        top: d.top + c.offsetHeight,
460                        left: d.left
461                    }).show(), b.scroll && (m.scrollTop(0), m.css({
462                        maxHeight: b.scrollHeight,
463                        overflow: "auto"
464                    }), a.browser.msie && "undefined" == typeof document.body.style.maxHeight)) {
465                    var e = 0;
466                    g.each(function() {
467                        e += this.offsetHeight
468                    });
469                    var f = e > b.scrollHeight;
470                    m.css("height", f ? b.scrollHeight : e), f || g.width(m.width() - parseInt(g.css("padding-left")) - parseInt(g.css("padding-right")))
471                }
472            },
473            selected: function() {
474                var b = g && g.filter("." + f.ACTIVE).removeClass(f.ACTIVE);
475                return b && b.length && a.data(b[0], "ac_data")
476            },
477            emptyList: function() {
478                m && m.empty()
479            },
480            unbind: function() {
481                l && l.remove()
482            }
483        }
484    }, a.fn.selection = function(a, b) {
485        if (void 0 !== a) return this.each(function() {
486            if (this.createTextRange) {
487                var c = this.createTextRange();
488                void 0 === b || a == b ? (c.move("character", a), c.select()) : (c.collapse(!0), c.moveStart("character", a), c.moveEnd("character", b), c.select())
489            } else this.setSelectionRange ? this.setSelectionRange(a, b) : this.selectionStart && (this.selectionStart = a, this.selectionEnd = b)
490        });
491        var c = this[0];
492        if (c.createTextRange) {
493            var d = document.selection.createRange(),
494                e = c.value,
495                f = "<->",
496                g = d.text.length;
497            d.text = f;
498            var h = c.value.indexOf(f);
499            return c.value = e, this.selection(h, h + g), {
500                start: h,
501                end: h + g
502            }
503        }
504        return void 0 !== c.selectionStart ? {
505            start: c.selectionStart,
506            end: c.selectionEnd
507        } : void 0
508    }
509}(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.