Free javascript Hosting


livecount.js

Uploaded on Jan 06 2010 20:33 by manasbe

var jQueryInit = false;
function initJQuery() {
if (typeof(jQuery) == 'undefined') {
if (! jQueryInit) {
jQueryInit = true;
document.write("<scr" + "ipt type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js\"></scr" + "ipt>");
}
setTimeout("initJQuery()", 250);
} else {
jQuery(document).ready(function() {

// Setup Workspace
Chitika.LiveCount.setup();

// Register ColorMod
Chitika.LiveCount.color();

// Kick off monitor
Chitika.LiveCount.monitor();

});
}
}

// Initialize JQuery on body load
initJQuery();

// Configuration
var timeout = 3;
var lastCount = 0;
var userIcon = "http://labs.chitika.com/LiveCount/user.png";
var usersIcon = "http://labs.chitika.com/LiveCount/users.png";
var monitorTimer;

// Initiate Chitika Engine
if(!window.Chitika){ Chitika = {}; }

// Create Module
Chitika.LiveCount = {};


/******* Monitor Visitor Number *******/
Chitika.LiveCount.monitor = function(e){

jQuery.getJSON("http://labs.chitika.com/LiveCount/count.php?timeout=" + timeout + "&c=?", function(lc){
if (lc.count == 1) {
jQuery(".lcWrapper").css("background-image", "url('"+userIcon+"')").text(lc.count + " Visitor");
} else {
jQuery(".lcWrapper").css("background-image", "url('"+usersIcon+"')").text(lc.count + " Visitors");
}

if (lastCount != lc.count) {
//jQuery(".lcWrapper").effect("highlight", {}, 3000);
lastCount = lc.count;
}

});

monitorTimer = setTimeout ( "Chitika.LiveCount.monitor()", timeout * 1000 );

}


/******* Setup Workstation *******/
Chitika.LiveCount.setup = function(){
// Generate Elements
var lcWrapper = jQuery("<div>")
.css("z-index","99999")
.css("position","fixed")
.css("bottom","0px")
.css("left","5px")
.css("font-family","Verdana, Arial, Helvetica, sans-serif")
.css("font-size", "12px")
.css("font-weight", "normal")
.css("padding", "4px 6px 4px 22px")
.css("color", "#2276bb")
.css("background-color", "#DDEEF6")
.css("border-top", "1px solid #C0DEED")
.css("border-left", "1px solid #C0DEED")
.css("border-right", "1px solid #C0DEED")
.css("-moz-border-radius-topleft", "5px")
.css("-webkit-border-top-left-radius", "5px")
.css("-moz-border-radius-topright", "5px")
.css("-webkit-border-top-right-radius", "5px")
.css("background", "#DDEEF6 url('http://labs.chitika.com/LiveCount/user.png') no-repeat 4px 3px")
.text("Visitors")
.addClass("lcWrapper");
// Finally, append all to body
jQuery("body").prepend(lcWrapper);
}


/******* Register modified version of jQuery Color Animations *******/
Chitika.LiveCount.color = function() {
/*
* jQuery Color Animations
* Copyright 2007 John Resig
*/
(function(jQuery){
jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
jQuery.fx.step[attr] = function(fx){
if ( fx.state == 0 ) { fx.start = getColor( fx.elem, attr ); fx.end = getRGB( fx.end ); }
fx.elem.style[attr] = "rgb(" + [
Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
].join(",") + ")";
}
});

// Parse strings looking for color tuples [255,255,255]
function getRGB(color) {
var result;
// Check if we're already dealing with an array of colors
if ( color && color.constructor == Array && color.length == 3 ) return color;
// Look for rgb(num,num,num)
if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color)) return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];
// Look for rgb(num%,num%,num%)
if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color)) return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];
// Look for #a0b1c2
if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color)) return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];
// Look for #fff
if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color)) return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];
}

function getColor(elem, attr) {
var color;
do {
color = jQuery.curCSS(elem, attr);
// Keep going until we find an element that has color, or we hit the body
if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") ) break;
attr = "backgroundColor";
} while ( elem = elem.parentNode );
return getRGB(color);
};
})(jQuery);
}

Back to list