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

Error when trying to trigger notification on load #20

Open
nmsmith22389 opened this issue Apr 9, 2016 · 2 comments
Open

Error when trying to trigger notification on load #20

nmsmith22389 opened this issue Apr 9, 2016 · 2 comments

Comments

@nmsmith22389
Copy link

I appear to be encountering an error when trying to pop a notification on document load. When run in the CodePen it seems to run fine but on my hosting it encounters an error. I'll post links to both so you can see.

CodePen
Hosting

@hoxxep
Copy link
Owner

hoxxep commented Apr 9, 2016

The issue on your site appears to be that

$(document).ready(function () {
  Snarl.addNotification({
    title: 'Issue',
    text: 'Testing, testing...'
  });
});

Is running before Snarl can initialise itself. The reason this usually isn't an issue is because a notification tends to only be created on a button click event, rather than on the same $(document).ready event that you're also listening on.

As a temporary workaround if you need Snarl to launch immediately on the $(document).ready event: wrapping the Snarl.addNotification function in a setTimeout(..., 10) will allow the Snarl initialiser function to be injected into the browser's event queue ahead of the addNotification function 99.9% of the time.

On the other hand, if you're planning to only use Snarl in events which occur after the $(document).ready you should be fine 👍

@nmsmith22389
Copy link
Author

Thank you so much! I figured the ready function would give it enough time but I guess I was wrong. I updated the code to include a timeout and it worked! Thanks!

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

No branches or pull requests

2 participants