K
K
kostarus612015-10-19 23:53:51
JavaScript
kostarus61, 2015-10-19 23:53:51

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;
}


Tell me who knows what and where to fix it or am I doing it wrong at all?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kostarus61, 2015-10-20
@kostarus61

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
                  }
               });
            }

Is this variable declaration correct? In fact, this is a global variable, which is not good.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question