charmhoodie


Shoes d.left && G d.top – 1 && F < d.bottom + 1); return g }, U = function () { var a, f, h, j, k, m, n, p, q, r, s, t, u = c.elements; if ((o = d.loadMode) && P < 8 && (a = u.length)) { for (f = 0, Q++; f < a; f++)if (u[f] && !u[f]._lazyRace) if (!M || c.prematureUnveil && c.prematureUnveil(u[f])) aa(u[f]); else if ((p = u[f][i]("data-expand")) && (m = 1 * p) || (m = O), r || (r = !d.expand || d.expand 500 && e.clientWidth > 500 ? 500 : 370 : d.expand, c._defEx = r, s = r * d.expFactor, t = d.hFac, J = null, O < s && P 2 && o > 2 && !b.hidden ? (O = s, Q = 0) : O = o > 1 && Q > 1 && P = n && (F = h.top) = n * t && (G = h.left) <= y && (I || H || G || F) && (d.loadHidden || S(u[f])) && (l && P < 3 && !p && (o < 3 || Q 9) break } else !k && l && !j && P < 4 && Q 2 && (g[0] || d.preloadAfterLoad) && (g[0] || !p && (I || H || G || F || "auto" != u[f][i](d.sizesAttr))) && (j = g[0] || u[f]); j && !k && aa(j) } }, V = B(U), W = function (a) { var b = a.target; if (b._lazyCache) return void delete b._lazyCache; R(a), s(b, d.loadedClass), t(b, d.loadingClass), u(b, Y), v(b, "lazyloaded") }, X = A(W), Y = function (a) { X({ target: a.target }) }, Z = function (a, b) { try { a.contentWindow.location.replace(b) } catch (c) { a.src = b } }, $ = function (a) { var b, c = a[i](d.srcsetAttr); (b = d.customMedia[a[i]("data-media") || a[i]("media")]) && a.setAttribute("media", b), c && a.setAttribute("srcset", c) }, _ = A(function (a, b, c, e, f) { var g, h, j, l, o, p; (o = v(a, "lazybeforeunveil", b)).defaultPrevented || (e && (c ? s(a, d.autosizesClass) : a.setAttribute("sizes", e)), h = a[i](d.srcsetAttr), g = a[i](d.srcAttr), f && (j = a.parentNode, l = j && n.test(j.nodeName || "")), p = b.firesLoad || "src" in a && (h || g || l), o = { target: a }, s(a, d.loadingClass), p && (clearTimeout(m), m = k(R, 2500), u(a, Y, !0)), l && q.call(j.getElementsByTagName("source"), $), h ? a.setAttribute("srcset", h) : g && !l && (L.test(a.nodeName) ? Z(a, g) : a.src = g), f && (h || l) && w(a, { src: g })), a._lazyRace && delete a._lazyRace, t(a, d.lazyClass), z(function () { var b = a.complete && a.naturalWidth > 1; p && !b || (b && s(a, “ls-is-cached”), W(o), a._lazyCache = !0, k(function () { “_lazyCache” in a && delete a._lazyCache }, 9)), “lazy” == a.loading && P– }, !0) }), aa = function (a) { if (!a._lazyRace) { var b, c = K.test(a.nodeName), e = c && (a[i](d.sizesAttr) || a[i](“sizes”)), f = “auto” == e; (!f && l || !c || !a[i](“src”) && !a.srcset || a.complete || r(a, d.errorClass) || !r(a, d.lazyClass)) && (b = v(a, “lazyunveilread”).detail, f && E.updateElem(a, !0, a.offsetWidth), a._lazyRace = !0, P++, _(a, b, f, e, c)) } }, ba = C(function () { d.loadMode = 3, V() }), ca = function () { 3 == d.loadMode && (d.loadMode = 2), ba() }, da = function () { if (!l) { if (f.now() – p < 999) return void k(da, 999); l = !0, d.loadMode = 3, V(), j("scroll", ca, !0) } }; return { _: function () { p = f.now(), c.elements = b.getElementsByClassName(d.lazyClass), g = b.getElementsByClassName(d.lazyClass + " " + d.preloadClass), j("scroll", V, !0), j("resize", V, !0), a.MutationObserver ? new MutationObserver(V).observe(e, { childList: !0, subtree: !0, attributes: !0 }) : (e[h]("DOMNodeInserted", V, !0), e[h]("DOMAttrModified", V, !0), setInterval(V, 999)), j("hashchange", V, !0), ["focus", "mouseover", "click", "load", "transitionend", "animationend"].forEach(function (a) { b[h](a, V, !0) }), /d$|^c/.test(b.readyState) ? da() : (j("load", da), b[h]("DOMContentLoaded", V), k(da, 2e4)), c.elements.length ? (U(), z._lsFlush()) : V() }, checkElems: V, unveil: aa, _aLSL: ca } }(), E = function () { var a, c = A(function (a, b, c, d) { var e, f, g; if (a._lazysizesWidth = d, d += "px", a.setAttribute("sizes", d), n.test(b.nodeName || "")) for (e = b.getElementsByTagName("source"), f = 0, g = e.length; f < g; f++)e[f].setAttribute("sizes", d); c.detail.dataAttr || w(a, c.detail) }), e = function (a, b, d) { var e, f = a.parentNode; f && (d = y(a, f, d), e = v(a, "lazybeforesizes", { width: d, dataAttr: !!b }), e.defaultPrevented || (d = e.detail.width) && d !== a._lazysizesWidth && c(a, f, e, d)) }, f = function () { var b, c = a.length; if (c) for (b = 0; b < c; b++)e(a[b]) }, g = C(f); return { _: function () { a = b.getElementsByClassName(d.autosizesClass), j("resize", g) }, checkElems: g, updateElem: e } }(), F = function () { !F.i && b.getElementsByClassName && (F.i = !0, E._(), D._()) }; return k(function () { d.init && F() }), c = { cfg: d, autoSizer: E, loader: D, init: F, uP: w, aC: s, rC: t, hC: r, fire: v, gW: y, rAF: z } }); /*! lazysizes-rias - v5.1.0 */ !function (a, b) { var c = function () { b(a.lazySizes), a.removeEventListener("lazyunveilread", c, !0) }; b = b.bind(null, a, a.document), "object" == typeof module && module.exports ? b(require("lazysizes")) : a.lazySizes ? c() : a.addEventListener("lazyunveilread", c, !0) }(window, function (a, b, c) { "use strict"; function d(b, c) { var d, e, f, g, h = a.getComputedStyle(b); e = b.parentNode, g = { isPicture: !(!e || !n.test(e.nodeName || "")) }, f = function (a, c) { var d = b.getAttribute("data-" + a); if (!d) { var e = h.getPropertyValue("--ls-" + a); e && (d = e.trim()) } if (d) { if ("true" == d) d = !0; else if ("false" == d) d = !1; else if (m.test(d)) d = parseFloat(d); else if ("function" == typeof j[a]) d = j[a](b, d); else if (r.test(d)) try { d = JSON.parse(d) } catch (a) { } g[a] = d } else a in j && "function" != typeof j[a] ? g[a] = j[a] : c && "function" == typeof j[a] && (g[a] = j[a](b, d)) }; for (d in j) f(d); return c.replace(q, function (a, b) { b in g || f(b, !0) }), g } function e(a, b) { var c = [], d = function (a, c) { return l[typeof b[c]] ? b[c] : a }; return c.srcset = [], b.absUrl && (t.setAttribute("href", a), a = t.href), a = ((b.prefix || "") + a + (b.postfix || "")).replace(q, d), b.widths.forEach(function (d) { var e = b.widthmap[d] || d, f = b.aspectratio || b.ratio, g = !b.aspectratio && j.traditionalRatio, h = { u: a.replace(o, e).replace(p, f ? g ? Math.round(d * f) : Math.round(d / f) : ""), w: d }; c.push(h), c.srcset.push(h.c = h.u + " " + d + "w") }), c } function f(a, c, d) { var f = 0, g = 0, h = d; if (a) { if ("container" === c.ratio) { for (f = h.scrollWidth, g = h.scrollHeight; !(f && g || h === b);)h = h.parentNode, f = h.scrollWidth, g = h.scrollHeight; f && g && (c.ratio = g / f) } a = e(a, c), a.isPicture = c.isPicture, v && "IMG" == d.nodeName.toUpperCase() ? d.removeAttribute(i.srcsetAttr) : d.setAttribute(i.srcsetAttr, a.srcset.join(", ")), Object.defineProperty(d, "_lazyrias", { value: a, writable: !0 }) } } function g(a, b) { var e = d(a, b); return j.modifyOptions.call(a, { target: a, details: e, detail: e }), c.fire(a, "lazyriasmodifyoptions", e), e } function h(a) { return a.getAttribute(a.getAttribute("data-srcattr") || j.srcAttr) || a.getAttribute(i.srcsetAttr) || a.getAttribute(i.srcAttr) || a.getAttribute("data-pfsrcset") || "" } var i, j, k = c.cfg, l = { string: 1, number: 1 }, m = /^-*+*d+.*d*$/, n = /^picture$/i, o = /s*{s*widths*}s*/i, p = /s*{s*heights*}s*/i, q = /s*{s*([a-z0-9]+)s*}s*/gi, r = /^[.*]|{.*}$/, s = /^(?:auto|d+(px)?)$/, t = b.createElement("a"), u = b.createElement("img"), v = "srcset" in u && !("sizes" in u), w = !!a.HTMLPictureElement && !v; !function () { var a, b = function () { }, d = { prefix: "", postfix: "", srcAttr: "data-src", absUrl: !1, modifyOptions: b, widthmap: {}, ratio: !1, traditionalRatio: !1, aspectratio: !1 }; i = c && c.cfg, i.supportsType || (i.supportsType = function (a) { return !a }), i.rias || (i.rias = {}), "widths" in (j = i.rias) || (j.widths = [], function (a) { for (var b, c = 0; !b || b 30 && (c += 1), b = 36 * c, a.push(b) }(j.widths)); for (a in d) a in j || (j[a] = d[a]) }(), addEventListener("lazybeforesizes", function (a) { if (a.detail.instance == c) { var b, d, e, k, l, m, n, p, q, r, t, u, v; if (b = a.target, a.detail.dataAttr && !a.defaultPrevented && !j.disabled && (q = b.getAttribute(i.sizesAttr) || b.getAttribute("sizes")) && s.test(q)) { if (d = h(b), e = g(b, d), t = o.test(e.prefix) || o.test(e.postfix), e.isPicture && (k = b.parentNode)) for (l = k.getElementsByTagName("source"), m = 0, n = l.length; m < n; m++)(t || o.test(p = h(l[m]))) && (f(p, e, l[m]), u = !0); t || o.test(d) ? (f(d, e, b), u = !0) : u && (v = [], v.srcset = [], v.isPicture = !0, Object.defineProperty(b, "_lazyrias", { value: v, writable: !0 })), u && (w ? b.removeAttribute(i.srcAttr) : "auto" != q && (r = { width: parseInt(q, 10) }, x({ target: b, detail: r }))) } } }, !0); var x = function () { var d = function (a, b) { return a.w - b.w }, e = function (a) { var b, c, d = a.length, e = a[d - 1], f = 0; for (f; f = a.d) { !e.cached && (b = a[f - 1]) && b.d > a.d – .13 * Math.pow(a.d, 2.2) && (c = Math.pow(b.d – .6, 1.6), b.cached && (b.d += .15 * c), b.d + (e.d – a.d) * c > a.d && (e = b)); break } return e }, f = function (a, b) { var d; return !a._lazyrias && c.pWS && (d = c.pWS(a.getAttribute(i.srcsetAttr || “”))).length && (Object.defineProperty(a, “_lazyrias”, { value: d, writable: !0 }), b && a.parentNode && (d.isPicture = “PICTURE” == a.parentNode.nodeName.toUpperCase())), a._lazyrias }, g = function (b) { var d = a.devicePixelRatio || 1, e = c.getX && c.getX(b); return Math.min(e || d, 2.4, d) }, h = function (b, c) { var h, i, j, k, l, m; if (l = b._lazyrias, l.isPicture && a.matchMedia) for (i = 0, h = b.parentNode.getElementsByTagName(“source”), j = h.length; i < j; i++)if (f(h[i]) && !h[i].getAttribute("type") && (!(k = h[i].getAttribute("media")) || (matchMedia(k) || {}).matches)) { l = h[i]._lazyrias; break } return (!l.w || l.w a._lazysizesWidth) && (a._lazysizesWidth = b), a._lazysizesWidth }, l = function (a) { var b; return b = (getComputedStyle(a) || { getPropertyValue: function () { } }).getPropertyValue("background-size"), !j[b] && j[a.style.backgroundSize] && (b = a.style.backgroundSize), b }, m = function (a, b) { if (b) { var c = b.match(h); c && c[1] ? a.setAttribute("type", c[1]) : a.setAttribute("media", d.customMedia[b] || b) } }, n = function (a, c, h) { var i = b.createElement("picture"), j = c.getAttribute(d.sizesAttr), k = c.getAttribute("data-ratio"), l = c.getAttribute("data-optimumx"); c._lazybgset && c._lazybgset.parentNode == c && c.removeChild(c._lazybgset), Object.defineProperty(h, "_lazybgset", { value: c, writable: !0 }), Object.defineProperty(c, "_lazybgset", { value: i, writable: !0 }), a = a.replace(e, " ").split(f), i.style.display = "none", h.className = d.lazyClass, 1 != a.length || j || (j = "auto"), a.forEach(function (a) { var c, e = b.createElement("source"); j && "auto" != j && e.setAttribute("sizes", j), (c = a.match(g)) ? (e.setAttribute(d.srcsetAttr, c[1]), m(e, c[2]), m(e, c[3])) : e.setAttribute(d.srcsetAttr, a), i.appendChild(e) }), j && (h.setAttribute(d.sizesAttr, j), c.removeAttribute(d.sizesAttr), c.removeAttribute("sizes")), l && h.setAttribute("data-optimumx", l), k && h.setAttribute("data-ratio", k), i.appendChild(h), c.appendChild(i) }, o = function (a) { if (a.target._lazybgset) { var b = a.target, d = b._lazybgset, e = b.currentSrc || b.src; if (e) { var f = c.fire(d, "bgsetproxy", { src: e, useSrc: i.test(e) ? JSON.stringify(e) : e }); f.defaultPrevented || (d.style.backgroundImage = "url(" + f.detail.useSrc + ")") } b._lazybgsetLoading && (c.fire(d, "_lazyloaded", {}, !1, !0), delete b._lazybgsetLoading) } }; addEventListener("lazybeforeunveil", function (a) { var d, e, f; !a.defaultPrevented && (d = a.target.getAttribute("data-bgset")) && (f = a.target, e = b.createElement("img"), e.alt = "", e._lazybgsetLoading = !0, a.detail.firesLoad = !0, n(d, f, e), setTimeout(function () { c.loader.unveil(e), c.rAF(function () { c.fire(e, "_lazyloaded", {}, !0, !0), e.complete && o({ target: e }) }) })) }), b.addEventListener("load", o, !0), a.addEventListener("lazybeforesizes", function (a) { if (a.detail.instance == c && a.target._lazybgset && a.detail.dataAttr) { var b = a.target._lazybgset, d = l(b); j[d] && (a.target._lazysizesParentFit = d, c.rAF(function () { a.target.setAttribute("data-parent-fit", d), a.target._lazysizesParentFit && delete a.target._lazysizesParentFit })) } }, !0), b.documentElement.addEventListener("lazybeforesizes", function (a) { !a.defaultPrevented && a.target._lazybgset && a.detail.instance == c && (a.detail.width = k(a.target._lazybgset)) }) } }); /*! lazysizes data-srcs data-bgs plugin */ document.addEventListener('lazybeforesizes', function (e) { var attrVal = e.target.getAttribute('data-srcs'); var targetWidth = e.target.clientWidth; if (!attrVal) return; var srcs = attrVal.split(","); var widths = [48, 180, 360, 540, 720, 900, 1024, 1280, 1366, 1440, 1536, 1600, 1920, 2056, 2560, 2732, 2880, 3072, 3200, 3840]; srcs = [srcs[0] || srcs[1], srcs[1] || srcs[0]]; var availableWidths = widths.filter(function (w) { return w <= Math.max(targetWidth, widths[0]) * window.devicePixelRatio; }); var srcset = availableWidths.map(function (w) { return srcs[window.innerWidth 1 ) { %>

0) { %> -%

From price * 1 && !from_on) { %>

    <% for (var i = 0; i
  • .shoplazza-currency__show .shoplazza-currency__list{ visibility: visible; opacity: 1; } .shoplazza-currency__show .shoplazza-currency__list ul{ display: block; } .shoplazza-currency__show i{ transform: rotate(180deg); } ]]>

0 ? ‘\D’ : ‘$’) + ‘)’; var num; if (config.n === 0) { num = this.toFixed(0); } else { num = parseFloat(this).toFixed(config.n + 1).slice(0, -1); } return (config.c ? num.replace(‘.’, config.c) : num).replace(new RegExp(re, ‘g’), ‘$&’ + (config.s || ‘,’)); }; function getPrice(str) { var price = (str + ”).replace(/[rn]/g, “”).replace(/ +/g, “”); price = price.charAt(price.length – 2) == ‘.’ ? price + ‘0’ : price; var decimal = false; // 是否需要精度 // 判断是否需要精度 if (price.charAt(price.length – 3) == ‘,’ || price.charAt(price.length – 3) == ‘.’) { decimal = true; price = price.substr(0, price.length – 3) + ‘*’ + price.substr(price.length – 3); } // 去掉千分位分割 price = price.replace(/./g, ”).replace(/,/g, ”).replace(/’/g, ”); if (decimal) { price = price.replace(‘*’, ‘.’); } // 去掉货币符号 res = /d+(.d+)?/g.exec(price.replace(/,/g, ”)); return res && res[0] ? res[0] : price; } // 获取B端配置后初始化货币组件 (function getConfig() { $.ajax({ url: ‘/api/multi-currency/finance-list’, success: function (res) { // 设置状态顺序 if (res && res.state === 0 && res.data.open_state) { currencyUpdate(res.data.list, res.data.default_code); } } }); })(); // 货币插件加载处理 function currencyUpdate(list, default_code) { function enableStorage() { try { window.localStorage.setItem(‘test_item’, ‘1’); window.localStorage.removeItem(‘test_item’); } catch (e) { return false; } return true; } // 初始化localstorage货币状态 enableStorage() && !window.localStorage.getItem(‘store_currency’) && window.localStorage.setItem(‘store_currency’, JSON.stringify({})); // map[key, value] var map = {}; // class=money 标记需要切换的dom结构 var $money = $(‘.money’); var local_currency = enableStorage() ? JSON.parse(window.localStorage.getItem(‘store_currency’)) : {}; // 同步数据map初始化 $money.each(function (i, item) { var html_price = $(item).text().trim(); map[html_price] = html_price; }) // 货币转换 function currencyConvert(price, symbol, finance, position, format) { price += ”; symbol = symbol || local_currency.symbol || window.SHOP_PARAMS.finance_symbol; finance = finance || local_currency.finance || window.SHOP_PARAMS.finance; position = position || local_currency.position || window.SHOPLAZZA.currency_symbol_pos || ”; format = format || local_currency.format || window.SHOPLAZZA.money_format || ‘amount’; var p = price.split(‘-‘); for (var i = 0; p && i < p.length; i++) { if (position == 'right') { p[i] = (Number(Number(getPrice(p[i])) * Number(finance)).format(format) + symbol); } else { p[i] = (symbol + Number(Number(getPrice(p[i])) * Number(finance)).format(format)); } } return p.join('-'); } $(document).on('plugin_currency_update', $.debounce(currencyChange, 100)); // 优先使用用户设置的货币,然后是店铺货币 var code = default_code; var isVaild = false; // 校验货币是否被删除 if (local_currency && local_currency.code) { for (var i = 0; i < list.length; i++) { if (list[i].code == local_currency.code) { code = local_currency.code; isVaild = true; // 当前localstore中的货币还在 break; } } } // storage中的货币被删除, 使用默认货币 !isVaild && (local_currency = {}); function renderLabel (code) { var currency = list.filter(function (item) { return item.code == code; }) if (!currency.length) return; return '' + currency[0].code + '‘ + currency[0].code + ” } function currencyChange(event) { // plugin_currency_update事件默认update当前货币 var $li = event && event.type == ‘click’ ? $(this) : $(‘.shoplazza-currency__list li[data-value=’ + (local_currency.code || code) + ‘]:eq(0)’); if (!$li.length) return; var $money = $(‘.money’); var newmap = {}; $(‘.shoplazza-currency__label’).html(renderLabel($li.data(‘value’))); $money.each(function (i, item) { var text = $(item).text().trim(); var origin_price = map[text]; // 能从map中获取的是同步价格,否则是异步价格。 if (origin_price) { // 同步价格计算 var price = currencyConvert(origin_price, $li.data(‘symbol’), $li.data(‘finance’), $li.data(‘position’), $li.data(‘format’)); $(item).html(price); // 更新map对象 newmap[price] = origin_price; } else { // 不更新相同货币单位 if (text && text.split(‘-‘) && text.split(‘-‘)[0].replace(/[0-9.,’s+]/g, ”) == $li.data(‘symbol’)) { return; } var price = currencyConvert(text, $li.data(‘symbol’), $li.data(‘finance’), $li.data(‘position’), $li.data(‘format’)); $(item).html(price); // 更新map对象 newmap[price] = text; } }) map = newmap; var store = { symbol: $li.data(‘symbol’), finance: $li.data(‘finance’), position: $li.data(‘position’), code: $li.data(‘value’), format: $li.data(‘format’) } // if (!event.isTrigger || store.code == local_currency.code) { // 主动change之后记录用户操作 enableStorage() && window.localStorage.setItem(‘store_currency’, JSON.stringify(store)); // } local_currency = store; // 更新购物车文案和checkout文案 $(document).trigger(‘plugin_update_checkout_cart’); } $(‘.multiply_currency’).html(window.template(‘currency-list-art-tpl’, { list: list })); $(‘.shoplazza-currency__list li’).click(currencyChange); currencyChange(); $(‘.shoplazza-currency__label’).html(renderLabel(code)); $(‘.shoplazza-currency’).click(function (event) { if(window.innerWidth 7页,显示… onChange: function() {} }, opt ); template.defaults.imports.clamp = function(target, lower, upper) { return target > lower ? (target < upper ? target : upper) : lower; }; var $this = this; $this.on("pagination-change",opt.onChange); this.html(template('tpl-pagination', opt)).off('click').on('click', '.sep-pagination__link', function(e) { var page = parseInt(e.currentTarget.getAttribute('data-page'), 10); if(page opt.total) return; opt.page = page; $this.html(template('tpl-pagination', opt)).trigger('pagination-change', { page: page }); }); return this; }; }) ]]> <%- $imports.getI18n("Spend {{ amount }} more and get free shipping!", { '{{ amount }}': ''+freeAmountTips+'' }) %> You are eligible for free shipping! ]]> () Your shopping bag is empty Continue Shopping <% for(var j = 0; available_items && j

<% for(var k = 0; k : Checkout VIEW BAG ]]> )([^<]*(?:(?!)<[^<]*)*)()/gi)[0]; var $body = $(bodyHTML); var $children = $body.find("#collection_products").children().filter(":not(.top-product)"); var $digital = $body.find(".collection_digital"); hasMore = !!$children.length; $('#search_end')[!hasMore?'removeClass':'addClass']('tw-hidden'); if(page ==1){ $("#collection_products").html(""); $("#collection__none")[$children.length == 0?"removeClass":"addClass"]("tw-hidden"); $(".collection_digital").html($digital.html() || '') !hasMore && $('#search_end')['addClass']('tw-hidden'); } $("#collection_products").append($children); // 更新商品数量 $('.collection_count').remove(); $('.collection__title').after($body.find('.collection_count')); window.history.replaceState(null, '', url.replace(/&?page=d+/,"")); }).always(function(){ loading = false; page == 1 ? $.loading.hide() : $.loading.hide({ selector: '#collection_products_loading' }); $(document).trigger('plugin_currency_update'); }); }).off('sort.collection').on('sort.collection',function(){ $('body').toggleClass('is-fixed-sort'); $('#collection-sort__drawer').find('li').removeClass('tw-opacity-40').end().find('li[value='+sort_by+']').addClass('tw-opacity-40'); }).off('click.collection').on("click.collection","#collection-sort__drawer li",function(e){ if (sort_by == $(this).attr('value')) return; sort_by = $(this).attr('value'); $(document).trigger('sort.collection'); loading || $(document).trigger("search",{page:(page=1)}); }).on("click.collection",".custom-checkbox",function(e){ e.preventDefault(); e.stopPropagation(); var $tagWrapper = $('.collection-filter__item-select[data-tag="'+$(this).parent().data('tag')+'"]') $tagWrapper.find('.custom-checkbox:not([data-value="'+$(this).data('value')+'"])').removeClass('tag-active'); $tagWrapper.find('.custom-checkbox[data-value="'+$(this).data('value')+'"]').toggleClass('tag-active'); loading || $(document).trigger("search",{page:(page=1)}); $(document).trigger('update.remove_btn'); }).on("click.collection",".collection-filter-clear",function(){ $('.custom-checkbox').removeClass('tag-active'); loading || $(document).trigger("search",{page:1}); $(document).trigger('update.remove_btn'); }).on("click.collection",".collection-filter__switch", function(e){ $('body').toggleClass('is-fixed-tags'); $('#collection-filter__drawer').css({top: getFixedTop()+'px'}); }).on('click.collection',".collection-sort-switch",function(e){ $('#collection-sort__drawer').css({top: getFixedTop()+'px'}); $(document).trigger('sort.collection'); }).off("update.remove_btn").on('update.remove_btn',function(){ $('.collection-filter-clear[data-toggle]')[$('.tag-active').length ? 'removeClass': 'addClass']('lg:tw-hidden'); }).trigger('update.remove_btn').on('click.collection',"#collection-sort__drawer,#collection-filter__drawer",function(e){ if (['collection-sort__drawer','collection-filter__drawer'].indexOf($(e.target).attr('id')) == -1) { e.stopPropagation(); } }); }) } catch (e) {console.log(e);} ]]> 0) { $(‘.header__cart_bubble’).removeClass(‘tw-hidden’); } else { $(‘.header__cart_bubble’).addClass(‘tw-hidden’); } } }); }).trigger(‘update_header_cart’); }, mask: function () { // 点击”after”关闭 $doc.on(‘click.drawer_open’, ‘.drawer_open’, function (e) { if ($(e.target)[0].tagName.toLowerCase() == ‘body’) { $(‘body’).removeClass(‘tw-overflow-hidden drawer_open’); } }) $doc.on(‘click’, ‘.drawer_close’, function () { $body.trigger(‘click.drawer_open’); }) }, search: function () { $doc.on(‘click’, ‘#search_expand_btn’, function () { $(‘body’).addClass(‘tw-overflow-hidden drawer_open’); }); }, } } $(‘[data-section-id=”header”]’).header().init(); }) } catch (e) {console.log(e);} ]]> window.breakpoint ? $content.css(‘display’, ‘block’) : $content.css(‘display’, ‘none’); }) }); } catch (e) {console.log(e);} ]]> -1 && listeners.splice(idx, 1); $this.data(eventName + ‘.listeners’, listeners); return this; }); // 监听购物车页面插件的加购成功事件 $(document).ajaxComplete(function (e, xhr, config) { if (config.url == “/api/cart” && config.type == “POST” && xhr.status == 200) { var variant_id = $.params(“?” + config.data).variant_id; variant_id && (cart.model.selected.push(variant_id)); $(document).trigger(‘dj.cart.refresh’); } }); var cart = { init: function (cartObj) { cart.model.selected = (cartObj.line_items || []).map(function (item) { return item.variant_id; }); cart.render(cartObj); cart.bindEvents(); }, settings: {}, model: { selected: [], cartObj: {}, timeout: 0 }, render: function (cartObj) { window.cartObj = cartObj; // 新加购商品默认选中 var prevVariantIds = ($(document).data(‘djcart’) && $(document).data(‘djcart’).line_items || []).map(function (item) { return item.variant_id; }); (cartObj.line_items || []).forEach(function (item) { if ( item.available && prevVariantIds.indexOf(item.variant_id) === -1 && cart.model.selected.indexOf(item.variant_id) === -1 ) { cart.model.selected.push(item.variant_id); } }); cart.model.cartObj = cartObj; // save model $(document).data(‘djcart’, cartObj); (cartObj.ineffectives || []).forEach(function (item) { if (item._pushed === true) return; // 防止多次处理 item._pushed = true; cartObj.line_items.push(item); }); cartObj.all_selected = (cartObj.line_items || []) .filter(function (item) { return item.available }) .every(function (item) { return cart.model.selected.indexOf(item.variant_id) !== -1 }); cartObj.available_items = (cartObj.line_items || []) .filter(function (item) { return item.available }); cartObj.available_items_count = 0; cartObj.available_items.map(function (item) { cartObj.available_items_count += (item.quantity – 0) }) cartObj.all_unavailable = (cartObj.line_items || []).every(function (item) { return !item.available }); cartObj.selected_count = cart.model.selected.length; var lastProgress = $(‘.cart_progress-bar’).data(‘width’) || 0; var discountPrice = 0; Object.keys($.discountPrice || {}).map(function (i) { return discountPrice += ($.discountPrice[i] – 0); }); $(‘#atc-modal’).html(template(‘cart-art-tpl’, Object.assign(cartObj, { discountPrice: discountPrice, lastProgress: lastProgress }))); setTimeout(function () { $(‘.cart_progress-bar’).css({ width: $(‘.cart_progress-bar’).data(‘width’) }) },20) $(‘#cart_drawer_wrapper’).removeClass(‘tw-hidden’); setTimeout(function () { $(“#atc-modal”).removeClass(‘tw-translate-x-full tw-opacity-0’); },50); $(document).trigger(‘dj.common.cart.update’); // cart UI 变更触发的事件 }, bindEvents: function () { var $cart = $(‘#atc-modal’); // 添加减少商品 $cart.off(‘click.counter’) .on(‘click.counter’, ‘.cart__item_enabled .cart__counter:not(.cart__counter_disabled)’, function () { var $this = $(this); var $productItem = $this.parents(‘.cart__item’); var $counterInput = $productItem.find(‘input[type=”number”]’); var quantity = $counterInput.val() * 1; var minNumber = $counterInput.attr(‘min’); var maxNumber = $counterInput.attr(‘max’); if (quantity == 1 && $this.attr(‘alt’) == ‘-‘) { // 删除当前选中商品 $(document).trigger(‘deleteCartItem’, { product_id: $productItem.attr(‘data-track-id’), variant_id: $productItem.attr(‘data-id’), id: $productItem.attr(‘data-cart-id’) }); return; } if ($this.attr(‘alt’) === ‘+’) { quantity = quantity + 1; } else if ($this.attr(‘alt’) === ‘-‘) { quantity = quantity – 1; } quantity = quantity maxNumber ? maxNumber : quantity; $counterInput.val(quantity); // 控制请求频次 window.clearTimeout(cart.model.timeout); cart.model.timeout = window.setTimeout(function () { $(document).trigger(‘updateCart’, { product_id: $productItem.attr(‘data-track-id’), variant_id: $productItem.attr(‘data-id’), id: $productItem.attr(‘data-cart-id’), quantity: quantity }); }, 300); }) .off(‘click.modal.show’).on(‘click.modal.show’, ‘.show-modal’, function () { $(‘#cart-preview-image .preview-image’).attr(‘src’, $(this).attr(‘data-image’)); $(‘#cart-preview-image’).modal(‘show’); }) .off(‘click.modal.hide’).on(‘click.modal.hide’, ‘#cart-preview-image .hide-modal’, function () { $(‘#cart-preview-image’).modal(‘hide’); }) $(document).off(‘dj.cart.refresh’).on(‘dj.cart.refresh’, $.debounce(function () { $.ajax({ type: ‘POST’, dataType: ‘json’, contentType: ‘application/json; charset=utf-8’, url: ‘/api/cart/cart-select’, success: function (res) { cart.render(res.cart); } }) }, 50)); $(document).off(‘dj.cart.postage.render’).on(‘dj.cart.postage.render’, function (cartObj) { var discountPrice = 0; Object.keys($.discountPrice || {}).map(function (i) { return discountPrice += ($.discountPrice[i] – 0); }); var total_price = window.cartObj[‘total_price’]; var freeAmountDiff = (500-(total_price-discountPrice)).toFixed(2); var rate = (total_price-discountPrice)/500; rate = rate > 1 ? 100 : rate*100; var lastProgress = $(‘.cart_progress-bar’).data(‘width’) || 0; $(‘.cart__free_shipping’).html(window.template(‘cart-postage-art-tpl’, { rate: rate, freeAmountDiff: freeAmountDiff, lastProgress: lastProgress })); setTimeout(function () { $(‘.cart_progress-bar’).css({ width: $(‘.cart_progress-bar’).data(‘width’) }) },20) }); $(document).off(‘updateCart’).on(‘updateCart’, function (event, data) { // 控制请求频次 cart.update(data); }); $(document).off(‘variantUpdate’).on(‘variantUpdate’, function (event, data) { // 控制请求频次 cart.variantUpdate(data); }) $(document).off(‘addToCart’).on(‘addToCart’, function (event, data) { // 控制请求频次 cart.add(data); }); $(document).off(‘refreshCart’).on(‘refreshCart’, function (event, data) { // 控制请求频次 cart.render(data); }); $(document).off(‘deleteCartItem’).on(‘deleteCartItem’, function (event, data) { cart.deleteItem(data); }); $(document.body).off(‘variant-switch’).on(“variant-switch”,function(e,data){ if (data && data.param) { data.param = JSON.parse(data.param || “{}”); if ((data.variant == data.new_variant) && (data.qty == data.new_qty)) { // 无更新 setTimeout(function () { $(document.body).trigger(‘variant-switch-close’); }, 100); return; } else if ((data.new_variant == data.param.variant_id) && (data.param.quantity != data.new_qty)) {// 修改了数量 $(document).trigger(‘updateCart’, { product_id: data.param.product_id, variant_id: data.param.variant_id, id: data.param.id, quantity: data.new_qty }); return; } else if ((data.new_variant != data.param.variant_id) && data.new_qty) { // 修改了款式 $(document).trigger(‘variantUpdate’, { line_items: [{ product_id: data.param.product_id, variant_id: data.param.variant_id, quantity: 0 }, { product_id: data.param.product_id, variant_id: data.new_variant, quantity: data.new_qty, }], selected: cart.model.selected }); return; } else { $(document.body).trigger(‘variant-switch-close’); } } }) // 输入商品数量 $cart.off(‘blur.qty’, ‘.cart__item_enabled .cart__qty-input’).on(‘blur.qty’, ‘.cart__item_enabled .cart__qty-input’, function () { var $this = $(this); var $productItem = $this.parents(‘.cart__item’); var quantity = Math.max(parseInt($this.val(), 10) || 1, 1); var minNumber = $this.attr(‘min’); var maxNumber = ~~$this.attr(‘max’); var product_id = $productItem.attr(‘data-track-id’); var variant_id = $productItem.attr(‘data-id’); var id = $productItem.attr(‘data-cart-id’); quantity = quantity maxNumber ? maxNumber : quantity; if ($.cart.model.cartObj.line_items[$(‘.cart__item’).index($productItem)].quantity != quantity) { $(document).trigger(‘updateCart’, { product_id: product_id, variant_id: variant_id, id: id, quantity: quantity }); } }); // 表单提交 $cart.off(‘click.submit’).on(‘click.submit’, ‘.cart__checkout:not(.cart__checkout_disabled)’, function () { $.loading.show({selector:”.cart__checkout”}); var reqParams = { line_items: cart.getLineItems(), refer_info: { source: ‘cart’ } }; $(document.body).asyncTrigger( ‘dj.cart_checkout’, { cart: $(document).data(‘djcart’), reqParams: reqParams }, function (err, data) { $.ajax({ type: ‘POST’, dataType: ‘json’, contentType: ‘application/json; charset=utf-8’, url: ‘/api/cart/cart-select’, success: function (res) { // 如果数据出现错误(被插件改错),使用修改前的数据 data.reqParams.line_items = res.cart.line_items .filter(function (item) { return cart.model.selected.indexOf(item.variant_id) !== -1; }) .map(function (item) { return { variant_id: item.variant_id, quantity: item.quantity, note: item.note, properties: item.properties } }); $(document.body).trigger(‘checkoutSubmit’, reqParams); if (err) data = { reqParams: reqParams }; $.post(‘/api/checkout/order’, data.reqParams, function (ret) { $.loading.hide(); if (ret.state === ‘success’) { if (window.safeHref) { return (window.safeHref = ‘/checkout/’ + ret.data.order_token + ‘?step=contact_information’); } else { return (location.safeHref = ‘/checkout/’ + ret.data.order_token + ‘?step=contact_information’); } } $.toast.show({ type: ‘success’, content: ret.errors[0] || ‘Some items information has been updated, please re-order’ }); handleError(‘all’); }); } }) } ); }); $(document).off(‘scroll.cart’).on(‘scroll.cart’,$.throttle(function(){ var isMobile = $(window).width() < window.breakpoint; var isHeaderFixed = $('.header__fixed').length; var headerBoxShadow = $('.header__fixed').css('box-shadow') == 'none' ? '' : $('.header__fixed').css('box-shadow'); var offsetTop = $('.header').outerHeight(); $('.cart_order_summary, .checkout__sticky_amount').css({ top: (isMobile ? $('.header__fixed').length ? offsetTop : '0' : offsetTop) +'px', }) $('.checkout__sticky_btn').css({ top: offsetTop + $('.checkout__sticky_amount').outerHeight()+'px', }) if ($(window).width() offsetTop +$('.checkout__sticky_amount').outerHeight()) { $('.checkout__sticky_btn').addClass('tw-shadow-5'); isHeaderFixed && $('.header__fixed').css('box-shadow', 'none'); } else { $('.checkout__sticky_btn').removeClass('tw-shadow-5'); isHeaderFixed && $('.header__fixed').css('box-shadow', headerBoxShadow); } } }, 10, 50 )); }, add: function (reqParams) { if (cart.model.selected.indexOf(reqParams.variant_id) === -1) { cart.model.selected.push(reqParams.variant_id) } reqParams.selected = cart.model.selected; $.ajax({ type: 'post', data: reqParams, url: '/api/cart?fields=carts', success: function (ret) { cart.render(ret.data); // 更新header购物车的数量显示 $(document).trigger('dj.common.cart.change', ret.cart); //加购行为提示 $.toast.show({ type: 'success', content: reqParams.tip || "Added successfully" }); $(document.body).trigger('variant-switch-close'); }, error: function (ret) { ret.responseJSON && ret.responseJSON.errors && $.toast.show({ content: ret.responseJSON.errors[0] || 'Unknown error', type: 'error' }); handleError(ret.responseJSON ? ret.responseJSON.state : 'all'); $(document.body).trigger('variant-switch-close'); } }); }, variantUpdate: function (reqParams) { cart.model.selected = cart.model.selected.filter(function (item) { return item !== reqParams.line_items[0].variant_id; }); cart.model.selected.push(reqParams.line_items[1].variant_id); reqParams.selected = cart.model.selected; $.ajax({ type: 'post', dataType: 'json', data: reqParams, url: '/api/cart/update', success: function (ret) { cart.render(ret.cart); $.toast.show({ type: 'success', content: "Updated successfully" }); $(document.body).trigger('variant-switch-close'); }, error: function (ret) { ret.responseJSON && ret.responseJSON.errors && $.toast.show({ content: ret.responseJSON.errors[0] || 'Unknown error', type: 'error' }); handleError(ret.responseJSON ? ret.responseJSON.state : 'all'); $(document.body).trigger('variant-switch-close'); } }); }, update: function (reqParams) { $('.cart_loading_mask').show(); var variant_id = reqParams.variant_id; var quantity = reqParams.quantity; var product = cart.model.cartObj.line_items.filter(function (item) { return item.variant_id == variant_id; })[0]; if (product && product.quantity == quantity) { cart.render(cart.model.cartObj); // reset return; } var oldData = JSON.parse(JSON.stringify(cart.model.cartObj)); $.ajax({ type: 'patch', data: { product_id: reqParams.product_id, variant_id: reqParams.variant_id, quantity: reqParams.quantity, id: reqParams.id }, dataType: 'json', url: '/api/cart/' + reqParams.variant_id, success: function (ret) { cart.render(ret.cart); // 更新header购物车的数量显示 $(document).trigger('dj.common.cart.change', ret.cart); $(document.body).trigger('variant-switch-close'); $('.cart_loading_mask').hide(); // 触发滚动,fixed元素定位 $(document).trigger('scroll'); $.toast.show({ type: 'success', content: "Updated successfully" }); }, error: function (ret) { cart.render(oldData); ret.responseJSON && ret.responseJSON.errors && $.toast.show({ content: ret.responseJSON.errors[0] || 'Unknown error', type: 'error' }); handleError(ret.responseJSON ? ret.responseJSON.state : 'all'); $(document.body).trigger('variant-switch-close'); $('.cart_loading_mask').hide(); // 触发滚动,fixed元素定位 $(document).trigger('scroll'); } }); }, deleteItem: function (reqParams) { var oldData = JSON.parse(JSON.stringify(cart.model.cartObj)); cart.model.selected = cart.model.selected.filter(function (item) { return item !== reqParams.variant_id; }); reqParams.selected = cart.model.selected; // $.loading.show(); $.ajax({ type: 'delete', dataType: 'json', data: reqParams, url: '/api/cart/' + reqParams.variant_id, success: function (ret) { // $.loading.hide(); cart.render(ret.cart); // 更新header购物车的数量显示 $(document).trigger('dj.common.cart.change', ret.cart); }, error: function (ret) { $.loading.hide(); cart.render(oldData); ret.responseJSON && ret.responseJSON.errors && $.toast.show({ content: ret.responseJSON.errors[0] || 'Unknown error', type: 'error' }); handleError(ret.responseJSON ? ret.responseJSON.state : 'all'); } }); }, // 获取购物车line_items getLineItems: function () { var $cart = $('#atc-modal'); var lineItems = []; $cart.find('.cart__item.cart__item_enabled').each(function () { var $self = $(this); if (cart.model.selected.indexOf($self.attr('data-id')) !== -1) { lineItems.push({ variant_id: $self.attr('data-id'), quantity: $self.find('.cart__qty-input').val(), note: '', properties: $self.attr('data-properties') }); } }); return lineItems; } }; var handleError = function (state) { var error = ['line_items_variant_not_exist', 'line_items_variant_sold_out', 'cart_removed', 'all']; if (error.indexOf(state) > -1) { setTimeout(function () { location.reload(); }, 2000); } }; window.template.defaults.imports.JSON = JSON; $.cart = cart; var overflow = ”; $(document).off(“cart-drawer dj.addToCart”).on(“cart-drawer dj.addToCart”, $.throttle(function (e, options) { if(options && options.source==”buy_now”) return ; if (options && options.process == ‘to_toast’) { $.toast.show({ content: window.SHOP_PARAMS.product_lang.added_to_cart_successfully, type: ‘success’ }); return; } else if (options && options.process == ‘to_cart’) { window.safeHref = ‘/cart’; return; } $(“#cart_drawer_wrapper”).addClass(‘tw-hidden’); $.get(‘/api/cart’, function (e) { cart.init((window.cartObj = (e && e.cart) || {})); overflow = $(‘body’).css(‘overflow’); $(‘body’).css(‘overflow’, ‘hidden’); }) },100,100)).off(“click.cart_close”).on(“click.cart_close”, “.cart_drawer-close, .cart_drawer_mask”, function () { $.loading.hide(); $(“#atc-modal”).addClass(‘tw-translate-x-full tw-opacity-0’); setTimeout(function () { $(“#cart_drawer_wrapper”).addClass(‘tw-hidden’); $(‘body’).css(‘overflow’, overflow); $(“#atc-modal”).empty(); },250) }) }); } catch (e) {console.log(e);} ]]>
Source

Leave a Comment

Your email address will not be published. Required fields are marked *