45 lines
829 B
JavaScript
45 lines
829 B
JavaScript
|
|
||
|
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) {
|
||
|
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;
|
||
|
};
|
||
|
|
||
|
|
||
|
}
|