diff --git a/wp-includes/js/media-grid.js b/wp-includes/js/media-grid.js index 91ebab12a3..2df661b091 100644 --- a/wp-includes/js/media-grid.js +++ b/wp-includes/js/media-grid.js @@ -238,7 +238,7 @@ editAttachment: function( event ) { event.preventDefault(); - this.controller.setState( 'edit-image' ); + this.controller.content.mode( 'edit-image' ); }, /** @@ -288,6 +288,27 @@ } }); + media.view.EditImage.Details = media.view.EditImage.extend({ + initialize: function( options ) { + this.editor = window.imageEdit; + this.frame = options.frame; + this.controller = options.controller; + media.View.prototype.initialize.apply( this, arguments ); + }, + + back: function() { + this.frame.content.mode( 'edit-metadata' ); + }, + + save: function() { + var self = this; + + this.model.fetch().done( function() { + self.frame.content.mode( 'edit-metadata' ); + }); + } + }); + /** * A frame for editing the details of a specific media item. * @@ -342,6 +363,7 @@ this.on( 'content:create:edit-metadata', this.editMetadataMode, this ); this.on( 'content:create:edit-image', this.editImageMode, this ); + this.on( 'content:render:edit-image', this.editImageModeRender, this ); this.on( 'close', this.detach ); // Bind default title creation. @@ -381,15 +403,8 @@ * Add the default states to the frame. */ createStates: function() { - var editImageState = new media.controller.EditImage( { model: this.model } ); - // Noop some methods. - editImageState._toolbar = function() {}; - editImageState._router = function() {}; - editImageState._menu = function() {}; this.states.add([ - new media.controller.EditAttachmentMetadata( { model: this.model } ), - editImageState - + new media.controller.EditAttachmentMetadata( { model: this.model } ) ]); }, @@ -427,10 +442,24 @@ * should be set with the proper region view. */ editImageMode: function( contentRegion ) { - contentRegion.view = new media.view.EditImage( { model: this.model, controller: this } ); - // Defer a call to load the editor, which - // requires DOM elements to exist. - _.defer( _.bind( contentRegion.view.loadEditor, contentRegion.view ) ); + var editImageController = new media.controller.EditImage( { + model: this.model, + frame: this + } ); + // Noop some methods. + editImageController._toolbar = function() {}; + editImageController._router = function() {}; + editImageController._menu = function() {}; + + contentRegion.view = new media.view.EditImage.Details( { + model: this.model, + frame: this, + controller: editImageController + } ); + }, + + editImageModeRender: function( view ) { + view.on( 'ready', view.loadEditor ); }, /** diff --git a/wp-includes/js/media-grid.min.js b/wp-includes/js/media-grid.min.js index a6d5145d90..4299894e46 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"]}),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",contentUserSetting:!1,filterable:"all"})])},bindRegionModeHandlers:function(){this.on("content:create:browse",this.browseContent,this),this.on("edit:attachment",this.openEditAttachmentModal,this)},addNewClickHandler:function(a){a.preventDefault(),this.trigger("toggle:upload:attachment")},openEditAttachmentModal:function(a){d.media({frame:"edit-attachments",gridRouter:this.gridRouter,library:this.state().get("library"),model:a})},browseContent:function(a){var c=this.state();this.browserView=a.view=new f.view.AttachmentsBrowser({controller:this,collection:c.get("library"),selection:c.get("selection"),model:c,sortable:c.get("sortable"),search:c.get("searchable"),filters:c.get("filterable"),display:c.get("displaySettings"),dragInfo:c.get("dragInfo"),sidebar:"errors",suggestedWidth:c.get("suggestedWidth"),suggestedHeight:c.get("suggestedHeight"),AttachmentView:c.get("AttachmentView"),scrollElement:document}),this.browserView.on("ready",b.bind(this.bindDeferred,this)),this.errors=d.Uploader.errors,this.errors.on("add remove reset",this.sidebarVisibility,this)},sidebarVisibility:function(){this.browserView.$(".media-sidebar").toggle(this.errors.length)},bindDeferred:function(){this.browserView.dfd.done(b.bind(this.startHistory,this))},startHistory:function(){window.history&&window.history.pushState&&c.history.start({root:_wpMediaGridSettings.adminUrl,pushState:!0})}}),f.view.Attachment.Details.TwoColumn=f.view.Attachment.Details.extend({template:f.template("attachment-details-two-column"),editAttachment:function(a){a.preventDefault(),this.controller.setState("edit-image")},toggleSelectionHandler:function(){},render:function(){f.view.Attachment.Details.prototype.render.apply(this,arguments),f.mixin.removeAllPlayers(),this.$("audio, video").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"},baseUrl:function(a){return"upload.php"+a},search:function(b){a("#media-search-input").val(b).trigger("input")},showItem:function(a){var b=f.frame.state().get("library");f.frame.trigger("edit:attachment",b.findWhere({id:parseInt(a,10)}))}}),f.view.MediaFrame.EditAttachments=f.view.MediaFrame.extend({className:"edit-attachment-frame",template:f.template("edit-attachment-frame"),regions:["title","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.listenTo(this.model,"destroy",this.close,this),this.createStates(),this.on("content:create:edit-metadata",this.editMetadataMode,this),this.on("content:create:edit-image",this.editImageMode,this),this.on("close",this.detach),this.on("title:create:default",this.createTitle,this),this.title.mode("default"),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.on("open",function(){a("body").on("keydown.media-modal",b.bind(c.keyEvent,c))}),this.modal.on("close",function(){c.modal.remove(),a("body").off("keydown.media-modal"),a('li.attachment[data-id="'+c.model.get("id")+'"]').focus(),c.resetRoute()}),this.modal.content(this),this.modal.open())},createStates:function(){var a=new f.controller.EditImage({model:this.model});a._toolbar=function(){},a._router=function(){},a._menu=function(){},this.states.add([new f.controller.EditAttachmentMetadata({model:this.model}),a])},editMetadataMode:function(a){a.view=new f.view.Attachment.Details.TwoColumn({controller:this,model:this.model}),a.view.views.set(".attachment-compat",new f.view.AttachmentCompat({controller:this,model:this.model})),this.model&&this.gridRouter.navigate(this.gridRouter.baseUrl("?item="+this.model.id))},editImageMode:function(a){a.view=new f.view.EditImage({model:this.model,controller:this}),b.defer(b.bind(a.view.loadEditor,a.view))},rerender:function(){"edit-metadata"!==this.content.mode()?this.content.mode("edit-metadata"):this.content.render(),this.$(".left").toggleClass("disabled",!this.hasPrevious()),this.$(".right").toggleClass("disabled",!this.hasNext())},previousMediaItem:function(){this.hasPrevious()&&(this.model=this.library.at(this.getCurrentIndex()-1),this.rerender())},nextMediaItem:function(){this.hasNext()&&(this.model=this.library.at(this.getCurrentIndex()+1),this.rerender())},getCurrentIndex:function(){return this.library.indexOf(this.model)},hasNext:function(){return this.getCurrentIndex()+1-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.BulkSelection=f.View.extend({className:"bulk-select",initialize:function(){this.model=new c.Model({currentAction:""}),this.views.add(new f.view.Label({value:e.bulkActionsLabel,attributes:{"for":"bulk-select-dropdown"}})),this.views.add(new f.view.BulkSelectionActionDropdown({controller:this})),this.views.add(new f.view.BulkSelectionActionButton({disabled:!0,text:e.apply,controller:this}))}}),f.view.BulkSelectionActionDropdown=f.View.extend({tagName:"select",id:"bulk-select-dropdown",initialize:function(){f.view.Button.prototype.initialize.apply(this,arguments),this.listenTo(this.controller.controller.state().get("selection"),"add remove reset",b.bind(this.enabled,this)),this.$el.append(a("").val("").html(e.bulkActions)).append(a("").val("delete").html(e.deletePermanently)),this.$el.prop("disabled",!0),this.$el.on("change",b.bind(this.changeHandler,this))},changeHandler:function(){this.controller.model.set({currentAction:this.$el.val()})},enabled:function(){var a=!this.controller.controller.state().get("selection").length;this.$el.prop("disabled",a)}}),f.view.BulkSelectionActionButton=f.view.Button.extend({tagName:"button",initialize:function(){f.view.Button.prototype.initialize.apply(this,arguments),this.listenTo(this.controller.model,"change",this.enabled,this),this.listenTo(this.controller.controller.state().get("selection"),"add remove reset",b.bind(this.enabled,this))},click:function(){var a=this.controller.controller.state().get("selection");if(f.view.Button.prototype.click.apply(this,arguments),"delete"===this.controller.model.get("currentAction")&&confirm(e.warnBulkDelete))for(;a.length>0;)a.at(0).destroy();this.enabled()},enabled:function(){var a=this.controller.model.get("currentAction"),b=this.controller.controller.state().get("selection"),c=!a||!b.length;this.$el.prop("disabled",c)}}),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"]}),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",contentUserSetting:!1,filterable:"all"})])},bindRegionModeHandlers:function(){this.on("content:create:browse",this.browseContent,this),this.on("edit:attachment",this.openEditAttachmentModal,this)},addNewClickHandler:function(a){a.preventDefault(),this.trigger("toggle:upload:attachment")},openEditAttachmentModal:function(a){d.media({frame:"edit-attachments",gridRouter:this.gridRouter,library:this.state().get("library"),model:a})},browseContent:function(a){var c=this.state();this.browserView=a.view=new f.view.AttachmentsBrowser({controller:this,collection:c.get("library"),selection:c.get("selection"),model:c,sortable:c.get("sortable"),search:c.get("searchable"),filters:c.get("filterable"),display:c.get("displaySettings"),dragInfo:c.get("dragInfo"),sidebar:"errors",suggestedWidth:c.get("suggestedWidth"),suggestedHeight:c.get("suggestedHeight"),AttachmentView:c.get("AttachmentView"),scrollElement:document}),this.browserView.on("ready",b.bind(this.bindDeferred,this)),this.errors=d.Uploader.errors,this.errors.on("add remove reset",this.sidebarVisibility,this)},sidebarVisibility:function(){this.browserView.$(".media-sidebar").toggle(this.errors.length)},bindDeferred:function(){this.browserView.dfd.done(b.bind(this.startHistory,this))},startHistory:function(){window.history&&window.history.pushState&&c.history.start({root:_wpMediaGridSettings.adminUrl,pushState:!0})}}),f.view.Attachment.Details.TwoColumn=f.view.Attachment.Details.extend({template:f.template("attachment-details-two-column"),editAttachment:function(a){a.preventDefault(),this.controller.content.mode("edit-image")},toggleSelectionHandler:function(){},render:function(){f.view.Attachment.Details.prototype.render.apply(this,arguments),f.mixin.removeAllPlayers(),this.$("audio, video").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"},baseUrl:function(a){return"upload.php"+a},search:function(b){a("#media-search-input").val(b).trigger("input")},showItem:function(a){var b=f.frame.state().get("library");f.frame.trigger("edit:attachment",b.findWhere({id:parseInt(a,10)}))}}),f.view.EditImage.Details=f.view.EditImage.extend({initialize:function(a){this.editor=window.imageEdit,this.frame=a.frame,this.controller=a.controller,f.View.prototype.initialize.apply(this,arguments)},back:function(){this.frame.content.mode("edit-metadata")},save:function(){var a=this;this.model.fetch().done(function(){a.frame.content.mode("edit-metadata")})}}),f.view.MediaFrame.EditAttachments=f.view.MediaFrame.extend({className:"edit-attachment-frame",template:f.template("edit-attachment-frame"),regions:["title","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.listenTo(this.model,"destroy",this.close,this),this.createStates(),this.on("content:create:edit-metadata",this.editMetadataMode,this),this.on("content:create:edit-image",this.editImageMode,this),this.on("content:render:edit-image",this.editImageModeRender,this),this.on("close",this.detach),this.on("title:create:default",this.createTitle,this),this.title.mode("default"),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.on("open",function(){a("body").on("keydown.media-modal",b.bind(c.keyEvent,c))}),this.modal.on("close",function(){c.modal.remove(),a("body").off("keydown.media-modal"),a('li.attachment[data-id="'+c.model.get("id")+'"]').focus(),c.resetRoute()}),this.modal.content(this),this.modal.open())},createStates:function(){this.states.add([new f.controller.EditAttachmentMetadata({model:this.model})])},editMetadataMode:function(a){a.view=new f.view.Attachment.Details.TwoColumn({controller:this,model:this.model}),a.view.views.set(".attachment-compat",new f.view.AttachmentCompat({controller:this,model:this.model})),this.model&&this.gridRouter.navigate(this.gridRouter.baseUrl("?item="+this.model.id))},editImageMode:function(a){var b=new f.controller.EditImage({model:this.model,frame:this});b._toolbar=function(){},b._router=function(){},b._menu=function(){},a.view=new f.view.EditImage.Details({model:this.model,frame:this,controller:b})},editImageModeRender:function(a){a.on("ready",a.loadEditor)},rerender:function(){"edit-metadata"!==this.content.mode()?this.content.mode("edit-metadata"):this.content.render(),this.$(".left").toggleClass("disabled",!this.hasPrevious()),this.$(".right").toggleClass("disabled",!this.hasNext())},previousMediaItem:function(){this.hasPrevious()&&(this.model=this.library.at(this.getCurrentIndex()-1),this.rerender())},nextMediaItem:function(){this.hasNext()&&(this.model=this.library.at(this.getCurrentIndex()+1),this.rerender())},getCurrentIndex:function(){return this.library.indexOf(this.model)},hasNext:function(){return this.getCurrentIndex()+1-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.BulkSelection=f.View.extend({className:"bulk-select",initialize:function(){this.model=new c.Model({currentAction:""}),this.views.add(new f.view.Label({value:e.bulkActionsLabel,attributes:{"for":"bulk-select-dropdown"}})),this.views.add(new f.view.BulkSelectionActionDropdown({controller:this})),this.views.add(new f.view.BulkSelectionActionButton({disabled:!0,text:e.apply,controller:this}))}}),f.view.BulkSelectionActionDropdown=f.View.extend({tagName:"select",id:"bulk-select-dropdown",initialize:function(){f.view.Button.prototype.initialize.apply(this,arguments),this.listenTo(this.controller.controller.state().get("selection"),"add remove reset",b.bind(this.enabled,this)),this.$el.append(a("").val("").html(e.bulkActions)).append(a("").val("delete").html(e.deletePermanently)),this.$el.prop("disabled",!0),this.$el.on("change",b.bind(this.changeHandler,this))},changeHandler:function(){this.controller.model.set({currentAction:this.$el.val()})},enabled:function(){var a=!this.controller.controller.state().get("selection").length;this.$el.prop("disabled",a)}}),f.view.BulkSelectionActionButton=f.view.Button.extend({tagName:"button",initialize:function(){f.view.Button.prototype.initialize.apply(this,arguments),this.listenTo(this.controller.model,"change",this.enabled,this),this.listenTo(this.controller.controller.state().get("selection"),"add remove reset",b.bind(this.enabled,this))},click:function(){var a=this.controller.controller.state().get("selection");if(f.view.Button.prototype.click.apply(this,arguments),"delete"===this.controller.model.get("currentAction")&&confirm(e.warnBulkDelete))for(;a.length>0;)a.at(0).destroy();this.enabled()},enabled:function(){var a=this.controller.model.get("currentAction"),b=this.controller.controller.state().get("selection"),c=!a||!b.length;this.$el.prop("disabled",c)}}),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