HubSpot / messenger

Growl-style alerts and messages for your app. #hubspot-open-source
http://github.hubspot.com/messenger/
MIT License
4.02k stars 406 forks source link

Simple Requirement #37

Closed udayms closed 11 years ago

udayms commented 11 years ago

How can I display a message, wait for X seconds and then fire a function?

zackbloom commented 11 years ago

You could use a normal timeout:

Messenger().post('test');
setTimeout(myFunction, 5000);

Is your goal to always call a specific function X seconds after any message is shown?

udayms commented 11 years ago

I want something where I can pass to the Messenger call a function that will be fired after the message disappears.

Maybe something like - Messenger().post('Hello', function(){ console.log("function fired after message display!"); });

OR something like - Messenger().post('Hello', fn);

var fn = function(){ console.log("function fired after message display!"); }

OR - Messenger().post({ message: 'hello', callback: fn });

Somehow setTimeout has always seemed like a hack to me :) I would be more comfortable with something callback or event driven.

My two cents :)

zackbloom commented 11 years ago

Sure, you can bind on to the hide event on the message:

var msg = Messenger().post("test")
msg.on('hide', function(){
  // Anything you need
});