JQuery: check if jquery plugin is already called

I created a jQuery plugin that needs to be “closed” before it can be called again, so I need to check if the jQuery plugin is called (active). I know that I can save the value using jQuery.data () and just delete / reset it when the plugin closes, but is there any other or smarter way?

+3
source share
3 answers
typeof $.fn.my_func !== "undefined"
+1
source

if you want to know if the plugin is active, use the global variable as follows:

$.fn.my_func(params)
{
    if(window.my_func_active)
    {
        console.log('Cannot run plugin');
        return;
    }

    window.my_func_active = true;
    //blah
    endme = function()
    {
       //shutdown here
       delete window.my_func_active;
    }
}
0
source

, . jQuery.

var n = $('someSpecialDiv').queue("specialQue");

$('someSpecialDiv').queue("specialQue", function () {
    $.myPlugin();  //Always run your plugin(only this plugin) after queueing to this queue
  });

  alert(n.length); //This would tell you if your function is in execution if > 0

, ?

0

Source: https://habr.com/ru/post/1764556/


All Articles