Search code examples
javascriptjquerynotificationsjgrowlnoty

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.


Solution

  • 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. :)