diff options
| -rw-r--r-- | lib/domUtils.js | 14 | ||||
| -rw-r--r-- | vimiumFrontend.js | 4 |
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) { |
