sciactive / pnotify

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

Multiple PNotify Messages #261

Closed sasoriza closed 7 years ago

sasoriza commented 8 years ago

I can not get PNotify to work with multiple notifications. This is my code:

    <script type="text/javascript">
        var pnotifymessage = jQuery('ul.messages'); // This is the content I want to display in a notification
        $j(document).ready(function(){
            $j(pnotifymessage).each(function(){
                var i = '';
                var type = 'info';
                var icon = 'fa fa-info-circle';
                if ($j('ul.messages li').hasClass('error-msg')) {
                    type = 'error';
                    icon = 'fa fa-exclamation-triangle';
                } else if ($j('ul.messages li').hasClass('success-msg')) {
                    type = 'success';
                    icon = 'fa fa-check-circle-o';
                }
                i += $j(this).html();
                $j(function(){
                    var stack_topRight = {"dir1": "down", "dir2": "right", "push": "top"};
                    new PNotify({
                        text: '<ul>' + i + '</ul>',
                        type: type,
                        icon: icon,
                        insert_brs: false,
                        animate_speed: "fast",
                        stack: stack_topRight,
                        buttons: {
                            closer_hover: false,
                            sticker: false
                        },
                        desktop: {
                            desktop: true
                        }
                    });
                });
            });
        });
    </script>

If I replace the entire PNotify function with alert(i); I will get two alert dialogs. With the PNotify version however, the second notification will not show up. What am I doing wrong? Thanks