Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give users the bit of JS that delays the JS until load #11

Open
danjenkins opened this issue Dec 1, 2016 · 3 comments
Open

Give users the bit of JS that delays the JS until load #11

danjenkins opened this issue Dec 1, 2016 · 3 comments

Comments

@danjenkins
Copy link

I always start out with the generator and I always have to fill in the onload functions

I'm guessing this would be useful to other people too

Otherwise you just get "can't add listener to null"

@danjenkins
Copy link
Author

@beaufortfrancois
Copy link
Owner

What would you add exactly?

@danjenkins
Copy link
Author

function ready(fn) {
  if (document.readyState != 'loading'){
    fn();
  } else {
    document.addEventListener('DOMContentLoaded', fn);
  }
}

Based on http://youmightnotneedjquery.com/#ready

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants