(function(window) {

  var hasLocalStorage;
  var LS_STATE_KEY = "remotestorage:widget:state";
  // states allowed to immediately jump into after a reload.
  var VALID_ENTRY_STATES = {
    initial: true,
    connected: true,
    offline: true
  };

  function stateSetter(widget, state) {
    return function() {
      if (hasLocalStorage) {
        localStorage[LS_STATE_KEY] = state;
      }
      if (widget.view) {
        if (widget.rs.remote) {
          widget.view.setUserAddress(widget.rs.remote.userAddress);
        }
        widget.view.setState(state, arguments);
      } else {
        widget._rememberedState = state;
      }
    };
  }

  function errorsHandler(widget){
    //decided to not store error state
    return function(error){
      if (error instanceof RemoteStorage.DiscoveryError) {
        console.error('discovery failed',  error, '"' + error.message + '"');
        widget.view.setState('initial', [error.message]);
      } else if (error instanceof RemoteStorage.SyncError) {
        widget.view.setState('offline', []);
      } else if (error instanceof RemoteStorage.Unauthorized){
        widget.view.setState('unauthorized');
      } else {
        widget.view.setState('error', [error]);
      }
    };
  }

  function flashFor(evt) {
    if (evt.method === 'GET' && evt.isFolder) {
      return false;
    }
    return true;
  }

  /**
   * Class: RemoteStorage.Widget
   *   the Widget Controler that comunicates with the view
   *   and listens to its remoteStorage instance
   *
   *   While listening to the Events emitted by its remoteStorage
   *   it set's corresponding states of the View.
   *
   *   ready        :  connected
   *   disconnected :  initial
   *   connecting   :  authing
   *   authing      :  authing
   *   wire-busy    :  busy
   *   wire-done    :  connected
   *   error        :  depending on the error initial,offline, unauthorized or error
   **/
  RemoteStorage.Widget = function(remoteStorage) {
    this.requestsToFlashFor = 0;
    // setting event listeners on rs events to put
    // the widget into corresponding states
    this.rs = remoteStorage;
    this.rs.on('ready', stateSetter(this, 'connected'));
    this.rs.on('disconnected', stateSetter(this, 'initial'));
    this.rs.on('connecting', stateSetter(this, 'authing'));
    this.rs.on('authing', stateSetter(this, 'authing'));
    if(this.rs.remote) {
      this.rs.remote.on('wire-busy', function(evt) {
        if(flashFor(evt)) {
          this.requestsToFlashFor++;
          stateSetter(this, 'busy')();
        }
      }.bind(this));
      this.rs.remote.on('wire-done', function(evt) {
        if(flashFor(evt) && this.requestsToFlashFor === 0) {
          stateSetter(this, 'connected')();
        }
      }.bind(this));
    }
    this.rs.on('error', errorsHandler(this) );
    if (hasLocalStorage) {
      var state = localStorage[LS_STATE_KEY];
      if (state && VALID_ENTRY_STATES[state]) {
        this._rememberedState = state;

        if (state === 'connected' && ! remoteStorage.connected) {
          this._rememberedState = 'initial';
        }
      }
    }
  };

  RemoteStorage.Widget.prototype = {

    /**
    *   Method: display(domID)
    *     displays the widget via the view.display method
    *     returns: this
    **/
    display: function(domID) {
      if (! this.view) {
        this.setView(new RemoteStorage.Widget.View(this.rs));
      }
      this.view.display.apply(this.view, arguments);
      return this;
    },

    /**
    *   Method: setView(view)
    *    sets the view and initializes event listeners to
    *    react on widget(widget.view) events
    **/
    setView: function(view) {
      this.view = view;
      this.view.on('connect', function(options) {
        if (typeof(options) === 'string') {
          // options is simply a useraddress
          this.rs.connect(options);
        } else if (options.special) {
          this.rs[options.special].connect(options);
        }
      }.bind(this));
      this.view.on('disconnect', this.rs.disconnect.bind(this.rs));
      if (this.rs.sync) {
        this.view.on('sync', this.rs.sync.bind(this.rs));
      }
      try {
        this.view.on('reset', function(){
          var location = RemoteStorage.Authorize.getLocation();
          this.rs.on('disconnected', location.reload.bind(location));
          this.rs.disconnect();
        }.bind(this));
      } catch(e) {
        if (e.message && e.message.match(/Unknown event/)) {
          // ignored. (the 0.7 widget-view interface didn't have a 'reset' event)
        } else {
          throw e;
        }
      }

      if (this._rememberedState) {
        setTimeout(stateSetter(this, this._rememberedState), 0);
        delete this._rememberedState;
      }
    }
  };
  /**
   *  Method: displayWidget(domID)
   *    same as display
   **/
  RemoteStorage.prototype.displayWidget = function(domID) {
    return this.widget.display(domID);
  };

  RemoteStorage.Widget._rs_init = function(remoteStorage) {
    hasLocalStorage = remoteStorage.localStorageAvailable();
    if (! remoteStorage.widget) {
      remoteStorage.widget = new RemoteStorage.Widget(remoteStorage);
    }
  };

  RemoteStorage.Widget._rs_supported = function(remoteStorage) {
    return typeof(document) !== 'undefined';
  };

})(typeof(window) !== 'undefined' ? window : global);

@@ -1966,29 +1966,28 @@
 rage) %7B%0A    
-this.
+var 
 requestsToFl
@@ -1998,16 +1998,17 @@
 or = 0;%0A
+%0A
     // s
@@ -2359,22 +2359,70 @@
 ing'));%0A
+    this.rs.on('error', errorsHandler(this));%0A%0A
     if
+ 
 (this.rs
@@ -2487,32 +2487,33 @@
 vt) %7B%0A        if
+ 
 (flashFor(evt)) 
@@ -2524,21 +2524,16 @@
         
-this.
 requests
@@ -2608,32 +2608,33 @@
  %7D.bind(this));%0A
+%0A
       this.rs.re
@@ -2680,16 +2680,17 @@
       if
+ 
 (flashFo
@@ -2699,17 +2699,58 @@
 evt)
- && this.
+) %7B%0A          requestsToFlashFor--;%0A          if (
 requ
@@ -2768,17 +2768,18 @@
 For 
-==
+%3C
 = 0) %7B%0A
+  
     
@@ -2814,24 +2814,26 @@
 nected')();%0A
+  
         %7D%0A  
@@ -2822,32 +2822,42 @@
 ();%0A          %7D%0A
+        %7D%0A
       %7D.bind(thi
@@ -2871,54 +2871,8 @@
   %7D%0A
-    this.rs.on('error', errorsHandler(this) );
 %0A   

Make widget stop pulsing after all requests are done