|
String.prototype.startsWith=function(a){return this.indexOf(a)==0};String.prototype.endsWith=function(a){return this.lastIndexOf(a)==this.length-a.length};(function(d){var f=0;var b={attributes:[],assignTo:["a","input[type='submit']"],captureOnce:false,client:null,id:"id",exclude:".analytics-exclude",url:null};function a(i){var g=[];var h=d(i).prop("tagName");if(h!=undefined){var k=d(i).parent();if(k!=undefined){d.each(a(d(i).parent()),function(l,m){if(d(m).is(b.exclude)){g=null}else{if(g!==null){g.push(m)}}})}if(g!==null){if(h=="HTML"||h=="BODY"){g.push(h)}else{var j=d(i).analyticsUniqueId().attr("id");g.push(h+'[id="'+j+'"]')}}}return g}function c(g){a(g)}function e(m){$this=d(this);if(b.url&&!$this.is(".analytics-captured")&&!$this.is(b.exclude)){var g=a($this);if(g!==null&&g.length>0){g=g.join(" ");var l=null;if($this.attr("href")){m.preventDefault();l=$this.attr("href")}var k={};if(b.id){k[b.id]=g}else{k.id=g}if(b.client){k.client=b.client}var j=$this.data();for(var i in j){if(i.startsWith("analytics")){var h=i.replace(/analytics/g,"").toLowerCase();k[h]=j[i]}}d.each(d(b.attributes),function(n,o){k[o]=$this.attr(o)});d.ajax({type:"POST",url:b.url,contentType:"application/x-www-form-urlencoded",data:k}).always(function(){if(b.captureOnce){$this.addClass("analytics-captured")}if(l){window.location=l}})}}}d.fn.analyticsUniqueId=function(){if(this.length==0){return}return this.each(function(){if(!d(this).attr("id")){d(this).attr("id","analytics-id-"+ ++f)}})};d.fn.analytics=function(h){if(d(this).length==0){return}b=d.extend({},b,h);var g=b.assignTo.join(",");return this.each(function(){d(this).find(g).andSelf().filter(g).each(function(){c(d(this));d(this).on("click",e)})}).on("DOMNodeInserted",function(i){d(i.target).find(g).andSelf().filter(g).each(function(){c(d(this));d(this).on("click",e)})})}})(jQuery);
|