Skip to content

Instantly share code, notes, and snippets.

@davidsonsns
Last active July 20, 2017 17:49
Show Gist options
  • Save davidsonsns/60b1c98668f5b56c1416c666b776fad4 to your computer and use it in GitHub Desktop.
Save davidsonsns/60b1c98668f5b56c1416c666b776fad4 to your computer and use it in GitHub Desktop.
HTML 5 Notification in sequence
function NotificationSequence() {
const notifications = []
const showNotifications = (notification) => {
Notification.requestPermission(function (permission) {
const n = new Notification(notification.title, notification)
setTimeout(() => {
n.close()
notifications.pop()
if (notifications.length) {
showNotifications(notifications[notifications.length - 1])
}
}, 5000);
})
}
this.push = function(v) {
notifications.unshift(v)
if (notifications.length === 1) {
showNotifications(notifications[notifications.length - 1])
}
}
this.get = function() {
return notifications;
}
}
@davidsonsns
Copy link
Author

Example utilization

const n = new NotificationSequence();
n.push({
  title: 'the title',
  body: 'the body here'
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment