2010-09-19 07:54:35 +02:00
|
|
|
|
|
|
|
function HoverListener(coordinateGrid) {
|
|
|
|
|
|
|
|
|
|
|
|
var t = this;
|
|
|
|
var bindType;
|
|
|
|
var change;
|
|
|
|
var firstCell;
|
|
|
|
var cell;
|
|
|
|
|
|
|
|
|
|
|
|
t.start = function(_change, ev, _bindType) {
|
|
|
|
change = _change;
|
|
|
|
firstCell = cell = null;
|
|
|
|
coordinateGrid.build();
|
|
|
|
mouse(ev);
|
|
|
|
bindType = _bindType || 'mousemove';
|
|
|
|
$(document).bind(bindType, mouse);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function mouse(ev) {
|
2011-11-20 03:21:10 +01:00
|
|
|
_fixUIEvent(ev);
|
2010-09-19 07:54:35 +02:00
|
|
|
var newCell = coordinateGrid.cell(ev.pageX, ev.pageY);
|
|
|
|
if (!newCell != !cell || newCell && (newCell.row != cell.row || newCell.col != cell.col)) {
|
|
|
|
if (newCell) {
|
|
|
|
if (!firstCell) {
|
|
|
|
firstCell = newCell;
|
|
|
|
}
|
|
|
|
change(newCell, firstCell, newCell.row-firstCell.row, newCell.col-firstCell.col);
|
|
|
|
}else{
|
|
|
|
change(newCell, firstCell);
|
|
|
|
}
|
|
|
|
cell = newCell;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
t.stop = function() {
|
|
|
|
$(document).unbind(bindType, mouse);
|
|
|
|
return cell;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2011-11-20 03:21:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
function _fixUIEvent(event) { // jQuery 1.7 workaround (for issue 1168)
|
|
|
|
if (event.pageX === undefined) {
|
|
|
|
event.pageX = event.originalEvent.pageX;
|
|
|
|
event.pageY = event.originalEvent.pageY;
|
|
|
|
}
|
2012-01-08 23:46:27 +01:00
|
|
|
}
|