Fix drag selection

rel-1.0
Vitaliy Filippov 2016-04-04 14:14:48 +03:00
parent f4ea9e29b1
commit c744294335
1 changed files with 26 additions and 9 deletions

View File

@ -1,7 +1,7 @@
/**
* Very simple and fast tree grid/table, compatible with dynamic loading and jQuery fixedHeaderTable
* License: MPL 2.0+, (c) Vitaliy Filippov 2016+
* Version: 2016-03-25
* Version: 2016-04-04
*/
/**
@ -211,6 +211,7 @@ TreeGrid.prototype.initCellSelection = function(restrictToNode)
{
dragDiv = document.createElement('div');
dragDiv.className = 'selection-rect';
dragDiv.style.display = 'none';
document.body.appendChild(dragDiv);
}
});
@ -220,7 +221,14 @@ TreeGrid.prototype.initCellSelection = function(restrictToNode)
if (startDrag)
{
evt = getEventCoord(evt);
dragDiv.style.display = 'block';
if (dragDiv.style.display == 'none')
{
if ((startDrag[0] < evt.pageX-10 || startDrag[0] > evt.pageX+10) &&
(startDrag[1] < evt.pageY-10 || startDrag[1] > evt.pageY+10))
dragDiv.style.display = 'block';
else
return;
}
if (startDrag[0] < evt.pageX)
{
dragDiv.style.left = startDrag[0]+'px';
@ -264,14 +272,23 @@ TreeGrid.prototype.initCellSelection = function(restrictToNode)
y1 = t;
}
startDrag = null;
if (x2 > x1+10 && y2 > y1+10)
function doSelect()
{
if (!this.parentNode._node)
return;
var i = self.getNodeIndex(this);
if (!self.onCellSelect || self.onCellSelect(this.parentNode._node, i, this))
this.className += ' selected';
}
if (x2 > x1+10 && y2 > y1+10)
rectangleSelect(self.table.getElementsByTagName('td'), x1, y1, x2, y2, doSelect);
else
{
var t = evt.target || evt.srcElement;
doSelect.apply(t);
}
if (x2 > x1+10 && y2 > y1+10 || evt.shiftKey)
{
rectangleSelect(self.table.getElementsByTagName('td'), x1, y1, x2, y2, function()
{
var i = self.getNodeIndex(this);
if (!self.onCellSelect || self.onCellSelect(this.parentNode._node, i, this))
this.className += ' selected';
});
if (document.selection)
document.selection.empty();
else