aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJez Ng2012-02-02 10:11:32 -0500
committerJez Ng2012-02-11 19:01:00 -0500
commit82ccce8d0936425ee16c6d432601c5ac781fb385 (patch)
tree47c53a37f12167edd9de66b01bc481982c7dccd2
parenta8842428a5a0bddf7b7dcb3d3d5aaaeb4c70a374 (diff)
downloadvimium-82ccce8d0936425ee16c6d432601c5ac781fb385.tar.bz2
Set scroll position only after DOM has loaded.
-rw-r--r--lib/domUtils.js14
-rw-r--r--vimiumFrontend.js4
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/domUtils.js b/lib/domUtils.js
index fd182c59..159867d9 100644
--- a/lib/domUtils.js
+++ b/lib/domUtils.js
@@ -1,4 +1,18 @@
var domUtils = {
+ /**
+ * Runs :callback if the DOM has loaded, otherwise runs it on load
+ */
+ documentReady: (function() {
+ var loaded = false;
+ window.addEventListener("DOMContentLoaded", function() { loaded = true; });
+ return function(callback) {
+ if (loaded)
+ callback();
+ else
+ window.addEventListener("DOMContentLoaded", callback);
+ };
+ })(),
+
/*
* Takes an array of XPath selectors, adds the necessary namespaces (currently only XHTML), and applies them
* to the document root. The namespaceResolver in evaluateXPath should be kept in sync with the namespaces
diff --git a/vimiumFrontend.js b/vimiumFrontend.js
index 70bcc718..b26f4dd2 100644
--- a/vimiumFrontend.js
+++ b/vimiumFrontend.js
@@ -170,7 +170,9 @@ function initializePreDomReady() {
});
} else if (port.name == "setScrollPosition") {
port.onMessage.addListener(function(args) {
- if (args.scrollX > 0 || args.scrollY > 0) { window.scrollBy(args.scrollX, args.scrollY); }
+ if (args.scrollX > 0 || args.scrollY > 0) {
+ domUtils.documentReady(function() { window.scrollBy(args.scrollX, args.scrollY); });
+ }
});
} else if (port.name == "returnCurrentTabUrl") {
port.onMessage.addListener(function(args) {