Better `getUnboundedScrollPosition` for windows
Instead of using browser sniffing, `getUnboundedScrollPosition` can do better and not have to depend on the `getDocumentScrollElement` module.
Tim Yung committed
Oct 31, 2013 at 15:24 UTC
0dc011c40c5929023e59daafbd94c0d17b0b7d9b
2 files changed
+4
-30
src/vendor/core/dom/getDocumentScrollElement.js
deleted
-27
@@ -1,27 +0,0 @@
1
-/**
2
- * @providesModule getDocumentScrollElement
3
- * @typechecks
4
- */
5
-
6
-"use strict";
7
-
8
-// TODO: Replace this with a UserAgent module.
9
-var isWebkit = navigator.userAgent.indexOf('AppleWebKit') > -1;
10
-
11
-/**
12
- * Gets the element with the document scroll properties such as `scrollLeft` and
13
- * `scrollHeight`. This may differ across different browsers.
14
- *
15
- * NOTE: The return value can be null if the DOM is not yet ready.
16
- *
17
- * @param {?DOMDocument} doc Defaults to current document.
18
- * @return {?DOMElement}
19
- */
20
-function getDocumentScrollElement(doc) {
21
- doc = doc || document;
22
- return !isWebkit && doc.compatMode === 'CSS1Compat' ?
23
- doc.documentElement :
24
- doc.body;
25
-}
26
-
27
-module.exports = getDocumentScrollElement;
src/vendor/core/dom/getUnboundedScrollPosition.js
+4
-3
@@ -5,8 +5,6 @@
5
6
"use strict";
7
8
-var getDocumentScrollElement = require('getDocumentScrollElement');
9
-
8
/**
9
* Gets the scroll position of the supplied element or window.
10
*
@@ -19,7 +17,10 @@ var getDocumentScrollElement = require('getDocumentScrollElement');
17
*/
18
function getUnboundedScrollPosition(scrollable) {
19
if (scrollable === window) {
22
- return getUnboundedScrollPosition(getDocumentScrollElement());
20
+ return {
21
+ x: document.documentElement.scrollLeft || document.body.scrollLeft,
22
+ y: document.documentElement.scrollTop || document.body.scrollTop
23
+ };
24
}
25
return {
26
x: scrollable.scrollLeft,