aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-01-03 19:56:38 -0800
committerAlon Zakai <alonzakai@gmail.com>2014-01-03 19:56:38 -0800
commit19466211d035482e7b511f239ab0c8cd3a506a47 (patch)
treeb66d89ba92e4482ed5093ea046c33e617efe10c1
parentc0beb1cff3a831039884f90ef2978e2345610992 (diff)
parentfe66c89196353e99712993a362c31b1914d07cb2 (diff)
Merge pull request #1941 from onnoj/incoming
Added workaround for window.scrollX compat.
-rw-r--r--src/library_browser.js19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/library_browser.js b/src/library_browser.js
index b368c6ac..e0f53052 100644
--- a/src/library_browser.js
+++ b/src/library_browser.js
@@ -478,19 +478,30 @@ mergeInto(LibraryManager.library, {
// in the coordinates.
var rect = Module["canvas"].getBoundingClientRect();
var x, y;
+
+ // Neither .scrollX or .pageXOffset are defined in a spec, but
+ // we prefer .scrollX because it is currently in a spec draft.
+ // (see: http://www.w3.org/TR/2013/WD-cssom-view-20131217/)
+ var scrollX = ((typeof window.scrollX !== 'undefined') ? window.scrollX : window.pageXOffset);
+ var scrollY = ((typeof window.scrollY !== 'undefined') ? window.scrollY : window.pageYOffset);
+#if ASSERTIONS
+ // If this assert lands, it's likely because the browser doesn't support scrollX or pageXOffset
+ // and we have no viable fallback.
+ assert((typeof scrollX !== 'undefined') && (typeof scrollY !== 'undefined'), 'Unable to retrieve scroll position, mouse positions likely broken.');
+#endif
if (event.type == 'touchstart' ||
event.type == 'touchend' ||
event.type == 'touchmove') {
var t = event.touches.item(0);
if (t) {
- x = t.pageX - (window.scrollX + rect.left);
- y = t.pageY - (window.scrollY + rect.top);
+ x = t.pageX - (scrollX + rect.left);
+ y = t.pageY - (scrollY + rect.top);
} else {
return;
}
} else {
- x = event.pageX - (window.scrollX + rect.left);
- y = event.pageY - (window.scrollY + rect.top);
+ x = event.pageX - (scrollX + rect.left);
+ y = event.pageY - (scrollY + rect.top);
}
// the canvas might be CSS-scaled compared to its backbuffer;