PageSourceSearch

https://printerval.com/modules/localization/js/switch-languages.js?v=20261002033852

js printerval.com collected 2026-10-02 03:54:10 UTC 5,558 bytes, 122 lines download raw bytes

1// Hiện/ẩn hàng Country/Region trong popup. Dùng ID có sẵn nên không phụ thuộc
2// blade cache (footer-content được viewCache nên class blade mới có thể chưa có).
3function toggleCountryRow(show) {
4    var countryItem = document.getElementById('switch-item-country');
5    if (countryItem && countryItem.closest) {
6        var row = countryItem.closest('.switch-language-row');
7        if (row) {
8            row.style.display = show ? '' : 'none';
9        }
10    }
11}
12function openPopup() {
13    currencySwitch = defaultCurrencySwitch;
14    countrySelect = defaultCountrySelect;
15    var popup = document.getElementById('select-group-option');
16    popup.classList.remove("currency-only");
17    toggleCountryRow(true);
18    popup.classList.add("active");
19}
20// Mở popup ở chế độ CHỈ đổi tiền tệ (ẩn phần Country/Region) - dùng cho trang checkout.
21// Hiện ĐÚNG tiền hiện tại để user tự chọn; gợi ý theo IP do popup auto-detect
22// (header-select-country) lo khi vào trang, không nhảy currency ở popup bấm tay.
23function openCurrencyOnly() {
24    var popup = document.getElementById('select-group-option');
25    if (popup) {
26        currencySwitch = defaultCurrencySwitch;
27        countrySelect = defaultCountrySelect;
28        // Đồng bộ hiển thị về đúng tiền hiện tại (phòng popup HTML bị cache lệch)
29        var currentEl = document.querySelector('.js-select-country-text[data-unit="' + currencySwitch + '"]');
30        if (currentEl) {
31            selectCurrency(currencySwitch, currentEl.innerText.trim());
32        }
33        popup.classList.add("currency-only");
34        toggleCountryRow(false);
35        popup.classList.add("active");
36    }
37}
38function closePopup() {
39    var popup = document.getElementById('select-group-option');
40    popup.classList.remove("active");
41    popup.classList.remove("currency-only");
42    toggleCountryRow(true);
43    currencySwitch = defaultCurrencySwitch;
44    countrySelect = defaultCountrySelect;
45    document.getElementById("currency-inner-text").textContent = defaultTextCurrencySwitch;
46    document.getElementById("country-inner-text").textContent = defaultTextCountrySwitch;
47    document.getElementById("image-switch-country").src = defaultImageCountrySwitch;
48    var flagEl = document.getElementById("currency-selected-flag");
49    if (flagEl && typeof currencyFlagMap !== 'undefined' && currencyFlagMap[defaultCurrencySwitch]) {
50        flagEl.src = currencyFlagMap[defaultCurrencySwitch];
51    }
52}
53function openSelectCountry(countLocale) {
54    if (countLocale > 1) {
55        document.getElementById('switch-item-country').classList.add("active")
56    }
57}
58function openSelectCurrency() {
59    document.getElementById('switch-item-currency').classList.add("active")
60}
61
62function selectCountry(text, img, url) {
63    countrySelect = url;
64    document.getElementById('switch-item-country').classList.remove("active")
65    document.getElementById("country-inner-text").textContent = text;
66    document.getElementById("image-switch-country").src = img;
67}
68function selectCurrency(currency, text) {
69    currencySwitch = currency;
70    document.getElementById('switch-item-currency').classList.remove("active")
71    document.getElementById("currency-inner-text").textContent = text;
72    var flagEl = document.getElementById("currency-selected-flag");
73    if (flagEl && typeof currencyFlagMap !== 'undefined' && currencyFlagMap[currency]) {
74        flagEl.src = currencyFlagMap[currency];
75    }
76}
77function saveSwitch() {
78    setCookie("currency", currencySwitch, 365);
79    // Đánh dấu user đã tự chọn tiền tệ -> popup auto-detect (header) không pop lên gợi ý nữa
80    setCookie("is_currency_selected", 1, 365);
81    if (countrySelect == defaultCountrySelect) {
82        // Lưu vị trí cuộn + tắt khôi phục tự động (hay nhảy xuống cuối vì popup ở footer);
83        // sau reload tự khôi phục đúng chỗ (xem localization-restore-scroll).
84        try {
85            sessionStorage.setItem('localization_scroll', window.scrollY || window.pageYOffset || 0);
86        } catch (e) {}
87        if ('scrollRestoration' in history) {
88            history.scrollRestoration = 'manual';
89        }
90        window.location.reload();
91    } else {
92        window.location = countrySelect;
93    }
94}
95
96function setCookie(name, value, days) {
97    var expires = "";
98    if (days) {
99        var date = new Date();
100        date.setTime(date.getTime() + (days*24*60*60*1000));
101        expires = "; expires=" + date.toUTCString();
102    }
103    document.cookie = name + "=" + (value || "")  + expires + "; path=/";
104}
105
106window.addEventListener('click', function(e){   
107    if (document.getElementById('switch-item-currency')) {
108        if (document.getElementById('switch-item-currency').contains(e.target) || document.getElementById('switch-item-country').contains(e.target)) {
109            if (document.getElementById('switch-item-country').contains(e.target)) {
110                document.getElementById('switch-item-currency').classList.remove("active")
111            }
112            if (document.getElementById('switch-item-currency').contains(e.target)) {
113                document.getElementById('switch-item-country').classList.remove("active")
114            }
115            // Clicked in box
116        } else {
117            // Clicked outside the box
118            document.getElementById('switch-item-country').classList.remove("active")
119            document.getElementById('switch-item-currency').classList.remove("active")
120        }
121    }
122});

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.