Dan Parker
Dan Parker

Reputation: 843

Replacing javascript Alerts with Kendo Notification

I'm wondering the best way to replace all my alert('error...') with kendo notifications, the easiest way.

so I can just do

myKendoAlert('my message', info); and I don't have to add a specific html div or span holder to each page.

currently I'm doing something like:

var popupNotification = $("#popupNotification").kendoNotification({
    position: {
        pinned: false,
        bottom: 100,
        right: 100
    },
    templates: [{
        type: "info",
        template: "<div>Test : #= myMessage #</div>"
    }],
    autoHideAfter: 0,
    stacking: "up"

}).data("kendoNotification");

But I need to put this in a common javascript file with a function I can use on all pages. with, info, error, success... (and clear on success)

Upvotes: 1

Views: 3324

Answers (2)

Parin Parikh
Parin Parikh

Reputation: 44

var notificationWidget = null;

function alert(message, type) {
    if (notificationWidget == null) {

    notificationWidget = $("#notification").kendoNotification({
        button: true,
        hideOnClick: true,
        //appendTo: "#container",
        //width: "30em",

        position: {
            pinned: true,
            top: "5em",
            left: null,
            bottom: null,
            right: 10
        },
        autoHideAfter: 8000
    }).data("kendoNotification");
}

    notificationWidget.show(message, type);
}

Upvotes: 1

Robin Giltner
Robin Giltner

Reputation: 3055

Just add a method to your namespace to do just that, and call it from where ever you need to.

Here is a sample that is similar to what I do, putting two methods, showSuccess and showError on the top level of the javascript namespace for my application (I use toastr, but same approach).

I have my app object on the window object, with two methods I can call from wherever.

http://jsbin.com/novena/1/edit

Upvotes: 1

Related Questions