commit 0b414c91d07bdc140983e08c87653914f6c10366 Author: Luke Childs Date: Mon Jan 16 16:10:17 2017 +0700 Extract domLoaded from Onionite diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..635b656 --- /dev/null +++ b/.gitignore @@ -0,0 +1,72 @@ +## Node + +# Logs +logs +*.log +npm-debug.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules +jspm_packages + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +## OS X + +*.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..1597176 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,6 @@ +language: node_js +node_js: node +script: npm run lint +notifications: + email: + on_success: never diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e2db8f2 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2016 Luke Childs + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e41beb0 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# domloaded + +> Check when the DOM is loaded + +[![Build Status](https://travis-ci.org/lukechilds/domloaded.svg?branch=master)](https://travis-ci.org/lukechilds/domloaded) + +## Install + +```shell +npm install --save domloaded +``` + +## License + +MIT © Luke Childs diff --git a/package.json b/package.json new file mode 100644 index 0000000..b799c74 --- /dev/null +++ b/package.json @@ -0,0 +1,36 @@ +{ + "name": "domloaded", + "version": "0.0.0", + "description": "Check when the DOM is loaded", + "main": "src/index.js", + "scripts": { + "lint": "xo", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "xo": { + "env": "browser" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/lukechilds/domloaded.git" + }, + "keywords": [ + "check", + "dom", + "loaded", + "ready", + "promise", + "async", + "asynchronous" + ], + "author": "Luke Childs (http://lukechilds.co.uk)", + "license": "MIT", + "bugs": { + "url": "https://github.com/lukechilds/domloaded/issues" + }, + "homepage": "https://github.com/lukechilds/domloaded", + "dependencies": {}, + "devDependencies": { + "xo": "^0.17.1" + } +} diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..5929b2c --- /dev/null +++ b/src/index.js @@ -0,0 +1,14 @@ +// Global +const doc = document; + +// Run callback when DOM is loaded +module.exports = cb => { + // Run now if DOM has already loaded + if (['interactive', 'complete'].indexOf(doc.readyState) >= 0) { + cb(); + + // Otherwise wait for DOM + } else { + doc.addEventListener('DOMContentLoaded', cb); + } +};