Apostolos
Apostolos

Reputation: 8101

Pnotify and fullcalendar

I am using pnotify and loading callback function to show a notification when the fullcalendar plugin has loaded all events.

loading:function(isLoading, view){

    if (isLoading === false){
        new PNotify({
            title:"Finished loading events",
            type:'success',
            delay: 1000
        });

My problems is that when ever I move to different dates it calls loading again so I am left with so many notifications shown on my screen that it becomes very unusable. How can I bypass this? Is there a way to check if a notification is active and just change the text and title of it?

Upvotes: 0

Views: 267

Answers (2)

Carvo
Carvo

Reputation: 51

You can just store it in a variable, do your necessary code (like nullable/undefined checks, etc) and call "update()" (here: http://sciactive.com/pnotify/ - for example, find for 'Click Notice' and see the source)

var p = new PNotify({
    title: 'Some title',
    text: 'Check me out! I\'m a error.',
    type: 'error',
    icon: 'fa fa-times-circle'          
});
// ... code ...
p.update({title: 'My new title'});

Upvotes: 0

Luís Cruz
Luís Cruz

Reputation: 14970

You can add that logic based on the template you're using (check the template docs).

Your code would be something like

loading:function(isLoading, view){
    var exists = false;
    $(".ui-pnotify-title").each(function() {
        if ($(this).html() == 'Finished loading events')
            exists = true;
    });

    if (!exists) {
        new PNotify({
            title:"Finished loading events",
            type:'success',
            delay: 1000
        });
    }
}

It would be better if you could use a specific id or class to detect if the notification is already shown, but this works.

Take a look at the working jsfiddle.

Upvotes: 0

Related Questions