Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Noty.js removing oldest notification on new notification

I am using this script http://ned.im/noty/ for showing notifications

    var n = noty({
        text: message,
        type: type,
        dismissQueue: true,
        force: true,
        layout : "bottomLeft",
        theme: 'newTheme',
        maxVisible : 5
    });

So this is the current config, it has queued 5 items. The problem is that I can't figure out how to remove the first notification on showing new one, when a button is clicked. Any ideas are welcome.

like image 699
dev Avatar asked Mar 21 '23 06:03

dev


2 Answers

Okay I figured it out using the noty.js API: http://ned.im/noty/#api

first I defined the top notification

var notyclose_id    = $("#noty_bottomLeft_layout_container>li:first-child>.noty_bar").attr('id');

after that I get the amount of notifications

var noty_list_count = $("#noty_bottomLeft_layout_container li").size();

than I check if this amount is bigger or equal to my notifications setting

    if(noty_list_count >= 5) 
        $.noty.close(notyclose_id);

and if yes I use the api to close it. :)

like image 198
dev Avatar answered Apr 02 '23 03:04

dev


Was looking for this and ended up here; current version for the time being (3.1.0) allows you to use the killer option:

noty({
    text: 'I have just killed it',
    type: 'success',
    killer : true
})

Looks like it "kills" all previous notifications in the queue, making "this one" the only one displayed.

like image 28
Franco Avatar answered Apr 02 '23 02:04

Franco