PageSourceSearch

https://www.lidl.lt/s/storesearch-frontend/26_20_3/base.js

js lidl.lt collected 2026-10-02 08:08:01 UTC 8,193 bytes, 253 lines download raw bytes

1import {
2  loadPopUpScript,
3  prepareStoreSearchAndOpen,
4  selectAppCountry,
5} from "./store-search-utils.js";
6
7function initStoreSearch() {
8  if (window.hasOwnProperty("storeSearchInit")) {
9    return;
10  }
11  window.storeSearchInit = true;
12
13  const detectedRegion = sessionStorage.getItem("detected-region");
14  if (detectedRegion) {
15    // show pop-up with detectedRegion stored in sessionStorage after page reload
16    loadPopUpScript().then(() => {
17      const event = new CustomEvent("open-store-search-pop-up", {
18        detail: {
19          detectedRegion: detectedRegion,
20          showAltPopUp: true,
21        },
22      });
23      sessionStorage.removeItem("detected-region");
24      window.dispatchEvent(event);
25    });
26  }
27
28  function createStoreSearch() {
29    const usedButtons = [
30      "store-selector-flyer-addon",
31      "store-search-button",
32      "store-rating-button",
33    ].filter((type) => document.querySelector(type));
34    Promise.all(
35      usedButtons.map((type) => customElements.whenDefined(type)),
36    ).then(() => {
37      let openToggle = document.querySelectorAll(
38        "[data-map-search-toggle-preload]",
39      );
40      openToggle.forEach((toggle) => {
41        if (toggle.hasAttribute("data-store-rating") && toggle.isLink) {
42          return;
43        }
44
45        let hasFlyerButton = toggle.hasAttribute("data-source-flyer");
46        let hasRatingButton = toggle.hasAttribute("data-store-rating");
47        let hasCXButton = toggle.hasAttribute("data-source-cx");
48
49        toggle.addEventListener("click", () => {
50          let storeData = {
51            type: hasRatingButton ? "storeRating" : "storeSearch",
52            source: hasRatingButton
53              ? "storeRating"
54              : hasCXButton
55                ? "storeOneCX"
56                : hasFlyerButton
57                  ? "storeFlyer"
58                  : "storeSearch",
59          };
60          prepareStoreSearchAndOpen(storeData);
61        });
62      });
63    });
64
65    //Search Field
66    let searchFields = document.querySelectorAll("[data-map-search-field]");
67    if (searchFields && searchFields.length === 1) {
68      let storeData = {
69        type: "storeSearch",
70        searchFieldStandalone: true,
71        source: "storeSEOPages",
72      };
73      prepareStoreSearchAndOpen(storeData);
74    }
75
76    //Store StoreStock event
77    window.addEventListener(
78      "product:open-store-stock-dialog",
79      function storeSearchOpen(e) {
80        let storeData = {
81          type: "storeStock",
82          erp: e.detail.erp,
83          storeId: e.detail.storeId,
84          source: "storeStock",
85        };
86        prepareStoreSearchAndOpen(storeData);
87      },
88    );
89
90    //General StoreSearch event
91    window.addEventListener("mapsearch", function storeSearchOpen(e) {
92      let type = null;
93      if (e && e.detail) {
94        type = e.detail.type;
95      }
96      let productId = null;
97      if (typeof type == "undefined") {
98        type = "storeSearch";
99      }
100
101      if (type === "default") {
102        type = "storeSearch";
103      } else if (type === "rating") {
104        type = "storeRating";
105      } else if (type === "storeStock") {
106        type = "storeStock";
107        productId = e.detail.erp;
108      }
109      let storeData = {
110        type: type,
111        erp: productId,
112        storeId: null,
113        source: type,
114      };
115      prepareStoreSearchAndOpen(storeData);
116    });
117
118    const countryCode = selectAppCountry(
119      window.mindShiftNav?.country,
120      window.mindShiftNav?.locale,
121    );
122    if (countryCode === "ES") {
123      window.addEventListener("open-store-search-pop-up", (e) => {
124        loadPopUpScript().then(() => {
125          let detectedRegion = null;
126          let showAltPopUp = null;
127          if (e && e.detail) {
128            detectedRegion = e.detail.detectedRegion;
129            showAltPopUp = e.detail.showAltPopUp;
130          }
131          const popUpComponent = document.createElement("store-search-pop-up");
132          popUpComponent.setAttribute("detected-region", detectedRegion);
133          popUpComponent.setAttribute("show-alt-pop-up", showAltPopUp);
134          document.body.appendChild(popUpComponent);
135        });
136      });
137    }
138  }
139
140  function checkMindshiftNav() {
141    // language switching for multi language countries
142    if (window.location.href.indexOf("/s/") !== -1) {
143      (async () => {
144        if (window.hasOwnProperty("mindShiftNav")) {
145          const multilanguageLocales = new Map();
146          for (const lang of window.mindShiftNav.availableLangs) {
147            multilanguageLocales.set(
148              lang,
149              lang + "-" + window.mindShiftNav.country,
150            );
151          }
152          if (window.hasOwnProperty("navLangUrls")) {
153            let type;
154            if (document.querySelector("[data-store-search-page-type]")) {
155              const typeFromPage = document.querySelector(
156                "[data-store-search-page-type]",
157              ).dataset.storeSearchPageType;
158              if (typeFromPage !== null && typeFromPage !== undefined) {
159                type = typeFromPage;
160              }
161            }
162            let navLangs = {};
163            let pathname = decodeURIComponent(window.location.pathname);
164            const currentLanguageShortURL = await _getShortUrlPart(
165              window.mindShiftNav.locale,
166              type,
167            );
168            // if another language is set from the mindshift cookie, "window.mindShiftNav.locale" and locale in pathname do not match
169            if (!pathname.includes(currentLanguageShortURL)) {
170              for (let language of multilanguageLocales.keys()) {
171                const languageShortURL = await _getShortUrlPart(
172                  multilanguageLocales.get(language),
173                  type,
174                );
175                if (pathname.includes(languageShortURL)) {
176                  // set pathname to the desired value to bring it inline with header
177                  pathname = pathname.replace(
178                    multilanguageLocales.get(language) + languageShortURL,
179                    window.mindShiftNav.locale + currentLanguageShortURL,
180                  );
181                }
182              }
183            }
184            for (let language of multilanguageLocales.keys()) {
185              const languageShortURL = await _getShortUrlPart(
186                multilanguageLocales.get(language),
187                type,
188              );
189              navLangs[language] = decodeURIComponent(pathname).replace(
190                window.mindShiftNav.locale + currentLanguageShortURL,
191                multilanguageLocales.get(language) + languageShortURL,
192              );
193            }
194            if (window.navLangUrls) {
195              window.navLangUrls.replace(navLangs);
196            } else {
197              window.navLangUrls = navLangs;
198            }
199          }
200        }
201      })();
202    }
203  }
204
205  async function _getShortUrlPart(locale, type) {
206    let stage = "";
207    if (window.location.href.indexOf("https://dev.lidl") !== -1) {
208      stage = "dev";
209    } else if (window.location.href.indexOf("https://test.lidl") !== -1) {
210      stage = "test";
211    } else if (window.location.href.indexOf("https://qa.lidl") !== -1) {
212      stage = "qas";
213    } else {
214      stage = "live";
215    }
216    const queryUrl =
217      "https://" +
218      stage +
219      ".api.schwarz/odj/stores-api/v2/myapi/stores-frontend/config?locale=" +
220      locale;
221    try {
222      let response = await fetch(queryUrl, {
223        method: "GET",
224        headers: {
225          "Content-Type": "application/json",
226          "x-apikey": "KxboQtt40BG4VpBL16IhaRd2CXh0QbAc",
227        },
228      });
229      if (response.ok) {
230        const config = await response.json();
231
232        if (type === "NEO") {
233          return "/" + config.data.newOpeningsPath;
234        } else if (type === "SPECIAL_SALES") {
235          //TODO proof once config is extended by be
236          return "/" + config.data.specialSalesPath;
237        } else {
238          return "/" + config.data.detailPagePath;
239        }
240      } else {
241        return null;
242      }
243    } catch (error) {
244      console.error("unable to fetch config", error);
245      return null;
246    }
247  }
248
249  createStoreSearch();
250  checkMindshiftNav();
251}
252
253initStoreSearch();

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.