7

The Jquery noty plugin timeout is not working when fed with a list of messages. I get the list of messages from servlet and call noty like this.

<script>
    function callNotification()
    {
        <c:foreach var = "message" items = "${sessionScope.notification}">
             notify('${message}');
        </c:foreach>
    }
    function notify(message)
    {
       noty({
                "text": message,
                "theme": noty_theme_facebook",
                "layout": topRight,
                "information","animateOpen":{"height":"toggle"},
                "information","animateOpen":{"height":"toggle"},
                "speed":500,
                "timeout":5000,
                "closeButton":true,
                "closeOnSelfClick":true,
                "closeOnSelfOver":false,
                "modal":false
          })
    </script>

Ideally this should loop over the messages and print them with a timeout of 5000ms. But this prints all of the messages at once. I further tried to use the javascript native setTimeout function and replaced my callNotification with this.

 function callNotification()
    {
        <c:foreach var = "message" items = "${sessionScope.notification}">
         (function(message){ 
            setTimeout(function(){notify('${message}');},5000)
         }('${message}')
        }}
        </c:foreach>
    }

But this also proved ineffective. Strangely the timeout seems to work fine when I replace "layout":center in notify method. Where am I going wrong. I want the messages to be displayed with the time out of 5 seconds after which the first message gets automatically erased and the next shows up.

Adil Malik
  • 6,279
  • 7
  • 48
  • 77
Rohit Kumar
  • 117
  • 1
  • 2
  • 10

7 Answers7

8

Noty is coded so that if you have buttons in your Noty, it disables the timeout. That doesn't make sense to me, but that's how it is.

This is the culprit (line 62):

60: // If we have button disable closeWith & timeout options
61: this.options.closeWith = [];
62: this.options.timeout = false;

Just remove this.options.timeout = false; and that will keep the timeout working if you have a Noty with buttons.

Gavin
  • 7,544
  • 4
  • 52
  • 72
3

To get this working I changed the following in jquery.noty.js ...

self.$bar.delay(self.options.timeout).promise().done(function () {
                self.close();
            });

to this ...

setTimeout(function () {
                self.close();
            }, self.options.timeout);
2

My answer is for v2.3.7.

Noty returns a javascript object, hence if you check it on firebug by doing console.dir(n), you will find all the methods and properties of the returned object.

Following will set 3 seconds timeout:

var n = noty({text: 'noty - a jquery notification library!'});
n.setTimeout(3000);
2

Try closeWith with timeout option hope it will work fine

   function generate(type, text) {

                var n = noty({
                    text        : text,
                    type        : type,
                    dismissQueue: true,
                    layout      : 'topRight',
                    closeWith   : ['click','timeout'],
                    theme       : 'relax',
                    maxVisible  : 10,
                    timeout     :7000,

                    animation   : {
                        open  : 'animated bounceInRight',
                        close : 'animated bounceOutRight',
                        easing: 'swing',
                        speed : 500
                    }
                });
Aitazaz Khan
  • 1,609
  • 1
  • 13
  • 35
0

You need to provide this option as a parameter: "buttons: false"

0

You can also achieve this by specifying this option during initialization

buttons: false

More here http://ned.im/noty/#/about

Flexo
  • 87,323
  • 22
  • 191
  • 272
Panda
  • 63
  • 5
0

In your jquery.noty.packaged.js create a global variable named "master_self" file.Now in line 103 or 104 there must be a line var self = this; just below that line assign master_self as self master_self = self;

Now create a function in the same file:

function autoTimeout(timeoutVal){
    setTimeout(function(){
                            var self = master_self;
                            if (typeof self.options.animation.close == 'string') {
                                self.$bar.addClass(self.options.animation.close).one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() {
                                    if(self.options.callback.afterClose) self.options.callback.afterClose.apply(self);
                                    console.log(self);
                                    self.closeCleanUp();
                                });
                            } else {
                                self.$bar.clearQueue().stop().animate(
                                    self.options.animation.close,
                                    self.options.animation.speed,
                                    self.options.animation.easing,
                                    function() {
                                        if(self.options.callback.afterClose) self.options.callback.afterClose.apply(self);
                                    })
                                    .promise().done(function() {
                                        self.closeCleanUp();
                                    });
                            }
                         },timeoutVal);
}

Now call this function explicitly on the notification which you want to timeout in this way just after calling the noty object for creating notification:

autoTimeout(1000);
iniravpatel
  • 1,553
  • 16
  • 24