sciactive / pnotify

Beautiful JavaScript notifications with Web Notifications support.
https://sciactive.com/pnotify/
Apache License 2.0
3.65k stars 513 forks source link

New Feature: user_hide flag in addition to timer_hide on before/after_close #237

Closed phoebebright closed 6 years ago

phoebebright commented 8 years ago

I want my notifications to all be sticky so the only way to clear them is for the user to close them. This all works with the following settings until I need to refresh the list of notices.

            new PNotify({
                type: type,
                text: d.describe + "\n" + created_text,
                auto_display: unseen,
                hide:false,
                sticker: false,
                closer_hover: false,
                desktop: {

                    desktop: true
                },
                history: {

                    history: true,
                    menu: true
                },
                reference: {
                    ref: d.ref,
                    id: d.id
                },
                before_close: function(notice, timer_hide) {       
                        notice_seen(notice.options.reference.id);
                },
            });

What I would like to do is be able to check if the notice is in the DOM and only add new ones, but I don't see an obvious way of doing that, so I have used a brute force PNotify.removeAll(); and then reloaded everything. However, the removeAll is triggering the before_close so the notices are being marked as seen.

Would it be possible to have an additional user_hide parameter to indicate if the user closed the notice?

phoebebright commented 8 years ago

Solved my other problem re updating with only new notices by adding

addclass: "noticeid_" + d.id,

and then check if it exists:

if ($(".noticeid_"+d.id).length == 0) {
hperrin commented 6 years ago

Cool. I'm glad you found a solution. :)