From f3c673558ab2b9ba302d19163e8112633ae51fa2 Mon Sep 17 00:00:00 2001 From: Daryl Koopersmith Date: Tue, 30 Oct 2012 23:59:57 +0000 Subject: [PATCH] Media JS: Several improvements to the Attachment views. * Bind Attachment details updates to the Attachments initialize method. * Improve Attachment view unbinding. * Re-render Attachment views when titles and captions are updated. see #21390. git-svn-id: http://core.svn.wordpress.org/trunk@22339 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/media-views.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/wp-includes/js/media-views.js b/wp-includes/js/media-views.js index b8b5ea4920..4150c17ef0 100644 --- a/wp-includes/js/media-views.js +++ b/wp-includes/js/media-views.js @@ -1039,18 +1039,25 @@ initialize: function() { this.controller = this.options.controller; - this.model.on( 'change:sizes change:uploading', this.render, this ); + this.model.on( 'change:sizes change:uploading change:caption change:title', this.render, this ); this.model.on( 'change:percent', this.progress, this ); this.model.on( 'add', this.select, this ); this.model.on( 'remove', this.deselect, this ); + // Update the model's details view. + this.model.on( 'selection:single selection:unsingle', this.details, this ); + this.details( this.model, this.controller.state().get('selection') ); + // Prevent default navigation on all links. this.$el.on( 'click', 'a', this.preventDefault ); }, + destroy: function() { + this.model.off( null, null, this ); + }, + render: function() { - var state = this.controller.state(), - attachment = this.model.toJSON(), + var attachment = this.model.toJSON(), options = _.defaults( this.model.toJSON(), { orientation: 'landscape', uploading: false, @@ -1063,7 +1070,7 @@ }); options.buttons = this.buttons; - options.describe = state.get('describe'); + options.describe = this.controller.state().get('describe'); if ( 'image' === options.type ) _.extend( options, this.imageSize() ); @@ -1079,17 +1086,9 @@ if ( this.selected() ) this.select(); - // Update the model's details view. - this.model.on( 'selection:single selection:unsingle', this.details, this ); - this.details( this.model, state.get('selection') ); - return this; }, - destroy: function() { - this.model.off( 'single', this.details, this ); - }, - progress: function() { if ( this.$bar && this.$bar.length ) this.$bar.width( this.model.get('percent') + '%' );