From e25565f4b7ea5071ee756896e72eddd2ccd24942 Mon Sep 17 00:00:00 2001 From: Daryl Koopersmith Date: Tue, 20 Nov 2012 14:04:59 +0000 Subject: [PATCH] Media: Allow all galleries to be sortable. fixes #22488, see #21390. git-svn-id: http://core.svn.wordpress.org/trunk@22713 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/js/media-upload.js | 9 +++++++++ wp-includes/js/media-views.js | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/wp-admin/js/media-upload.js b/wp-admin/js/media-upload.js index c33b7ef223..390c57adb9 100644 --- a/wp-admin/js/media-upload.js +++ b/wp-admin/js/media-upload.js @@ -320,6 +320,15 @@ var tb_position; selection.gallery = attachments.gallery; + // Fetch the query's attachments, and then break ties from the + // query to allow for sorting. + selection.more().done( function() { + // Break ties with the query. + selection.props.set({ query: false }); + selection.unmirror(); + selection.props.unset('orderby'); + }); + return wp.media({ frame: 'post', state: 'gallery-edit', diff --git a/wp-includes/js/media-views.js b/wp-includes/js/media-views.js index 383d6b8e95..54bae65e42 100644 --- a/wp-includes/js/media-views.js +++ b/wp-includes/js/media-views.js @@ -2540,6 +2540,7 @@ this.scroll = _.chain( this.scroll ).bind( this ).throttle( this.options.refreshSensitivity ).value(); this.initSortable(); + this.collection.props.on( 'change:orderby', this.refreshSortable, this ); _.bindAll( this, 'css' ); this.model.on( 'change:edge change:gutter', this.css, this ); @@ -2549,6 +2550,7 @@ }, destroy: function() { + this.collection.props.off( null, null, this ); this.collection.off( 'add remove reset', null, this ); this.model.off( 'change:edge change:gutter', this.css, this ); $(window).off( 'resize.attachments', this._resizeCss ); @@ -2628,6 +2630,14 @@ }, this ); }, + refreshSortable: function() { + if ( ! this.options.sortable || ! $.fn.sortable ) + return; + + // If the `collection` has a `comparator`, disable sorting. + this.$el.sortable( 'option', 'disabled', !! this.collection.comparator ); + }, + render: function() { // If there are no elements, load some. if ( ! this.collection.length ) {