zz-shopify-components
Version:
Reusable Shopify components for theme projects
36 lines (32 loc) • 1.05 kB
JavaScript
// 用来处理多国家多跳转的问题
// el: 传入的元素
// links: 站点地图文本
var bindSiteJump = bindSiteJump
? bindSiteJump
: function bindSiteJump(el, links) {
if (!links) {
console.log('SiteJump: links are required');
return;
}
const SITE_JUMP_MAP = links;
console.log(SITE_JUMP_MAP, 'SITE_JUMP_MAP');
const arr = SITE_JUMP_MAP.split('\n'); // 按换行符拆分为数组
const siteMap = {};
// 将站点地图解析成对象
arr.forEach((item) => {
const [key, value] = item.split(': ');
if (key && value) {
siteMap[key.trim()] = value.trim();
}
});
const countryElement =
document.getElementsByClassName('countryWord')[0];
if (countryElement) {
const country = countryElement.innerText.trim();
const targetUrl = siteMap[country] || siteMap['default'] || '/';
// 加跟踪参数并跳转到匹配的站点
toSubSiteBP(targetUrl);
} else {
console.error('SiteJump: Country element not found');
}
};