Answer the question
In order to leave comments, you need to log in
Text replacement noty plugin?
Goodnight!
I'll start right away with the core of the problem. I'm using Noty's jQuery plugin to display notifications. It has such a function as setText - Text Replacement and setType - Type Replacement. I need to make it so that if I click on one button several times, the plugin does not display notifications with a delay several times, but replaces the text in an already open notification.
I do it like this:
function send(){
var n; // Объявляю переменную для Noty
$.ajax({
type: "POST",
dataType: "json",
......
success: (function(){
return function(data){
if(n){ // Вся проблема здесь как проверить есть ли открытое уведомление или нет?
n.setText(data.message); // Тут текст на который надо заменить в текущем уведомлении
n.setType(data.status); // Тут тип
} else { // Ну и если нету открытого то выводим как обычно
n = noty({
text: data.message,
type: data.status,
.........
callback: {
afterClose: function(){ n=null; }, // По закрытию уведомления обнуляем значение n
}
});
}
};
})()
})
return false;
}
Answer the question
In order to leave comments, you need to log in
In general, I did it as follows, window.n = noty({:
if(typeof(n) !== "undefined"){
n.setText(data.message);
n.setType(data.status);
} else {
window.n = noty({
text: data.message,
type: data.status,
.........
callback: {
afterClose: function(){ delete n; }, // По закрытию уведомления обнуляем значение n
}
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question