1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-18 12:52:42 +01:00

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
This commit is contained in:
epriestley 2015-01-24 14:57:12 -08:00
parent 4ceaaf5ea1
commit 6288d8a7d4
2 changed files with 31 additions and 10 deletions

View file

@ -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',

View file

@ -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.