Consume mousewheel event when there's hovered textarea.

Only when it needs to be scrolled.
This commit is contained in:
Hyunje Alex Jun 2015-04-11 02:16:37 +09:00
parent a5aab04264
commit dc7b14d0e1

View File

@ -58,6 +58,27 @@ function bindMouseWheelHandler(element, i) {
return [deltaX, deltaY]; return [deltaX, deltaY];
} }
function shouldBeConsumedByTextarea(deltaX, deltaY) {
var hoveredTextarea = element.querySelector('textarea:hover')
if (hoveredTextarea) {
var maxScrollTop = hoveredTextarea.scrollHeight - hoveredTextarea.clientHeight;
if (maxScrollTop > 0) {
if (!(hoveredTextarea.scrollTop === 0 && deltaY > 0) &&
!(hoveredTextarea.scrollTop === maxScrollTop && deltaY < 0)) {
return true;
}
}
var maxScrollLeft = hoveredTextarea.scrollLeft - hoveredTextarea.clientWidth;
if (maxScrollLeft > 0) {
if (!(hoveredTextarea.scrollLeft === 0 && deltaX < 0) &&
!(hoveredTextarea.scrollLeft === maxScrollLeft && deltaX > 0)) {
return true;
}
}
}
return false;
}
function mousewheelHandler(e) { function mousewheelHandler(e) {
// FIXME: this is a quick fix for the select problem in FF and IE. // FIXME: this is a quick fix for the select problem in FF and IE.
// If there comes an effective way to deal with the problem, // If there comes an effective way to deal with the problem,
@ -71,6 +92,10 @@ function bindMouseWheelHandler(element, i) {
var deltaX = delta[0]; var deltaX = delta[0];
var deltaY = delta[1]; var deltaY = delta[1];
if (shouldBeConsumedByTextarea(deltaX, deltaY)) {
return;
}
shouldPrevent = false; shouldPrevent = false;
if (!i.settings.useBothWheelAxes) { if (!i.settings.useBothWheelAxes) {
// deltaX will only be used for horizontal scrolling and deltaY will // deltaX will only be used for horizontal scrolling and deltaY will