diff options
Diffstat (limited to 'bin/wiki/ImportarDesdeURL/node_modules/smartquotes/lib/listen.js')
-rw-r--r-- | bin/wiki/ImportarDesdeURL/node_modules/smartquotes/lib/listen.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/bin/wiki/ImportarDesdeURL/node_modules/smartquotes/lib/listen.js b/bin/wiki/ImportarDesdeURL/node_modules/smartquotes/lib/listen.js new file mode 100644 index 00000000..50a0314d --- /dev/null +++ b/bin/wiki/ImportarDesdeURL/node_modules/smartquotes/lib/listen.js @@ -0,0 +1,38 @@ +const element = require('./element'), + string = require('./string'); + +function listen(root) { + const observer = new MutationObserver( mutations => { + mutations.forEach( mutation => { + for(let node of mutation.addedNodes) { + element(node); + } + }); + }); + listen.runOnReady( () => { + observer.observe(root || document.body, { + childList: true, + subtree: true + }); + }); + return observer; +} + +listen.runOnReady = function(run) { + // if called without arguments, run on the entire body after the document has loaded + if (document.readyState !== 'loading') { + // we're already ready + run(); + } else if (document.addEventListener) { + document.addEventListener('DOMContentLoaded', run, false); + } else { + const readyStateCheckInterval = setInterval(() => { + if (document.readyState !== 'loading') { + clearInterval(readyStateCheckInterval); + run(); + } + }, 10); + } +}; + +module.exports = listen; |