views:

60

answers:

2

Hi all.

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?

A: 

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;
    }
}
RobertPitt
Not really. Its kind of the same solution I suggested with jQuery.data().Is there a way you can check if a plugin is instantiated?
Bruno
Upvoted your question because im stumped and this looks interesting :)
RobertPitt
A: 
typeof $.fn.my_func !== "undefined"
John Strickler
Have you tested that? typeof $.fn.my_func will always be function in my case. I'm NOT interested in if the plugin exists
Bruno
Hmmm... maybe I'm confused by what you mean by 'closed'?
John Strickler
Basically when a plugin runs, he wants to be a flag available so that he can logically decide weather another instance of a function should be able to executed on an element.
RobertPitt