Last active
July 20, 2017 17:49
-
-
Save davidsonsns/60b1c98668f5b56c1416c666b776fad4 to your computer and use it in GitHub Desktop.
HTML 5 Notification in sequence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example utilization