From c84a3d2df0fd2a98f901677044ab5796848460a0 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Sun, 25 Feb 2018 16:40:33 +0000 Subject: [PATCH] Media: grid view - correct placeholder positioning during uploads. Preventing contextually created attachments from being added to the grid collection in Attachments.validator. Remove the previous filtering introduced in [41937] which caused the placement issue. Props lancewillett, Junaidkbr, designsimply, joemcgill. Fixes #42968. git-svn-id: https://develop.svn.wordpress.org/trunk@42739 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/media-models.js | 9 +++++++++ src/wp-includes/js/media-views.js | 15 --------------- src/wp-includes/js/media/controllers/library.js | 15 --------------- src/wp-includes/js/media/models/attachments.js | 9 +++++++++ 4 files changed, 18 insertions(+), 30 deletions(-) diff --git a/src/wp-includes/js/media-models.js b/src/wp-includes/js/media-models.js index af64387257..28caa1553a 100644 --- a/src/wp-includes/js/media-models.js +++ b/src/wp-includes/js/media-models.js @@ -642,6 +642,15 @@ var Attachments = Backbone.Collection.extend(/** @lends wp.media.model.Attachmen * @returns {Boolean} */ validator: function( attachment ) { + + // Filter out contextually created attachments (e.g. headers, logos, etc.). + if ( + ! _.isUndefined( attachment.attributes.context ) && + '' !== attachment.attributes.context + ) { + return false; + } + if ( ! this.validateDestroyed && attachment.destroyed ) { return false; } diff --git a/src/wp-includes/js/media-views.js b/src/wp-includes/js/media-views.js index 5b10a05d5f..bd1798bd4d 100644 --- a/src/wp-includes/js/media-views.js +++ b/src/wp-includes/js/media-views.js @@ -953,9 +953,6 @@ Library = wp.media.controller.State.extend(/** @lends wp.media.controller.Librar }) ); } - this._filterContext(); - this.get('library').on( 'add', this._filterContext, this ); - this.resetDisplays(); }, @@ -1157,18 +1154,6 @@ Library = wp.media.controller.State.extend(/** @lends wp.media.controller.Librar } }, - /** - * Filter out contextually created attachments (e.g. headers, logos, etc.) - * - * @since 4.9.0 - */ - _filterContext: function() { - var library = this.get('library'); - - library.set( library.filter( function( item ) { - return item.get('context') === ''; - } ) ); - } }); // Make selectionSync available on any Media Library state. diff --git a/src/wp-includes/js/media/controllers/library.js b/src/wp-includes/js/media/controllers/library.js index 6f30cbb354..0422572c68 100644 --- a/src/wp-includes/js/media/controllers/library.js +++ b/src/wp-includes/js/media/controllers/library.js @@ -85,9 +85,6 @@ Library = wp.media.controller.State.extend(/** @lends wp.media.controller.Librar }) ); } - this._filterContext(); - this.get('library').on( 'add', this._filterContext, this ); - this.resetDisplays(); }, @@ -289,18 +286,6 @@ Library = wp.media.controller.State.extend(/** @lends wp.media.controller.Librar } }, - /** - * Filter out contextually created attachments (e.g. headers, logos, etc.) - * - * @since 4.9.0 - */ - _filterContext: function() { - var library = this.get('library'); - - library.set( library.filter( function( item ) { - return item.get('context') === ''; - } ) ); - } }); // Make selectionSync available on any Media Library state. diff --git a/src/wp-includes/js/media/models/attachments.js b/src/wp-includes/js/media/models/attachments.js index c76bbbdfac..06510ef9fc 100644 --- a/src/wp-includes/js/media/models/attachments.js +++ b/src/wp-includes/js/media/models/attachments.js @@ -151,6 +151,15 @@ var Attachments = Backbone.Collection.extend(/** @lends wp.media.model.Attachmen * @returns {Boolean} */ validator: function( attachment ) { + + // Filter out contextually created attachments (e.g. headers, logos, etc.). + if ( + ! _.isUndefined( attachment.attributes.context ) && + '' !== attachment.attributes.context + ) { + return false; + } + if ( ! this.validateDestroyed && attachment.destroyed ) { return false; }