;(function($) {
$.extend({
viewPort : function () {
var scrollLeft = $(document).scrollLeft();
var scrollTop = $(document).scrollTop();
var windowWidth = $(window).width();// - 20;
var windowHeight = $(window).height();// - 20;
var offsetCenterLeft = windowWidth / 2 + scrollLeft;
var offsetCenterTop = windowHeight / 2 + scrollTop;
return {
left : scrollLeft,
right : scrollLeft + windowWidth,
top : scrollTop,
bottom : scrollTop + windowHeight,
center : { left : offsetCenterLeft, top : offsetCenterTop }
}
}
});
})(jQuery);
;(function($) {
$.fn.extend({
tableTracking: function(settings) {
var options = {
colCSS : {
backgroundColor : '#eeeeee'
},
rowCSS : {
backgroundColor : '#dddddd'
},
cellCSS : {
backgroundColor : '#aaaaaa'
},
toolTip : {
offsetTop : -5,
offsetLeft : -5,
css : {
border : 'black 2px solid',
position : 'absolute',
/*height : '100px',
width : '100px',*/
backgroundColor : 'white'
}
},
delay : 0,
follow : true,
clickLock : true,
forceHorizontalViewPort : true,
forceVirticalViewPort : false
}
var lastCell = null;
var lastCellIndex = null;
var lastRowIndex = null;
$.extend(options, settings);
return this.each(function() {
var $activeTip = null;
if (this.tagName == 'TABLE') {
$(this).find('td').each(function () {
//var $cell = $(this);
var timer = null;
if (options.follow) {
this.onmouseover = function (e) {
e = e || event;
var target = e.target || e.srcElement;
if (options.delay) {
timer = setTimeout(function (){ cellMouseOver(target) }, options.delay)
}
else {
cellMouseOver(target)
}
}
this.onmouseout = function (e) {
e = e || event;
var target = e.target || e.srcElement;
if (timer) {
clearTimeout(timer);
timer = null;
}
cellMouseOut(target);
}
}
else {
this.onclick = function (e) {
e = e || event;
var target = e.target || e.srcElement;
cellClick(target)
}
}
});
}
function cellClick(cell) {
if (lastCell) {
cellMouseOut(lastCell);
}
cellMouseOver(cell);
lastCell = cell;
}
function rowMouseOver (row) {
for (var x = 0 ; x < row.cells.length; x++) {
swapCSS(row.cells[x], options.rowCSS);
}
}
function rowMouseOut (row) {
for (var x = 0 ; x < row.cells.length; x++) {
swapCSS(row.cells[x]);
}
}
function cellMouseOver (cell) {
colMouseOver(cell.parentNode.parentNode, cell.cellIndex);
rowMouseOver(cell.parentNode);
swapCSS(cell, options.cellCSS);
displayTip(cell);
/*if (cell.cellIndex != lastCellIndex && lastCellIndex != null) {
colMouseOut(cell.parentNode.parentNode, lastCellIndex);
}
if (cell.parentNode.rowIndex != lastRowIndex && lastRowIndex != null) {
rowMouseOut(cell.parentNode.parentNode.rows[lastRowIndex]);
}
lastCellIndex = cell.cellIndex;
lastRowIndex = cell.parentNode.rowIndex;*/
}
function cellMouseOut (cell) {
colMouseOut(cell.parentNode.parentNode, cell.cellIndex);
rowMouseOut(cell.parentNode);
swapCSS(cell);
hideTip();
}
function colMouseOver (table, colIndex) {
for (var x = 0; x < table.rows.length; x++) {
var row = table.rows[x];
if (row.cells.length > colIndex) {
swapCSS(row.cells[colIndex], options.colCSS);
}
}
}
function colMouseOut (table, colIndex) {
var x;
for (x = 0; x < table.rows.length; x++) {
var row = table.rows[x];
if (row.cells.length > colIndex) {
swapCSS(row.cells[colIndex]);
}
}
}
function displayTip (cell) {
if (options.tipContents) {
var $cell = $(cell);
var contents = options.tipContents(cell);
var container = getTipContainer(cell);
container.css ({
top : $cell.offset().top + $cell.outerHeight() + options.toolTip.offsetTop,
left : $cell.offset().left + $cell.outerWidth() + options.toolTip.offsetLeft
})
container.html('');
container.append(contents);
container.css({ display : 'inline'})//.dropShadow();
}
}
function hideTip () {
if ($activeTip) {
$activeTip.css({ display : 'none'})
}
}
function monitorActiveTip() {
var scrolling = false;
$(window).bind('scrollstart', function () { scrolling = true });
$(window).bind('scrollstop', function () { scrolling = false });
var interval = setInterval(function () {
if (!scrolling && $activeTip.css('display') != "none") {
//alert($activeTip.css('display'));
var outerWidth = $activeTip.outerWidth();
var outerHeight = $activeTip.outerHeight();
var viewPort = $.viewPort();
var position = $activeTip.position();
if (position.left + outerWidth > viewPort.right ) {
$activeTip.css({
left : viewPort.right - outerWidth
});
}
else if ( position.left < viewPort.left ) {
$activeTip.css({
left : viewPort.left
});
}
/*if (position.top + outerHeight > viewPort.bottom) {
$activeTip.css({
top : viewPort.bottom - outerHeight
});
}
else if ( position.top < viewPort.top) {
$activeTip.css({
top : viewPort.top
});
}*/
}
}, 100);
}
function getTipContainer(appendTo) {
if (!$activeTip) {
$activeTip = $('<div />').css(options.toolTip.css).appendTo(appendTo);
if (options.forceHorizontalViewPort || options.forceVerticalViewPort) {
monitorActiveTip();
}
}
return $activeTip;
}
function swapCSS(obj, css) {
var $obj = $(obj);
if (!obj.origCSS) {
obj.origCSS = { };
}
if (obj.origCSS && !css) {
for (var at in obj.origCSS) {
var val = (obj.origCSS[at]) ? obj.origCSS[at] : '';
obj.style[at] = val;
}
obj.currCSS = null;
obj.origCSS = null;
}
else if (obj.currCSS != css) {
for (var attr in css) {
var currVal = $obj.css(attr)
if (!obj.origCSS[attr]) {
obj.origCSS[attr] = currVal; //(currVal) ? currVal : 'none';
}
}
obj.currCSS = css;
$obj.css(css);
}
}
})
}
});
})(jQuery);