jssdk.js
18.8 KB
!function(e){"use strict";function t(e,t){if("undefined"==typeof document)return t;e=e||"";var i=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");return n.type="text/css",n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e)),i.appendChild(n),t}function i(){}function n(e){s=[e]}function o(e,t,i){return e&&e.apply&&e.apply(t.context||t,i)}function a(e){return/\?/.test(e)?"&":"?"}function r(t){function r(e){Y++||(H(),$&&(N[W]={s:[e]}),z&&(e=z.apply(t,[e])),o(B,t,[e,S,t]),o(R,t,[t,S]))}function c(e){Y++||(H(),$&&e!=C&&(N[W]=e),o(L,t,[t,e]),o(R,t,[t,e]))}t=e.extend({},E,t);var d,g,q,j,M,B=t.success,L=t.error,R=t.complete,z=t.dataFilter,P=t.callbackParameter,Q=t.callback,J=t.cache,$=t.pageCache,G=t.charset,W=t.url,F=t.data,X=t.timeout,Y=0,H=i;return T&&T(function(e){e.done(B).fail(L),B=e.resolve,L=e.reject}).promise(t),t.abort=function(){!Y++&&H()},o(t.beforeSend,t,[t])===!1||Y?t:(W=W||l,F=F?"string"==typeof F?F:e.param(F,t.traditional):l,W+=F?a(W)+F:l,P&&(W+=a(W)+encodeURIComponent(P)+"=?"),!J&&!$&&(W+=a(W)+"_"+(new Date).getTime()+"="),W=W.replace(/=\?(&|$)/,"="+Q+"$1"),$&&(d=N[W])?d.s?r(d.s[0]):c(d):(I[Q]=n,q=e(_)[0],q.id=m+O++,G&&(q[p]=G),D&&D.version()<11.6?(j=e(_)[0]).text="document.getElementById('"+q.id+"')."+v+"()":q[u]=u,U&&(q.htmlFor=q.id,q.event=y),q[b]=q[v]=q[w]=function(e){if(!q[x]||!/i/.test(q[x])){try{q[y]&&q[y]()}catch(e){}e=s,s=0,e?r(e[0]):c(f)}},q.src=W,H=function(e){M&&clearTimeout(M),q[w]=q[b]=q[v]=null,A[k](q),j&&A[k](j)},A[h](q,g=A.firstChild),j&&A[h](j,g),M=X>0&&setTimeout(function(){c(C)},X)),t)}function c(e){var t=new RegExp(e+"=([^;$]*)","i"),i="$1";return t.test(decodeURIComponent(document.cookie))?RegExp[i]:""}function d(e,t,i){var n,o,a,r,c="";"undefined"!=typeof t&&(i=i||{},null===t&&(t="",i.expires=-1),i.expires&&("number"==typeof i.expires||i.expires.toUTCString)&&("number"==typeof i.expires?(r=new Date,r.setTime(r.getTime()+24*i.expires*60*60*1e3)):r=i.expires,c="; expires="+r.toUTCString()),n=i.path?"; path="+i.path:"",o=i.domain?"; domain="+i.domain:"",a=i.secure?"; secure":"",document.cookie=[e,"=",encodeURIComponent(t),c,n,o,a].join(""))}e="default"in e?e.default:e;var s,u="async",p="charset",l="",f="error",h="insertBefore",m="_jqjsp",g="on",y=g+"click",v=g+f,b=g+"load",w=g+"readystatechange",x="readyState",k="removeChild",_="<script>",S="success",C="timeout",I=window,T=e.Deferred,A=e("head")[0]||document.documentElement,N={},O=0,E={callback:m,url:location.href},D=I.opera,U=!!e("<div>").html("<!--[if IE]><i><![endif]-->").find("i").length;r.setup=function(t){e.extend(E,t)},e.jsonp=r,t(".featuretip.tip-wrap{position:fixed;top:0;left:0;width:100%;height:100%;z-index:1000;background:rgba(0,0,0,.5)}.featuretip .tip{position:fixed;left:50%;top:50%;margin-left:-140px;margin-top:-140px;width:280px;background:#fff;border-top:40px solid #000;text-align:center;line-height:1.25}.featuretip .tip .title{margin:20px auto;font-size:24px;font-weight:700;text-align:center}.featuretip .tip .highlight{font-size:18px}.featuretip .tip .content{font-size:16px;color:#444;text-align:center}.featuretip .tip .button{display:block;margin:20px auto;width:150px;height:30px;font-size:14px;line-height:30px;text-align:center;color:#fff;background:#000;text-decoration:none}",void 0),t(".feature-coin.tip-wrap{position:fixed;top:0;left:0;width:100%;height:100%;z-index:1000;background:rgba(0,0,0,.5)}.feature-coin .tip{position:fixed;left:50%;top:50%;margin-left:-140px;margin-top:-140px;width:280px;background:#fff;text-align:center;line-height:1.25;background-repeat:no-repeat}.feature-coin .tip .tip-close{position:absolute;right:0;top:0;width:25px;height:25px;line-height:25px;text-align:center;font-size:16px;color:#fff;background:#000;cursor:pointer}.feature-coin .tip .title{margin:21px auto;font-size:22px;font-weight:700;text-align:center}.feature-coin .tip .highlight{font-size:18px}.feature-coin .tip .content{padding:4px;font-size:16px;color:#444;text-align:center;height:48px;overflow:hidden}.feature-coin .bottom-button{text-align:center}.feature-coin .tip .button,.feature-coin .tip .coin{display:inline-block;margin:20px auto;width:116px;height:26px;font-size:14px;line-height:26px;text-align:center;color:#fff;background:#000;text-decoration:none;border:2px solid #000}.feature-coin .tip .coin{color:#000;background:#fff}",void 0);var q={Android:function(){return!!navigator.userAgent.match(/Android/i)},BlackBerry:function(){return!!navigator.userAgent.match(/BlackBerry/i)},iOS:function(){return!!navigator.userAgent.match(/iPhone|iPad|iPod/i)},Windows:function(){return!!navigator.userAgent.match(/IEMobile/i)},any:function(){return q.Android()||q.BlackBerry()||q.iOS()||q.Windows()}},j=q.any()?"//m.yohobuy.com/home/mycurrency":"//www.yohobuy.com/home/currency",M=e('<div class="featuretip tip-wrap"><div class="tip"><div class="title"></div><div class="content"></div><a class="button" href="">返回</a></div></div>'),B=e('<div class="feature-coin tip-wrap"><div class="tip"><div class="tip-close">×</div><div class="title"></div><div class="content"></div><div class="bottom-button"><a class="button" href="">去逛逛</a><a class="coin" href=\''+j+'?openby:yohobuy={"action":"go.mine"}\'>查看有货币</a></div></div></div>'),L=function(){if(!window._jssdkQS){var e={},t=void 0,i=void 0,n=window.location.search.slice(1).split("&");for(i=0;i<n.length;i++)t=n[i].split("="),e[t[0]]=t[1];window._jssdkQS=e}return window._jssdkQS},R=function(){var t=window.location.search;t.indexOf("&expires=")===-1&&(t=t?t+"&":"?",t+="expires=604800000"),e('<iframe style="display:none;" src="//m.yohobuy.com/activity/wechat/1111'+t+'"></iframe>').prependTo("body")},z=function(){var t=e("body");t.on("click",".feature-coin .close,.feature-coin .tip-close",function(e){B.fadeOut(),e.preventDefault()}),t.on("click",".feature-coin.tip-wrap",function(e){"feature-coin tip-wrap"===e.target.className&&(B.fadeOut(),e.preventDefault())}),t.on("click",".featuretip .close",function(e){M.fadeOut(),e.preventDefault()}),t.on("click",".featuretip .refresh",function(){location.reload()}),t.on("click",".featuretip.tip-wrap",function(e){"featuretip tip-wrap"===e.target.className&&(M.fadeOut(),e.preventDefault())})},P={queryString:L,init:function(){R(),z()},isApp:function e(){var t=L(),e=!!t.app_version||"app"===t.openrefer&&t.uid;return!!e},image:function(e,t,i,n,o){return n=isNaN(Number(n))?2:n,e=e||"",e=e.replace(/{width}/g,t).replace(/{height}/g,i).replace(/{mode}/g,n),e.indexOf("imageView2")>0&&(o=o||90,e+="/q/"+o),e.replace("quality/80","quality/60").replace("http:","")},sParamByIframe:function(t){e('<iframe style="display:none;" src="//m.yohobuy.com/activity/wechat/1111?'+t+'"></iframe>').prependTo("body")},showTip:function(t){t=t||{title:"",content:"",close:!0},M.find(".title").html(t.title),M.find(".content").html(t.content),t.close?M.find(".button").addClass("close"):M.find(".button").addClass("refresh").html("刷新"),e("body").append(M),M.show()},showCoinTip:function(t){t=t||{title:"",content:"",close:!0},B.find(".title").html(t.title),B.find(".content").html(t.content),t.close&&B.find(".button").addClass("close"),t.coin?B.find(".coin").css("display","inline-block"):B.find(".coin").hide(),t.img&&B.find(".tip").css("background-image","url("+t.img+")"),e("body").append(B),B.show()}},Q=function(){var e=location.href.split("?")[0];return"//m.yohobuy.com/signin.html?refer="+encodeURIComponent(location.href)+'&openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"'+e.replace(/\//g,"\\/")+'","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}'},J={uid:"",noLoginUrl:Q,init:function(){var t=this;return r({url:"//m.yohobuy.com/passport/login/user?callback=?"}).then(function(i){return 200===i.code&&(t.uid=Number(i.data)||0),!t.uid&&P.isApp()&&(t.uid=Number(P.queryString().uid)||0),e.Deferred().resolve(t.uid)},function(){return P.isApp()&&(t.uid=Number(P.queryString().uid)||0),e.Deferred().resolve(t.uid)})},auth:function(){if(!this.uid){var t=Q();e("a.auth").attr("href",t)}},favout:function(e){e&&this.uid&&r({url:"//service.yoho.cn/activity/favorite/addFavorite?productSkn="+e+"&uid="+this.uid+"&callback=?"}).then(function(e){200===e.code?P.showTip({content:"恭喜您,收藏成功",close:!0}):P.showTip({content:e.message,close:!0})},function(){P.showTip({title:"收藏失败<br>请刷新重新领取",content:"如多次收藏失败,请联系客服人员<br>带来不便敬请谅解",close:!1})})},getMktCode:function(){var e=void 0;return e=this.uid?Number(this.uid)%1024>=512?0x5af3107a40c3:0x5af3107a40c1:0x5af3107a40c5}},$=["checkJsApi","onMenuShareTimeline","onMenuShareAppMessage","onMenuShareQQ","onMenuShareWeibo","onMenuShareQZone"],G={title:document.title,link:location.href,desc:"YOHO!BUY",imgUrl:"http://static.yohobuy.com/m/v1/img/touch/apple-touch-icon-144x144-precomposed-new.png"},W=function(){var t=P.queryString().share_id;if(t)return r({url:"//m.yohobuy.com/activity/share?callback=?",data:{shareId:t}}).then(function(t){return t&&200===t.code&&t.data&&(G.title=t.data.title,G.link=t.data.link||location.href,G.desc=t.data.content||t.data.title,G.imgUrl=t.data.pic),e.Deferred().resolve()},function(){return e.Deferred().resolve()});var i=e("#shareTitle").val(),n=e("#shareImg").val(),o=e("#shareDesc").val(),a=e("#shareLink").val();return G.title=i?i:G.title,G.imgUrl=n?n:G.imgUrl,G.desc=o?o:G.desc,G.link=a?a:G.link,e.Deferred().resolve()},F={init:function(){/QQ/i.test(navigator.userAgent)&&e.ajax({url:"//qzonestyle.gtimg.cn/qzone/qzact/common/share/share.js",dataType:"script",cache:!0,success:function(){W().then(function(){window.setShareInfo&&window.setShareInfo({title:G.title,summary:G.desc,pic:G.imgUrl,url:G.link})})}}),/MicroMessenger/i.test(navigator.userAgent)&&e.ajax({url:"//res.wx.qq.com/open/js/jweixin-1.1.0.js",dataType:"script",cache:!0,success:function(){r({url:"//m.yohobuy.com/activity/wechat/share?callback=?",data:{url:location.href}}).then(function(e){window.wx&&(window.wx.config({debug:!1,appId:e.appId,timestamp:e.timestamp,nonceStr:e.nonceStr,signature:e.signature,jsApiList:$}),W().then(function(){window.wx.ready(function(){window.wx.onMenuShareAppMessage(G),window.wx.onMenuShareTimeline(G),window.wx.onMenuShareQQ(G),window.wx.onMenuShareWeibo(G),window.wx.onMenuShareQZone(G)})}))})}})}},X={"baidu.com":0x5af3107a4037,"so.com":0x5af3107a4031,"sogou.com":0x5af3107a4035,"bing.com":0x5af3107a4039,"m.sm.cn":0x5af3107a403b,"google.com":0x5af3107a403d},Y=function(){var e,t=document.referrer;for(var i in X)if(t.indexOf(i)>-1){e=X[i];break}return e},H=function(){var e=P.queryString(),t=e.mkt_code||e.union_type||Y()||"100000000000349";delete e.openapp;var i=e.share_id?'"share":"/operations/api/v5/webshare/getShare","shareparam":{"share_id":"'+e.share_id+'"},':"",n="yohobuy://yohobuy.com/goapp?ct="+t+'&openby:yohobuy={"action":"go.h5",'+i+'"params":{"islogin":"N","url":"http://feature.yoho.cn'+location.pathname+'","param":'+JSON.stringify(e)+"}}";return n},Z={init:function(){if(P.queryString().openapp){var e=navigator.userAgent.toLowerCase(),t=e.indexOf("os")>-1||e.indexOf("iphone")>-1||e.indexOf("mac")>-1||e.indexOf("ipad")>-1,i=H();if(t)window.location.href=i;else{var n=document.createElement("iframe");n.src=i,n.style.display="none",document.body.appendChild(n)}}}},V={cookie:c,setCookie:d},K=function(e){e.app=P.queryString(),e.app.uid=e.uid,r({url:"//m.yohobuy.com/activity/coin/sendCoin?callback=?",data:e}).then(function(e){200===e.code&&e.data?200===e.data.code?P.showCoinTip({title:"恭喜您,成功领取有货币!",content:"特殊情况下到账有延时<br>请耐心等待",close:!0,coin:!0,img:e.data.popupImg}):501===e.data.code?P.showCoinTip({title:"领取失败",content:"哎呀,你来的有点早,活动还没开始呢<br/>稍后再来哦",close:!0,img:e.data.popupImg}):502===e.data.code?P.showCoinTip({title:"领取失败",content:"抱歉,活动已结束了,下次要快哟~~",close:!0,img:e.data.popupImg}):503===e.data.code?P.showCoinTip({title:"已经领取",content:"贪心会长胖,你已经领取过了啦~~",close:!0,img:e.data.popupImg}):504===e.data.code?P.showCoinTip({title:"领取失败",content:"哎呀,你来晚了,有货币已经领完了,<br/>下次早点来哦",close:!0,img:e.data.popupImg}):e.data.msg&&P.showCoinTip({title:"领取失败",content:"抱歉,系统错误,有货君正奋力解决中...请稍后再来",close:!0,img:e.data.popupImg}):e.message&&P.showCoinTip({title:"领取失败",content:"抱歉,系统错误,有货君正奋力解决中...请稍后再来",close:!0,img:e.data&&e.data.popupImg})},function(){P.showCoinTip({title:"领取失败",content:"抱歉,系统错误,有货君正奋力解决中...请稍后再来",close:!0})})},ee=function(e){e.app=P.queryString(),e.app.uid=e.uid,r({url:"//m.yohobuy.com/coupon/couponSend?callback=?",data:e}).then(function(e){200===e.code?P.showTip({title:"领取成功",content:"恭喜您,领取成功",close:!0}):401===e.code?P.showTip({title:"已经领取",content:'快去分享给更多<br>喜爱<span class="highlight">潮流</span>的小伙伴吧!',close:!0}):e.message&&P.showTip({title:"领取失败<br>请刷新重新领取",content:e.message+"<br>如多次领取失败,请联系客服人员<br>带来不便敬请谅解",close:!1})},function(){P.showTip({title:"领取失败<br>请刷新重新领取",content:"如多次领取失败,请联系客服人员<br>带来不便敬请谅解",close:!1})})},te=function(t){if(t){var i=V.cookie("yoho-coin-token");i&&(K({token:i,uid:t}),V.setCookie("yoho-coin-token",""))}e("body").on("click",".yoho-coin",function(){var t=e(this).data("token");return J.uid?void K({token:t,uid:J.uid}):(V.setCookie("yoho-coin-token",t),e("#intimacy-link").length<=0&&e("body").append("<a href='"+J.noLoginUrl()+'\' style="display:none;" id="intimacy-link"><span class="intimacy-link"></span></a>'),void e(".intimacy-link").click())})},ie=function(t){if(t){var i=V.cookie("yoho-conpon-token");i&&(ee({token:i,uid:t}),V.setCookie("yoho-conpon-token",""))}e("body").on("click",".yoho-conpon",function(){var t=e(this).data("token");return J.uid?void ee({token:t,uid:J.uid}):(V.setCookie("yoho-conpon-token",t),e("#intimacy-link").length<=0&&e("body").append("<a href='"+J.noLoginUrl()+'\' style="display:none;" id="intimacy-link"><span class="intimacy-link"></span></a>'),void e(".intimacy-link").click())})},ne={init:function(e){te(e),ie(e)}},oe=!1,ae=function(e,t,i,n,o){if(i){e.find(".brand-name").html(i.brand_name),e.find(".product-detail").attr("href","//m.yohobuy.com/product/pro_"+i.product_id+"_"+i.goods_id+"/"+i.cn_alphabet+'.html?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":'+i.product_skn+"}}"),e.find(".product-detail-img").attr("src",P.image(i.default_images,n.w,n.h,2,60)),e.find(".product-name").html(i.product_name),e.find(".vip-price-val").html("¥"+i.vip_price),e.find(".sale-price").html("¥"+i.sales_price),i.sales_price===i.market_price?e.find(".market-price").hide():e.find(".market-price").html("¥"+i.market_price).show();var a=e.find(".product-brand");a&&(i.shop_id?a.attr("href","//m.yohobuy.com/product/index/brand?domain="+i.brand_domain+'&openby:yohobuy={"action":"go.shop","params":{"shop_id":'+i.shop_id+',"shop_template_type":'+i.shop_template_type+"}}"):a.attr("href","//m.yohobuy.com/product/index/brand?domain="+i.brand_domain+'&openby:yohobuy={"action":"go.brand","params":{"brand_id":'+i.brand_id+"}}")),o&&(o.I_INDEX||(o.I_INDEX=0),o.I_INDEX++,e.find(".product-detail").attr("fp",JSON.stringify(o)),a&&(o.I_INDEX++,a.attr("fp",JSON.stringify(o))));var r=e.find(".list-product");if(r){var c="",d=t.gender?t.gender:"1,3",s="//list.m.yohobuy.com?gender="+d;r.data("sort")&&(c+=',"sort":'+i.small_sort_id,s+="&sort="+i.small_sort_id),r.data("misort")&&(c+=',"misort":'+i.middle_sort_id,s+="&misort="+i.middle_sort_id),r.data("msort")&&(c+=',"msort":'+i.max_sort_id,s+="&msort="+i.max_sort_id),s+='&openby:yohobuy={"action":"go.list","params":{"actiontype":1,"gender":'+d+c+"}}",r.attr("href",s)}return e.html(e.html()),e}},re=function e(t){if(t.length){var i=t.shift();return i&&i.default_images?i:e(t)}},ce=function(t,i,n){var o=t.attr("cloneitem"),a=t.find(".loading"),c=t.find(".feature-product-info");if(c.length){if(n.abtest&&(!i.uid||Number(i.uid)%1024>=512))return void(o?e(c[0]).remove():(c.removeClass("novisible"),a.hide()));var d=t.find(".imgwh").val()||"";d=d.split("x")||[];var s={w:d[0]||300,h:d[1]||400},u=t.attr("fp");u=u?JSON.parse(u):"",r({url:"//m.yohobuy.com/activity/individuation?callback=?",data:e.extend({},i,n)}).then(function(i){if(!i||!i.length)return void(o?e(c[0]).remove():(c.removeClass("novisible"),a.hide()));if(o)for(var r=isNaN(Number(o))?i.length:Number(o),d=0;d<r;d++){var p=re(i);if(0===d){var l=e(c[0]),f=ae(l,n,p,s,u);f?f.removeClass("novisible"):l.remove()}else{var h=ae(e(c[0]).clone(),n,p,s,u);h&&(h.removeClass("novisible"),h.appendTo(t))}}else c.each(function(t,o){o=e(o),ae(o,n,re(i),s,u)}),c.removeClass("novisible"),a.hide()},function(){o?e(c[0]).remove():(c.removeClass("novisible"),a.hide())})}},de=function(){var t=J.getMktCode();P.sParamByIframe("cover=1&mkt_code="+t+"&expires=604800000");var i=[];e("a").each(function(){var t=e(this).attr("href");!t||/^#.*$/.test(t)||/^javascript.*$/i.test(t)||i.push(t)});var n=0,o=setInterval(function(){return n++,n>3?void clearInterval(o):void(window._yas&&window._yas.sendAppLogs&&window.appBaseLogs&&(clearInterval(o),window._yas.sendAppLogs({appop:"YB_H5_PAGE_AB_OPEN_L",param:JSON.stringify({C_ID:P.queryString().yh_channel||1,PAGE_URL:window.originUrl,PAGE_NAME:decodeURI(window.qs.title||document.title),ACTION_URL:i,CROWD_CODE:t+""})},!0),e("a").click(function(){var i=e(this).attr("href");!i||/^#.*$/.test(i)||/^javascript.*$/i.test(i)||window._yas.sendAppLogs({appop:"YB_H5_PAGE_AB_FLR_C",param:JSON.stringify({C_ID:P.queryString().yh_channel||1,PAGE_URL:window.originUrl,PAGE_NAME:decodeURI(window.qs.title||document.title),F_URL:i,CROWD_CODE:t+""})},!0)})))},1e3)},se=function(t){e(".product-source").each(function(i,n){n=e(n);var o=n.attr("condition");if(o){o=JSON.parse(o);var a=P.queryString().yh_channel;o.abtest&&(oe=!0),a&&(o.yh_channel=a),i>3?setTimeout(function(){ce(n,t,o)},300):ce(n,t,o)}}),oe&&de()},ue={init:function(e){!e&&P.isApp()?document.addEventListener("deviceready",function(){window.yohoInterface.triggerEvent(function(e){J.uid=e.uid,se({uid:e.uid,udid:e.udid})},function(){},{method:"get.analyticAppData"})},!1):se({uid:e,udid:V.cookie("_yasvd")})}};e(function(){Z.init(),J.init().then(function(e){ue.init(e),ne.init(e),J.auth(),F.init(),P.init()})});var pe={auth:J.auth,favout:J.favout,getMktCode:function(){return J.getMktCode()},getUid:function(){return J.uid}},le="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};!function(e){"object"===("undefined"==typeof module?"undefined":le(module))&&"object"===le(module.exports)?module.exports=e():"function"==typeof define&&define.amd?define([],e):window._jssdk=e()}(function(){return pe})}(jQuery);