From 18fb3e9015a99924946a9ad47641dab49292835a Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Wed, 20 Aug 2014 19:28:11 +0000 Subject: [PATCH] Cleanup after [29220]: * `media.view.Attachment` should not reach outside itself with global jQuery selectors * `media.view.Attachment.Details` will re-render when `media.view.Attachment`'s single status changes. Add a `ready` callback to apply initial input focus See #23560. git-svn-id: https://develop.svn.wordpress.org/trunk@29556 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/media-views.js | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/src/wp-includes/js/media-views.js b/src/wp-includes/js/media-views.js index 8c14fe0acf..76d6dc52ee 100644 --- a/src/wp-includes/js/media-views.js +++ b/src/wp-includes/js/media-views.js @@ -4893,12 +4893,6 @@ selection.add( models ); selection.single( model ); - - // When selecting attachments, focus should be transferred to the right details panel - if ( ! isTouchDevice ) { - $('.attachment-details input').first().focus(); - } - return; // If the `method` is set to `toggle`, just flip the selection @@ -4906,12 +4900,6 @@ } else if ( 'toggle' === method ) { selection[ this.selected() ? 'remove' : 'add' ]( model ); selection.single( model ); - - if ( ! isTouchDevice && this.selected() ) { - // When selecting an attachment, focus should be transferred to the right details panel - $('.attachment-details input').first().focus(); - } - return; } else if ( 'add' === method ) { selection.add( model ); @@ -4974,13 +4962,7 @@ } // Add 'selected' class to model, set aria-checked to true and make the checkbox tabable. - this.$el.addClass( 'selected' ).attr( 'aria-checked', true ) - .find( '.check' ).attr( 'tabindex', '0' ); - - // When selecting an attachment, focus should be transferred to the right details panel. - if ( ! isTouchDevice ) { - $('.attachment-details input').first().focus(); - } + this.$el.addClass( 'selected' ).attr( 'aria-checked', true ).find( '.check' ).attr( 'tabindex', '0' ); }, /** * @param {Backbone.Model} model @@ -6502,11 +6484,19 @@ this.options = _.defaults( this.options, { rerenderOnModelChange: false }); + + this.on( 'ready', this.initialFocus ); /** * call 'initialize' directly on the parent class */ media.view.Attachment.prototype.initialize.apply( this, arguments ); }, + + initialFocus: function() { + if ( ! isTouchDevice ) { + this.$( ':input' ).eq( 0 ).focus(); + } + }, /** * @param {Object} event */