diff options
| author | Jez Ng | 2012-02-02 10:11:32 -0500 |
|---|---|---|
| committer | Jez Ng | 2012-02-11 19:01:00 -0500 |
| commit | 82ccce8d0936425ee16c6d432601c5ac781fb385 (patch) | |
| tree | 47c53a37f12167edd9de66b01bc481982c7dccd2 /lib/domUtils.js | |
| parent | a8842428a5a0bddf7b7dcb3d3d5aaaeb4c70a374 (diff) | |
| download | vimium-82ccce8d0936425ee16c6d432601c5ac781fb385.tar.bz2 | |
Set scroll position only after DOM has loaded.
Diffstat (limited to 'lib/domUtils.js')
| -rw-r--r-- | lib/domUtils.js | 14 |
1 files changed, 14 insertions, 0 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 |
