-
Notifications
You must be signed in to change notification settings - Fork 0
/
sc-linktrack.min.js
1 lines (1 loc) · 3.86 KB
/
sc-linktrack.min.js
1
(function(e,t,n){"use strict";var r,i={},s,o,u,a=false,f=e.s;if(e.jQuery===undefined||f===undefined){return}r=e.jQuery.noConflict();try{i.addEvent=function(e,t,n){if(e.addEventListener){e.addEventListener(t,n,false)}else{e.attachEvent("on"+t,n)}};i.delegateStl=function(t,n){var r="",i=t.match(/[\w\=]*-?id\=([\w\W\/\-\&\'\"\=\#]*)[\&\#]?/i),s=n.propOverride;if(a||n.$this.attr("data-called")){return}n.$this.attr("data-called","true");if(!i){return}r=i[i.length-1];f=e.s_gi(e.s_account);f.trackExternalLinks=false;f.linkTrackVars=s;f[s]=r;f.tl(this,"o","sc_linktrack2.0")};i.arrayNodeIndex=function(e,t){var n=t.length,r=0;for(r;r<n;r+=1){if(e===t[r]){return r+1}}return false};i.partsName=function(e,t){if(e.id){return e.id}var n=i.arrayNodeIndex(e,t);return n};i.createId=function(e,t,n){var s="",o="",u=n.base,a="",f,l="",c={};s=t.indexOf("?")>-1?"&":"?";o=n.idType||"l-id=";f=r(e).closest(n.parentEl)[0];if(!n.idDivNum){u+="_"+n.idName}else{l=i.partsName(f,n.list);u+="_"+n.idName+l}if(n.idLinkNum){c=r(n.targetEl,f);a=i.partsName(e,c);u+="_"+a}return s+o+u};i.isIchibaDomain=function(t){var n=e.accountSetting._internalSite.length,r=0;for(r;r<n;r+=1){if(e.accountSetting._internalSite[r].replace("/","")===t){return true}}return false};i.linkClick=function(e){var t,n,r,s=this.getAttribute("sc-override");e=e.data;e.thisLink=this;if(this.href){n=this.href;e.cleanHref=n.replace(/[\?|\&]\w{1,2}\-?id\=[\w\W\/\-\&\'\"\=\#]*/gi,"");r=this.hostname}else{e.tempStlFlag=true;e.cleanHref=""}if(s){i.attachId(e,s);return}if(e.forceParam||i.isIchibaDomain(r)){e.idType=/item|basket|cart/i.test(r)?"s-id=":"l-id="}else if(/grp\d{2}\W{1}ias/i.test(r)){e.idType="ap=s-id="}else{e.tempStlFlag=true}t=i.createId(this,e.cleanHref,e);if(t){i.attachId(e,t)}};i.attachId=function(e,t){if(e.forceStl||e.tempStlFlag){e.$this=r(e.thisLink);i.delegateStl(t,e)}else{e.thisLink.href=e.cleanHref+t}};i.checkDrag=function(){var e=r("body");e.bind("touchmove",function(){a=true});e.bind("touchstart",function(){a=false})};s=function(e){this.parentEl=e.parentel||"";this.targetEl=e.targetel||"a";this.bindTrigger=e.bindtrigger||"click";this.path=e.path||0;this.idName=e.idname||"";this.idDivNum=e.iddivnum||false;this.idLinkNum=e.idlinknum||false;this.forceParam=e.forceparam||false;this.forceStl=e.forcestl||false;this.idTypeOverride=e.idtypeoverride||false;this.propOverride=e.propoverride||"prop18";this.list=r(this.parentEl);if(this.list[0]){this.init(this)}};s.prototype={init:function(){this.getBase();this.addToInput();this.attachLinkClick()},getBase:function(){var e,t,r;if(o){this.base=o}else{e=n.host.replace(".rakuten.co.jp","");t=this.getLayout();r=this.getPath(this.path);this.base=o=e+"_"+t+"_"+r}},getPath:function(e){var t=parseInt(e,10),r=n.pathname,i=[],s="",o=0;if(isNaN(t)||r==="/"){return"/"}if(t>0){i=r.match(/\W{1}\w*/g);for(o;o<t;o+=1){if(i[o]){s+=i[o]}}r=s}r=r.replace(/\/index\.html?/i,"");return r.slice(1)},getLayout:function(){var n;if(e.sc_layout!==undefined){n=e.sc_layout}if(!n){try{n=t.getElementsByName("ge_layout")[0].value}catch(r){n=""}}if(!n){n=t.getElementsByName("viewport").length?"SP":"PC"}return n},addToInput:function(){var e=u.length,t=0,n;for(t;t<e;t++){n=r(u[t]);if(n.attr("parentel")===this.parentEl){n.attr("result",this.base+"_"+this.idName);break}}},attachLinkClick:function(){var e=this.list.length,t=0;if(r.prototype.on){for(t;t<e;t++){r(this.list[t]).on(this.bindTrigger,this.targetEl,this,i.linkClick)}}else if(r.prototype.delegate){for(t;t<e;t++){r(this.list[t]).delegate(this.targetEl,this.bindTrigger,this,i.linkClick)}}else{for(t;t<e;t++){r(this.targetEl,this.list[t]).bind(this.bindTrigger,this,i.linkClick)}}}};i.init=function(){var e={},t={},n,o,a,f=0,l=0,c;u=r("input.sclinktrack");o=u.length;o=u.length;for(f;f<o;f++){t={};e=u[f].attributes;a=e.length;for(l=0;l<a;l++){n=e[l];t[n.nodeName.toLowerCase()]=n.value}c=new s(t)}i.checkDrag()};i.addEvent(e,"load",i.init)}catch(l){return}})(window,document,location)