PageSourceSearch

https://manaaptieka.lv/wp-content/themes/mana-aptieka/js/search-pa…c741e336b4c1754fff12ba69631710f2.1790976472

js manaaptieka.lv collected 2026-10-02 21:29:21 UTC 11,425 bytes, 231 lines download raw bytes

1jQuery(function ($) {
2    let searchPanelParentHTML = $("html");
3    let searchPanelParent = $("body");
4    let searchHeader = $(".navbar-header");
5    let searchPanel = $(".search-panel");
6    let closeSearchPanel = $(".close-search-panel");
7    // ----------------------------------------
8    let searchUrl = $(".home-url").val();
9    let searchInputValue = "";
10    // ----------------------------------------
11    let productsForSearchPanelData = JSON.parse($(".products-for-search-panel").val());
12    let noResultsProducts = $(".search-panel-products-no-results");
13    let productsWrapper = $(".search-panel-column-list-inner-products");
14    // ----------------------------------------
15    let pharmacyIDs = JSON.parse($(".pharmacies-ids-json").val());
16    let apiProductsPreloader = $(".preloader-api-products");
17    let noResultsApiProducts = $(".search-panel-api-products-no-results");
18    let apiProductsWrapper = $(".search-panel-column-list-inner-api-products");
19    let apiProductsMinimum = $(".search-panel-api-products-minimum-value");
20    // ----------------------------------------
21    let otherDataPreloader = $(".preloader-other-data");
22    let noResultsOtherData = $(".search-panel-other-data-no-results");
23    let otherDataWrapper = $(".search-panel-column-list-inner-other-data");
24    // ----------------------------------------
25    let debounceTimeoutFromApi;
26    let ajaxRequestFromApi;
27    let debounceTimeoutOtherData;
28    let ajaxRequestOtherData;
29    // ----------------------------------------
30
31    searchPanelParent.on("input paste", ".search-input", function () {
32        searchInputValue = $(this).val();
33        if (searchInputValue.length === 0) {
34            searchHeader.removeClass("navbar-header-search-opened");
35            searchPanel.removeClass("search-panel-visible");
36            // Products
37            noResultsProducts.removeClass("d-none");
38            productsWrapper.html("").addClass("d-none");
39            // END Products
40            // Api products
41            apiProductsPreloader.addClass("d-none");
42            noResultsApiProducts.addClass("d-none");
43            apiProductsWrapper.html("").addClass("d-none");
44            apiProductsMinimum.removeClass("d-none");
45            // END Api products
46            // Other data
47            otherDataPreloader.addClass("d-none");
48            noResultsOtherData.addClass("d-none");
49            otherDataWrapper.html("").addClass("d-none");
50            // END Other data
51            if (!$(".navbar-header").hasClass("navbar-header-opened")) {
52                searchPanelParentHTML.removeClass("modal-open");
53            }
54        } else {
55            searchHeader.addClass("navbar-header-search-opened");
56            searchPanel.addClass("search-panel-visible");
57            if ($(window).width() < 1025) {
58                searchPanelParentHTML.addClass("modal-open");
59            }
60
61            // FILLING PRODUCTS
62            // FILLING PRODUCTS
63            // FILLING PRODUCTS
64            let productsToFill = [];
65            for (let i = 0; i < productsForSearchPanelData.length; i++) {
66                if (productsForSearchPanelData[i].title.toLowerCase().includes(searchInputValue.toLowerCase())) {
67                    productsToFill.push(productsForSearchPanelData[i]);
68                }
69            }
70            if (productsToFill.length > 0) {
71                let productsToFillHTML = "";
72                for (let i = 0; i < 3; i++) {
73                    if (typeof productsToFill[i] !== "undefined") {
74                        let priceOrDiscount = (productsToFill[i].discount) ? "-" + productsToFill[i].discount + "%" : number_format(productsToFill[i].price, 2, '.', ' ') + " EUR";
75                        productsToFillHTML += "<div class=\"search-results-product\">\n" +
76                            "                        <a href=\"" + productsToFill[i].permalink + "\" class=\"search-results-product-link\">\n" +
77                            "                            <div class=\"search-results-product-image\">\n" +
78                            "                                <img src=\"" + productsToFill[i].thumb + "\" class=\"" + productsToFill[i].thumb_class + "\">\n" +
79                            "                            </div>\n" +
80                            "                            <div class=\"search-results-product-content\">\n" +
81                            "                                <div class=\"search-results-product-title\">" + productsToFill[i].title + "</div>\n" +
82                            "                                <div class=\"search-results-product-price\">\n" +
83                            "                                    <div class=\"product-price-value\">" + priceOrDiscount + "</div>\n" +
84                            "                                </div>\n" +
85                            "                            </div>\n" +
86                            "                        </a>\n" +
87                            "                    </div>";
88                    }
89                }
90                noResultsProducts.addClass("d-none");
91                productsWrapper.html(productsToFillHTML).removeClass("d-none");
92                if (productsToFill.length > 3) {
93                    productsWrapper.append("<div class=\"all-results-button\">\n" +
94                        "                        <a href=\"" + searchUrl + "?s=" + searchInputValue + "\" class=\"all-results-button-link\">Visi rezultāti</a>\n" +
95                        "                    </div>");
96                }
97            } else {
98                noResultsProducts.removeClass("d-none");
99                productsWrapper.html("").addClass("d-none");
100            }
101            // END FILLING PRODUCTS
102            // END FILLING PRODUCTS
103            // END FILLING PRODUCTS
104
105            // FILLING FROM API DATA
106            // FILLING FROM API DATA
107            // FILLING FROM API DATA
108            if (searchInputValue.length > 2) {
109                apiProductsPreloader.removeClass("d-none");
110                noResultsApiProducts.addClass("d-none");
111                apiProductsMinimum.addClass("d-none");
112                apiProductsWrapper.html("").addClass("d-none");
113                // DEBOUNCING + ABORT
114                clearTimeout(debounceTimeoutFromApi);
115                debounceTimeoutFromApi = setTimeout(() => {
116                    if (ajaxRequestFromApi) {
117                        ajaxRequestFromApi.abort();
118                    }
119                    let testEnvironment = ($(this).hasClass("search-input-test")) ? 1 : 0;
120                    ajaxRequestFromApi = $.ajax({
121                        url: "/wp-admin/admin-ajax.php",
122                        type: "post",
123                        data: {
124                            action: 'searchApiProducts',
125                            pharmacyIDs: pharmacyIDs,
126                            searchInputValue: searchInputValue.toUpperCase(),
127                            testEnvironment: testEnvironment
128                        },
129                        success: function (response) {
130                            apiProductsPreloader.addClass("d-none");
131                            if (response) {
132                                noResultsApiProducts.addClass("d-none");
133                                apiProductsWrapper.html(response).removeClass("d-none");
134                            } else {
135                                noResultsApiProducts.removeClass("d-none");
136                                apiProductsWrapper.html("").addClass("d-none");
137                            }
138                        }
139                    });
140                }, 200);
141                // END DEBOUNCING + ABORT
142            } else {
143                apiProductsPreloader.addClass("d-none");
144                noResultsApiProducts.addClass("d-none");
145                apiProductsWrapper.html("").addClass("d-none");
146                apiProductsMinimum.removeClass("d-none");
147            }
148            // END FILLING FROM API DATA
149            // END FILLING FROM API DATA
150            // END FILLING FROM API DATA
151
152            // FILLING OTHER DATA
153            // FILLING OTHER DATA
154            // FILLING OTHER DATA
155            otherDataPreloader.removeClass("d-none");
156            noResultsOtherData.addClass("d-none");
157            otherDataWrapper.html("").addClass("d-none");
158            // DEBOUNCING + ABORT
159            clearTimeout(debounceTimeoutOtherData);
160            debounceTimeoutOtherData = setTimeout(() => {
161                if (ajaxRequestOtherData) {
162                    ajaxRequestOtherData.abort();
163                }
164                ajaxRequestOtherData = $.ajax({
165                    url: "/wp-admin/admin-ajax.php",
166                    type: "post",
167                    data: {
168                        action: 'searchOtherData',
169                        searchInputValue: searchInputValue
170                    },
171                    success: function (response) {
172                        otherDataPreloader.addClass("d-none");
173                        if (response) {
174                            noResultsOtherData.addClass("d-none");
175                            otherDataWrapper.html(response).removeClass("d-none");
176                        } else {
177                            noResultsOtherData.removeClass("d-none");
178                            otherDataWrapper.html("").addClass("d-none");
179                        }
180                    }
181                });
182            }, 200);
183            // END DEBOUNCING + ABORT
184            // END FILLING OTHER DATA
185            // END FILLING OTHER DATA
186            // END FILLING OTHER DATA
187
188        }
189    });
190
191    closeSearchPanel.on("click", function () {
192        searchHeader.removeClass("navbar-header-search-opened");
193        searchPanel.removeClass("search-panel-visible");
194        if (!$(".navbar-header").hasClass("navbar-header-opened")) {
195            searchPanelParentHTML.removeClass("modal-open");
196        }
197    });
198
199    // -----------------------------------------------------------------------------------------------------------------
200
201    $(".header-search-form").on("submit", function (e) {
202        if ($(this).find(".search-input").val() === "") e.preventDefault();
203    });
204
205    // -----------------------------------------------------------------------------------------------------------------
206
207    function number_format(number, decimals, dec_point, thousands_sep) {
208        // Strip all characters but numerical ones.
209        number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
210        var n = !isFinite(+number) ? 0 : +number,
211            prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
212            sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
213            dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
214            s = '',
215            toFixedFix = function (n, prec) {
216                var k = Math.pow(10, prec);
217                return '' + Math.round(n * k) / k;
218            };
219        // Fix for IE parseFloat(0.55).toFixed(0) = 0;
220        s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
221        if (s[0].length > 3) {
222            s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
223        }
224        if ((s[1] || '').length < prec) {
225            s[1] = s[1] || '';
226            s[1] += new Array(prec - s[1].length + 1).join('0');
227        }
228        return s.join(dec);
229    }
230
231});

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.