WordPress/wp-includes/js/media-grid.min.js

1 line
10 KiB
JavaScript

!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:"",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)),a(document).on("screen:options:open",b.bind(this.screenOptionsOpen,this)),a(document).on("screen:options:close",b.bind(this.screenOptionsClose,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)},screenOptionsOpen:function(){this.$el.addClass("media-grid-view-options")},screenOptionsClose:function(){this.$el.removeClass("media-grid-view-options")},createRouter:function(){this.gridRouter=new f.view.MediaFrame.Manage.Router,window.history&&window.history.pushState&&c.history.start({root:_wpMediaGridSettings.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"}),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(a){a.preventDefault(),this.trigger("toggle:upload:attachment")},editAttachment:function(a){d.media({frame:"edit-attachments",gridRouter:this.gridRouter,library:this.state().get("library"),model: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:title",this._syncTitle,this),this.model.on("change:caption",this._syncCaption,this),this.model.on("change:percent",this.progress,this),this.model.on("change:album",this._syncAlbum,this),this.model.on("change:artist",this._syncArtist,this),this.model.on("add",this.select,this),this.model.on("remove",this.deselect,this),this.model.on("sync",this.afterDelete,this))},preDestroy:function(a){a.preventDefault(),this.lastIndex=this.controller.getCurrentIndex(),this.hasNext=this.controller.hasNext()},trashAttachment:function(a){this.preDestroy(a),f.view.Attachment.Details.prototype.trashAttachment.apply(this,arguments)},deleteAttachment:function(a){this.preDestroy(a),f.view.Attachment.Details.prototype.deleteAttachment.apply(this,arguments)},afterDelete:function(a){if(a.destroyed){var b=this.controller,c=this.lastIndex;if(!b.library.length)return void f.frame.modal.close();this.hasNext&&(c-=1),b.model=b.library.at(c),b.nextMediaItem()}},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),this.on("close",this.detach),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.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"),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.model?this.gridRouter.navigate(this.gridRouter.baseUrl("?item="+this.model.id)):this.resetRoute()},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:e.editMetadata,priority:20}}),"undefined"!=typeof this.model&&"image"===this.model.get("type")&&a.set({"edit-image":{text:e.editImage,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<this.library.length},hasPrevious:function(){return this.getCurrentIndex()-1>-1},keyEvent:function(b){var c=a(b.target);return 27===b.keyCode?(this.resetRoute(),b):c.is("input")||c.is("textarea")?b:(39===b.keyCode&&this.nextMediaItem(),void(37===b.keyCode&&this.previousMediaItem()))},resetRoute:function(){this.gridRouter.navigate(this.gridRouter.baseUrl(""))}}),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").activateMode("edit"):this.controller.deactivateMode("edit").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);