diff --git a/js/mexp.js b/js/mexp.js index c8d33fc..e5e2808 100644 --- a/js/mexp.js +++ b/js/mexp.js @@ -147,17 +147,36 @@ media.view.MEXP = view.extend( { + noMorePosts: false, + fetchedSuccess: function( response ) { media.view.MEXP.__super__.fetchedSuccess.apply( this, [response] ); - if ( 'page' in response.meta && 'total_pages' in response.meta ) { + if ( response.meta && 'page' in response.meta && 'total_pages' in response.meta ) { if ( response.meta.page >= response.meta.total_pages ) { + this.noMorePosts = true; jQuery( '#' + this.service.id + '-loadmore' ).attr( 'disabled', true ); } } - } + }, + + /** + * Fix bug in MEXP plugin. + * Pagination disabled attr has no effect other than visual. + * https://github.com/Automattic/media-explorer/pull/67 + */ + paginate : function( event ) { + + if ( this.noMorePosts ) { + return; + } + + media.view.MEXP.__super__.paginate.apply( this, [event] ); + + }, + } );