cronixis
cronixis

Reputation: 368

bootstrap-notify.js - How to set maximum displayed message allowed on page?

This is the bootstrap-notify settings that I am using:

var options = {
                    title: title,
                    message: message
                };

                var settings = {
                    element: '#page-wrapper',
                    position: 'fixed',
                    type: type,
                    placement: {
                        from: "top",
                        align: "center"
                    },
                    z_index: 3000,
                    animate: {
                        enter: "animated fadeInDown",
                        exit: "animated fadeOutUp",
                    },
                    template:
                        '<div data-notify="container" role="alert" class="col-xs-11 col-sm-8 alert alert-{0}" style="margin: 15px 0 15px 0">\
                            <button type="button" class="close" data-notify="dismiss">\
                                <span aria-hidden="true">×</span>\
                                <span class="sr-only">Close</span>\
                            </button>\
                            <span data-notify="icon"></span>\
                            <span data-notify="title">{1}</span>\
                            <span data-notify="message" style="padding-right:15px">{2}</span>\
                            <a href="{3}" target="{4}" data-notify="url"></a>\
                        </div>'
                };

                $.notify(options, settings);

I would like to set a maximum number of message displayed on the page at anyone time so that it doesn't flood the page with messages.

Upvotes: 4

Views: 5066

Answers (2)

makif
makif

Reputation: 300

For one message: Give a class to notify div element in template setting and remove it before notify. Like this:

$('div.notification').remove();
$.notify({
    message: "I hope I can help you"
}, {
    type: 'danger',
    template: '<div data-notify="container" class="notification alert alert-{0}" role="alert">' +
        '<img data-notify="icon" class="img-circle pull-left">' +
        '<span data-notify="title">{1}</span>' +
        '<span data-notify="message" style="display: inline-block;">{2}</span>' +
    '</div>'
});

Upvotes: 1

benjamin.wu
benjamin.wu

Reputation: 86

template:
            '<div data-notify="container" role="alert" class="col-xs-11 col-sm-2 alert alert-{0}" style="margin: 15px 0 15px 0; width: 150px;">\
                <button type="button" class="close" data-notify="dismiss" style="top:7px;">\
                    <span aria-hidden="true">×</span>\
                    <span class="sr-only">Close</span>\
                </button>\
                <span data-notify="icon"></span>\
                <span data-notify="title">{1}</span>\
                <span data-notify="message" style="padding-right:15px">{2}</span>\
                <a href="{3}" target="{4}" data-notify="url"></a>\
            </div>'

add width to style and that is ok!

Upvotes: 1

Related Questions