From 7766259fe3f7e101789a2387da221ac0756e2ee5 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Fri, 4 Jan 2013 23:31:52 +0000 Subject: [PATCH] Don't unnecessarily re-render the attachment details view when editing the title and caption. Re-rendering causes issues with tabbing and focus, and is only necessary for other views (such as "Caption this image..." when editing a gallery). Merges [23283] to the 3.5 branch. props koopersmith. fixes #23054. git-svn-id: https://develop.svn.wordpress.org/branches/3.5@23284 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/js/media-views.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/wp-includes/js/media-views.js b/wp-includes/js/media-views.js index 105042004..b1485b9f4 100644 --- a/wp-includes/js/media-views.js +++ b/wp-includes/js/media-views.js @@ -2842,7 +2842,9 @@ initialize: function() { var selection = this.options.selection; - this.model.on( 'change:sizes change:uploading change:caption change:title', this.render, this ); + this.model.on( 'change:sizes change:uploading', this.render, this ); + this.model.on( 'change:title', this._syncTitle, this ); + this.model.on( 'change:caption', this._syncCaption, this ); this.model.on( 'change:percent', this.progress, this ); // Update the selection. @@ -3160,6 +3162,28 @@ } }); + // Ensure settings remain in sync between attachment views. + _.each({ + caption: '_syncCaption', + title: '_syncTitle' + }, function( method, setting ) { + media.view.Attachment.prototype[ method ] = function( model, value ) { + var $setting = this.$('[data-setting="' + setting + '"]'); + + if ( ! $setting.length ) + return this; + + // If the updated value is in sync with the value in the DOM, there + // is no need to re-render. If we're currently editing the value, + // it will automatically be in sync, suppressing the re-render for + // the view we're editing, while updating any others. + if ( value === $setting.find('input, textarea, select, [value]').val() ) + return this; + + return this.render(); + }; + }); + /** * wp.media.view.Attachment.Library */