From 110978e2d3a1e5c0e2aedfefd40f6c785e18c0c8 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Thu, 13 Feb 2014 07:36:01 +0000 Subject: [PATCH] Update media-views and wp.Backbone.View for Backbone 1.1. * Collection set/add/remove/reset methods now return models, not `this`, so they can no longer be chained. * Options passed to Backbone.View's constructor are no longer attached automatically. wp.Backbone.View now does this automatically. See [27170] for Backbone 1.1 itself. props gcorne. fixes #26799. git-svn-id: https://develop.svn.wordpress.org/trunk@27171 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/media-views.js | 12 ++++++++---- src/wp-includes/js/wp-backbone.js | 4 +++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/js/media-views.js b/src/wp-includes/js/media-views.js index 6b912f0453..d32b996c28 100644 --- a/src/wp-includes/js/media-views.js +++ b/src/wp-includes/js/media-views.js @@ -3566,13 +3566,15 @@ models = collection.models.slice( modelIndex, singleIndex + 1 ); } - selection.add( models ).single( model ); + selection.add( models ); + selection.single( model ); return; // If the `method` is set to `toggle`, just flip the selection // status, regardless of whether the model is the single model. } else if ( 'toggle' === method ) { - selection[ this.selected() ? 'remove' : 'add' ]( model ).single( model ); + selection[ this.selected() ? 'remove' : 'add' ]( model ); + selection.single( model ); return; } @@ -3589,7 +3591,8 @@ // If the model is not selected, run the `method` on the // selection. By default, we `reset` the selection, but the // `method` can be set to `add` the model to the selection. - selection[ method ]( model ).single( model ); + selection[ method ]( model ); + selection.single( model ); } }, @@ -3994,7 +3997,8 @@ // Silently shift the model to its new index. collection.remove( model, { silent: true - }).add( model, { + }); + collection.add( model, { silent: true, at: ui.item.index() }); diff --git a/src/wp-includes/js/wp-backbone.js b/src/wp-includes/js/wp-backbone.js index 9e0041d4d0..0db9161faa 100644 --- a/src/wp-includes/js/wp-backbone.js +++ b/src/wp-includes/js/wp-backbone.js @@ -340,10 +340,12 @@ window.wp = window.wp || {}; // The constructor for the `Views` manager. Subviews: wp.Backbone.Subviews, - constructor: function() { + constructor: function( options ) { this.views = new this.Subviews( this, this.views ); this.on( 'ready', this.ready, this ); + this.options = options || {}; + Backbone.View.apply( this, arguments ); },