[wp-trac] [WordPress Trac] #24859: Media Library does not have a loading indicator

WordPress Trac noreply at wordpress.org
Wed Sep 25 14:52:13 UTC 2013


#24859: Media Library does not have a loading indicator
-------------------------+------------------
 Reporter:  jeffr0       |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  3.7
Component:  Media        |     Version:  3.5
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |
-------------------------+------------------

Comment (by kadamwhite):

 +1 on showing while the library is initially loading.

 From a code perspective, it is strange to me that we're augmenting `ajax`
 with Backbone.Events, and not just extending the `media` object.
 `media.on('ajax', ... )` feels more obvious and useful than
 `media.ajax.on('ajax', ...)` -- Less repetition of "ajax," more obvious
 path to leverage `media` for other communication purposes.

 When we implemented this type of functionality in the app I'm working on
 currently, we handled the spinner in this fashion (pseudo-code ahead):

 {{{#!javascript
 // media-views.js
 media.view.AttachmentsBrowser = media.View.extend({
     // ...
     spinnerCount: 0,
     initialize: function() {
         // ...
         media.on('ajax:start', function() {
             this.spinnerCount += 1;
             this.updateSpinner();
         });
         media.on('ajax:end', function() {
             this.spinnerCount -= 1;
             this.updateSpinner();
         });
         // ...
     },
     updateSpinner: function( result, options ) {
         var spinnerActions = ['query-attachments'];

         if ( _.indexOf(spinnerActions, options.data.action) < 0 )
                 return;

         if ( 0 < this.spinnerCount ) {
             this.toolbar.get('spinner').show();
         } else {
             this.toolbar.get('spinner').hide();
         }
     }
     // ...
 });

 // media-models.js
     ajax: function( action, options ) {
         var media = this,
             result;

         if ( _.isObject( action ) ) {
             options = action;
         }

         result = wp.ajax.send.apply( this, arguments );

         media.trigger('ajax:start');

         result.done(function() {
             // View doesn't have to care about interacting with the
 request
             media.trigger('ajax:end');
         });

         return result;
     }
 }}}

--
Ticket URL: <http://core.trac.wordpress.org/ticket/24859#comment:9>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list