Make WordPress Core

Changeset 29312


Ignore:
Timestamp:
07/27/2014 05:57:25 PM (10 years ago)
Author:
ocean90
Message:

Media Grid: Improve lazy loading.

props kovshenin.
see #24716.

Location:
trunk/src/wp-includes/js
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/media-grid.js

    r29306 r29312  
    207207                suggestedHeight: state.get('suggestedHeight'),
    208208
    209                 AttachmentView: state.get('AttachmentView')
     209                AttachmentView: state.get('AttachmentView'),
     210
     211                scrollElement: document
    210212            });
    211213        }
  • trunk/src/wp-includes/js/media-views.js

    r29299 r29312  
    52025202        cssTemplate: media.template('attachments-css'),
    52035203
    5204         events: {
    5205             'scroll': 'scroll'
    5206         },
    5207 
    52085204        initialize: function() {
    52095205            this.el.id = _.uniqueId('__attachments-view-');
     
    52365232            this.collection.on( 'reset', this.render, this );
    52375233
    5238             // Throttle the scroll handler.
     5234            // Throttle the scroll handler and bind this.
    52395235            this.scroll = _.chain( this.scroll ).bind( this ).throttle( this.options.refreshSensitivity ).value();
     5236
     5237            this.options.scrollElement = this.options.scrollElement || this.el;
     5238            $( this.options.scrollElement ).on( 'scroll', this.scroll );
    52405239
    52415240            this.initSortable();
     
    54075406        scroll: function() {
    54085407            var view = this,
     5408                el = this.options.scrollElement,
     5409                scrollTop = el.scrollTop,
    54095410                toolbar;
    54105411
    5411             if ( ! this.$el.is(':visible') || ! this.collection.hasMore() ) {
     5412            // The scroll event occurs on the document, but the element
     5413            // that should be checked is the document body.
     5414            if ( el == document ) {
     5415                el = document.body;
     5416                scrollTop = $(document).scrollTop();
     5417            }
     5418
     5419            if ( ! $(el).is(':visible') || ! this.collection.hasMore() ) {
    54125420                return;
    54135421            }
     
    54165424
    54175425            // Show the spinner only if we are close to the bottom.
    5418             if ( this.el.scrollHeight - ( this.el.scrollTop + this.el.clientHeight ) < this.el.clientHeight / 3 ) {
     5426            if ( el.scrollHeight - ( scrollTop + el.clientHeight ) < el.clientHeight / 3 ) {
    54195427                toolbar.get('spinner').show();
    54205428            }
    54215429
    5422             if ( this.el.scrollHeight < this.el.scrollTop + ( this.el.clientHeight * this.options.refreshThreshold ) ) {
     5430            if ( el.scrollHeight < scrollTop + ( el.clientHeight * this.options.refreshThreshold ) ) {
    54235431                this.collection.more().done(function() {
    54245432                    view.scroll();
     
    58605868                model:                this.model,
    58615869                sortable:             this.options.sortable,
     5870                scrollElement:        this.options.scrollElement,
    58625871
    58635872                // The single `Attachment` view to be used in the `Attachments` view.
Note: See TracChangeset for help on using the changeset viewer.