Reputation: 362
I have build a jQuery plugin who needs to be 'closed' before it can be called again, so I need to check if the jQuery plugin is called (active). I know I could save a value with jQuery.data() and simply remove/reset it when the plugin closes but is there another or smarter way?
Upvotes: 3
Views: 1493
Reputation: 23034
Hmmm, interesting case. You can consider using jQuery's queues..
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
I'm not sure whether this helps your case?
Upvotes: 0
Reputation: 57258
if you want to know if the plugin is active use a global variable like so:
$.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;
}
}
Upvotes: 0