decrease mouse handlers count and every-time class checking during mousemove

This commit is contained in:
Alexandr Subbotin 2014-10-22 15:40:12 +04:00 committed by Hyunje Alex Jun
parent 3821413589
commit 05b20f45ef

View File

@ -250,30 +250,28 @@
var currentLeft; var currentLeft;
var currentPageX; var currentPageX;
var inScrolling = false; var mouseMoveHandler = function (e) {
$scrollbarX.bind(eventClass('mousedown'), function (e) {
currentPageX = e.pageX;
currentLeft = $scrollbarX.position().left;
$scrollbarXRail.addClass('in-scrolling');
inScrolling = true;
e.stopPropagation();
e.preventDefault();
});
$(ownerDocument).bind(eventClass('mousemove'), function (e) {
if (inScrolling) {
updateScrollLeft(currentLeft, e.pageX - currentPageX); updateScrollLeft(currentLeft, e.pageX - currentPageX);
updateGeometry(); updateGeometry();
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
} };
});
$(ownerDocument).bind(eventClass('mouseup'), function (e) { var mouseUpHandler = function (e) {
if (inScrolling) {
inScrolling = false;
$scrollbarXRail.removeClass('in-scrolling'); $scrollbarXRail.removeClass('in-scrolling');
} $(ownerDocument).unbind(eventClass('mousemove'), mouseMoveHandler);
};
$scrollbarX.bind(eventClass('mousedown'), function (e) {
currentPageX = e.pageX;
currentLeft = $scrollbarX.position().left;
$scrollbarXRail.addClass('in-scrolling');
$(ownerDocument).bind(eventClass('mousemove'), mouseMoveHandler);
$(ownerDocument).one(eventClass('mouseup'), mouseUpHandler);
e.stopPropagation();
e.preventDefault();
}); });
currentLeft = currentLeft =
@ -284,30 +282,28 @@
var currentTop; var currentTop;
var currentPageY; var currentPageY;
var inScrolling = false; var mouseMoveHandler = function (e) {
$scrollbarY.bind(eventClass('mousedown'), function (e) {
currentPageY = e.pageY;
currentTop = $scrollbarY.position().top;
inScrolling = true;
$scrollbarYRail.addClass('in-scrolling');
e.stopPropagation();
e.preventDefault();
});
$(ownerDocument).bind(eventClass('mousemove'), function (e) {
if (inScrolling) {
updateScrollTop(currentTop, e.pageY - currentPageY); updateScrollTop(currentTop, e.pageY - currentPageY);
updateGeometry(); updateGeometry();
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
} };
});
$(ownerDocument).bind(eventClass('mouseup'), function (e) { var mouseUpHandler = function (e) {
if (inScrolling) {
inScrolling = false;
$scrollbarYRail.removeClass('in-scrolling'); $scrollbarYRail.removeClass('in-scrolling');
} $(ownerDocument).unbind(eventClass('mousemove'), mouseMoveHandler);
};
$scrollbarY.bind(eventClass('mousedown'), function (e) {
currentPageY = e.pageY;
currentTop = $scrollbarY.position().top;
$scrollbarYRail.addClass('in-scrolling');
$(ownerDocument).bind(eventClass('mousemove'), mouseMoveHandler);
$(ownerDocument).one(eventClass('mouseup'), mouseUpHandler);
e.stopPropagation();
e.preventDefault();
}); });
currentTop = currentTop =