tags:

views:

31

answers:

4

I want the notify to occur only after the unblock event, however both occur together. I am pretty new to JQuery.

function isSuccess()
            {
                $(function () {
                  setTimeout('unblock()',1000);
                  $.notifyBar({
                    html: "Thank you, your settings were updated!",
                    delay: 2000,
                    animationSpeed: "normal"
                  });

                });

            }
+2  A: 

If you want notifyBar to be executed after unblock, place it after unblock

setTimeout(function() {
    unblock();
    $.notifyBar({
        ...
    });
},1000);
Nikita Rybak
Thanks Nikita, would'nt it delay the notify by 1 sec also since its included in setTimeOut ?
Popo
@Popo Darin has clarified it in his comment
Nikita Rybak
+3  A: 
$(function () {
    setTimeout(function() {
        unblock();
        $.notifyBar({
            html: "Thank you, your settings were updated!",
            delay: 2000,
            animationSpeed: "normal"
        });
    }, 1000);
});
Darin Dimitrov
Thanks Andy, can you tell me why did my code did not worked and yours did. I thought first setTimeout would last for 1 second, then the notify bar would occur but they both occured simultaneously, Popo.
Popo
`setTimeout` doesn't last for 1 second. It waits one second before executing the method without blocking meaning that it will immediately call the `notifyBar` function. One second later the unblock will be called and 2 seconds later the notify bar. With the new code, we wait 1 second, then we unblock and 2 seconds later we show the notification bar.
Darin Dimitrov
Thanks for the explanation, it was very informative =)
Popo
+1  A: 

wrap in another anonymous function

function isSuccess()
{
    $(function () {
        function unblockAndNotify() {
            unblock();
            $.notifyBar({
                html: "Thank you, your settings were updated!",
                delay: 2000,
                animationSpeed: "normal"
            });
        }
        setTimeout(unblockAndNotify,1000);
    });
}

EDIT: I was going to do what Darin did and declare the function inline with the setTimeout, but didn't want to introduce too many new concepts at once.

Luke Schafer
+1  A: 

You need to re-arrange the order of calls.
Either you have to call $.notifyBar() from within unblock() or you are doing something like

setTimeout(function(){
   unblock();
   $.notifyBar({
          html: "Thank you, your settings were updated!",
          delay: 2000,
          animationSpeed: "normal"
   });
}, 1000);
jAndy