Skip to content
This repository was archived by the owner on Jul 25, 2019. It is now read-only.

Commit 8d8fa51

Browse files
committed
bugfix: mouse wheel didn't scroll the window when cursor was over Handsontable
1 parent 5815e29 commit 8d8fa51

File tree

4 files changed

+115
-12
lines changed

4 files changed

+115
-12
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Features:
22
- initial release of Native Scrollbars feature (experimental, don't use yet)
33

44
Bugfixes:
5+
- mouse wheel didn't scroll the window when cursor was over Handsontable ([#383](https://github.com/warpech/jquery-handsontable/issues/383), [#627](https://github.com/warpech/jquery-handsontable/issues/627))
56
- methods `countVisibleRows` and `countVisibleCols` were broken since version 0.9.0
67
- WalkontableDom.prototype.offset now returns offset relatively to the document also for position: fixed
78

Diff for: src/3rdparty/walkontable/src/table.js

+8
Original file line numberDiff line numberDiff line change
@@ -527,4 +527,12 @@ WalkontableTable.prototype.isRowInViewport = function (r) {
527527

528528
WalkontableTable.prototype.isColumnInViewport = function (c) {
529529
return (!this.isColumnBeforeViewport(c) && !this.isColumnAfterViewport(c));
530+
};
531+
532+
WalkontableTable.prototype.isLastRowFullyVisible = function () {
533+
return (this.getLastVisibleRow() === this.instance.getSetting('totalRows') - 1 && this.rowStrategy.remainingSize <= 0);
534+
};
535+
536+
WalkontableTable.prototype.isLastColumnFullyVisible = function () {
537+
return (this.getLastVisibleColumn() === this.instance.getSetting('totalColumns') - 1 && this.columnStrategy.remainingSize <= 0);
530538
};

Diff for: src/3rdparty/walkontable/src/wheel.js

+22-12
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
11
function WalkontableWheel(instance) {
2-
var that = this;
3-
4-
//reference to instance
5-
this.instance = instance;
6-
72
if (instance.getSetting('scrollbarModelV') === 'native' || instance.getSetting('scrollbarModelH') === 'native') {
83
return;
94
}
105

11-
$(this.instance.wtTable.TABLE).on('mousewheel', function (event, delta, deltaX, deltaY) {
12-
clearTimeout(that.instance.wheelTimeout);
13-
that.instance.wheelTimeout = setTimeout(function () { //timeout is needed because with fast-wheel scrolling mousewheel event comes dozen times per second
6+
$(instance.wtTable.TABLE).on('mousewheel', function (event, delta, deltaX, deltaY) {
7+
if (deltaY > 0 && instance.getSetting('offsetRow') === 0) {
8+
return; //attempt to scroll up when it's already showing first row
9+
}
10+
else if (deltaY < 0 && instance.wtTable.isLastRowFullyVisible()) {
11+
return; //attempt to scroll down when it's already showing last row
12+
}
13+
else if (deltaX < 0 && instance.getSetting('offsetColumn') === 0) {
14+
return; //attempt to scroll left when it's already showing first column
15+
}
16+
else if (deltaX > 0 && instance.wtTable.isLastColumnFullyVisible()) {
17+
return; //attempt to scroll right when it's already showing last column
18+
}
19+
20+
//now we are sure we really want to scroll
21+
clearTimeout(instance.wheelTimeout);
22+
instance.wheelTimeout = setTimeout(function () { //timeout is needed because with fast-wheel scrolling mousewheel event comes dozen times per second
1423
if (deltaY) {
1524
//ceil is needed because jquery-mousewheel reports fractional mousewheel deltas on touchpad scroll
1625
//see http://stackoverflow.com/questions/5527601/normalizing-mousewheel-speed-across-browsers
17-
if (that.instance.wtScrollbars.vertical.visible) { // if we see scrollbar
18-
that.instance.scrollVertical(-Math.ceil(deltaY)).draw();
26+
if (instance.wtScrollbars.vertical.visible) { // if we see scrollbar
27+
instance.scrollVertical(-Math.ceil(deltaY)).draw();
1928
}
2029
}
2130
else if (deltaX) {
22-
if (that.instance.wtScrollbars.horizontal.visible) { // if we see scrollbar
23-
that.instance.scrollHorizontal(Math.ceil(deltaX)).draw();
31+
if (instance.wtScrollbars.horizontal.visible) { // if we see scrollbar
32+
instance.scrollHorizontal(Math.ceil(deltaX)).draw();
2433
}
2534
}
2635
}, 0);
36+
2737
event.preventDefault();
2838
});
2939
}

Diff for: src/3rdparty/walkontable/test/jasmine/spec/table.spec.js

+84
Original file line numberDiff line numberDiff line change
@@ -781,4 +781,88 @@ describe('WalkontableTable', function () {
781781
expect(wtHider.outerWidth()).toBeGreaterThan(getTableWidth($table));
782782
expect(wtHider.find('tr:first td:last').width()).toEqual(wtHider.find('tr:first td:last').prev().width());
783783
});
784+
785+
describe('isLastRowFullyVisible', function () {
786+
/*it('should be false because it is only partially visible', function () {
787+
createDataArray(8, 4);
788+
789+
var wt = new Walkontable({
790+
table: $table[0],
791+
data: getData,
792+
totalRows: getTotalRows,
793+
totalColumns: getTotalColumns,
794+
width: 185,
795+
height: 185,
796+
scrollH: 'auto',
797+
scrollV: 'auto',
798+
stretchH: 'hybrid'
799+
});
800+
wt.draw();
801+
802+
expect(wt.wtTable.isLastRowFullyVisible()).toEqual(false);
803+
});*/
804+
805+
it('should be true because it is fully visible', function () {
806+
createDataArray(8, 4);
807+
808+
var wt = new Walkontable({
809+
table: $table[0],
810+
data: getData,
811+
totalRows: getTotalRows,
812+
totalColumns: getTotalColumns,
813+
width: 185,
814+
height: 185,
815+
scrollH: 'auto',
816+
scrollV: 'auto',
817+
stretchH: 'hybrid'
818+
});
819+
wt.draw();
820+
wt.scrollVertical(1);
821+
wt.draw();
822+
823+
expect(wt.wtTable.isLastRowFullyVisible()).toEqual(true);
824+
});
825+
});
826+
827+
describe('isLastColumnFullyVisible', function () {
828+
it('should be false because it is only partially visible', function () {
829+
createDataArray(18, 4);
830+
831+
var wt = new Walkontable({
832+
table: $table[0],
833+
data: getData,
834+
totalRows: getTotalRows,
835+
totalColumns: getTotalColumns,
836+
width: 209,
837+
height: 185,
838+
scrollH: 'auto',
839+
scrollV: 'auto',
840+
stretchH: 'hybrid'
841+
});
842+
wt.draw();
843+
844+
expect(wt.wtTable.isLastColumnFullyVisible()).toEqual(false); //few pixels are obstacled by scrollbar
845+
});
846+
847+
it('should be true because it is fully visible', function () {
848+
createDataArray(18, 4);
849+
850+
var wt = new Walkontable({
851+
table: $table[0],
852+
data: getData,
853+
totalRows: getTotalRows,
854+
totalColumns: getTotalColumns,
855+
width: 205,
856+
height: 185,
857+
scrollH: 'auto',
858+
scrollV: 'auto',
859+
stretchH: 'hybrid'
860+
});
861+
wt.draw();
862+
wt.scrollHorizontal(1);
863+
wt.draw();
864+
865+
expect(wt.wtTable.isLastColumnFullyVisible()).toEqual(true);
866+
});
867+
});
784868
});

0 commit comments

Comments
 (0)