From 47036da32ba4f998ca4ca7b6d09f2ba4596c2ab2 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Tue, 21 Jul 2015 15:09:28 +0000 Subject: [PATCH] Revert [32466], I will pick this up in 4.4. See #32466. git-svn-id: https://develop.svn.wordpress.org/trunk@33342 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/media-grid.js | 60 +++++-------------- src/wp-includes/js/media/routers/manage.js | 37 +++--------- .../js/media/views/frame/manage.js | 23 ++----- 3 files changed, 28 insertions(+), 92 deletions(-) diff --git a/src/wp-includes/js/media-grid.js b/src/wp-includes/js/media-grid.js index 71780c2fe9..01db38bad5 100644 --- a/src/wp-includes/js/media-grid.js +++ b/src/wp-includes/js/media-grid.js @@ -49,29 +49,9 @@ media.view.DeleteSelectedPermanentlyButton = require( './views/button/delete-sel * @augments Backbone.Router */ var Router = Backbone.Router.extend({ - initialize: function ( options ) { - this.controller = options.controller; - this.library = options.library; - this.on( 'route', this.checkRoute ); - }, - routes: { 'upload.php?item=:slug': 'showItem', - 'upload.php?search=:query': 'search', - 'upload.php': 'defaultRoute' - }, - - checkRoute: function ( event ) { - if ( 'defaultRoute' !== event ) { - this.modal = true; - } - }, - - defaultRoute: function () { - if ( this.modal ) { - wp.media.frame.close(); - this.modal = false; - } + 'upload.php?search=:query': 'search' }, // Map routes against the page URL @@ -86,18 +66,19 @@ var Router = Backbone.Router.extend({ // Show the modal with a specific item showItem: function( query ) { - var frame = this.controller, + var media = wp.media, + library = media.frame.state().get('library'), item; // Trigger the media frame to open the correct item - item = this.library.findWhere( { id: parseInt( query, 10 ) } ); + item = library.findWhere( { id: parseInt( query, 10 ) } ); if ( item ) { - frame.trigger( 'edit:attachment', item ); + media.frame.trigger( 'edit:attachment', item ); } else { - item = wp.media.attachment( query ); - frame.listenTo( item, 'change', function( model ) { - frame.stopListening( item ); - frame.trigger( 'edit:attachment', model ); + item = media.attachment( query ); + media.frame.listenTo( item, 'change', function( model ) { + media.frame.stopListening( item ); + media.frame.trigger( 'edit:attachment', model ); } ); item.fetch(); } @@ -664,36 +645,25 @@ Manage = MediaFrame.extend({ } }).render(); this.uploader.ready(); - this.$body.append( this.uploader.el ); + $('body').append( this.uploader.el ); this.options.uploader = false; } + this.gridRouter = new wp.media.view.MediaFrame.Manage.Router(); + // Call 'initialize' directly on the parent class. MediaFrame.prototype.initialize.apply( this, arguments ); // Append the frame view directly the supplied container. this.$el.appendTo( this.options.container ); - this.setLibrary( this.options ); - this.setRouter(); this.createStates(); this.bindRegionModeHandlers(); this.render(); this.bindSearchHandler(); }, - setLibrary: function ( options ) { - this.library = wp.media.query( options.library ); - }, - - setRouter: function () { - this.gridRouter = new wp.media.view.MediaFrame.Manage.Router({ - controller: this, - library: this.library - }); - }, - bindSearchHandler: function() { var search = this.$( '#media-search-input' ), currentSearch = this.options.container.data( 'search' ), @@ -712,9 +682,7 @@ Manage = MediaFrame.extend({ // Update the URL when entering search string (at most once per second) search.on( 'input', _.bind( input, this ) ); - if ( currentSearch ) { - searchView.val( currentSearch ).trigger( 'input' ); - } + searchView.val( currentSearch ).trigger( 'input' ); this.gridRouter.on( 'route:search', function () { var href = window.location.href; @@ -741,7 +709,7 @@ Manage = MediaFrame.extend({ // Add the default states. this.states.add([ new Library({ - library: this.library, + library: wp.media.query( options.library ), multiple: options.multiple, title: options.title, content: 'browse', diff --git a/src/wp-includes/js/media/routers/manage.js b/src/wp-includes/js/media/routers/manage.js index 70e5bf8fc5..73959699b1 100644 --- a/src/wp-includes/js/media/routers/manage.js +++ b/src/wp-includes/js/media/routers/manage.js @@ -7,29 +7,9 @@ * @augments Backbone.Router */ var Router = Backbone.Router.extend({ - initialize: function ( options ) { - this.controller = options.controller; - this.library = options.library; - this.on( 'route', this.checkRoute ); - }, - routes: { 'upload.php?item=:slug': 'showItem', - 'upload.php?search=:query': 'search', - 'upload.php': 'defaultRoute' - }, - - checkRoute: function ( event ) { - if ( 'defaultRoute' !== event ) { - this.modal = true; - } - }, - - defaultRoute: function () { - if ( this.modal ) { - wp.media.frame.close(); - this.modal = false; - } + 'upload.php?search=:query': 'search' }, // Map routes against the page URL @@ -44,18 +24,19 @@ var Router = Backbone.Router.extend({ // Show the modal with a specific item showItem: function( query ) { - var frame = this.controller, + var media = wp.media, + library = media.frame.state().get('library'), item; // Trigger the media frame to open the correct item - item = this.library.findWhere( { id: parseInt( query, 10 ) } ); + item = library.findWhere( { id: parseInt( query, 10 ) } ); if ( item ) { - frame.trigger( 'edit:attachment', item ); + media.frame.trigger( 'edit:attachment', item ); } else { - item = wp.media.attachment( query ); - frame.listenTo( item, 'change', function( model ) { - frame.stopListening( item ); - frame.trigger( 'edit:attachment', model ); + item = media.attachment( query ); + media.frame.listenTo( item, 'change', function( model ) { + media.frame.stopListening( item ); + media.frame.trigger( 'edit:attachment', model ); } ); item.fetch(); } diff --git a/src/wp-includes/js/media/views/frame/manage.js b/src/wp-includes/js/media/views/frame/manage.js index 7d0a2b96b2..46d758b64e 100644 --- a/src/wp-includes/js/media/views/frame/manage.js +++ b/src/wp-includes/js/media/views/frame/manage.js @@ -60,36 +60,25 @@ Manage = MediaFrame.extend({ } }).render(); this.uploader.ready(); - this.$body.append( this.uploader.el ); + $('body').append( this.uploader.el ); this.options.uploader = false; } + this.gridRouter = new wp.media.view.MediaFrame.Manage.Router(); + // Call 'initialize' directly on the parent class. MediaFrame.prototype.initialize.apply( this, arguments ); // Append the frame view directly the supplied container. this.$el.appendTo( this.options.container ); - this.setLibrary( this.options ); - this.setRouter(); this.createStates(); this.bindRegionModeHandlers(); this.render(); this.bindSearchHandler(); }, - setLibrary: function ( options ) { - this.library = wp.media.query( options.library ); - }, - - setRouter: function () { - this.gridRouter = new wp.media.view.MediaFrame.Manage.Router({ - controller: this, - library: this.library - }); - }, - bindSearchHandler: function() { var search = this.$( '#media-search-input' ), currentSearch = this.options.container.data( 'search' ), @@ -108,9 +97,7 @@ Manage = MediaFrame.extend({ // Update the URL when entering search string (at most once per second) search.on( 'input', _.bind( input, this ) ); - if ( currentSearch ) { - searchView.val( currentSearch ).trigger( 'input' ); - } + searchView.val( currentSearch ).trigger( 'input' ); this.gridRouter.on( 'route:search', function () { var href = window.location.href; @@ -137,7 +124,7 @@ Manage = MediaFrame.extend({ // Add the default states. this.states.add([ new Library({ - library: this.library, + library: wp.media.query( options.library ), multiple: options.multiple, title: options.title, content: 'browse',