From 5aee14e9a14ffbdf28ee039e20e14c00bc059cd4 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Mon, 18 Aug 2014 02:13:16 +0000 Subject: [PATCH] Media Grid: on page load with `?item=` in the URL, if the model is not in the library: fetch it. Defer the triggering of `edit:attachment` until the model has been fetched. Fixes #29052. Built from https://develop.svn.wordpress.org/trunk@29525 git-svn-id: http://core.svn.wordpress.org/trunk@29301 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/media-grid.js | 17 ++++++++++++----- wp-includes/js/media-grid.min.js | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/wp-includes/js/media-grid.js b/wp-includes/js/media-grid.js index 0cb0654ff2..7324f3bdc8 100644 --- a/wp-includes/js/media-grid.js +++ b/wp-includes/js/media-grid.js @@ -306,10 +306,20 @@ // Show the modal with a specific item showItem: function( query ) { - var library = media.frame.state().get('library'); + var library = media.frame.state().get('library'), item; // Trigger the media frame to open the correct item - media.frame.trigger( 'edit:attachment', library.findWhere( { id: parseInt( query, 10 ) } ) ); + item = library.findWhere( { id: parseInt( query, 10 ) } ); + if ( item ) { + media.frame.trigger( 'edit:attachment', item ); + } else { + item = media.attachment( query ); + media.frame.listenTo( item, 'change', function( model ) { + media.frame.stopListening( item ); + media.frame.trigger( 'edit:attachment', model ); + } ); + item.fetch(); + } } }); @@ -373,9 +383,6 @@ if ( this.options.model ) { this.model = this.options.model; - } else { - // this is a hack - this.model = this.library.at( 0 ); } this.bindHandlers(); diff --git a/wp-includes/js/media-grid.min.js b/wp-includes/js/media-grid.min.js index c59fd99020..26c883a426 100644 --- a/wp-includes/js/media-grid.min.js +++ b/wp-includes/js/media-grid.min.js @@ -1 +1 @@ -!function(a,b,c,d){var e,f=d.media;f.view.l10n?e=f.view.l10n:(e=f.view.l10n="undefined"==typeof _wpMediaViewsL10n?{}:_wpMediaViewsL10n,delete e.settings),f.controller.EditAttachmentMetadata=f.controller.State.extend({defaults:{id:"edit-attachment",title:e.attachmentDetails,content:"edit-metadata",menu:!1,toolbar:!1,router:!1}}),f.view.MediaFrame.Manage=f.view.MediaFrame.extend({initialize:function(){var c=this;b.defaults(this.options,{title:"",modal:!1,selection:[],library:{},multiple:"add",state:"library",uploader:!0,mode:["grid","edit"]}),this.$window=a(window),this.$adminBar=a("#wpadminbar"),this.$window.on("scroll resize",b.debounce(b.bind(this.fixPosition,this),15)),a(document).on("click",".add-new-h2",b.bind(this.addNewClickHandler,this)),this.$el.addClass("wp-core-ui"),(d.Uploader.limitExceeded||!d.Uploader.browser.supported)&&(this.options.uploader=!1),this.options.uploader&&(this.uploader=new f.view.UploaderWindow({controller:this,uploader:{dropzone:document.body,container:document.body}}).render(),this.uploader.ready(),a("body").append(this.uploader.el),this.options.uploader=!1),this.gridRouter=new f.view.MediaFrame.Manage.Router,f.view.MediaFrame.prototype.initialize.apply(this,arguments),this.$el.appendTo(this.options.container),this.createStates(),this.bindRegionModeHandlers(),this.render(),a("#media-search-input").on("input",b.debounce(function(b){var d=a(b.currentTarget).val(),e="";d&&(e+="?search="+d),c.gridRouter.navigate(c.gridRouter.baseUrl(e))},1e3))},createStates:function(){var a=this.options;this.options.states||this.states.add([new f.controller.Library({library:f.query(a.library),multiple:a.multiple,title:a.title,content:"browse",toolbar:"select",contentUserSetting:!1,filterable:"all"})])},bindRegionModeHandlers:function(){this.on("content:create:browse",this.browseContent,this),this.on("edit:attachment",this.openEditAttachmentModal,this)},fixPosition:function(){var a,b;this.isModeActive("select")&&(a=this.$(".attachments-browser"),b=a.find(".media-toolbar"),a.offset().top-1},keyEvent:function(b){var c=a(b.target);return c.is("input")||c.is("textarea")?b:(27===b.keyCode&&this.modal.close(),39===b.keyCode&&this.nextMediaItem(),void(37===b.keyCode&&this.previousMediaItem()))},resetRoute:function(){this.gridRouter.navigate(this.gridRouter.baseUrl(""))}}),f.view.SelectModeToggleButton=f.view.Button.extend({initialize:function(){f.view.Button.prototype.initialize.apply(this,arguments),this.listenTo(this.controller,"select:activate select:deactivate",this.toggleBulkEditHandler)},click:function(){f.view.Button.prototype.click.apply(this,arguments),this.controller.isModeActive("select")?this.controller.deactivateMode("select").activateMode("edit"):this.controller.deactivateMode("edit").activateMode("select")},render:function(){return f.view.Button.prototype.render.apply(this,arguments),this.$el.addClass("select-mode-toggle-button"),this},toggleBulkEditHandler:function(){var a,b=this.controller.content.get().toolbar;a=b.$(".media-toolbar-secondary > *, .media-toolbar-primary > *"),this.controller.isModeActive("select")?(this.model.set("text",e.cancelSelection),a.not(".delete-selected-button").hide(),b.$(".select-mode-toggle-button").show(),b.$(".delete-selected-button").removeClass("hidden")):(this.model.set("text",e.bulkSelect),this.controller.content.get().$el.removeClass("fixed"),b.$el.css("width",""),b.$(".delete-selected-button").addClass("hidden"),a.not(".spinner, .delete-selected-button").show(),this.controller.state().get("selection").reset())}}),f.view.DeleteSelectedButton=f.view.Button.extend({initialize:function(){f.view.Button.prototype.initialize.apply(this,arguments),this.options.filters&&this.listenTo(this.options.filters.model,"change",this.filterChange),this.listenTo(this.controller,"selection:toggle",this.toggleDisabled)},filterChange:function(a){"trash"===a.get("status")?this.model.set("text",e.untrashSelected):f.view.settings.mediaTrash?this.model.set("text",e.trashSelected):this.model.set("text",e.deleteSelected)},toggleDisabled:function(){this.model.set("disabled",!this.controller.state().get("selection").length)},render:function(){return f.view.Button.prototype.render.apply(this,arguments),this.$el.addClass(this.controller.isModeActive("select")?"delete-selected-button":"delete-selected-button hidden"),this}}),f.view.DateFilter=f.view.AttachmentFilters.extend({id:"media-attachment-date-filters",createFilters:function(){var a={};b.each(f.view.settings.months||{},function(b,c){a[c]={text:b.text,props:{year:b.year,monthnum:b.month}}}),a.all={text:e.allDates,props:{monthnum:!1,year:!1},priority:10},this.filters=a}})}(jQuery,_,Backbone,wp); \ No newline at end of file +!function(a,b,c,d){var e,f=d.media;f.view.l10n?e=f.view.l10n:(e=f.view.l10n="undefined"==typeof _wpMediaViewsL10n?{}:_wpMediaViewsL10n,delete e.settings),f.controller.EditAttachmentMetadata=f.controller.State.extend({defaults:{id:"edit-attachment",title:e.attachmentDetails,content:"edit-metadata",menu:!1,toolbar:!1,router:!1}}),f.view.MediaFrame.Manage=f.view.MediaFrame.extend({initialize:function(){var c=this;b.defaults(this.options,{title:"",modal:!1,selection:[],library:{},multiple:"add",state:"library",uploader:!0,mode:["grid","edit"]}),this.$window=a(window),this.$adminBar=a("#wpadminbar"),this.$window.on("scroll resize",b.debounce(b.bind(this.fixPosition,this),15)),a(document).on("click",".add-new-h2",b.bind(this.addNewClickHandler,this)),this.$el.addClass("wp-core-ui"),(d.Uploader.limitExceeded||!d.Uploader.browser.supported)&&(this.options.uploader=!1),this.options.uploader&&(this.uploader=new f.view.UploaderWindow({controller:this,uploader:{dropzone:document.body,container:document.body}}).render(),this.uploader.ready(),a("body").append(this.uploader.el),this.options.uploader=!1),this.gridRouter=new f.view.MediaFrame.Manage.Router,f.view.MediaFrame.prototype.initialize.apply(this,arguments),this.$el.appendTo(this.options.container),this.createStates(),this.bindRegionModeHandlers(),this.render(),a("#media-search-input").on("input",b.debounce(function(b){var d=a(b.currentTarget).val(),e="";d&&(e+="?search="+d),c.gridRouter.navigate(c.gridRouter.baseUrl(e))},1e3))},createStates:function(){var a=this.options;this.options.states||this.states.add([new f.controller.Library({library:f.query(a.library),multiple:a.multiple,title:a.title,content:"browse",toolbar:"select",contentUserSetting:!1,filterable:"all"})])},bindRegionModeHandlers:function(){this.on("content:create:browse",this.browseContent,this),this.on("edit:attachment",this.openEditAttachmentModal,this)},fixPosition:function(){var a,b;this.isModeActive("select")&&(a=this.$(".attachments-browser"),b=a.find(".media-toolbar"),a.offset().top-1},keyEvent:function(b){var c=a(b.target);return c.is("input")||c.is("textarea")?b:(27===b.keyCode&&this.modal.close(),39===b.keyCode&&this.nextMediaItem(),void(37===b.keyCode&&this.previousMediaItem()))},resetRoute:function(){this.gridRouter.navigate(this.gridRouter.baseUrl(""))}}),f.view.SelectModeToggleButton=f.view.Button.extend({initialize:function(){f.view.Button.prototype.initialize.apply(this,arguments),this.listenTo(this.controller,"select:activate select:deactivate",this.toggleBulkEditHandler)},click:function(){f.view.Button.prototype.click.apply(this,arguments),this.controller.isModeActive("select")?this.controller.deactivateMode("select").activateMode("edit"):this.controller.deactivateMode("edit").activateMode("select")},render:function(){return f.view.Button.prototype.render.apply(this,arguments),this.$el.addClass("select-mode-toggle-button"),this},toggleBulkEditHandler:function(){var a,b=this.controller.content.get().toolbar;a=b.$(".media-toolbar-secondary > *, .media-toolbar-primary > *"),this.controller.isModeActive("select")?(this.model.set("text",e.cancelSelection),a.not(".delete-selected-button").hide(),b.$(".select-mode-toggle-button").show(),b.$(".delete-selected-button").removeClass("hidden")):(this.model.set("text",e.bulkSelect),this.controller.content.get().$el.removeClass("fixed"),b.$el.css("width",""),b.$(".delete-selected-button").addClass("hidden"),a.not(".spinner, .delete-selected-button").show(),this.controller.state().get("selection").reset())}}),f.view.DeleteSelectedButton=f.view.Button.extend({initialize:function(){f.view.Button.prototype.initialize.apply(this,arguments),this.options.filters&&this.listenTo(this.options.filters.model,"change",this.filterChange),this.listenTo(this.controller,"selection:toggle",this.toggleDisabled)},filterChange:function(a){"trash"===a.get("status")?this.model.set("text",e.untrashSelected):f.view.settings.mediaTrash?this.model.set("text",e.trashSelected):this.model.set("text",e.deleteSelected)},toggleDisabled:function(){this.model.set("disabled",!this.controller.state().get("selection").length)},render:function(){return f.view.Button.prototype.render.apply(this,arguments),this.$el.addClass(this.controller.isModeActive("select")?"delete-selected-button":"delete-selected-button hidden"),this}}),f.view.DateFilter=f.view.AttachmentFilters.extend({id:"media-attachment-date-filters",createFilters:function(){var a={};b.each(f.view.settings.months||{},function(b,c){a[c]={text:b.text,props:{year:b.year,monthnum:b.month}}}),a.all={text:e.allDates,props:{monthnum:!1,year:!1},priority:10},this.filters=a}})}(jQuery,_,Backbone,wp); \ No newline at end of file