jQuery callbacks cumulation
<p>I'm building a simple jQuery plugin called magicForm (How ridiculous is this?). Now face to a problem that I think I'm not figuring out properly.</p>

<p>My plugin is supposed to be applied on a container element, that will show each of its inputs one by one as user fills them. That's not the exact purpose of my problem. 
Each time I initialize the container, I declare an event click callback. Let me show an example.</p>

<pre class="lang-js prettyprint-override"><code>(function($){
  var methods = {
    init: function(options){
      return this.each(function(){
        var form, inputs;

        var settings = {
          debug: false
        };
        settings = $.extend(settings, options);
        form = $(this);

        $('a.submit', form).on('click', function(event){
          if (settings.submitCallback) {
            settings.submitCallback.call(form, inputs);
          }
          return false;
        });
      });
    },
    reset: function() {

    }
  }

  $.fn.magicForm = function(method) {
    if ( methods[method] ) {
      return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
    } else if ( typeof method === 'object' || ! method ) {
      return methods.init.apply( this, arguments );
    } else {
      $.error( 'Method ' +  method + ' does not exist.' );
    }
  };
})($);
</code></pre>

<p>I'm focusing on a specific part of this code :</p>

<pre class="lang-js prettyprint-override"><code>$('a.submit', form).on('click', function(event){
    if (settings.submitCallback) {
        settings.submitCallback.call(form, inputs);
    }
    return false;
});
</code></pre>

<p>Because each time the <code>init</code> method is called, that poor callback is registered. </p>

<p>I was experiencing this painfully, when I invoked my plugin on an element nested in a twitter bootstrap 'tab', nested itself in a bootstrap modal :
I was calling <code>init</code> each time the event 'shown' of my bootstrap modal was triggered.</p>

<p>So, this is how I fixed it in my <code>init</code> method :</p>

<pre class="lang-js prettyprint-override"><code>// Prevent callback cumulation
if (!$(this).data('form_initialized')) {
    $('a.submit', form).on('click', function(event){
        if (settings.submitCallback) {
            settings.submitCallback.call(form, inputs);
        }
        return false;
    });
    $(this).data('form_initialized', true);
}
</code></pre>

<p>And I'm far from feeling sure about this.</p>

<p>Thank your for your time ! </p>
