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

1 line
11 KiB
JavaScript
Raw Normal View History

!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.$body=a(document.body),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",autoSelect:!1})])},bindRegionModeHandlers:function(){this.on("content:create:browse",this.browseContent,this),this.on("edit:attachment",this.openEditAttachmentModal,this),this.on("select:activate",this.bindKeydown,this),this.on("select:deactivate",this.unbindKeydown,this)},handleKeydown:function(a){27===a.which&&(a.preventDefault(),this.deactivateMode("select").activateMode("edit"))},bindKeydown:function(){this.$body.on("keydown.select",b.bind(this.handleKeydown,this))},unbindKeydown:function(){this.$body.off("keydown.select")},fixPosition:function(){var a,b;this.isModeActive("select")&&(a=this.$(".attachments-browser"),b=a.find(".media-toolbar"),a.offset().top+16<this.$window.scrollTop()+this.$adminBar.height()?(a.addClass("fixed"),b.css("width",a.width()+"px")):(a.removeClass("fixed"),b.css("width","")))},addNewClickHandler:function(a){a.preventDefault(),this.trigger("toggle:upload:attachment")},openEditAttachmentModal:function(a){d.media({frame:"edit-attachments",controller:this,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&&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.a