From 25fc168c95e81697d3ce4b9066c14e18cd579e84 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sat, 24 Jan 2015 14:00:41 -0800 Subject: [PATCH] Fix an issue with dragging the scrollbar handle from a noninitial position Summary: See . Repro steps: - Scroll partway down the page. - Click and drag the scroll handle. Prior to this diff, the handle incorrectly jumps back to the top of the page. This is because we didn't store the handle's original position. (In testing, I always dragged from near the top of the page, and I don't normally drag scrollbars, so I didn't notice this.) Test Plan: Clicking and dragging a partially scrolled handle now works correctly. Reviewers: btrahan, chad Reviewed By: chad Subscribers: epriestley Differential Revision: https://secure.phabricator.com/D11483 --- resources/celerity/map.php | 16 ++++++++-------- webroot/rsrc/externals/javelin/lib/Scrollbar.js | 10 ++++++++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/resources/celerity/map.php b/resources/celerity/map.php index ded01d65bf..0dce05bfcc 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -199,7 +199,7 @@ return array( 'rsrc/externals/javelin/lib/Resource.js' => '44959b73', 'rsrc/externals/javelin/lib/Routable.js' => 'b3e7d692', 'rsrc/externals/javelin/lib/Router.js' => '29274e2b', - 'rsrc/externals/javelin/lib/Scrollbar.js' => 'e8e4c640', + 'rsrc/externals/javelin/lib/Scrollbar.js' => '65a65098', 'rsrc/externals/javelin/lib/URI.js' => '6eff08aa', 'rsrc/externals/javelin/lib/Vector.js' => 'cc1bd0b0', 'rsrc/externals/javelin/lib/WebSocket.js' => '3f840822', @@ -673,7 +673,7 @@ return array( 'javelin-resource' => '44959b73', 'javelin-routable' => 'b3e7d692', 'javelin-router' => '29274e2b', - 'javelin-scrollbar' => 'e8e4c640', + 'javelin-scrollbar' => '65a65098', 'javelin-stratcom' => '8b0ad945', 'javelin-tokenizer' => '7644823e', 'javelin-typeahead' => '70baed2f', @@ -1244,6 +1244,12 @@ return array( 'javelin-dom', 'javelin-fx', ), + '65a65098' => array( + 'javelin-install', + 'javelin-dom', + 'javelin-stratcom', + 'javelin-vector', + ), '6882e80a' => array( 'javelin-dom', ), @@ -1845,12 +1851,6 @@ return array( 'javelin-behavior-device', 'phabricator-keyboard-shortcut', ), - 'e8e4c640' => array( - 'javelin-install', - 'javelin-dom', - 'javelin-stratcom', - 'javelin-vector', - ), 'e9581f08' => array( 'javelin-behavior', 'javelin-stratcom', diff --git a/webroot/rsrc/externals/javelin/lib/Scrollbar.js b/webroot/rsrc/externals/javelin/lib/Scrollbar.js index d02c464ee5..b8e643b484 100644 --- a/webroot/rsrc/externals/javelin/lib/Scrollbar.js +++ b/webroot/rsrc/externals/javelin/lib/Scrollbar.js @@ -127,6 +127,7 @@ JX.install('Scrollbar', { _timeout: null, _dragOrigin: null, + _scrollOrigin: null, /** @@ -181,7 +182,12 @@ JX.install('Scrollbar', { */ _ondrag: function(e) { e.kill(); + + // Store the position where the drag started. this._dragOrigin = JX.$V(e).y; + + // Store the original position of the handle. + this._scrollOrigin = this._viewport.scrollTop; }, @@ -195,9 +201,9 @@ JX.install('Scrollbar', { var offset = (JX.$V(e).y - this._dragOrigin); var ratio = offset / JX.Vector.getDim(this._bar).y; - var target = ratio * JX.Vector.getDim(this._content).y; + var adjust = ratio * JX.Vector.getDim(this._content).y; - this._viewport.scrollTop = target; + this._viewport.scrollTop = this._scrollOrigin + adjust; },