From b7c8dee8f5fd11d40e2f94fe794f896a41c23786 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 10 Jul 2014 19:39:14 +0000 Subject: [PATCH] Media Grid: decouple the Grid and Edit modal frames. Next steps: we shouldn't have to reload the frame while paginating. See #24716. Built from https://develop.svn.wordpress.org/trunk@29076 git-svn-id: http://core.svn.wordpress.org/trunk@28862 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/media-grid.js | 42 +++++++++++++----------------- wp-includes/js/media-grid.min.js | 2 +- wp-includes/js/media-models.js | 2 ++ wp-includes/js/media-models.min.js | 2 +- 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/wp-includes/js/media-grid.js b/wp-includes/js/media-grid.js index 019a964318..b1f0428838 100644 --- a/wp-includes/js/media-grid.js +++ b/wp-includes/js/media-grid.js @@ -216,26 +216,12 @@ // Handle a frame-level event for editing an attachment. this.on( 'edit:attachment', this.editAttachment, this ); - this.on( 'edit:attachment:next', this.editNextAttachment, this ); - this.on( 'edit:attachment:previous', this.editPreviousAttachment, this ); }, addNewClickHandler: function() { this.trigger( 'show:upload:attachment' ); }, - editPreviousAttachment: function( currentModel ) { - var library = this.state().get('library'), - currentModelIndex = library.indexOf( currentModel ); - this.trigger( 'edit:attachment', library.at( currentModelIndex - 1 ) ); - }, - - editNextAttachment: function( currentModel ) { - var library = this.state().get('library'), - currentModelIndex = library.indexOf( currentModel ); - this.trigger( 'edit:attachment', library.at( currentModelIndex + 1 ) ); - }, - /** * Open the Edit Attachment modal. */ @@ -244,15 +230,13 @@ library = this.state().get('library'); // Create a new EditAttachment frame, passing along the library and the attachment model. - this.editAttachmentFrame = new media.view.Frame.EditAttachments({ + this.editAttachmentFrame = wp.media( { + frame: 'edit-attachments', gridRouter: this.gridRouter, library: library, model: model - }); + } ); - // Listen to events on the edit attachment frame for triggering pagination callback handlers. - this.listenTo( this.editAttachmentFrame, 'edit:attachment:next', this.editNextAttachment ); - this.listenTo( this.editAttachmentFrame, 'edit:attachment:previous', this.editPreviousAttachment ); // Listen to keyboard events on the modal $( 'body' ).on( 'keydown.media-modal', function( e ) { self.editAttachmentFrame.keyEvent( e ); @@ -385,7 +369,7 @@ * * Requires an attachment model to be passed in the options hash under `model`. */ - media.view.Frame.EditAttachments = media.view.Frame.extend({ + media.view.MediaFrame.EditAttachments = media.view.Frame.extend({ className: 'edit-attachment-frame', template: media.template( 'edit-attachment-frame' ), @@ -535,6 +519,16 @@ }); }, + resetContent: function() { + this.modal.close(); + wp.media( { + frame: 'edit-attachments', + gridRouter: this.gridRouter, + library: this.library, + model: this.model + } ); + }, + /** * Click handler to switch to the previous media item. */ @@ -542,8 +536,8 @@ if ( ! this.hasPrevious() ) { return; } - this.modal.close(); - this.trigger( 'edit:attachment:previous', this.model ); + this.model = this.library.at( this.getCurrentIndex() - 1 ); + this.resetContent(); }, /** @@ -553,8 +547,8 @@ if ( ! this.hasNext() ) { return; } - this.modal.close(); - this.trigger( 'edit:attachment:next', this.model ); + this.model = this.library.at( this.getCurrentIndex() + 1 ); + this.resetContent(); }, getCurrentIndex: function() { diff --git a/wp-includes/js/media-grid.min.js b/wp-includes/js/media-grid.min.js index e8ef96c07d..175bfc840a 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.EditImageNoFrame=f.controller.State.extend({defaults:{id:"edit-attachment",title:e.editImage,menu:!1,router:"edit-metadata",content:"edit-metadata",url:""},_ready:function(){},_postActivate:function(){this._content(),this._router()},_router:function(){var a,b=this.frame.router,c=this.get("router");this.frame.$el.toggleClass("hide-router",!c),c&&(this.frame.router.render(c),a=b.get(),a&&a.select&&a.select(this.frame.content.mode()))},_content:function(){var a=this.get("content");a&&this.frame.content.render(a)}}),f.view.MediaFrame.Manage=f.view.MediaFrame.extend({initialize:function(){var c=this;b.defaults(this.options,{title:e.mediaLibraryTitle,modal:!1,selection:[],library:{},multiple:"add",state:"library",uploader:!0,mode:["grid","edit"]}),a(document).on("click",".add-new-h2",b.bind(this.addNewClickHandler,this)),this.$el.addClass("wp-core-ui media-grid-view"),(d.Uploader.limitExceeded||!d.Uploader.browser.supported)&&(this.options.uploader=!1),this.options.uploader&&(this.uploader=new f.view.UploaderWindow({controller:this,uploader:{dropzone:a("body"),container:a("body")}}).render(),this.uploader.ready(),a("body").append(this.uploader.el),this.options.uploader=!1),f.view.MediaFrame.prototype.initialize.apply(this,arguments),this.$el.appendTo(this.options.container),this.createSelection(),this.createStates(),this.bindHandlers(),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)),b.delay(b.bind(this.createRouter,this),1e3)},createRouter:function(){this.gridRouter=new f.view.MediaFrame.Manage.Router,window.history&&window.history.pushState&&c.history.start({root:mediaGridSettings.adminUrl,pushState:!0})},createSelection:function(){var a=this.options.selection;a instanceof f.model.Selection||(this.options.selection=new f.model.Selection(a,{multiple:this.options.multiple})),this._selection={attachments:new f.model.Attachments,difference:[]}},createStates:function(){var a,b=this.options;this.options.states||(a=new f.controller.Library({library:f.query(b.library),multiple:b.multiple,title:b.title,priority:20,toolbar:!1,router:!1,content:"browse",filterable:"mime-types"}),a._renderTitle=function(a){var b=this.get("title")||"";a.$el.addClass("wrap"),b+='Add New',a.$el.html(b)},this.states.add([a]))},bindHandlers:function(){this.on("content:create:browse",this.browseContent,this),this.on("content:render:edit-image",this.editImageContent,this),this.on("edit:attachment",this.editAttachment,this),this.on("edit:attachment:next",this.editNextAttachment,this),this.on("edit:attachment:previous",this.editPreviousAttachment,this)},addNewClickHandler:function(){this.trigger("show:upload:attachment")},editPreviousAttachment:function(a){var b=this.state().get("library"),c=b.indexOf(a);this.trigger("edit:attachment",b.at(c-1))},editNextAttachment:function(a){var b=this.state().get("library"),c=b.indexOf(a);this.trigger("edit:attachment",b.at(c+1))},editAttachment:function(b){var c=this,d=this.state().get("library");this.editAttachmentFrame=new f.view.Frame.EditAttachments({gridRouter:this.gridRouter,library:d,model:b}),this.listenTo(this.editAttachmentFrame,"edit:attachment:next",this.editNextAttachment),this.listenTo(this.editAttachmentFrame,"edit:attachment:previous",this.editPreviousAttachment),a("body").on("keydown.media-modal",function(a){c.editAttachmentFrame.keyEvent(a)})},browseContent:function(a){var b=this.state();a.view=new f.view.AttachmentsBrowser({controller:this,collection:b.get("library"),selection:b.get("selection"),model:b,sortable:b.get("sortable"),search:b.get("searchable"),filters:b.get("filterable"),display:b.get("displaySettings"),dragInfo:b.get("dragInfo"),bulkEdit:!0,sidebar:!1,suggestedWidth:b.get("suggestedWidth"),suggestedHeight:b.get("suggestedHeight"),AttachmentView:b.get("AttachmentView")})},editImageContent:function(){var a=this.state().get("image"),b=new f.view.EditImage({model:a,controller:this}).render();this.content.set(b),b.loadEditor()}}),f.view.Attachment.Details.TwoColumn=f.view.Attachment.Details.extend({template:d.template("attachment-details-two-column"),initialize:function(){this.model&&(this.$el.attr("aria-label",this.model.get("title")).attr("aria-checked",!1),this.model.on("change:sizes change:uploading",this.render,this),this.model.on("change:title",this._syncTitle,this),this.model.on("change:caption",this._syncCaption,this),this.model.on("change:percent",this.progress,this),this.model.on("add",this.select,this),this.model.on("remove",this.deselect,this))},render:function(){f.view.Attachment.Details.prototype.render.apply(this,arguments),f.mixin.removeAllPlayers(),a("audio, video",this.$el).each(function(a,b){var c=f.view.MediaDetails.prepareSrc(b);new MediaElementPlayer(c,f.mixin.mejsSettings)})}}),f.view.MediaFrame.Manage.Router=c.Router.extend({routes:{"upload.php?item=:slug":"showitem","upload.php?search=:query":"search",":default":"defaultRoute"},baseUrl:function(a){return"upload.php"+a},search:function(b){this.closeModal(),a("#media-search-input").val(b).trigger("input")},showitem:function(a){var b=f.frame.state().get("library");this.closeModal(),f.frame.trigger("edit:attachment",b.findWhere({id:parseInt(a,10)}))},closeModal:function(){f.frame.modal&&f.frame.modal.close()},defaultRoute:function(){this.closeModal(),a("#media-search-input").val("").trigger("input")}}),f.view.Frame.EditAttachments=f.view.Frame.extend({className:"edit-attachment-frame",template:f.template("edit-attachment-frame"),regions:["router","content"],events:{click:"collapse","click .delete-media-item":"deleteMediaItem","click .left":"previousMediaItem","click .right":"nextMediaItem"},initialize:function(){var c=this;f.view.Frame.prototype.initialize.apply(this,arguments),b.defaults(this.options,{modal:!0,state:"edit-attachment"}),this.gridRouter=this.options.gridRouter,this.library=this.options.library,this.model=this.options.model?this.options.model:this.library.at(0),this.createStates(),this.on("content:render:edit-metadata",this.editMetadataContent,this),this.on("content:render:edit-image",this.editImageContentUgh,this),"undefined"!=typeof this.model&&"image"===this.model.get("type")&&(this.on("router:create",this.createRouter,this),this.on("router:render",this.browseRouter,this)),this.options.hasPrevious=this.hasPrevious(),this.options.hasNext=this.hasNext(),this.options.modal&&(this.modal=new f.view.Modal({controller:this,title:this.options.title}),this.modal.close=function(){c.modal.remove(),a("body").off("keydown.media-modal"),c.resetRoute()},this.modal.content(this),this.modal.open())},createStates:function(){this.states.add([new f.controller.EditImageNoFrame({model:this.model})])},render:function(){return!this.state()&&this.options.state&&this.setState(this.options.state),f.view.Frame.prototype.render.apply(this,arguments)},editMetadataContent:function(){var a=new f.view.Attachment.Details.TwoColumn({controller:this,model:this.model});this.content.set(a),this.gridRouter.navigate(this.gridRouter.baseUrl("?item="+this.model.id))},editImageContentUgh:function(){b.defer(b.bind(this.editImageContent,this))},editImageContent:function(){var a=new f.view.EditImage({model:this.model,controller:this}).render();this.content.set(a),a.loadEditor()},createRouter:function(a){a.view=new f.view.Router({controller:this})},browseRouter:function(a){a.set({"edit-metadata":{text:"Edit Metadata",priority:20},"edit-image":{text:"Edit Image",priority:40}})},previousMediaItem:function(){this.hasPrevious()&&(this.modal.close(),this.trigger("edit:attachment:previous",this.model))},nextMediaItem:function(){this.hasNext()&&(this.modal.close(),this.trigger("edit:attachment:next",this.model))},getCurrentIndex:function(){return this.library.indexOf(this.model)},hasNext:function(){return this.getCurrentIndex()+1-1},keyEvent:function(b){var c=a(b.target);if(27===b.keyCode)return this.resetRoute(),b;if(c.is("input")||c.is("textarea"))return b;if(39===b.keyCode){if(!this.hasNext())return;this.nextMediaItem()}if(37===b.keyCode){if(!this.hasPrevious())return;this.previousMediaItem()}},resetRoute:function(){this.gridRouter.navigate(this.gridRouter.baseUrl(""))}}),f.view.GridFieldOptions=f.View.extend({className:"media-grid-field-options",template:f.template("media-grid-field-options"),events:{"change input":"toggleFields"},toggleFields:function(b){var c,d,e=a(b.currentTarget);d=e.data("setting"),c=a(".data-"+d,".data-fields"),e.is(":checked")?(c.show(),deleteUserSetting("hidegrid"+d)):(c.hide(),setUserSetting("hidegrid"+d,1)),a(":checked",this.$el).length?c.parent().show():c.parent().hide()}}),f.view.BulkSelectionToggleButton=f.view.Button.extend({initialize:function(){f.view.Button.prototype.initialize.apply(this,arguments),this.listenTo(this.controller,"bulk-edit:activate bulk-edit:deactivate",b.bind(this.toggleBulkEditHandler,this))},click:function(){var a=this.controller.activeModes.where({id:"bulk-edit"}).length;f.view.Button.prototype.click.apply(this,arguments),a?(this.controller.deactivateMode("bulk-edit"),this.controller.activateMode("edit")):(this.controller.deactivateMode("edit"),this.controller.activateMode("bulk-edit"))},toggleBulkEditHandler:function(){var a=this.controller.activeModes.where({id:"bulk-edit"}).length;a?this.$el.addClass("button-primary"):(this.$el.removeClass("button-primary"),this.controller.state().get("selection").reset())}}),f.view.BulkDeleteButton=f.view.Button.extend({initialize:function(){f.view.Button.prototype.initialize.apply(this,arguments),this.$el.hide(),this.listenTo(this.controller,"bulk-edit:activate bulk-edit:deactivate",b.bind(this.visibility,this))},click:function(){for(f.view.Button.prototype.click.apply(this,arguments);this.controller.state().get("selection").length>0;)this.controller.state().get("selection").at(0).destroy()},visibility:function(){var a=this.controller.activeModes.where({id:"bulk-edit"}).length;a?this.$el.show():this.$el.hide()}})}(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.EditImageNoFrame=f.controller.State.extend({defaults:{id:"edit-attachment",title:e.editImage,menu:!1,router:"edit-metadata",content:"edit-metadata",url:""},_ready:function(){},_postActivate:function(){this._content(),this._router()},_router:function(){var a,b=this.frame.router,c=this.get("router");this.frame.$el.toggleClass("hide-router",!c),c&&(this.frame.router.render(c),a=b.get(),a&&a.select&&a.select(this.frame.content.mode()))},_content:function(){var a=this.get("content");a&&this.frame.content.render(a)}}),f.view.MediaFrame.Manage=f.view.MediaFrame.extend({initialize:function(){var c=this;b.defaults(this.options,{title:e.mediaLibraryTitle,modal:!1,selection:[],library:{},multiple:"add",state:"library",uploader:!0,mode:["grid","edit"]}),a(document).on("click",".add-new-h2",b.bind(this.addNewClickHandler,this)),this.$el.addClass("wp-core-ui media-grid-view"),(d.Uploader.limitExceeded||!d.Uploader.browser.supported)&&(this.options.uploader=!1),this.options.uploader&&(this.uploader=new f.view.UploaderWindow({controller:this,uploader:{dropzone:a("body"),container:a("body")}}).render(),this.uploader.ready(),a("body").append(this.uploader.el),this.options.uploader=!1),f.view.MediaFrame.prototype.initialize.apply(this,arguments),this.$el.appendTo(this.options.container),this.createSelection(),this.createStates(),this.bindHandlers(),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)),b.delay(b.bind(this.createRouter,this),1e3)},createRouter:function(){this.gridRouter=new f.view.MediaFrame.Manage.Router,window.history&&window.history.pushState&&c.history.start({root:mediaGridSettings.adminUrl,pushState:!0})},createSelection:function(){var a=this.options.selection;a instanceof f.model.Selection||(this.options.selection=new f.model.Selection(a,{multiple:this.options.multiple})),this._selection={attachments:new f.model.Attachments,difference:[]}},createStates:function(){var a,b=this.options;this.options.states||(a=new f.controller.Library({library:f.query(b.library),multiple:b.multiple,title:b.title,priority:20,toolbar:!1,router:!1,content:"browse",filterable:"mime-types"}),a._renderTitle=function(a){var b=this.get("title")||"";a.$el.addClass("wrap"),b+='Add New',a.$el.html(b)},this.states.add([a]))},bindHandlers:function(){this.on("content:create:browse",this.browseContent,this),this.on("content:render:edit-image",this.editImageContent,this),this.on("edit:attachment",this.editAttachment,this)},addNewClickHandler:function(){this.trigger("show:upload:attachment")},editAttachment:function(b){var c=this,e=this.state().get("library");this.editAttachmentFrame=d.media({frame:"edit-attachments",gridRouter:this.gridRouter,library:e,model:b}),a("body").on("keydown.media-modal",function(a){c.editAttachmentFrame.keyEvent(a)})},browseContent:function(a){var b=this.state();a.view=new f.view.AttachmentsBrowser({controller:this,collection:b.get("library"),selection:b.get("selection"),model:b,sortable:b.get("sortable"),search:b.get("searchable"),filters:b.get("filterable"),display:b.get("displaySettings"),dragInfo:b.get("dragInfo"),bulkEdit:!0,sidebar:!1,suggestedWidth:b.get("suggestedWidth"),suggestedHeight:b.get("suggestedHeight"),AttachmentView:b.get("AttachmentView")})},editImageContent:function(){var a=this.state().get("image"),b=new f.view.EditImage({model:a,controller:this}).render();this.content.set(b),b.loadEditor()}}),f.view.Attachment.Details.TwoColumn=f.view.Attachment.Details.extend({template:d.template("attachment-details-two-column"),initialize:function(){this.model&&(this.$el.attr("aria-label",this.model.get("title")).attr("aria-checked",!1),this.model.on("change:sizes change:uploading",this.render,this),this.model.on("change:title",this._syncTitle,this),this.model.on("change:caption",this._syncCaption,this),this.model.on("change:percent",this.progress,this),this.model.on("add",this.select,this),this.model.on("remove",this.deselect,this))},render:function(){f.view.Attachment.Details.prototype.render.apply(this,arguments),f.mixin.removeAllPlayers(),a("audio, video",this.$el).each(function(a,b){var c=f.view.MediaDetails.prepareSrc(b);new MediaElementPlayer(c,f.mixin.mejsSettings)})}}),f.view.MediaFrame.Manage.Router=c.Router.extend({routes:{"upload.php?item=:slug":"showitem","upload.php?search=:query":"search",":default":"defaultRoute"},baseUrl:function(a){return"upload.php"+a},search:function(b){this.closeModal(),a("#media-search-input").val(b).trigger("input")},showitem:function(a){var b=f.frame.state().get("library");this.closeModal(),f.frame.trigger("edit:attachment",b.findWhere({id:parseInt(a,10)}))},closeModal:function(){f.frame.modal&&f.frame.modal.close()},defaultRoute:function(){this.closeModal(),a("#media-search-input").val("").trigger("input")}}),f.view.MediaFrame.EditAttachments=f.view.Frame.extend({className:"edit-attachment-frame",template:f.template("edit-attachment-frame"),regions:["router","content"],events:{click:"collapse","click .delete-media-item":"deleteMediaItem","click .left":"previousMediaItem","click .right":"nextMediaItem"},initialize:function(){var c=this;f.view.Frame.prototype.initialize.apply(this,arguments),b.defaults(this.options,{modal:!0,state:"edit-attachment"}),this.gridRouter=this.options.gridRouter,this.library=this.options.library,this.model=this.options.model?this.options.model:this.library.at(0),this.createStates(),this.on("content:render:edit-metadata",this.editMetadataContent,this),this.on("content:render:edit-image",this.editImageContentUgh,this),"undefined"!=typeof this.model&&"image"===this.model.get("type")&&(this.on("router:create",this.createRouter,this),this.on("router:render",this.browseRouter,this)),this.options.hasPrevious=this.hasPrevious(),this.options.hasNext=this.hasNext(),this.options.modal&&(this.modal=new f.view.Modal({controller:this,title:this.options.title}),this.modal.close=function(){c.modal.remove(),a("body").off("keydown.media-modal"),c.resetRoute()},this.modal.content(this),this.modal.open())},createStates:function(){this.states.add([new f.controller.EditImageNoFrame({model:this.model})])},render:function(){return!this.state()&&this.options.state&&this.setState(this.options.state),f.view.Frame.prototype.render.apply(this,arguments)},editMetadataContent:function(){var a=new f.view.Attachment.Details.TwoColumn({controller:this,model:this.model});this.content.set(a),this.gridRouter.navigate(this.gridRouter.baseUrl("?item="+this.model.id))},editImageContentUgh:function(){b.defer(b.bind(this.editImageContent,this))},editImageContent:function(){var a=new f.view.EditImage({model:this.model,controller:this}).render();this.content.set(a),a.loadEditor()},createRouter:function(a){a.view=new f.view.Router({controller:this})},browseRouter:function(a){a.set({"edit-metadata":{text:"Edit Metadata",priority:20},"edit-image":{text:"Edit Image",priority:40}})},resetContent:function(){this.modal.close(),d.media({frame:"edit-attachments",gridRouter:this.gridRouter,library:this.library,model:this.model})},previousMediaItem:function(){this.hasPrevious()&&(this.model=this.library.at(this.getCurrentIndex()-1),this.resetContent())},nextMediaItem:function(){this.hasNext()&&(this.model=this.library.at(this.getCurrentIndex()+1),this.resetContent())},getCurrentIndex:function(){return this.library.indexOf(this.model)},hasNext:function(){return this.getCurrentIndex()+1-1},keyEvent:function(b){var c=a(b.target);if(27===b.keyCode)return this.resetRoute(),b;if(c.is("input")||c.is("textarea"))return b;if(39===b.keyCode){if(!this.hasNext())return;this.nextMediaItem()}if(37===b.keyCode){if(!this.hasPrevious())return;this.previousMediaItem()}},resetRoute:function(){this.gridRouter.navigate(this.gridRouter.baseUrl(""))}}),f.view.GridFieldOptions=f.View.extend({className:"media-grid-field-options",template:f.template("media-grid-field-options"),events:{"change input":"toggleFields"},toggleFields:function(b){var c,d,e=a(b.currentTarget);d=e.data("setting"),c=a(".data-"+d,".data-fields"),e.is(":checked")?(c.show(),deleteUserSetting("hidegrid"+d)):(c.hide(),setUserSetting("hidegrid"+d,1)),a(":checked",this.$el).length?c.parent().show():c.parent().hide()}}),f.view.BulkSelectionToggleButton=f.view.Button.extend({initialize:function(){f.view.Button.prototype.initialize.apply(this,arguments),this.listenTo(this.controller,"bulk-edit:activate bulk-edit:deactivate",b.bind(this.toggleBulkEditHandler,this))},click:function(){var a=this.controller.activeModes.where({id:"bulk-edit"}).length;f.view.Button.prototype.click.apply(this,arguments),a?(this.controller.deactivateMode("bulk-edit"),this.controller.activateMode("edit")):(this.controller.deactivateMode("edit"),this.controller.activateMode("bulk-edit"))},toggleBulkEditHandler:function(){var a=this.controller.activeModes.where({id:"bulk-edit"}).length;a?this.$el.addClass("button-primary"):(this.$el.removeClass("button-primary"),this.controller.state().get("selection").reset())}}),f.view.BulkDeleteButton=f.view.Button.extend({initialize:function(){f.view.Button.prototype.initialize.apply(this,arguments),this.$el.hide(),this.listenTo(this.controller,"bulk-edit:activate bulk-edit:deactivate",b.bind(this.visibility,this))},click:function(){for(f.view.Button.prototype.click.apply(this,arguments);this.controller.state().get("selection").length>0;)this.controller.state().get("selection").at(0).destroy()},visibility:function(){var a=this.controller.activeModes.where({id:"bulk-edit"}).length;a?this.$el.show():this.$el.hide()}})}(jQuery,_,Backbone,wp); \ No newline at end of file diff --git a/wp-includes/js/media-models.js b/wp-includes/js/media-models.js index 9ba5f5e789..78d7d7f9ca 100644 --- a/wp-includes/js/media-models.js +++ b/wp-includes/js/media-models.js @@ -38,6 +38,8 @@ window.wp = window.wp || {}; frame = new MediaFrame.AudioDetails( attributes ); } else if ( 'video' === attributes.frame && MediaFrame.VideoDetails ) { frame = new MediaFrame.VideoDetails( attributes ); + } else if ( 'edit-attachments' === attributes.frame && MediaFrame.EditAttachments ) { + frame = new MediaFrame.EditAttachments( attributes ); } delete attributes.frame; diff --git a/wp-includes/js/media-models.min.js b/wp-includes/js/media-models.min.js index d419aac68b..f28f2a730f 100644 --- a/wp-includes/js/media-models.min.js +++ b/wp-includes/js/media-models.min.js @@ -1 +1 @@ -window.wp=window.wp||{},function(a){var b,c,d,e,f,g,h;h=wp.media=function(a){var b,c=h.view.MediaFrame;if(c)return a=_.defaults(a||{},{frame:"select"}),"select"===a.frame&&c.Select?b=new c.Select(a):"post"===a.frame&&c.Post?b=new c.Post(a):"manage"===a.frame&&c.Manage?b=new c.Manage(a):"image"===a.frame&&c.ImageDetails?b=new c.ImageDetails(a):"audio"===a.frame&&c.AudioDetails?b=new c.AudioDetails(a):"video"===a.frame&&c.VideoDetails&&(b=new c.VideoDetails(a)),delete a.frame,h.frame=b,b},_.extend(h,{model:{},view:{},controller:{},frames:{}}),g=h.model.l10n="undefined"==typeof _wpMediaModelsL10n?{}:_wpMediaModelsL10n,h.model.settings=g.settings||{},delete g.settings,f=function(a,b,c,d){return _.isEqual(a,b)?c===d?0:c>d?-1:1:a>b?-1:1},_.extend(h,{template:wp.template,post:wp.ajax.post,ajax:wp.ajax.send,fit:function(a){var b,c=a.width,d=a.height,e=a.maxWidth,f=a.maxHeight;return _.isUndefined(e)||_.isUndefined(f)?_.isUndefined(f)?b="width":_.isUndefined(e)&&d>f&&(b="height"):b=c/d>e/f?"width":"height","width"===b&&c>e?{width:e,height:Math.round(e*d/c)}:"height"===b&&d>f?{width:Math.round(f*c/d),height:f}:{width:c,height:d}},truncate:function(a,b,c){return b=b||30,c=c||"…",a.length<=b?a:a.substr(0,b/2)+c+a.substr(-1*b/2)}}),h.attachment=function(a){return b.get(a)},b=h.model.Attachment=Backbone.Model.extend({sync:function(b,c,d){return _.isUndefined(this.id)?a.Deferred().rejectWith(this).promise():"read"===b?(d=d||{},d.context=this,d.data=_.extend(d.data||{},{action:"get-attachment",id:this.id}),h.ajax(d)):"update"===b?this.get("nonces")&&this.get("nonces").update?(d=d||{},d.context=this,d.data=_.extend(d.data||{},{action:"save-attachment",id:this.id,nonce:this.get("nonces").update,post_id:h.model.settings.post.id}),c.hasChanged()&&(d.data.changes={},_.each(c.changed,function(a,b){d.data.changes[b]=this.get(b)},this)),h.ajax(d)):a.Deferred().rejectWith(this).promise():"delete"===b?(d=d||{},d.wait||(this.destroyed=!0),d.context=this,d.data=_.extend(d.data||{},{action:"delete-post",id:this.id,_wpnonce:this.get("nonces")["delete"]}),h.ajax(d).done(function(){this.destroyed=!0}).fail(function(){this.destroyed=!1})):Backbone.Model.prototype.sync.apply(this,arguments)},parse:function(a){return a?(a.date=new Date(a.date),a.modified=new Date(a.modified),a):a},saveCompat:function(b,c){var d=this;return this.get("nonces")&&this.get("nonces").update?h.post("save-attachment-compat",_.defaults({id:this.id,nonce:this.get("nonces").update,post_id:h.model.settings.post.id},b)).done(function(a,b,e){d.set(d.parse(a,e),c)}):a.Deferred().rejectWith(this).promise()}},{create:function(a){return c.all.push(a)},get:_.memoize(function(a,b){return c.all.push(b||{id:a})})}),e=h.model.PostImage=Backbone.Model.extend({initialize:function(c){this.attachment=!1,c.attachment_id&&(this.attachment=b.get(c.attachment_id),this.attachment.get("url")?(this.dfd=a.Deferred(),this.dfd.resolve()):this.dfd=this.attachment.fetch(),this.bindAttachmentListeners()),this.on("change:link",this.updateLinkUrl,this),this.on("change:size",this.updateSize,this),this.setLinkTypeFromUrl(),this.setAspectRatio(),this.set("originalUrl",c.url)},bindAttachmentListeners:function(){this.listenTo(this.attachment,"sync",this.setLinkTypeFromUrl),this.listenTo(this.attachment,"sync",this.setAspectRatio),this.listenTo(this.attachment,"change",this.updateSize)},changeAttachment:function(a,b){this.stopListening(this.attachment),this.attachment=a,this.bindAttachmentListeners(),this.set("attachment_id",this.attachment.get("id")),this.set("caption",this.attachment.get("caption")),this.set("alt",this.attachment.get("alt")),this.set("size",b.get("size")),this.set("align",b.get("align")),this.set("link",b.get("link")),this.updateLinkUrl(),this.updateSize()},setLinkTypeFromUrl:function(){var a,b=this.get("linkUrl");return b?(a="custom",this.attachment?this.attachment.get("url")===b?a="file":this.attachment.get("link")===b&&(a="post"):this.get("url")===b&&(a="file"),void this.set("link",a)):void this.set("link","none")},updateLinkUrl:function(){var a,b=this.get("link");switch(b){case"file":a=this.attachment?this.attachment.get("url"):this.get("url"),this.set("linkUrl",a);break;case"post":this.set("linkUrl",this.attachment.get("link"));break;case"none":this.set("linkUrl","")}},updateSize:function(){var a;if(this.attachment){if("custom"===this.get("size"))return this.set("width",this.get("customWidth")),this.set("height",this.get("customHeight")),void this.set("url",this.get("originalUrl"));a=this.attachment.get("sizes")[this.get("size")],a&&(this.set("url",a.url),this.set("width",a.width),this.set("height",a.height))}},setAspectRatio:function(){var a;return this.attachment&&this.attachment.get("sizes")&&(a=this.attachment.get("sizes").full)?void this.set("aspectRatio",a.width/a.height):void this.set("aspectRatio",this.get("customWidth")/this.get("customHeight"))}}),c=h.model.Attachments=Backbone.Collection.extend({model:b,initialize:function(a,b){b=b||{},this.props=new Backbone.Model,this.filters=b.filters||{},this.props.on("change",this._changeFilteredProps,this),this.props.on("change:order",this._changeOrder,this),this.props.on("change:orderby",this._changeOrderby,this),this.props.on("change:query",this._changeQuery,this),this.props.set(_.defaults(b.props||{})),b.observe&&this.observe(b.observe)},_changeOrder:function(){this.comparator&&this.sort()},_changeOrderby:function(a,b){this.comparator&&this.comparator!==c.comparator||(b&&"post__in"!==b?this.comparator=c.comparator:delete this.comparator)},_changeQuery:function(a,b){b?(this.props.on("change",this._requery,this),this._requery()):this.props.off("change",this._requery,this)},_changeFilteredProps:function(a){if(!this.props.get("query")){var b=_.chain(a.changed).map(function(b,d){var e=c.filters[d],f=a.get(d);if(e){if(f&&!this.filters[d])this.filters[d]=e;else{if(f||this.filters[d]!==e)return;delete this.filters[d]}return!0}},this).any().value();b&&(this._source||(this._source=new c(this.models)),this.reset(this._source.filter(this.validator,this)))}},validateDestroyed:!1,validator:function(a){return!this.validateDestroyed&&a.destroyed?!1:_.all(this.filters,function(b){return!!b.call(this,a)},this)},validate:function(a,b){var c=this.validator(a),d=!!this.get(a.cid);return!c&&d?this.remove(a,b):c&&!d&&this.add(a,b),this},validateAll:function(a,b){return b=b||{},_.each(a.models,function(a){this.validate(a,{silent:!0})},this),b.silent||this.trigger("reset",this,b),this},observe:function(a){return this.observers=this.observers||[],this.observers.push(a),a.on("add change remove",this._validateHandler,this),a.on("reset",this._validateAllHandler,this),this.validateAll(a),this},unobserve:function(a){return a?(a.off(null,null,this),this.observers=_.without(this.observers,a)):(_.each(this.observers,function(a){a.off(null,null,this)},this),delete this.observers),this},_validateHandler:function(a,b,c){return c=b===this.mirroring?c:{silent:c&&c.silent},this.validate(a,c)},_validateAllHandler:function(a,b){return this.validateAll(a,b)},mirror:function(a){return this.mirroring&&this.mirroring===a?this:(this.unmirror(),this.mirroring=a,this.reset([],{silent:!0}),this.observe(a),this)},unmirror:function(){this.mirroring&&(this.unobserve(this.mirroring),delete this.mirroring)},more:function(b){var c=a.Deferred(),d=this.mirroring,e=this;return d&&d.more?(d.more(b).done(function(){this===e.mirroring&&c.resolveWith(this)}),c.promise()):c.resolveWith(this).promise()},hasMore:function(){return this.mirroring?this.mirroring.hasMore():!1},parse:function(a,c){return _.isArray(a)||(a=[a]),_.map(a,function(a){var d,e,f;return a instanceof Backbone.Model?(d=a.get("id"),a=a.attributes):d=a.id,e=b.get(d),f=e.parse(a,c),_.isEqual(e.attributes,f)||e.set(f),e})},_requery:function(){this.props.get("query")&&this.mirror(d.get(this.props.toJSON()))},saveMenuOrder:function(){if("menuOrder"===this.props.get("orderby")){var a=this.chain().filter(function(a){return!_.isUndefined(a.id)}).map(function(a,b){return b+=1,a.set("menuOrder",b),[a.id,b]}).object().value();if(!_.isEmpty(a))return h.post("save-attachment-order",{nonce:h.model.settings.post.nonce,post_id:h.model.settings.post.id,attachments:a})}}},{comparator:function(a,b,c){var d=this.props.get("orderby"),e=this.props.get("order")||"DESC",g=a.cid,h=b.cid;return a=a.get(d),b=b.get(d),("date"===d||"modified"===d)&&(a=a||new Date,b=b||new Date),c&&c.ties&&(g=h=null),"DESC"===e?f(a,b,g,h):f(b,a,h,g)},filters:{search:function(a){return this.props.get("search")?_.any(["title","filename","description","caption","name"],function(b){var c=a.get(b);return c&&-1!==c.search(this.props.get("search"))},this):!0},type:function(a){var b=this.props.get("type");return!b||-1!==b.indexOf(a.get("type"))},uploadedTo:function(a){var b=this.props.get("uploadedTo");return _.isUndefined(b)?!0:b===a.get("uploadedTo")}}}),c.all=new c,h.query=function(a){return new c(null,{props:_.extend(_.defaults(a||{},{orderby:"date"}),{query:!0})})},d=h.model.Query=c.extend({initialize:function(a,b){var d;b=b||{},c.prototype.initialize.apply(this,arguments),this.args=b.args,this._hasMore=!0,this.created=new Date,this.filters.order=function(a){var b=this.props.get("orderby"),c=this.props.get("order");return this.comparator?this.length?1!==this.comparator(a,this.last(),{ties:!0}):"DESC"!==c||"date"!==b&&"modified"!==b?"ASC"===c&&"menuOrder"===b?0===a.get(b):!1:a.get(b)>=this.created:!0},d=["s","order","orderby","posts_per_page","post_mime_type","post_parent"],wp.Uploader&&_(this.args).chain().keys().difference(d).isEmpty().value()&&this.observe(wp.Uploader.queue)},hasMore:function(){return this._hasMore},more:function(b){var c=this;return this._more&&"pending"===this._more.state()?this._more:this.hasMore()?(b=b||{},b.remove=!1,this._more=this.fetch(b).done(function(a){(_.isEmpty(a)||-1===this.args.posts_per_page||a.lengthd?-1:1:a>b?-1:1},_.extend(h,{template:wp.template,post:wp.ajax.post,ajax:wp.ajax.send,fit:function(a){var b,c=a.width,d=a.height,e=a.maxWidth,f=a.maxHeight;return _.isUndefined(e)||_.isUndefined(f)?_.isUndefined(f)?b="width":_.isUndefined(e)&&d>f&&(b="height"):b=c/d>e/f?"width":"height","width"===b&&c>e?{width:e,height:Math.round(e*d/c)}:"height"===b&&d>f?{width:Math.round(f*c/d),height:f}:{width:c,height:d}},truncate:function(a,b,c){return b=b||30,c=c||"…",a.length<=b?a:a.substr(0,b/2)+c+a.substr(-1*b/2)}}),h.attachment=function(a){return b.get(a)},b=h.model.Attachment=Backbone.Model.extend({sync:function(b,c,d){return _.isUndefined(this.id)?a.Deferred().rejectWith(this).promise():"read"===b?(d=d||{},d.context=this,d.data=_.extend(d.data||{},{action:"get-attachment",id:this.id}),h.ajax(d)):"update"===b?this.get("nonces")&&this.get("nonces").update?(d=d||{},d.context=this,d.data=_.extend(d.data||{},{action:"save-attachment",id:this.id,nonce:this.get("nonces").update,post_id:h.model.settings.post.id}),c.hasChanged()&&(d.data.changes={},_.each(c.changed,function(a,b){d.data.changes[b]=this.get(b)},this)),h.ajax(d)):a.Deferred().rejectWith(this).promise():"delete"===b?(d=d||{},d.wait||(this.destroyed=!0),d.context=this,d.data=_.extend(d.data||{},{action:"delete-post",id:this.id,_wpnonce:this.get("nonces")["delete"]}),h.ajax(d).done(function(){this.destroyed=!0}).fail(function(){this.destroyed=!1})):Backbone.Model.prototype.sync.apply(this,arguments)},parse:function(a){return a?(a.date=new Date(a.date),a.modified=new Date(a.modified),a):a},saveCompat:function(b,c){var d=this;return this.get("nonces")&&this.get("nonces").update?h.post("save-attachment-compat",_.defaults({id:this.id,nonce:this.get("nonces").update,post_id:h.model.settings.post.id},b)).done(function(a,b,e){d.set(d.parse(a,e),c)}):a.Deferred().rejectWith(this).promise()}},{create:function(a){return c.all.push(a)},get:_.memoize(function(a,b){return c.all.push(b||{id:a})})}),e=h.model.PostImage=Backbone.Model.extend({initialize:function(c){this.attachment=!1,c.attachment_id&&(this.attachment=b.get(c.attachment_id),this.attachment.get("url")?(this.dfd=a.Deferred(),this.dfd.resolve()):this.dfd=this.attachment.fetch(),this.bindAttachmentListeners()),this.on("change:link",this.updateLinkUrl,this),this.on("change:size",this.updateSize,this),this.setLinkTypeFromUrl(),this.setAspectRatio(),this.set("originalUrl",c.url)},bindAttachmentListeners:function(){this.listenTo(this.attachment,"sync",this.setLinkTypeFromUrl),this.listenTo(this.attachment,"sync",this.setAspectRatio),this.listenTo(this.attachment,"change",this.updateSize)},changeAttachment:function(a,b){this.stopListening(this.attachment),this.attachment=a,this.bindAttachmentListeners(),this.set("attachment_id",this.attachment.get("id")),this.set("caption",this.attachment.get("caption")),this.set("alt",this.attachment.get("alt")),this.set("size",b.get("size")),this.set("align",b.get("align")),this.set("link",b.get("link")),this.updateLinkUrl(),this.updateSize()},setLinkTypeFromUrl:function(){var a,b=this.get("linkUrl");return b?(a="custom",this.attachment?this.attachment.get("url")===b?a="file":this.attachment.get("link")===b&&(a="post"):this.get("url")===b&&(a="file"),void this.set("link",a)):void this.set("link","none")},updateLinkUrl:function(){var a,b=this.get("link");switch(b){case"file":a=this.attachment?this.attachment.get("url"):this.get("url"),this.set("linkUrl",a);break;case"post":this.set("linkUrl",this.attachment.get("link"));break;case"none":this.set("linkUrl","")}},updateSize:function(){var a;if(this.attachment){if("custom"===this.get("size"))return this.set("width",this.get("customWidth")),this.set("height",this.get("customHeight")),void this.set("url",this.get("originalUrl"));a=this.attachment.get("sizes")[this.get("size")],a&&(this.set("url",a.url),this.set("width",a.width),this.set("height",a.height))}},setAspectRatio:function(){var a;return this.attachment&&this.attachment.get("sizes")&&(a=this.attachment.get("sizes").full)?void this.set("aspectRatio",a.width/a.height):void this.set("aspectRatio",this.get("customWidth")/this.get("customHeight"))}}),c=h.model.Attachments=Backbone.Collection.extend({model:b,initialize:function(a,b){b=b||{},this.props=new Backbone.Model,this.filters=b.filters||{},this.props.on("change",this._changeFilteredProps,this),this.props.on("change:order",this._changeOrder,this),this.props.on("change:orderby",this._changeOrderby,this),this.props.on("change:query",this._changeQuery,this),this.props.set(_.defaults(b.props||{})),b.observe&&this.observe(b.observe)},_changeOrder:function(){this.comparator&&this.sort()},_changeOrderby:function(a,b){this.comparator&&this.comparator!==c.comparator||(b&&"post__in"!==b?this.comparator=c.comparator:delete this.comparator)},_changeQuery:function(a,b){b?(this.props.on("change",this._requery,this),this._requery()):this.props.off("change",this._requery,this)},_changeFilteredProps:function(a){if(!this.props.get("query")){var b=_.chain(a.changed).map(function(b,d){var e=c.filters[d],f=a.get(d);if(e){if(f&&!this.filters[d])this.filters[d]=e;else{if(f||this.filters[d]!==e)return;delete this.filters[d]}return!0}},this).any().value();b&&(this._source||(this._source=new c(this.models)),this.reset(this._source.filter(this.validator,this)))}},validateDestroyed:!1,validator:function(a){return!this.validateDestroyed&&a.destroyed?!1:_.all(this.filters,function(b){return!!b.call(this,a)},this)},validate:function(a,b){var c=this.validator(a),d=!!this.get(a.cid);return!c&&d?this.remove(a,b):c&&!d&&this.add(a,b),this},validateAll:function(a,b){return b=b||{},_.each(a.models,function(a){this.validate(a,{silent:!0})},this),b.silent||this.trigger("reset",this,b),this},observe:function(a){return this.observers=this.observers||[],this.observers.push(a),a.on("add change remove",this._validateHandler,this),a.on("reset",this._validateAllHandler,this),this.validateAll(a),this},unobserve:function(a){return a?(a.off(null,null,this),this.observers=_.without(this.observers,a)):(_.each(this.observers,function(a){a.off(null,null,this)},this),delete this.observers),this},_validateHandler:function(a,b,c){return c=b===this.mirroring?c:{silent:c&&c.silent},this.validate(a,c)},_validateAllHandler:function(a,b){return this.validateAll(a,b)},mirror:function(a){return this.mirroring&&this.mirroring===a?this:(this.unmirror(),this.mirroring=a,this.reset([],{silent:!0}),this.observe(a),this)},unmirror:function(){this.mirroring&&(this.unobserve(this.mirroring),delete this.mirroring)},more:function(b){var c=a.Deferred(),d=this.mirroring,e=this;return d&&d.more?(d.more(b).done(function(){this===e.mirroring&&c.resolveWith(this)}),c.promise()):c.resolveWith(this).promise()},hasMore:function(){return this.mirroring?this.mirroring.hasMore():!1},parse:function(a,c){return _.isArray(a)||(a=[a]),_.map(a,function(a){var d,e,f;return a instanceof Backbone.Model?(d=a.get("id"),a=a.attributes):d=a.id,e=b.get(d),f=e.parse(a,c),_.isEqual(e.attributes,f)||e.set(f),e})},_requery:function(){this.props.get("query")&&this.mirror(d.get(this.props.toJSON()))},saveMenuOrder:function(){if("menuOrder"===this.props.get("orderby")){var a=this.chain().filter(function(a){return!_.isUndefined(a.id)}).map(function(a,b){return b+=1,a.set("menuOrder",b),[a.id,b]}).object().value();if(!_.isEmpty(a))return h.post("save-attachment-order",{nonce:h.model.settings.post.nonce,post_id:h.model.settings.post.id,attachments:a})}}},{comparator:function(a,b,c){var d=this.props.get("orderby"),e=this.props.get("order")||"DESC",g=a.cid,h=b.cid;return a=a.get(d),b=b.get(d),("date"===d||"modified"===d)&&(a=a||new Date,b=b||new Date),c&&c.ties&&(g=h=null),"DESC"===e?f(a,b,g,h):f(b,a,h,g)},filters:{search:function(a){return this.props.get("search")?_.any(["title","filename","description","caption","name"],function(b){var c=a.get(b);return c&&-1!==c.search(this.props.get("search"))},this):!0},type:function(a){var b=this.props.get("type");return!b||-1!==b.indexOf(a.get("type"))},uploadedTo:function(a){var b=this.props.get("uploadedTo");return _.isUndefined(b)?!0:b===a.get("uploadedTo")}}}),c.all=new c,h.query=function(a){return new c(null,{props:_.extend(_.defaults(a||{},{orderby:"date"}),{query:!0})})},d=h.model.Query=c.extend({initialize:function(a,b){var d;b=b||{},c.prototype.initialize.apply(this,arguments),this.args=b.args,this._hasMore=!0,this.created=new Date,this.filters.order=function(a){var b=this.props.get("orderby"),c=this.props.get("order");return this.comparator?this.length?1!==this.comparator(a,this.last(),{ties:!0}):"DESC"!==c||"date"!==b&&"modified"!==b?"ASC"===c&&"menuOrder"===b?0===a.get(b):!1:a.get(b)>=this.created:!0},d=["s","order","orderby","posts_per_page","post_mime_type","post_parent"],wp.Uploader&&_(this.args).chain().keys().difference(d).isEmpty().value()&&this.observe(wp.Uploader.queue)},hasMore:function(){return this._hasMore},more:function(b){var c=this;return this._more&&"pending"===this._more.state()?this._more:this.hasMore()?(b=b||{},b.remove=!1,this._more=this.fetch(b).done(function(a){(_.isEmpty(a)||-1===this.args.posts_per_page||a.length