Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Close the notification after destroy #10

merged 2 commits into from

2 participants


It's interesting to close/hide a desktop notification after destroy it to not be overflowed by them if you create a set of them.


It could be interesting to add a new property called timeout to close it automatically after specified number of seconds. What do you think about?


destroy() is only called when a notification is closed or there is an error, so I'm not sure if calling close again here really makes sense.

If you want to automatically close a notification after it is shown you can use something like:

notifyShow: function () {
    setTimeout(function() {
    }, 3000);

You can also use the tag property to control single / multiple instances of a notification.


Also, I would be open to adding a timeout property that called close for convenience here.

PR's welcome :)


Cool! But the method close is not in the notification prototype. Do you want to add it?


Ah, correct - yes sure open to adding a close method (let's just leave destroy to clearing up after a notification).


Ok. I'm fixing it.


Check this out.


Looks good to me :+1:

I'll check it out locally soon. Would be good to add a JS test for this, but I can maybe do that later if you don't have time.

Thanks for the PR!


Thanks for adding tests! :)

@alexgibson alexgibson merged commit 59707ca into alexgibson:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 0 deletions.
  1. +1 −0 
  2. +11 −0 notify.js
1 
@@ -47,6 +47,7 @@ Optional parameters
* body: (string) - notification message body
* icon: (string) - path for icon to display in notification
* tag: (string) - unique identifier to stop duplicate notifications
+* timeout: (integer) - number of seconds to close the notification automatically
* notifyShow: (function) - callback when notification is shown
* notifyClose: (function) - callback when notification is closed
* notifyClick: (function) - callback when notification is clicked
11 notify.js
@@ -111,6 +111,7 @@ = function () {
+ var that = this;
if (!Notify.isSupported()) {
@@ -122,6 +123,12 @@
'icon' : this.options.icon
+ if (this.options.timeout && !isNaN(this.options.timeout)) {
+ setTimeout(function () {
+ that.myNotify.close();
+ }, this.options.timeout * 1000);
+ }
this.myNotify.addEventListener('show', this, false);
this.myNotify.addEventListener('error', this, false);
this.myNotify.addEventListener('close', this, false);
@@ -161,6 +168,10 @@
this.myNotify.removeEventListener('click', this, false);
+ Notify.prototype.close = function () {
+ this.myNotify.close();
+ };
Notify.prototype.handleEvent = function (e) {
switch (e.type) {
case 'show':
Something went wrong with that request. Please try again.