title: How to listen to events from outside my jquery plugin?
body: <p>My plugin takes some time doing something. So I want to listen to when the plugin is done with its task, from outside, so that I can display something.</p>
  
  <p>I want to have something like this - </p>
  
  <pre><code> $('li').filterGroup ({
  
          onInit: function(){
            alert("plugin has started working");
          },
  
          onComplete: function(){
  
            alert("plugin has finished");
          }
      })
  </code></pre>
  
  <p>I tried writing this inside my plugin code - </p>
  
  <pre><code>(function($) {
      // jQuery plugin definition
  
      $.fn.filterGroup = function(config) 
      {
  
          var settings = {
                      //some settings defined here
                          };
  
  
  
  
              var thisDropdown = this; //master  copy
  
          if(config)
          {
              $.extend(settings, config);
          }
  
              /*Tried following changes to make events work*/
              /*Tried following changes to make events work*/
              /*Tried following changes to make events work*/
              //I tried the following – assuming I will be able to listen to an onComplete event from outside
  
          // reference the function from the options passed
              var theFunc = config.onInit;
              var anotherFunc = config.onComplete;
              theFunc.call(); //does not work - gives error "theFunc is not a function"
  
          this.each(function() 
          {      
                      //here my plugin logic is done
              anotherFunc.call(); //this is also not working - "anotherFunc is not a function"
          });
  
          // allow jQuery chaining
          return thisDropdown;
      };
  </code></pre>
  
  <p>But this is not working, I am getting error - </p>
  
  <pre><code>theFunc is not a function
  </code></pre>
  
  <p><em>Note -</em> I checked the PLugins authoring docs and specifically the events section <a href="http://docs.jquery.com/Plugins/Authoring#Events" rel="nofollow noreferrer">http://docs.jquery.com/Plugins/Authoring#Events</a>, but looks like that is for defining public functions which can be called from outside, so not what I am looking for. Where is the original jquery doc for this? I think I just need to follow the docs properly.</p>
  
  <p>Also checked the following questions but not getting -<br>
  <a href="https://stackoverflow.com/questions/1983449/bind-event-to-custom-plugin-function-in-jquery">Bind Event to Custom Plugin Function in jQuery</a><br>
  <a href="https://stackoverflow.com/questions/3930545/custom-event-for-custom-jquery-plugin">Custom Event For Custom JQuery Plugin</a><br>
  <a href="https://stackoverflow.com/questions/4673803/handle-events-in-a-jquery-plugin">Handle events in a jQuery plugin</a></p>
  
  <p><strong>Update</strong>  </p>
  
  <p>Okay, got my mistake, in my actual code I had <code>theFunc.call()</code> and <code>anotherFunc.call()</code> but in the calling part I had only handled <code>onComplete</code>. So, do I need to explicitly write the onInit() part in my plugin call -</p>
  
  <p>This part - </p>
  
  <pre><code>onInit: function(){
                alert("plugin has started working");
              }
  </code></pre>
  
  <p>I mean if events are defined inside plugin, what if I don't want to handle in the outside code?</p>