PageSourceSearch

https://manaaptieka.lv/wp-content/themes/mana-aptieka/js/filters.j…c741e336b4c1754fff12ba69631710f2.1790323453

js manaaptieka.lv collected 2026-09-25 08:05:09 UTC 43,871 bytes, 1,005 lines download raw bytes

1function getDayName(dateStr, locale) {
2    let date = new Date(dateStr);
3    return date.toLocaleDateString(locale, {weekday: 'long'});
4}
5
6function inArray(needle, haystack) {
7    let length = haystack.length;
8    for (let i = 0; i < length; i++) {
9        if (haystack[i] === needle) return true;
10    }
11    return false;
12}
13
14// ---------------------------------------------------------------------------------------------------------------------
15
16let markers = [];
17let infoWindows = [];
18let infoWindowOuter = null;
19let markerOuter = null;
20
21let triangleHeight = 12;
22let markerHeight = 42;
23
24// ---------------------------------------------------------------------------------------------------------------------
25
26let map; // Don't move these variables from here;
27let defaultLat = 56.96820094896186;
28let defaultLng = 24.10571139412774;
29
30// let maxZoomClusters = 14;
31// let clusters;
32// let clusterMarker;
33// let oms;
34//
35// let clusterStyles = [
36//     {
37//         textColor: '#71CDA9',
38//         textSize: 16,
39//         url: data.templateUrl + "/images/cluster-small.svg",
40//         height: 50,
41//         width: 50,
42//         backgroundPosition: 'center center',
43//     },
44//     {
45//         textColor: '#71CDA9',
46//         textSize: 16,
47//         url: data.templateUrl + "/images/cluster-medium.svg",
48//         height: 60,
49//         width: 60,
50//         backgroundPosition: 'center center',
51//     },
52//     {
53//         textColor: '#71CDA9',
54//         textSize: 16,
55//         url: data.templateUrl + "/images/cluster-big.svg",
56//         height: 70,
57//         width: 70,
58//         backgroundPosition: 'center center',
59//     }
60// ];
61
62function initFiltersMap() {
63
64    let daysLV = {
65        monday: "Pirmdiena",
66        tuesday: "Otrdiena",
67        wednesday: "Trešdiena",
68        thursday: "Ceturtdiena",
69        friday: "Piektdiena",
70        saturday: "Sestdiena",
71        sunday: "Svētdiena"
72    };
73
74    let defaultCoordinates = {
75        lat: defaultLat,
76        lng: defaultLng
77    };
78
79    // DATA
80    let markerIconDefault = {
81        url: data.templateUrl + "/images/map-pin.svg",
82        size: new google.maps.Size(30, 42),
83        origin: new google.maps.Point(0, 0),
84        anchor: new google.maps.Point(15, 42),
85        scaledSize: new google.maps.Size(30, 42)
86    };
87    let markerIconActive = {
88        url: data.templateUrl + "/images/map-pin-active.svg",
89        size: new google.maps.Size(30, 42),
90        origin: new google.maps.Point(0, 0),
91        anchor: new google.maps.Point(15, 42),
92        scaledSize: new google.maps.Size(30, 42)
93    };
94    // END DATA
95
96
97    // MAP INITIALIZING
98    map = new google.maps.Map(document.getElementById('pharmacies-map'), {
99        zoom: 7,
100        center: defaultCoordinates,
101        gestureHandling: 'cooperative',
102        zoomControl: true,
103        mapTypeControl: false,
104        streetViewControl: false,
105    });
106    // END MAP INITIALIZING
107
108    // CLUSTERING + SPIDERING
109    // clusterMarker = [];
110    // oms = new OverlappingMarkerSpiderfier(map, {
111    //     markersWontMove: true,
112    //     markersWontHide: true,
113    //     basicFormatEvents: true,
114    //     circleFootSeparation: 100,
115    //     spiralLengthStart: 23,
116    //     spiralLengthFactor: 23,
117    //     spiralFootSeparation: 100,
118    //     keepSpiderfied: true,
119    //     ignoreMapClick: true
120    // });
121    // END CLUSTERING + SPIDERING
122
123    // MARKERS
124    let coordinates = [];
125    for (let i = 0; i < data.pharmacies.length; i++) {
126        coordinates.push(
127            {
128                ID: data.pharmacies[i].ID,
129                api_pharmacy_id: data.pharmacies[i].api_pharmacy_id,
130                title: data.pharmacies[i].title,
131                permalink: data.pharmacies[i].permalink,
132                address: data.pharmacies[i].address,
133                address_on_map: data.pharmacies[i].address_on_map,
134                google_map_link: data.pharmacies[i].google_map_link,
135                waze_link: data.pharmacies[i].waze_link,
136                contact_phone: data.pharmacies[i].contact_phone,
137                mobile_phone: data.pharmacies[i].mobile_phone,
138                work_schedule: data.pharmacies[i].work_schedule_select,//todo change to work_schedule_select
139                thumb: data.pharmacies[i].thumb,
140                alt: data.pharmacies[i].alt,
141                thumb_class: data.pharmacies[i].thumb_class,
142                subtext: data.pharmacies[i].subtext,
143            }
144        );
145    }
146
147    markers = [];
148    infoWindows = [];
149    let zIndexCustom = 100;
150    let iterator;
151
152    for (let i = 0; i < coordinates.length; i++) {
153        if (coordinates[i].address_on_map !== null) {
154            let marker = new google.maps.Marker({
155                position: {
156                    lat: coordinates[i].address_on_map.lat,
157                    lng: coordinates[i].address_on_map.lng
158                },
159                animation: google.maps.Animation.DROP,
160                icon: markerIconDefault
161            });
162            marker.set("id", coordinates[i].ID);
163            marker.set("api_pharmacy_id", coordinates[i].api_pharmacy_id);
164            markers.push(marker);
165            marker.setMap(map);
166            marker.setZIndex(zIndexCustom);
167            zIndexCustom++;
168
169            // INFO WINDOWS
170            // INFO WINDOWS
171            // INFO WINDOWS
172            let infoWindowHTML = "<div class=\"single-place single-place-info-window\">";
173
174            infoWindowHTML += "<a href=\"" + coordinates[i].permalink + "\" class=\"single-place-title\">" + coordinates[i].title + "</a>";
175            infoWindowHTML += "<div class=\"single-place-availability d-none\">Pieejams: <span></span></div>";
176
177            if (coordinates[i].address || coordinates[i].contact_phone || coordinates[i].mobile_phone) {
178                infoWindowHTML += "<div class=\"single-place-contacts\">";
179                if (coordinates[i].address) {
180                    infoWindowHTML += "<div class=\"single-place-contact single-place-address\">" +
181                        "<img src=\"" + data.templateUrl + "/images/pin-contacts.svg\" alt=\"Address\">" +
182                        "<span>" + coordinates[i].address + "</span>" +
183                        "</div>";
184                }
185                if (coordinates[i].contact_phone) {
186                    infoWindowHTML += "<a href=\"tel:" + coordinates[i].contact_phone + "\" class=\"single-place-contact single-place-phone\">" +
187                        "<img src=\"" + data.templateUrl + "/images/phone-contacts.svg\" alt=\"Phone\">" +
188                        "<span>" + coordinates[i].contact_phone + "</span>" +
189                        "</a>" +
190                        "<br>";
191                }
192                if (coordinates[i].mobile_phone) {
193                    infoWindowHTML += "<a href=\"tel:" + coordinates[i].mobile_phone + "\" class=\"single-place-contact single-place-phone\">" +
194                        "<img src=\"" + data.templateUrl + "/images/phone-contacts.svg\" alt=\"Phone\">" +
195                        "<span>" + coordinates[i].mobile_phone + "</span>" +
196                        "</a>";
197                }
198                infoWindowHTML += "</div>";
199            }
200
201            infoWindowHTML += "<div class=\"single-place-row\">";
202            // Image
203            infoWindowHTML += "<div class=\"single-place-image\">" +
204                "<div class=\"single-place-image-inner " + coordinates[i].thumb_class + "\">" +
205                "    <a href=\"" + coordinates[i].permalink + "\">" +
206                "        <img src=\"" + coordinates[i].thumb + "\" alt=\"" + coordinates[i].alt + "\">" +
207                "    </a>" +
208                "</div>" +
209                "<div class=\"single-place-link\">" +
210                "    <a href=\"" + coordinates[i].permalink + "\">Skatīt aptieku</a>" +
211                "</div>" +
212                "</div>";
213            // END Image
214
215            // Content
216            if (coordinates[i].work_schedule) {
217                infoWindowHTML += "<div class=\"single-place-content\">" +
218                    "<div class=\"single-place-content-inner\">";
219
220                let dateStr = Date.now();
221                let day = getDayName(dateStr, "lv-LV");
222                let dayKey = null;
223                for (let prop in daysLV) {
224                    if (daysLV[prop] === day) {
225                        dayKey = prop;
226                        break;
227                    }
228                }
229                if (dayKey !== null) {
230                    infoWindowHTML += "<div class=\"single-place-work-schedule-preview\">" +
231                        "<div class=\"single-place-preview-time\">" +
232                        "<span>Darba laiks šodien: </span><br>" + coordinates[i].work_schedule[dayKey] +
233                        "</div>" +
234                        "<a href=\"\" class=\"single-place-work-schedule-opener\">Visi darba laiki</a>" +
235                        "</div>" +
236                        "<div class=\"single-place-work-schedule\">";
237                    for (let row in coordinates[i].work_schedule) {
238                        infoWindowHTML += "<div class=\"work-schedule-row\">";
239                        if (coordinates[i].work_schedule[row]) {
240                            infoWindowHTML += "<div class=\"work-schedule-row-day\">" + daysLV[row] + ":</div>" +
241                                "<div class=\"work-schedule-row-time\">" + coordinates[i].work_schedule[row] + "</div>";
242                        }
243                        infoWindowHTML += "</div>";
244                    }
245                    infoWindowHTML += "<a href=\"\" class=\"single-place-work-schedule-closer\">Aizvērt</a>" +
246                        "</div>";
247                }
248                infoWindowHTML += "</div>" +
249                    "</div>";
250            }
251            // END Content
252            infoWindowHTML += "</div>";
253
254            if (coordinates[i].google_map_link || coordinates[i].waze_link) {
255                infoWindowHTML += "<div class=\"single-place-routes\">";
256                if (coordinates[i].google_map_link) {
257                    infoWindowHTML += "<div class=\"single-place-route single-place-route-google-map\">" +
258                        "<a href=\"" + coordinates[i].google_map_link + "\" target=\"_blank\">" +
259                        "<img src=\"" + data.templateUrl + "/images/google-map.svg\" alt=\"Google Map\">" +
260                        "</a>" +
261                        "</div>";
262                }
263                if (coordinates[i].waze_link) {
264                    infoWindowHTML += "<div class=\"single-place-route single-place-route-waze\">" +
265                        "<a href=\"" + coordinates[i].waze_link + "\" target=\"_blank\">" +
266                        "<img src=\"" + data.templateUrl + "/images/waze.svg\" alt=\"Waze\">" +
267                        "</a>" +
268                        "</div>";
269                }
270                infoWindowHTML += "</div>";
271            }
272
273            if (coordinates[i].subtext) {
274                infoWindowHTML += "<div class=\"single-place-subtext\">" + coordinates[i].subtext + "</div>";
275            }
276
277            infoWindowHTML += "</div>";
278
279            let infoWindow = new google.maps.InfoWindow({content: infoWindowHTML});
280            infoWindows.push(infoWindow);
281            // END INFO WINDOWS
282            // END INFO WINDOWS
283            // END INFO WINDOWS
284
285            google.maps.event.addListener(marker, 'click', function () {
286                // Switch marker icon
287                marker.setZIndex(zIndexCustom);
288                zIndexCustom++;
289                for (iterator = 0; iterator < markers.length; iterator++) {
290                    markers[iterator].setIcon(markerIconDefault);
291                }
292                marker.setIcon(markerIconActive);
293                // END Switch marker icon
294
295                // infoWindows
296                closeAllInfoWindows();
297                openInfoWindow(infoWindow, map, marker);
298                // END infoWindows
299            });
300
301            google.maps.event.addListener(infoWindow, 'closeclick', function () {
302                for (iterator = 0; iterator < markers.length; iterator++) {
303                    markers[iterator].setIcon(markerIconDefault);
304                }
305            });
306
307            google.maps.event.addListener(infoWindow, 'domready', function () {
308                recenterInfoWindow(markerOuter);
309            });
310
311            map.addListener('click', function () {
312                closeAllInfoWindows();
313            });
314
315
316            // CLUSTERING + SPIDERING
317            // oms.addMarker(marker);
318            // clusterMarker.push(marker);
319            // END CLUSTERING + SPIDERING
320
321        }
322    }
323
324    // CLUSTERING + SPIDERING
325    // clusters = new MarkerClusterer(map, clusterMarker, {
326    //     // imagePath: data.templateUrl + "/images/m",
327    //     styles: clusterStyles,
328    //     maxZoom: maxZoomClusters
329    // });
330
331    // END CLUSTERING + SPIDERING
332
333    function closeAllInfoWindows() {
334        for (let i = 0; i < infoWindows.length; i++) {
335            infoWindows[i].close();
336        }
337    }
338
339    function openInfoWindow(infoWindow, map, marker) {
340        if (infoWindow != null) {
341            infoWindowOuter = infoWindow;
342            markerOuter = marker;
343            infoWindow.open(map, marker);
344        }
345    }
346
347    // END MARKERS
348}
349
350function zoomMap(lat, lng, zoom = null, bounds = null, map) {
351    const newLatLng = {lat: lat, lng: lng};
352    map.setCenter(newLatLng);
353    if (zoom !== null) {
354        setTimeout(function () {
355            map.setZoom(zoom);
356        }, 10)
357    } else if (bounds !== null) {
358        map.fitBounds(bounds);
359    }
360}
361
362function getDataAndZoomSingle(locationName) {
363    let geocoder = new google.maps.Geocoder();
364    geocoder.geocode({
365        'address': locationName,
366        'region': 'LV'
367    }, function (results, status) {
368        if (status === google.maps.GeocoderStatus.OK) {
369            let Lat = results[0].geometry.location.lat();
370            let Lng = results[0].geometry.location.lng();
371            zoomMap(Lat, Lng, 10, null, map);
372        } else {
373            console.log("Something got wrong " + status);
374        }
375    });
376}
377
378function getDataAndZoomMultiple(locations) {
379    let geocoder = new google.maps.Geocoder();
380    let coordinates = [];
381    let bounds = new google.maps.LatLngBounds();
382
383    let geocodeLocation = function (i) {
384        if (i < locations.length) {
385            geocoder.geocode({
386                'address': locations[i],
387                'region': 'LV'
388            }, function (results, status) {
389                if (status === google.maps.GeocoderStatus.OK) {
390                    let Lat = results[0].geometry.location.lat();
391                    let Lng = results[0].geometry.location.lng();
392                    let latLng = new google.maps.LatLng(Lat, Lng);
393                    coordinates.push({lat: Lat, lng: Lng});
394                    bounds.extend(latLng);
395
396                    if (i + 1 === locations.length) {
397                        calculateCenter(coordinates, bounds);
398                    } else {
399                        geocodeLocation(i + 1);
400                    }
401                } else {
402                    console.log("Something went wrong: " + status);
403                }
404            });
405        }
406    };
407
408    let calculateCenter = function (coords, bounds_value) {
409        let latSum = 0;
410        let lngSum = 0;
411
412        coords.forEach(coord => {
413            latSum += coord.lat;
414            lngSum += coord.lng;
415        });
416
417        let centerLat = latSum / coords.length;
418        let centerLng = lngSum / coords.length;
419
420        let centerCoordinates = {lat: centerLat, lng: centerLng};
421        console.log("Center Coordinates:", centerCoordinates);
422
423        zoomMap(centerCoordinates.lat, centerCoordinates.lng, null, bounds_value, map);
424    };
425
426    geocodeLocation(0);
427
428}
429
430function recenterInfoWindow(marker) {
431    let infoWindowHeight = jQuery(".pharmacies-map").find(".single-place-info-window").outerHeight();
432    let panByValue = ((triangleHeight + markerHeight + infoWindowHeight) / 2) * (-1);
433    map.panTo(marker.getPosition());
434    map.panBy(0, panByValue);
435}
436
437function checkZoomType(data) {
438    let firstSelected = data.items[0]
439    let firstSelectedTitle = data.options[firstSelected].text;
440    if (data.items.length === 1) {
441        getDataAndZoomSingle(firstSelectedTitle);
442    } else {
443        let selectedTitles = [];
444        for (let prop in data.options) {
445            if (inArray(prop, data.items)) selectedTitles.push(data.options[prop].text);
446        }
447        getDataAndZoomMultiple(selectedTitles);
448    }
449}
450
451// ---------------------------------------------------------------------------------------------------------------------
452
453jQuery(function ($) {
454    $.getScript(data.templateUrl + "/js/selectize-plugins.js", function () {
455        let filtersBody = $("body");
456        let currentPageLinkBase = $(".current-base-link").val();
457        let currentView = $(".active-screen-view").data("view");
458
459        let selectedMedicine = $(".selected-medicine").val();
460        if (typeof selectedMedicine === "undefined") selectedMedicine = null;
461        let selectedMedicineValueForURL = null;
462        let pharmaciesIDs = null;
463        let stockData = null;
464        let selectedCities = [];
465        let selectedServices = [];
466        let selectedMeasurements = [];
467
468        let sectionsCount = $(".place-section").length;
469        let hiddenSectionsCounter;
470        let pharmaciesStaticList = $(".pharmacies-list-inner");
471        let pharmaciesStaticMap = $(".pharmacies-map");
472        let noResultsList = $(".pharmacies-list-no-results");
473        let noResultsMap = $(".pharmacies-map-no-results");
474        let hiddenElements = [];
475
476        let markerIconDefaultCopy = {
477            url: data.templateUrl + "/images/map-pin.svg",
478            size: new google.maps.Size(30, 42),
479            origin: new google.maps.Point(0, 0),
480            anchor: new google.maps.Point(15, 42),
481            scaledSize: new google.maps.Size(30, 42)
482        };
483
484        // TRIGGER FILTERS
485        let selectedCitiesFilling = (values) => {
486            selectedCities = [];
487            for (let city = 0; city < values.length; city++) {
488                selectedCities.push(parseInt(values[city]));
489            }
490        }
491        $(".selectize-city-filter").selectize({
492            plugins: ['remove_button'],
493            hideSelected: true,
494            onInitialize: function () {
495                if ($(this)[0].items.length > 0) {
496                    checkZoomType($(this)[0]);
497                }
498            },
499            onChange: function (values) {
500                selectedCitiesFilling(values);
501                fillSelectize();
502                filtering(selectedCities, selectedServices, selectedMeasurements, selectedMedicine);
503                if (values.length === 0) zoomMap(defaultLat, defaultLng, 7, null, map);
504            },
505            onItemAdd: function (value, $item) {
506                this.blur();
507                if ($(window).width() <= 1180) {
508                    $('html, body').animate({
509                        scrollTop: $(".pharmacies-content").offset().top - 103
510                    }, 1000);
511                }
512                checkZoomType($(this)[0]);
513            },
514            onItemRemove: function (value) {
515                if ($(this)[0].items.length > 0) {
516                    checkZoomType($(this)[0]);
517                }
518            },
519            onDropdownOpen: function () {
520                $(".navbar-header").addClass("navbar-header-hidden");
521                if ($(window).width() < 600) {
522                    $('html, body').animate({
523                        scrollTop: $(".city-filter-wrapper").offset().top - 6
524                    }, 0);
525                }
526            },
527            onDropdownClose: function () {
528                $(".navbar-header").removeClass("navbar-header-hidden");
529            }
530        });
531
532        let selectedServicesFilling = () => {
533            selectedServices = [];
534            $(".service-filter").each(function (index, elem) {
535                if ($(elem).prop("checked")) selectedServices.push(parseInt($(elem).val()));
536            });
537        }
538        $(".service-filter").on("change", function () {
539            selectedServicesFilling();
540            filtering(selectedCities, selectedServices, selectedMeasurements, selectedMedicine);
541        });
542
543        let selectedMeasurementsFilling = () => {
544            selectedMeasurements = [];
545            $(".measurement-filter").each(function (index, elem) {
546                if ($(elem).prop("checked")) selectedMeasurements.push(parseInt($(elem).val()));
547            });
548        }
549        $(".measurement-filter").on("change", function () {
550            selectedMeasurementsFilling();
551            filtering(selectedCities, selectedServices, selectedMeasurements, selectedMedicine);
552        });
553        // END TRIGGER FILTERS
554
555        // CLEAN BUTTON
556        let cleanFilters = () => {
557            selectedCities = [];
558            selectedServices = [];
559            selectedMeasurements = [];
560            selectedMedicine = null;
561            selectedMedicineValueForURL = null;
562            pharmaciesIDs = null;
563            stockData = null;
564            $(".place-section").removeClass("hidden-location").removeClass("hidden-all-inner-elements");
565            $(".single-place").removeClass("hidden-location").removeClass("hidden-service").removeClass("hidden-measurement").removeClass("hidden-medicine").removeClass("hidden-general");
566            noResultsList.addClass("d-none");
567            noResultsMap.addClass("d-none");
568            pharmaciesStaticList.removeClass("d-none");
569            pharmaciesStaticMap.removeClass("d-none");
570            $(".service-filter").prop('checked', false);
571            $(".measurement-filter").prop('checked', false);
572            $("#city-filter")[0].selectize.clear();
573            changeUrl(selectedCities, selectedServices, selectedMeasurements);
574        }
575        let cleanFiltersButton = $(".clean-filters-button");
576        cleanFiltersButton.on("click", function (e) {
577            e.preventDefault();
578            cleanFilters();
579            filtering(selectedCities, selectedServices, selectedMeasurements, selectedMedicine);
580        });
581        // END CLEAN BUTTON
582
583        // -------------------------------------------------------------------------------------------------------------
584
585        // FILTERING
586        // FILTERING
587        // FILTERING
588
589        // STOCK FILTERING
590        // STOCK FILTERING
591        // STOCK FILTERING
592        let stockFiltering = (stock, pharmacies) => {
593            if (!(stock === null || ($.isArray(stock) && stock.length === 0))) {
594                $(".place-section:not(.hidden-location)").each(function (index, elem) {
595                    $(elem).find(".single-place").each(function (indexInner, elemInner) {
596                        let placeApiPharmacyID = $(elemInner).data("api-pharmacy-id");
597                        let stockFrontendValue = ($(".medicines-page-test").length > 0)
598                            ? stock[placeApiPharmacyID]
599                            : (stock[placeApiPharmacyID] > 3) ? ">3" : stock[placeApiPharmacyID];
600                        ((inArray(placeApiPharmacyID, pharmacies)) && typeof stock[placeApiPharmacyID] !== "undefined")
601                            ? $(elemInner).find(".single-place-availability").removeClass("d-none").find("span").html(stockFrontendValue)
602                            : $(elemInner).find(".single-place-availability").addClass("d-none").find("span").html("");
603                    });
604                });
605                for (let iterMarker = 0; iterMarker < markers.length; iterMarker++) {
606                    let markerApiPharmacyID = markers[iterMarker].get("api_pharmacy_id");
607                    markerApiPharmacyID = parseInt(markerApiPharmacyID);
608                    if ((inArray(markerApiPharmacyID, pharmacies)) && typeof stock[markerApiPharmacyID] !== "undefined") {
609                        let tempDiv = document.createElement('div');
610                        tempDiv.innerHTML = infoWindows[iterMarker].content;
611                        let availabilityElement = tempDiv.querySelector('.single-place-availability');
612                        if (availabilityElement) {
613                            availabilityElement.classList.remove('d-none');
614                            let spanElement = availabilityElement.querySelector('span');
615                            let stockFrontendValue = ($(".medicines-page-test").length > 0)
616                                ? stock[markerApiPharmacyID]
617                                : (stock[markerApiPharmacyID] > 3) ? ">3" : stock[markerApiPharmacyID];
618                            if (spanElement) spanElement.textContent = stockFrontendValue;
619                            infoWindows[iterMarker].setContent(tempDiv.innerHTML);
620                        }
621                    }
622                }
623            } else {
624                $(".place-section:not(.hidden-location)").each(function (index, elem) {
625                    $(elem).find(".single-place").each(function (indexInner, elemInner) {
626                        $(elemInner).find(".single-place-availability").addClass("d-none").find("span").html("");
627                    });
628                });
629                for (let iterMarker = 0; iterMarker < markers.length; iterMarker++) {
630                    let tempDiv = document.createElement('div');
631                    tempDiv.innerHTML = infoWindows[iterMarker].content;
632                    let availabilityElement = tempDiv.querySelector('.single-place-availability');
633                    if (availabilityElement) {
634                        availabilityElement.classList.add('d-none');
635                        let spanElement = availabilityElement.querySelector('span');
636                        if (spanElement) spanElement.textContent = "";
637                        infoWindows[iterMarker].setContent(tempDiv.innerHTML);
638                    }
639                }
640            }
641        }
642        // END STOCK FILTERING
643        // END STOCK FILTERING
644        // END STOCK FILTERING
645
646        // MAP FILTERING
647        // MAP FILTERING
648        // MAP FILTERING
649        let basicMapFiltering = () => {
650
651            // CLUSTERING + SPIDERING
652            // clusters.clearMarkers();
653            // clusterMarker = [];
654            // END CLUSTERING + SPIDERING
655
656            hiddenElements = [];
657            $(".single-place").each(function (index, elem) {
658                if ($(elem).hasClass("hidden-location") || $(elem).hasClass("hidden-service") || $(elem).hasClass("hidden-measurement") || $(elem).hasClass("hidden-medicine") || $(elem).hasClass("hidden-general")) {
659                    let singlePlaceID = $(elem).data("single-place-id");
660                    hiddenElements.push(singlePlaceID);
661                }
662            });
663            for (let iterMarker = 0; iterMarker < markers.length; iterMarker++) {
664                let markerID = markers[iterMarker].get("id");
665                if (inArray(markerID, hiddenElements)) {
666                    markers[iterMarker].setVisible(false);
667                    infoWindows[iterMarker].close();
668                    markers[iterMarker].setIcon(markerIconDefaultCopy);
669                } else {
670                    markers[iterMarker].setVisible(true);
671
672                    // CLUSTERING + SPIDERING
673                    // oms.addMarker(markers[iterMarker]);
674                    // clusterMarker.push(markers[iterMarker]);
675                    // END CLUSTERING + SPIDERING
676
677                }
678            }
679
680            // CLUSTERING + SPIDERING
681            // clusters = new MarkerClusterer(map, clusterMarker, {
682            //     styles: clusterStyles,
683            //     maxZoom: maxZoomClusters
684            // });
685            // END CLUSTERING + SPIDERING
686
687        }
688        // END MAP FILTERING
689        // END MAP FILTERING
690        // END MAP FILTERING
691
692        // LIST FILTERING
693        // LIST FILTERING
694        // LIST FILTERING
695        let basicListFiltering = (cities, services, measurements, pharmacies, stock) => {
696
697            // Filtering by Cities in List
698            if (cities.length > 0) {
699                $(".place-section").each(function (index, elem) {
700                    let placeID = $(elem).data("place-id");
701                    if (!inArray(placeID, cities)) {
702                        $(elem).addClass("hidden-location");
703                        $(elem).find(".single-place").addClass("hidden-location");
704                    } else {
705                        $(elem).removeClass("hidden-location");
706                        $(elem).find(".single-place").removeClass("hidden-location");
707                    }
708                });
709            } else {
710                $(".place-section").removeClass("hidden-location");
711                $(".single-place").removeClass("hidden-location");
712            }
713            // END Filtering by Cities in List
714
715            // Filtering by Services in List
716            if (services.length > 0) {
717                $(".place-section:not(.hidden-location)").each(function (index, elem) {
718                    $(elem).find(".single-place").each(function (indexInner, elemInner) {
719                        let placeServices = $(elemInner).data("services-ids");
720                        if (placeServices === null) placeServices = [];
721                        let serviceChecker = false;
722                        for (let service = 0; service < services.length; service++) {
723                            if ((inArray(services[service], placeServices))) {
724                                serviceChecker = true;
725                            } else {
726                                serviceChecker = false;
727                                break;
728                            }
729                        }
730                        (serviceChecker === false) ? $(elemInner).addClass("hidden-service") : $(elemInner).removeClass("hidden-service");
731                    });
732                });
733            } else {
734                $(".single-place").removeClass("hidden-service");
735            }
736            // END Filtering by Services in List
737
738            // Filtering by Measurements in List
739            if (measurements.length > 0) {
740                $(".place-section:not(.hidden-location)").each(function (index, elem) {
741                    $(elem).find(".single-place").each(function (indexInner, elemInner) {
742                        let placeMeasurements = $(elemInner).data("measurements-ids");
743                        if (placeMeasurements === null) placeMeasurements = [];
744                        let measurementChecker = false;
745                        for (let measurement = 0; measurement < measurements.length; measurement++) {
746                            if ((inArray(measurements[measurement], placeMeasurements))) {
747                                measurementChecker = true;
748                            } else {
749                                measurementChecker = false;
750                                break;
751                            }
752                        }
753                        (measurementChecker === false) ? $(elemInner).addClass("hidden-measurement") : $(elemInner).removeClass("hidden-measurement");
754                    });
755                });
756            } else {
757                $(".single-place").removeClass("hidden-measurement");
758            }
759            // END Filtering by Measurements in List
760
761            // Filtering by Medicine in List
762            if (pharmacies !== null && pharmacies.length > 0) {
763                $(".place-section:not(.hidden-location)").each(function (index, elem) {
764                    $(elem).find(".single-place").each(function (indexInner, elemInner) {
765                        let placeApiPharmacyID = $(elemInner).data("api-pharmacy-id");
766                        let pharmacyChecker = ((inArray(placeApiPharmacyID, pharmacies)));
767                        (pharmacyChecker === false) ? $(elemInner).addClass("hidden-medicine") : $(elemInner).removeClass("hidden-medicine");
768                    });
769                });
770            }
771            // END Filtering by Medicine in List
772
773            // General Filtering
774            if (cities.length === 0 && services.length === 0 && measurements.length === 0 && pharmacies.length === 0) {
775                $(".place-section:not(.hidden-location)").each(function (index, elem) {
776                    $(elem).find(".single-place").each(function (indexInner, elemInner) {
777                        $(elemInner).addClass("hidden-general");
778                    });
779                });
780            }
781            // END General Filtering
782
783            // Check if all elements hidden in still not hidden location
784            $(".place-section:not(.hidden-location)").each(function (index, elem) {
785                let hiddenPlacesCounter = 0;
786                let countCurrentSectionPlaces = $(elem).find(".single-place").length;
787                $(elem).find(".single-place").each(function (indexInner, elemInner) {
788                    if ($(elemInner).hasClass("hidden-service") || $(elemInner).hasClass("hidden-measurement") || $(elemInner).hasClass("hidden-medicine") || $(elemInner).hasClass("hidden-general")) hiddenPlacesCounter++;
789                });
790                (hiddenPlacesCounter === countCurrentSectionPlaces) ? $(elem).addClass("hidden-all-inner-elements") : $(elem).removeClass("hidden-all-inner-elements");
791            });
792            // END Check if all elements hidden in still not hidden location
793
794            // Check if all sections are hidden
795            hiddenSectionsCounter = 0;
796            $(".place-section").each(function (index, elem) {
797                if ($(elem).hasClass("hidden-location") || $(elem).hasClass("hidden-all-inner-elements")) hiddenSectionsCounter++;
798            });
799            if (hiddenSectionsCounter === sectionsCount) {
800                noResultsList.removeClass("d-none");
801                noResultsMap.removeClass("d-none");
802                pharmaciesStaticList.addClass("d-none");
803                pharmaciesStaticMap.addClass("d-none");
804            } else {
805                noResultsList.addClass("d-none");
806                noResultsMap.addClass("d-none");
807                pharmaciesStaticList.removeClass("d-none");
808                pharmaciesStaticMap.removeClass("d-none");
809            }
810            // END Check if all sections are hidden
811
812            // Fill hidden places for Map
813            basicMapFiltering();
814            // END Fill hidden places for Map
815
816            // Stock Filtering
817            stockFiltering(stock, pharmacies);
818            // END Stock Filtering
819
820            changeUrl(cities, services, measurements);
821        }
822        // END LIST FILTERING
823        // END LIST FILTERING
824        // END LIST FILTERING
825
826        // MAIN FILTERING
827        // MAIN FILTERING
828        // MAIN FILTERING
829        let filtering = (cities, services, measurements, medicine) => {
830            if (medicine !== null) {
831                selectedMedicineValueForURL = selectedMedicine;
832                selectedMedicine = null;
833                $.ajax({
834                    url: "/wp-admin/admin-ajax.php",
835                    type: "post",
836                    data: {
837                        action: 'medicineFiltering',
838                        medicine: medicine
839                    },
840                    dataType: 'json',
841                    success: function (response) {
842                        pharmaciesIDs = response["pharmacies"];
843                        stockData = response["stock"];
844                        basicListFiltering(cities, services, measurements, pharmaciesIDs, stockData);
845                        let hiddenCitiesIDsForSelectize = [];
846                        $(".hidden-all-inner-elements").each(function (index, elem) {
847                            hiddenCitiesIDsForSelectize.push($(elem).data("place-id"));
848                        });
849                        if (hiddenCitiesIDsForSelectize.length > 0) {
850                            let $citiesSelect = $('#city-filter').selectize();
851                            let citiesSelectize = $citiesSelect[0].selectize;
852                            hiddenCitiesIDsForSelectize.forEach(function (id) {
853                                citiesSelectize.removeOption(id);
854                            });
855                        }
856                        pharmaciesStaticMap.removeClass("d-none");
857                        pharmaciesStaticList.removeClass("d-none");
858                    }
859                });
860            } else {
861                if (cities.length > 0 || services.length > 0 || measurements.length > 0 || (pharmaciesIDs !== null && pharmaciesIDs.length > 0)) {
862                    basicListFiltering(cities, services, measurements, pharmaciesIDs, stockData);
863                } else {
864                    cleanFilters();
865                    basicMapFiltering();
866                    stockFiltering(stockData, pharmaciesIDs);
867                }
868                pharmaciesStaticMap.removeClass("d-none");
869                pharmaciesStaticList.removeClass("d-none");
870            }
871        }
872        // END MAIN FILTERING
873        // END MAIN FILTERING
874        // END MAIN FILTERING
875
876        // END FILTERING
877        // END FILTERING
878        // END FILTERING
879
880        // -------------------------------------------------------------------------------------------------------------
881
882        let fillSelectize = () => {
883            let itemsWrapper = $(".selected-cities-wrapper");
884            let items = $(".city-filter-wrapper .selectize-input").html();
885            itemsWrapper.html(items).find("#city-filter-selectized").remove();
886            let isEmptyItems = itemsWrapper.html();
887            (isEmptyItems !== "") ? itemsWrapper.addClass("selected-cities-wrapper-full") : itemsWrapper.removeClass("selected-cities-wrapper-full");
888            $("#city-filter-selectized").attr("placeholder", "Lūdzu, izvēlieties");
889            $(".city-filter-wrapper .selectize-input .item").css("display", "none");
890        }
891
892        filtersBody.on("click", ".selected-cities-wrapper .item a", function () {
893            let itemToDeleteButton = $(this);
894            let itemToDelete = itemToDeleteButton.parent();
895            let cityToDelete = itemToDelete.attr("data-value");
896            itemToDelete.remove();
897            $(".city-filter-wrapper .selectize-input .item").each(function () {
898                let iteratedItem = $(this);
899                let neededToDelete = iteratedItem.attr("data-value");
900                if (neededToDelete === cityToDelete) {
901                    iteratedItem.find("a.remove").trigger("click");
902                    iteratedItem.remove();
903                }
904            });
905            $(".city-filter-wrapper .selectize-dropdown").css("display", "none");
906            setTimeout(function () {
907                $(".city-filter-wrapper .selectize-input input").blur();
908                $(".city-filter-wrapper .selectize-input").removeClass("focus").removeClass("input-active").removeClass("dropdown-active");
909            }, 1);
910        });
911
912        let changeUrl = (citiesParam, servicesParam, measurementsParam) => {
913            let citiesString = citiesParam.join("-");
914            let servicesString = servicesParam.join("-");
915            let measurementsString = measurementsParam.join("-");
916            currentView = $(".active-screen-view").data("view");
917            let finalUrl = currentPageLinkBase + "?view=" + currentView;
918            if (citiesString) finalUrl += "&places=" + citiesString;
919            if (servicesString) finalUrl += "&services=" + servicesString;
920            if (measurementsString) finalUrl += "&measurements=" + measurementsString;
921            if (selectedMedicineValueForURL !== null) finalUrl += "&medicine=" + selectedMedicineValueForURL;
922            window.history.replaceState({}, "", finalUrl);
923        }
924
925        // ON LOAD
926        selectedCitiesFilling($("#city-filter")[0].selectize.getValue());
927        fillSelectize();
928        selectedServicesFilling();
929        selectedMeasurementsFilling();
930        filtering(selectedCities, selectedServices, selectedMeasurements, selectedMedicine);
931        // END ON LOAD
932
933        // -------------------------------------------------------------------------------------------------------------
934
935        // CHANGE MAP/LIST VIEW
936        let pharmaciesMap = $(".pharmacies-map-inner");
937        let pharmaciesList = $(".pharmacies-list");
938        filtersBody.on("click", ".filter-button-with-image", function (e) {
939            e.preventDefault();
940            let currentFilterTabButton = $(this);
941            $(".filter-button-with-image").removeClass("filter-button-with-image-active");
942            currentFilterTabButton.addClass("filter-button-with-image-active");
943            if (currentFilterTabButton.hasClass("filter-button-with-image-map")) {
944                pharmaciesMap.removeClass("d-none").addClass("active-screen-view");
945                pharmaciesList.addClass("d-none").removeClass("active-screen-view");
946            }
947            if (currentFilterTabButton.hasClass("filter-button-with-image-list")) {
948                pharmaciesList.removeClass("d-none").addClass("active-screen-view");
949                pharmaciesMap.addClass("d-none").removeClass("active-screen-view");
950            }
951            changeUrl(selectedCities, selectedServices, selectedMeasurements);
952            if ($(window).width() <= 1180) {
953                $('html, body').animate({
954                    scrollTop: $(".pharmacies-content").offset().top - 103
955                }, 1000);
956            }
957        });
958        // END CHANGE MAP/LIST VIEW
959
960        // COLLAPSE CATEGORY
961        let isLinkCollapsing = false;
962        filtersBody.on("click", ".category-collapsing-link", function (e) {
963            e.preventDefault();
964            if (isLinkCollapsing === false) {
965                isLinkCollapsing = true;
966                let currentSectionLink = $(this);
967                currentSectionLink.toggleClass("category-collapsing-link-active");
968                currentSectionLink.parents(".category-collapsing-title").siblings(".category-list").slideToggle(400);
969                setTimeout(function () {
970                    isLinkCollapsing = false;
971                }, 400);
972            }
973        });
974        // END COLLAPSE CATEGORY
975
976        // TOGGLE WORK SCHEDULE
977        filtersBody.on("click", ".single-place-work-schedule-opener", function (e) {
978            e.preventDefault();
979            let currentScheduleOpener = $(this);
980            currentScheduleOpener.parents(".single-place-work-schedule-preview").slideUp();
981            setTimeout(function () {
982                currentScheduleOpener.parents(".single-place-work-schedule-preview").siblings(".single-place-work-schedule").slideDown();
983                // Center infoWindow
984                setTimeout(function () {
985                    if (currentScheduleOpener.parents(".pharmacies-map").length > 0 && infoWindowOuter !== null) {
986                        recenterInfoWindow(markerOuter);
987                    }
988                }, 400);
989                // END Center infoWindow
990            }, 400);
991        });
992        filtersBody.on("click", ".single-place-work-schedule-closer", function (e) {
993            e.preventDefault();
994            let currentScheduleCloser = $(this);
995            currentScheduleCloser.parents(".single-place-work-schedule").slideUp();
996            setTimeout(function () {
997                currentScheduleCloser.parents(".single-place-work-schedule").siblings(".single-place-work-schedule-preview").slideDown();
998            }, 400);
999        });
1000        // END TOGGLE WORK SCHEDULE
1001
1002        // -------------------------------------------------------------------------------------------------------------
1003
1004    });
1005});

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.