From 6288d8a7d4b5eccadc38ae7e42c99024cd1324da Mon Sep 17 00:00:00 2001 From: epriestley Date: Sat, 24 Jan 2015 14:57:12 -0800 Subject: [PATCH] Support scrollbar snapback on Windows Summary: See D11472. I eyeballed the "140" number by screenshotting / measuring in Paint. Test Plan: Made the snapback thing return `true` and got snapback on OSX. Reviewers: chad Reviewed By: chad Subscribers: avivey, epriestley Differential Revision: https://secure.phabricator.com/D11485 --- resources/celerity/map.php | 16 ++++++------ .../rsrc/externals/javelin/lib/Scrollbar.js | 25 +++++++++++++++++-- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/resources/celerity/map.php b/resources/celerity/map.php index 5e3976ecca..92e4668042 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' => 'a89e4fc3', + 'rsrc/externals/javelin/lib/Scrollbar.js' => '8ebeb833', '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' => 'a89e4fc3', + 'javelin-scrollbar' => '8ebeb833', 'javelin-stratcom' => '8b0ad945', 'javelin-tokenizer' => '7644823e', 'javelin-typeahead' => '70baed2f', @@ -1468,6 +1468,12 @@ return array( 'javelin-stratcom', 'javelin-behavior', ), + '8ebeb833' => array( + 'javelin-install', + 'javelin-dom', + 'javelin-stratcom', + 'javelin-vector', + ), '8ef9ab58' => array( 'javelin-behavior', 'javelin-dom', @@ -1550,12 +1556,6 @@ return array( 'javelin-stratcom', 'javelin-dom', ), - 'a89e4fc3' => array( - 'javelin-install', - 'javelin-dom', - 'javelin-stratcom', - 'javelin-vector', - ), 'a8d8459d' => array( 'javelin-behavior', 'javelin-dom', diff --git a/webroot/rsrc/externals/javelin/lib/Scrollbar.js b/webroot/rsrc/externals/javelin/lib/Scrollbar.js index f80c65dd43..b54613c1fb 100644 --- a/webroot/rsrc/externals/javelin/lib/Scrollbar.js +++ b/webroot/rsrc/externals/javelin/lib/Scrollbar.js @@ -188,7 +188,7 @@ JX.install('Scrollbar', { e.kill(); // Store the position where the drag started. - this._dragOrigin = JX.$V(e).y; + this._dragOrigin = JX.$V(e); // Store the original position of the handle. this._scrollOrigin = this._viewport.scrollTop; @@ -203,14 +203,35 @@ JX.install('Scrollbar', { return; } - var offset = (JX.$V(e).y - this._dragOrigin); + var p = JX.$V(e); + var offset = (p.y - this._dragOrigin.y); var ratio = offset / JX.Vector.getDim(this._bar).y; var adjust = ratio * JX.Vector.getDim(this._content).y; + if (this._shouldSnapback()) { + if (Math.abs(p.x - this._dragOrigin.x) > 140) { + adjust = 0; + } + } + this._viewport.scrollTop = this._scrollOrigin + adjust; }, + /** + * Should the scrollbar snap back to the original position if the user + * drags the mouse away to the left or right, perpendicular to the + * scrollbar? + * + * Scrollbars have this behavior on Windows, but not on OSX or Linux. + */ + _shouldSnapback: function() { + // Since this is an OS-specific behavior, detect the OS. We can't + // reasonably use feature detection here. + return (navigator.platform.indexOf('Win') > -1); + }, + + /** * When the user releases the mouse after a drag, stop moving the * viewport.