From 3c9fa4d68e44fe092f17ad0e8fc1f2c5ad996c1f Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 10 Jul 2014 18:09:46 +0000 Subject: [PATCH] Media Grid: `hasNext` and `hasPrevious` are functions that must be called. Otherwise they are always truthy properties. See #24716. git-svn-id: https://develop.svn.wordpress.org/trunk@29072 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/media-grid.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/js/media-grid.js b/src/wp-includes/js/media-grid.js index de9bb41f92..58e453a2f3 100644 --- a/src/wp-includes/js/media-grid.js +++ b/src/wp-includes/js/media-grid.js @@ -432,8 +432,8 @@ this.on( 'router:render', this.browseRouter, this ); } - this.options.hasPrevious = ( this.options.library.indexOf( this.options.model ) > 0 ) ? true : false; - this.options.hasNext = ( this.options.library.indexOf( this.options.model ) < this.options.library.length - 1 ) ? true : false; + this.options.hasPrevious = this.hasPrevious(); + this.options.hasNext = this.hasNext(); // Initialize modal container view. if ( this.options.modal ) { @@ -545,8 +545,9 @@ * Click handler to switch to the previous media item. */ previousMediaItem: function() { - if ( ! this.options.hasPrevious ) + if ( ! this.hasPrevious() ) { return; + } this.modal.close(); this.trigger( 'edit:attachment:previous', this.model ); }, @@ -555,8 +556,9 @@ * Click handler to switch to the next media item. */ nextMediaItem: function() { - if ( ! this.options.hasNext ) + if ( ! this.hasNext() ) { return; + } this.modal.close(); this.trigger( 'edit:attachment:next', this.model ); }, @@ -588,14 +590,14 @@ } // The right arrow key if ( event.keyCode === 39 ) { - if ( ! this.hasNext ) { + if ( ! this.hasNext() ) { return; } this.nextMediaItem(); } // The left arrow key if ( event.keyCode === 37 ) { - if ( ! this.hasPrevious ) { + if ( ! this.hasPrevious() ) { return; } this.previousMediaItem();