`);
});
// add events to open/close switcher
let body = $('body'),
flagSwitcher = $('.redirect-store-flags-switcher'),
flagSwitcherToggle = $('.redirect-store-flags-switcher-toggle');
body.on('click', function () {
if (flagSwitcher.hasClass('_opened')) {
flagSwitcher.removeClass('_opened');
}
});
flagSwitcher.on('click', function (event) {
event.stopPropagation();
})
flagSwitcherToggle.on('click', function () {
flagSwitcher.toggleClass('_opened');
});
// preselected store
const firstStore = priorityStoresCodes[0];
$('.redirect-store-flags-switcher-toggle img').attr('src', orderedStores[firstStore]['icon']);
$('.redirect-store-flags-switcher-toggle span').text(orderedStores[firstStore]['text']);
$('#redirect-continue-to button').text('Continue to ' + orderedStores[firstStore]['text']);
$('#redirect-continue-to').attr('href', noStoreBaseUrl + (redirectStoreData[firstStore]['url'] ?? firstStore));
$('#redirect-continue-to').unbind('click');
$('#redirect-continue-to').on('click', function () {
document.cookie = `selected_store_code=${redirectStoreData[firstStore]['url'] ?? firstStore}; path=/; max-age=414603416;`;
});
$('#redirect-currency .symbol').text(orderedStores[firstStore]['currency']);
// global store link set selected store cookie
$('#redirect-continue-to-global').on('click', function () {
document.cookie = `selected_store_code=en; path=/; max-age=414603416;`;
});
// set current store as user selected store in cookies
document.cookie = `selected_store_code=en-ca; path=/; max-age=414603416;`;
// set list of options to switcher
$('.redirect-store-flags-switcher-in').html(null);
$('.redirect-store-flags-switcher-in').append(switcherOptions);
// on store select
$('.redirect-store-flags-switcher-in .store-flags-switcher-item').on('click', function () {
// change selected store
$('.redirect-store-flags-switcher-toggle img').attr('src', $(this).children('img').attr('src'));
$('.redirect-store-flags-switcher-toggle span').text($(this).text());
flagSwitcher.removeClass('_opened');
// change button link and text and add callback to save selected store in cookie
const storeCode = $(this).attr('data-store-code');
$('#redirect-continue-to button').text('Continue to ' + $(this).text());
$('#redirect-continue-to').attr('href', noStoreBaseUrl + (redirectStoreData[storeCode]['url'] ?? storeCode));
$('#redirect-continue-to').unbind('click');
$('#redirect-continue-to').on('click', function () {
document.cookie = `selected_store_code=${redirectStoreData[storeCode]['url'] ?? storeCode}; path=/; max-age=414603416;`;
});
$('#redirect-currency .symbol').text($(this).attr('data-currency'));
});
});