src/angular-autodisable.js
/**
     * Returns a new instance that can handle the promises returned by the callbacks.
     * It will disable the given element when the first promise is triggered. And will
     * re-enable the element, when the last promise is finished.
     *
     * @param  {Element} elementToDisable     DOM element that should be enabled and disabled.
     * @param  {String} eventName             Name of the event ('click' or 'submit')
     * @param  {String|Boolean} loadingClass  Class(es) to toggle to the element or false not desired.
     * @param  {Array} callbacks              Array of callback functions to trigger.
     * @return {Object}                       Object that handles the promises.
     */
Returns a new instance that can handle the promises returned by the callbacks.
It will disable the given element when the first promise is triggered. And will
re-enable the element, when the last promise is finished.

@param  {Element} elementToDisable     DOM element that should be enabled and disabled.
@param  {String} eventName             Name of the event ('click' or 'submit')
@param  {String|Boolean} loadingClass  Class(es) to toggle to the element or false not desired.
@param  {Array} callbacks              Array of callback functions to trigger.
@return {Object}                       Object that handles the promises.
Returns a new instance that can handle the promises returned by the callbacks . It will disable the given element when the first promise is triggered . And will re - enable the element when the last promise is finished . @param { Element } elementToDisable DOM element that should be enabled and disabled . @param { String } eventName Name of the event ( ' click ' or ' submit ' ) @param { String|Boolean } loadingClass Class ( es ) to toggle to the element or false not desired . @param { Array } callbacks Array of callback functions to trigger . @return { Object } Object that handles the promises .
function handlerInstance(elementToDisable, eventName, loadingClass, callbacks) {
      var instance = {},
          promisesTriggered = 0;
      instance.eventName = eventName;
      instance.callbacks = callbacks;
      instance.handlePromise = function(promise) {
        if (promisesTriggered === 0) {
          disableElement();
        }
        promisesTriggered++;
        promise
          .then(promiseDone, promiseDone);
      };
      function promiseDone() {
        promisesTriggered--;
        if (promisesTriggered === 0) {
          enableElement();
        }
      }
      function disableElement() {
        elementToDisable.attr(DISABLED, true);
        if (loadingClass) {
          elementToDisable.addClass(loadingClass);
        }
      }
      function enableElement() {
        elementToDisable.attr(DISABLED, false);
        if (loadingClass) {
          elementToDisable.removeClass(loadingClass);
        }
      }
      return instance;
    }
function handlerInstance ( elementToDisable , eventName , loadingClass , callbacks ) { var instance = { } , promisesTriggered = 0 ; instance . eventName = eventName ; instance . callbacks = callbacks ; instance . handlePromise = function ( promise ) { if ( promisesTriggered === 0 ) { disableElement ( ) ; } promisesTriggered ++ ; promise . then ( promiseDone , promiseDone ) ; } ; function promiseDone ( ) { promisesTriggered -- ; if ( promisesTriggered === 0 ) { enableElement ( ) ; } } function disableElement ( ) { elementToDisable . attr ( DISABLED , true ) ; if ( loadingClass ) { elementToDisable . addClass ( loadingClass ) ; } } function enableElement ( ) { elementToDisable . attr ( DISABLED , false ) ; if ( loadingClass ) { elementToDisable . removeClass ( loadingClass ) ; } } return instance ; }
Returns a new instance that can handle the promises returned by the callbacks.
Returns a new instance that can handle the promises returned by the callbacks .
/**
       * This should be called everytime a callback returns a promise.
       *
       * Disables the element for the first promise. And re-enables it when
       * the last promise is done.
       *
       * @param  {Promise} promise promise returned by a callback.
       */ /**
       * This is called every time a promise is done.
       *
       * Re-enables the element when the last promise is done.
       */ /**
       * Disables the element. It can also add the classes listed by
       * loadingClass.
       */ /**
       * Enables the element. It can also remove the classes listed by
       * loadingClass.
       */