$(function(){ window.checkoutShowCookieToast = function () { try { let isShowCookieToast = $('#cookieToast').length > 0 ? true : false let isMob = window.innerWidth <= 767 let url = window.location.href; let isMini = true ; if (isNotNullOrEmpty(url) && (url.indexOf("/mini/card/generator") != -1) || (url.indexOf("/mini/pets/card/generator") != -1 ) || (url.indexOf("/about/mini/privacy-cookies") != -1 ) ){ isMini = false; } if (!isShowCookieToast && isMini) { let targetDom = $('.spice-cookie-window') let isClickCookieToast = localStorage.getItem('isClickCookieToast'); if (!isClickCookieToast) { let baseDom = $("
") if (targetDom.length > 0 && isMob) { baseDom = $(" ") $(targetDom).prepend(baseDom) } else { $('body').append(baseDom) } $('#cookieToast').on('click', '.onClickCookie',function(){ $('#cookieToast').remove() localStorage.setItem('isClickCookieToast',true); }); } } } catch (e) { console.log(e); } } setTimeout(()=>{window.checkoutShowCookieToast();},1000) try { var gaClient = getCookie('gaClient') ? JSON.parse(getCookie('gaClient')) : ''; if (isNotNullOrEmpty(gaSex) || isNotNullOrEmpty(gaClient)) { setTimeout(function () { //添加登录ga if (isNotNullOrEmpty(gaSex)) { window.GTMuaEventsPusher('interactionEvent', 'Userinfo', 'Gender', gaSex); } if (isNotNullOrEmpty(gaClient)) { window.GTMuaEventsPusher('nonInteractionEvent', 'my account', 'track user logged', '', JSON.parse(gaClient)); Cookies.remove('gaClient'); } },5000) } } catch (e) {} var $headerSearch = $(".search-keyboard"); $headerSearch.find(".spice-seach-box-button").live("tap", function(){ var baseUrl = base+"/search?"; var keyword = $.trim($(".spice-seach-box-input").val()); if (keyword) { $headerSearch.find(".spice-seach-box-input").parent().removeClass("spice-error"); window.showFooterEmailMsg( $('.e-header-search') ); if(isIEUn){ keyword=encodeURI(keyword); } baseUrl = baseUrl + "keyword=" + keyword + "&search-cat=standard"; sendBaidu(keyword); window.location.href = baseUrl; } else { var keywordValue = $.trim($("#keywordValue").val()); if(keywordValue){ $headerSearch.find(".spice-seach-box-input").parent().removeClass("spice-error"); window.showFooterEmailMsg( $('.e-header-search') ); if(isIEUn){ keywordValue=encodeURI(keywordValue); } sendBaidu(keywordValue); baseUrl = baseUrl + "keyword=" + keywordValue + "&search-cat=hotsearch"; window.location.href = baseUrl; }else{ $headerSearch.find(".spice-seach-box-input").parent().addClass("spice-error"); window.showFooterEmailErrorMsg( $('.e-header-search') ); $headerSearch.find(".spice-seach-box-input").attr('placeholder',"请输入您要搜索的关键词"); $headerSearch.find(".spice-seach-box-input").parent().addClass("search-placeholder-color"); } } }) $headerSearch.find(".spice-search-btn").live("tap", function(){ var baseUrl = base+"/search?"; var keyword = $.trim($(".spice-seach-box-input").val()); if (keyword) { $headerSearch.find(".spice-seach-box-input").parent().removeClass("spice-error"); window.showFooterEmailMsg( $('.e-header-search') ); if(isIEUn){ keyword=encodeURI(keyword); } sendBaidu(keyword); baseUrl = baseUrl + "keyword=" + keyword + "&search-cat=standard"; window.location.href = baseUrl; } else { var keywordValue = $.trim($("#keywordValue").val()); if(keywordValue){ $headerSearch.find(".spice-seach-box-input").parent().removeClass("spice-error"); window.showFooterEmailMsg( $('.e-header-search') ); if(isIEUn){ keywordValue=encodeURI(keywordValue); } sendBaidu(keywordValue); baseUrl = baseUrl + "keyword=" + keywordValue + "&search-cat=hotsearch"; window.location.href = baseUrl; }else{ $headerSearch.find(".spice-seach-box-input").parent().addClass("spice-error"); window.showFooterEmailErrorMsg( $('.e-header-search') ); $headerSearch.find(".spice-seach-box-input").attr('placeholder',"请输入您要搜索的关键词"); $headerSearch.find(".spice-seach-box-input").parent().addClass("search-placeholder-color"); } } }) $headerSearch.find(".spice-seach-box-input").bind("keypress", function(event){ var baseUrl = base+"/search?"; var keyword = $.trim($(".spice-seach-box-input").val()); var content = $(this).val(); if(event.keyCode == '13') { if (keyword) { $headerSearch.find(".spice-seach-box-input").parent().removeClass("spice-error"); window.showFooterEmailMsg( $('.e-header-search') ); if(isIEUn){ keyword=encodeURI(keyword); } sendBaidu(keyword); baseUrl = baseUrl + "keyword=" + keyword + "&search-cat=standard"; window.location.href = baseUrl; } else { var keywordValue = $.trim($("#keywordValue").val()); if(keywordValue){ $headerSearch.find(".spice-seach-box-input").parent().removeClass("spice-error"); window.showFooterEmailMsg( $('.e-header-search') ); if(isIEUn){ keywordValue=encodeURI(keywordValue); } sendBaidu(keywordValue); baseUrl = baseUrl + "keyword=" + keywordValue + "&search-cat=hotsearch"; window.location.href = baseUrl; }else{ window.showFooterEmailErrorMsg( $('.e-header-search') ); $headerSearch.find(".spice-seach-box-input").parent().addClass("spice-error"); $headerSearch.find(".spice-seach-box-input").attr('placeholder',"请输入您要搜索的关键词"); $headerSearch.find(".spice-seach-box-input").parent().addClass("search-placeholder-color"); } } } }) //限制输入的字符长度 $headerSearch.find("#keyword").live("input", function () { //得到RemarksLength属性 var maxLength = $(this).attr("remarksLength"); if(maxLength==""||maxLength==null) { return; } var length = checkLength($(this).val()); if(length>maxLength) { //如果输入长度大于限定的最大长度则截取最大长度部分的字符 $(this).val(subString($(this).val(),maxLength)); } }); //搜索 var $searchCloseBtn = $('.e-search-open'); $searchCloseBtn.click(function(){ //如果搜索中已经查询过热词,历史记录,商品精选,再次点击不再查询 var searchHtml = $('div.search-keyboard-container').children().length; if(searchHtml<1){ var hotWordUrl = base + "/findSearchHis"; var hotWordDate = loxia.syncXhrGet(hotWordUrl, {}); $('div.search-keyboard-container').append(hotWordDate); $(window).trigger('resize.spice-autoReplaceImageSrc'); } var height =$('.search-keyboard').height(); $(".search-keyboard-nav").css({ 'height':height ? height:'393px' }) var pageUrl=window.location.href; window.GTMuaEventsPusher('interactionEvent','search','click search icon',pageUrl); }) //plp 新搜索 var $newPlpSearchBtn = $('.plp-e-search-open'); $newPlpSearchBtn.click(function(){ //如果搜索中已经查询过热词,历史记录,商品精选,再次点击不再查询 var searchHtml = $('div.search-keyboard-container').children().length; if(searchHtml<1){ var hotWordUrl = base + "/findSearchHis"; var hotWordDate = loxia.syncXhrGet(hotWordUrl, {}); $('div.search-keyboard-container').append(hotWordDate); $(window).trigger('resize.spice-autoReplaceImageSrc'); } var pageUrl=window.location.href; try{ window.GTMuaEventsPusher('interactionEvent','search','click search bar on PLP',pageUrl); }catch(e){} }) //pad + mobile 搜索 $('.e-header-search > a:eq(0)').on('tap', function() { //如果搜索中已经查询过热词,历史记录,商品精选,再次点击不再查询 var searchHtml = $('div.search-keyboard-container').children().length; if(searchHtml<1){ var hotWordUrl = base + "/findSearchHis"; var hotWordDate = loxia.syncXhrGet(hotWordUrl, {}); $('div.search-keyboard-container').append(hotWordDate); $(window).trigger('resize.spice-autoReplaceImageSrc'); } var pageUrl=window.location.href; window.GTMuaEventsPusher('interactionEvent','search','click search icon',pageUrl); $('.spice-autofocus').focus(); }) //清空历史搜索 $(document).on('tap','.e-clean-record',function(){ $('.e-clean-record').hide(); var url = base + "/clearSearchHis"; loxia.syncXhrGet(url, {}); }) }) function sendBaidu(keyword) { try{ if (keyword != null && keyword != undefined && keyword != "") { //百度统计 _hmt.push(['_trackCustomEvent', 'search', {'search_word':keyword}]); } }catch (e) { console.log("baidu tracking error!"); } } function searchHref(keyword,gaSearch){ var baseUrl = base+"/search?"; if(isIEUn){ keyword=encodeURI(keyword); } baseUrl = baseUrl + "keyword=" + keyword + "&search-cat=" + gaSearch; window.location.href = baseUrl; } //检查输入的长度方法,区分中英文 function checkLength(input) { var i, sum; sum = 0; for (i = 0; i < input.length; i++) { //中英文不同的长度检测办法,英文一个字符长度,中文两个支付长度 if ((input.charCodeAt(i) >= 0) && (input.charCodeAt(i) <= 255)) { sum = sum + 1; } else { sum = sum + 2; } } return sum; } //处理超过长度的字符,截取maxlength的字符 function subString(str,n){ var len=checkLength(str,n); if(len>n){ var newlen=Math.floor(n/2); var stringLength=str.length; var newString = ""; for(var i=newlen;i<=stringLength;i++){ var tempString = str.substr(0,i); if(checkLength(tempString)>n){ return newString; break; }else{ newString = tempString; } } }else{ return str; } } window.showFooterEmailErrorMsg = function(ele){ $('.spice-no-error-style-input [data-errormsg]',ele).attr('placeholder',function(){ return $(this).attr('data-errormsg'); }) } window.showFooterEmailMsg = function(ele){ $('.spice-no-error-style-input [data-errormsg]',ele).attr('placeholder',function(){ return $(this).attr('data-msg'); }) }