PageSourceSearch

https://binar-shop.ru/local/templates/main/components/api/search.title/main/script.js

js binar-shop.ru collected 2026-10-04 09:20:46 UTC 12,143 bytes, 277 lines download raw bytes

1(function ($) {
2    // настройки со значением по умолчанию
3    var defaults = {};
4
5    // публичные методы
6    var methods = {
7        // инициализация плагина
8        init: function (params) {
9            // актуальные настройки, будут индивидуальными при каждом запуске
10            var options = $.extend({}, defaults, params);
11
12            // инициализируем лишь единожды
13            if (!this.data("apiSearchTitle")) {
14                // закинем настройки в реестр data
15                this.data("apiSearchTitle", options);
16
17                //clear_icon
18                if ($(options.container_id).find(options.input_id).val())
19                    $.fn.apiSearchTitle("showClearIcon", options);
20
21                // далее вся логика
22                var tmr;
23                var curUrl = "";
24                var curSelection = 0;
25
26                $(options.container_id)
27                    .on("keyup paste", options.input_id, function (e) {
28                        //clear_icon
29                        if ($(this).val())
30                            $.fn.apiSearchTitle("showClearIcon", options);
31                        else $.fn.apiSearchTitle("hideClearIcon", options);
32
33                        var resultRows = $(options.container_id)
34                            .find(options.result_id)
35                            .find(".api-item");
36
37                        function api_st_navigate(direction) {
38                            if (
39                                $(options.container_id)
40                                    .find(options.result_id)
41                                    .find(".api-item-active")
42                                    .size() == 0
43                            ) {
44                                curSelection = -1;
45                            }
46
47                            if (direction == "up" && curSelection != -1) {
48                                if (curSelection != 0) {
49                                    curSelection--;
50                                }
51                            } else if (direction == "down") {
52                                if (curSelection != resultRows.size() - 1) {
53                                    curSelection++;
54                                }
55                            }
56                            api_st_set_active(curSelection);
57                        }
58
59                        function api_st_set_active(index) {
60                            resultRows.removeClass("api-item-active");
61                            resultRows.eq(index).addClass("api-item-active");
62                            curUrl = resultRows
63                                .eq(index)
64                                .find("a")
65                                .attr("href");
66                        }
67
68                        switch (e.keyCode) {
69                            case 37: //Left button
70                            case 39: //Right button
71                            case 32: //Backspace button
72                                break;
73
74                            case 27: // escape key - close search div
75                                $.fn.apiSearchTitle("hideBackdrop", options);
76                                break;
77
78                            case 13: //Enter button
79                                if (curUrl != "") {
80                                    window.location = curUrl;
81                                }
82                                break;
83
84                            case 38:
85                                api_st_navigate("up");
86                                break;
87
88                            case 40:
89                                api_st_navigate("down");
90                                break;
91
92                            default: {
93                                clearTimeout(tmr);
94                                tmr = setTimeout(function () {
95                                    $(options.container_id)
96                                        .find(options.ajax_icon_id)
97                                        .show();
98
99                                    $.ajax({
100                                        type: "POST",
101                                        data: {
102                                            sessid: options.sessid,
103                                            q: $(options.container_id)
104                                                .find(options.input_id)
105                                                .val(),
106                                            API_SEARCH_TITLE_ID:
107                                                options.component_id,
108                                            API_SEARCH_TITLE_AJAX: "Y",
109                                            spell: "1",
110                                        },
111                                        success: function (data) {
112                                            $(options.container_id)
113                                                .find(options.ajax_icon_id)
114                                                .hide();
115
116                                            $(options.container_id)
117                                                .find(options.result_id)
118                                                .html(data);
119
120                                            $(".base-loader").fadeOut(200);
121                                            $(".js-search-close").fadeIn(200);
122                                            /*.find('.api-item-picture')
123                                                .each(function(){
124                                                    var wrapHeight = $(this).closest('.api-item-link').height();
125                                                    $(this).css({
126                                                        'marginTop': '-'+ (wrapHeight/2) +'px'
127                                                    });
128                                                    $(this).find('img').css({
129                                                        'maxHeight': wrapHeight
130                                                    });
131                                                });*/
132
133                                            $.fn.apiSearchTitle(
134                                                "showScroll",
135                                                options
136                                            );
137
138                                            //backdrop
139                                            if (options.backdrop.active) {
140                                                $.fn.apiSearchTitle(
141                                                    "showBackdrop",
142                                                    options
143                                                );
144                                            }
145                                        },
146                                    });
147                                }, options.wait_time);
148                            }
149                        }
150                    })
151                    .keydown(function () {
152                        clearTimeout(tmr);
153                    });
154
155                //backdrop
156                if (options.backdrop.active) {
157                    $.fn.apiSearchTitle("initBackdrop", options);
158
159                    $(options.container_id).on(
160                        "click",
161                        options.input_id,
162                        function () {
163                            if (
164                                $(options.container_id).find(
165                                    ".api-category-list"
166                                ).length
167                            ) {
168                                $.fn.apiSearchTitle("showBackdrop", options);
169                            }
170                        }
171                    );
172                }
173
174                $(window).resize(function () {
175                    $.fn.apiSearchTitle("showScroll", options);
176                    $.fn.apiSearchTitle("checkWidth", options);
177                });
178
179                $.fn.apiSearchTitle("checkWidth", options);
180
181                //clear_icon
182                $(options.container_id).on(
183                    "click",
184                    options.clear_icon_id,
185                    function () {
186                        $(options.container_id).find(options.input_id).val("");
187                        $(options.container_id)
188                            .find(options.result_id)
189                            .html("");
190                        $.fn.apiSearchTitle("hideBackdrop", options);
191                        $(this).hide();
192                    }
193                );
194            }
195
196            return this;
197        },
198        initBackdrop: function (options) {
199            var backdrop = $("<div/>", {
200                id: options.backdrop.id,
201                class: options.backdrop.clas,
202                css: options.backdrop.css,
203                click: function () {
204                    $.fn.apiSearchTitle("hideBackdrop", options);
205                },
206            }).appendTo("body");
207
208            backdrop.hide();
209        },
210        hideBackdrop: function (options) {
211            $("#" + options.backdrop.id).fadeOut(0);
212            $(options.parent_id).removeClass("api-backdrop-active");
213            /*$(options.container_id).find(options.result_id).fadeOut(0);*/
214            $(options.container_id)
215                .find(options.scroll_id)
216                .css({ visibility: "hidden" });
217        },
218        showBackdrop: function (options) {
219            $("#" + options.backdrop.id).fadeIn(0);
220            $(options.parent_id)
221                .addClass("api-backdrop-active")
222                .css(options.parent.css);
223            /*$(options.container_id).find(options.result_id).fadeIn(0);*/
224
225            if (!$(options.container_id).find(".api-category-list").length)
226                $(options.container_id)
227                    .find(options.scroll_id)
228                    .css({ visibility: "hidden" });
229            else
230                $(options.container_id)
231                    .find(options.scroll_id)
232                    .css({ visibility: "visible" });
233        },
234        showScroll: function (options) {
235            var search_result_obj = $(options.container_id).find(
236                options.result_id
237            );
238            if (search_result_obj.length) {
239                var offset_top =
240                    search_result_obj.offset().top ||
241                    $(options.container_id).offset().top;
242
243                search_result_obj.css({
244                    "max-height": $(window).height() - (offset_top + 30),
245                });
246            }
247        },
248        showClearIcon: function (options) {
249            $(options.container_id).find(options.clear_icon_id).fadeIn(200);
250        },
251        hideClearIcon: function (options) {
252            $(options.container_id).find(options.clear_icon_id).hide();
253        },
254        checkWidth: function (options) {
255            if ($(options.container_id).width() <= 320) {
256                $(options.container_id).addClass("api-width-mini");
257            } else $(options.container_id).removeClass("api-width-mini");
258        },
259    };
260
261    $.fn.apiSearchTitle = function (method) {
262        if (methods[method]) {
263            return methods[method].apply(
264                this,
265                Array.prototype.slice.call(arguments, 1)
266            );
267        } else if (typeof method === "object" || !method) {
268            return methods.init.apply(this, arguments);
269        } else {
270            $.error(
271                'Error! Method "' +
272                    method +
273                    '" not found in plugin $.fn.apiSearchTitle'
274            );
275        }
276    };
277})(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.