/** * Clickehat by Benjamin Hutchins * @see Plugin info for more information */ var clickheat={server:"",wait:,quota:,doc:null,useDebug:(window.location.href.search(/debugclickheat/)!==-1),lastTime:-1,ajax:false,time:Date.now||function(){return +new Date},init:function(){domain=window.location.href.match(/http:\/\/[^/]+\//);if(domain!==null&&this.server.substring(0,domain[0].length)===domain[0]){this.server=this.server.substring(domain[0].length-1,this.server.length);this.ajax=true}if(document.addEventListener){document.addEventListener("mousedown",clickheat.click,false)}else{document.attachEvent("onmousedown",clickheat.click)}this.doc=(document.documentElement!==undefined&&document.documentElement.clientHeight!==0)?document.documentElement:document.body;this.debug("ClickHeat initialized.")},debug:function(a){if (clickheat.useDebug&&window.console){console.log(a)}return true},xhr:function(a,e,b,d){if(d===undefined){d="get"}var c=window.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();if(b&&d=="get"){a=a+(a.indexOf("?")!=-1?"&":"?")+b;b=null}c.open(d.toUpperCase(),a,true);c.onreadystatechange=function(){if(c.readyState!=4){return}if((c.status>=200)&&(c.status<300)){e(c.responseText,c.responseXML)}else{clickheat.debug("Server returned a status code "+c.status+" with the following error: "+c.responseText)}c.onreadystatechange=function(){}};c.setRequestHeader("Connection","close");c.send(null)},toQueryString:function(b){var c=[];for(var a in b){c.push(a+"="+encodeURIComponent(b[a]))}return c.join("&")},click:function(a){if(this.quota===0){return clickheat.debug("Click not logged: quota reached")}var k=a||window.event;var c={x:(k.pageX)?k.pageX-window.pageXOffset:k.clientX,y:(k.pageY)?k.pageY-window.pageYOffset:k.clientY};clickheat.debug("New click. Gathering data...");var m=c.x;var l=c.y;var n=clickheat.doc.clientWidth!==undefined?clickheat.doc.clientWidth:window.innerWidth;var j=clickheat.doc.clientHeight!==undefined?clickheat.doc.clientHeight:window.innerHeight;var i=window.pageXOffset===undefined?clickheat.doc.scrollLeft:window.pageXOffset;var g=window.pageYOffset===undefined?clickheat.doc.scrollTop:window.pageYOffset;var f=k.button||k.which;if(m>n||l>j){return clickheat.debug("Click not logged: out of document (should be a click on scrollbars)")}clickTime=clickheat.time();if(clickTime-clickheat.lastTime<1000){return clickheat.debug("Click not logged: at least 1 second between clicks")}clickheat.lastTime=clickTime;clickheat.quota--;var d=clickheat.toQueryString({title:document.title,href:window.location.href,x:(m+i),y:(l+g),w:n,which:f,random:clickTime});clickheat.debug("Ready to send click data...");if(clickheat.ajax){clickheat.xhr(clickheat.server,function(e){clickheat.debug("Click recorded with the following parameters:\n"+d+"\n\nServer answer: "+e)},d)}else{new Image().src=clickheat.server+"?"+d}var o=clickheat.time()+clickheat.wait;var b=function(){};while(o>clickheat.time()){b()}return true}};