/** * Clickehat by Benjamin Hutchins * @see Plugin info for more information */ var clickheat = { /** * Quickly get the timestamp */ time: Date.now || function(){ return +new Date; }, alpha: 70, lastDayOfMonth: 0, date: [], range: 'd', width: 0, caldate: '', path: habari.url.clickheat, init: function() { // add events $('#group select').change(function(){ clickheat.loadIframe(); }); $('#screen select').change(function(){ clickheat.resizeDiv(); clickheat.updateHeatmap(); }); $('#heatmap input').click(function(){ clickheat.updateHeatmap(); }); // start clickheat this.drawAlphaSelector(60); this.resizeDiv(); this.loadIframe(); this.runCleaner(); }, /** * Hide/Show options */ toggleVisibility: function(e) { e=$(e); $('#options').toggle(); var backup= e.html(); e.html( e.attr('alt') ); e.attr('alt', backup); }, /** * Returns the "top" value of an element */ getTop: function(obj) { if (typeof obj == 'string') obj= document.getElementById(obj); if (obj.offsetParent != undefined) return (obj.offsetTop + this.getTop(obj.offsetParent)); else return obj.offsetTop; }, /** * Resize the div relative to window height and selected screen size */ resizeDiv: function() { oD = document.documentElement != undefined && document.documentElement.clientHeight != 0 ? document.documentElement : document.body; iH = oD.innerHeight != undefined ? oD.innerHeight : oD.clientHeight; $('overflowDiv').css('height', (iH < 300 ? 400 : iH) - clickheat.getTop('overflowDiv') + 'px'); /** * Width of main display */ iW = oD.innerWidth != undefined ? oD.innerWidth : oD.clientWidth; clickheat.width = $('#screen select').val() == 0 ? iW : $('#screen select').val() - 5; $('#overflowDiv').css('width', clickheat.width + 'px'); $('#webPageFrame').css('width', (clickheat.width - 25) + 'px'); }, /** * Update calendar selected days */ updateCalendar: function(day) { /** clickheat.date[day, month, year, saved_day, month_origin, year_origin] */ if (day != undefined) clickheat.date[3] = day; clickheat.date[1] = clickheat.date[4]; clickheat.date[2] = clickheat.date[5]; /** Showing one day */ if (clickheat.range == 'd') { /** Remember the last day used */ clickheat.date[0] = clickheat.date[3]; min = clickheat.date[0]; max = clickheat.date[0]; } /** Showing one month */ if (clickheat.range == 'm') { clickheat.date[0] = 1; min = 1; max = weekDays.length; } /** Showing one week */ if (clickheat.range == 'w') { /** Remember the last day used */ clickheat.date[0] = clickheat.date[3]; week = weekDays[clickheat.date[0]]; min = 0; max = 0; for (d = 1; d < weekDays.length; d++) if (weekDays[d] == week) { if (min == 0) { clickheat.date[0] = d; min = d; } max = d; } /** Start was on the previous month */ if (min == 1 && max != 7) { clickheat.date[0] = clickheat.lastDayOfMonth - 6 + max; clickheat.date[1]--; if (clickheat.date[1] == 0) { clickheat.date[1] = 12; clickheat.date[2]--; } } } for (d = 1; d < weekDays.length; d++) document.getElementById('clickheat-calendar-' + d).className = (d >= min && d <= max ? 'clickheat-calendar-on' : ''); for (i = 1; i < 7; i++) { if (document.getElementById('clickheat-calendar-10' + i) != undefined) document.getElementById('clickheat-calendar-10' + i).className = (clickheat.range == 'w' && weekDays[min] == weekDays[1] ? 'clickheat-calendar-on' : ''); if (document.getElementById('clickheat-calendar-11' + i) != undefined) document.getElementById('clickheat-calendar-11' + i).className = (clickheat.range == 'w' && weekDays[max] == weekDays[weekDays.length - 1] ? 'clickheat-calendar-on' : ''); } document.getElementById('clickheat-calendar-d').className = (clickheat.range == 'd' ? 'clickheat-calendar-on' : ''); document.getElementById('clickheat-calendar-w').className = (clickheat.range == 'w' ? 'clickheat-calendar-on' : ''); document.getElementById('clickheat-calendar-m').className = (clickheat.range == 'm' ? 'clickheat-calendar-on' : ''); this.updateHeatmap(); }, /** * Ajax request to update PNGs */ updateHeatmap: function() { $('#pngDiv').html('