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

3 lines
82 KiB
JavaScript
Raw Normal View History

!function(a,b){var c,d=wp.media;c=d.view.l10n="undefined"==typeof _wpMediaViewsL10n?{}:_wpMediaViewsL10n,d.view.settings=c.settings||{},delete c.settings,d.model.settings.post=d.view.settings.post,a.support.transition=function(){var a,c=document.documentElement.style,d={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};return a=b.find(b.keys(d),function(a){return!b.isUndefined(c[a])}),a&&{end:d[a]}}(),d.events=b.extend({},Backbone.Events),d.transition=function(c,d){var e=a.Deferred();return d=d||2e3,a.support.transition?(c instanceof a||(c=a(c)),c.first().one(a.support.transition.end,e.resolve),b.delay(e.resolve,d)):e.resolve(),e.promise()},d.controller.Region=function(a){b.extend(this,b.pick(a||{},"id","view","selector"))},d.controller.Region.extend=Backbone.Model.extend,b.extend(d.controller.Region.prototype,{mode:function(a){return a?a===this._mode?this:(this.trigger("deactivate"),this._mode=a,this.render(a),this.trigger("activate"),this):this._mode},render:function(a){if(a&&a!==this._mode)return this.mode(a);var b,c={view:null};return this.trigger("create",c),b=c.view,this.trigger("render",b),b&&this.set(b),this},get:function(){return this.view.views.first(this.selector)},set:function(a,b){return b&&(b.add=!1),this.view.views.set(this.selector,a,b)},trigger:function(a){var c,d;if(this._mode)return d=b.toArray(arguments),c=this.id+":"+a,d[0]=c+":"+this._mode,this.view.trigger.apply(this.view,d),d[0]=c,this.view.trigger.apply(this.view,d),this}}),d.controller.StateMachine=function(a){this.states=new Backbone.Collection(a)},d.controller.StateMachine.extend=Backbone.Model.extend,b.extend(d.controller.StateMachine.prototype,Backbone.Events,{state:function(a){return this.states=this.states||new Backbone.Collection,a=a||this._state,a&&!this.states.get(a)&&this.states.add({id:a}),this.states.get(a)},setState:function(a){var b=this.state();return b&&a===b.id||!this.states||!this.states.get(a)?this:(b&&(b.trigger("deactivate"),this._lastState=b.id),this._state=a,this.state().trigger("activate"),this)},lastState:function(){return this._lastState?this.state(this._lastState):void 0}}),b.each(["on","off","trigger"],function(a){d.controller.StateMachine.prototype[a]=function(){return this.states=this.states||new Backbone.Collection,this.states[a].apply(this.states,arguments),this}}),d.controller._State=Backbone.Model.extend({constructor:function(){this.on("activate",this._preActivate,this),this.on("activate",this.activate,this),this.on("activate",this._postActivate,this),this.on("deactivate",this._deactivate,this),this.on("deactivate",this.deactivate,this),this.on("reset",this.reset,this),this.on("ready",this.ready,this),Backbone.Model.apply(this,arguments)},ready:function(){},activate:function(){},deactivate:function(){},reset:function(){},_preActivate:function(){this.active=!0},_postActivate:function(){},_deactivate:function(){this.active=!1}}),d.controller.State=d.controller._State.extend({constructor:function(){this.on("activate",this._preActivate,this),this.on("activate",this.activate,this),this.on("activate",this._postActivate,this),this.on("deactivate",this._deactivate,this),this.on("deactivate",this.deactivate,this),this.on("reset",this.reset,this),this.on("ready",this._ready,this),this.on("ready",this.ready,this),Backbone.Model.apply(this,arguments),this.on("change:menu",this._updateMenu,this)},_ready:function(){this._updateMenu()},_postActivate:function(){this.on("change:menu",this._menu,this),this.on("change:titleMode",this._title,this),this.on("change:content",this._content,this),this.on("change:toolbar",this._toolbar,this),this.frame.on("title:render:default",this._renderTitle,this),this._title(),this._menu(),this._toolbar(),this._content(),this._router()},_deactivate:function(){this.active=!1,this.frame.off("title:render:default",this._renderTitle,this),this.off("change:menu",this._menu,this),this.off("change:titleMode",this._title,this),this.off("change:content",this._content,this),this.off("change:toolbar",this._toolbar,this)
}})},mainVideoPlaylistToolbar:function(a){var b=this;this.selectionStatusToolbar(a),a.set("video-playlist",{style:"primary",text:c.createNewVideoPlaylist,priority:100,requires:{selection:!0},click:function(){var a=b.state().get("selection"),c=b.state("video-playlist-edit"),e=a.where({type:"video"});c.set("library",new d.model.Selection(e,{props:a.props.toJSON(),multiple:!0})),this.controller.setState("video-playlist-edit"),new d.view.FocusManager({el:this.el}).focus()}})},featuredImageToolbar:function(a){this.createSelectToolbar(a,{text:c.setFeaturedImage,state:this.options.state})},mainEmbedToolbar:function(a){a.view=new d.view.Toolbar.Embed({controller:this})},galleryEditToolbar:function(){var a=this.state().get("editing");this.toolbar.set(new d.view.Toolbar({controller:this,items:{insert:{style:"primary",text:a?c.updateGallery:c.insertGallery,priority:80,requires:{library:!0},click:function(){var a=this.controller,b=a.state();a.close(),b.trigger("update",b.get("library")),a.setState(a.options.state),a.reset()}}}}))},galleryAddToolbar:function(){this.toolbar.set(new d.view.Toolbar({controller:this,items:{insert:{style:"primary",text:c.addToGallery,priority:80,requires:{selection:!0},click:function(){var a=this.controller,b=a.state(),c=a.state("gallery-edit");c.get("library").add(b.get("selection").models),b.trigger("reset"),a.setState("gallery-edit")}}}}))},playlistEditToolbar:function(){var a=this.state().get("editing");this.toolbar.set(new d.view.Toolbar({controller:this,items:{insert:{style:"primary",text:a?c.updatePlaylist:c.insertPlaylist,priority:80,requires:{library:!0},click:function(){var a=this.controller,b=a.state();a.close(),b.trigger("update",b.get("library")),a.setState(a.options.state),a.reset()}}}}))},playlistAddToolbar:function(){this.toolbar.set(new d.view.Toolbar({controller:this,items:{insert:{style:"primary",text:c.addToPlaylist,priority:80,requires:{selection:!0},click:function(){var a=this.controller,b=a.state(),c=a.state("playlist-edit");c.get("library").add(b.get("selection").models),b.trigger("reset"),a.setState("playlist-edit")}}}}))},videoPlaylistEditToolbar:function(){var a=this.state().get("editing");this.toolbar.set(new d.view.Toolbar({controller:this,items:{insert:{style:"primary",text:a?c.updateVideoPlaylist:c.insertVideoPlaylist,priority:140,requires:{library:!0},click:function(){var a=this.controller,b=a.state(),c=b.get("library");c.type="video",a.close(),b.trigger("update",c),a.setState(a.options.state),a.reset()}}}}))},videoPlaylistAddToolbar:function(){this.toolbar.set(new d.view.Toolbar({controller:this,items:{insert:{style:"primary",text:c.addToVideoPlaylist,priority:140,requires:{selection:!0},click:function(){var a=this.controller,b=a.state(),c=a.state("video-playlist-edit");c.get("library").add(b.get("selection").models),b.trigger("reset"),a.setState("video-playlist-edit")}}}}))}}),d.view.MediaFrame.ImageDetails=d.view.MediaFrame.Select.extend({defaults:{id:"image",url:"",menu:"image-details",content:"image-details",toolbar:"image-details",type:"link",title:c.imageDetailsTitle,priority:120},initialize:function(a){this.image=new d.model.PostImage(a.metadata),this.options.selection=new d.model.Selection(this.image.attachment,{multiple:!1}),d.view.MediaFrame.Select.prototype.initialize.apply(this,arguments)},bindHandlers:function(){d.view.MediaFrame.Select.prototype.bindHandlers.apply(this,arguments),this.on("menu:create:image-details",this.createMenu,this),this.on("content:create:image-details",this.imageDetailsContent,this),this.on("content:render:edit-image",this.editImageContent,this),this.on("menu:render:image-details",this.renderMenu,this),this.on("toolbar:render:image-details",this.renderImageDetailsToolbar,this),this.on("toolbar:render:replace",this.renderReplaceImageToolbar,this)},createStates:function(){this.states.add([new d.controller.ImageDetails({image:this.image,editable:!1,menu:"image-details"}),new d.controller.ReplaceImage({id:"replace-image",library:d.query({type:"image"}),image:this.image,multiple:!1,title:c.imageReplaceTitle,menu:"image-details",toolbar:"rep
e&&b&&(a=e[b]),this.filters={all:{text:a||c.allMediaItems,props:{uploadedTo:null,orderby:"date",order:"DESC"},priority:10},uploaded:{text:c.uploadedToThisPost,props:{uploadedTo:d.view.settings.post.id,orderby:"menuOrder",order:"ASC"},priority:20}}}}),d.view.AttachmentFilters.All=d.view.AttachmentFilters.extend({createFilters:function(){var a={};b.each(d.view.settings.mimeTypes||{},function(b,c){a[c]={text:b,props:{type:c,uploadedTo:null,orderby:"date",order:"DESC"}}}),a.all={text:c.allMediaItems,props:{type:null,uploadedTo:null,orderby:"date",order:"DESC"},priority:10},a.uploaded={text:c.uploadedToThisPost,props:{type:null,uploadedTo:d.view.settings.post.id,orderby:"menuOrder",order:"ASC"},priority:20},this.filters=a}}),d.view.AttachmentFilters.mimeTypes=d.view.AttachmentFilters.extend({createFilters:function(){var a={};b.each(d.view.settings.mimeTypes||{},function(b,c){a[c]={text:b,props:{type:c,uploadedTo:null,orderby:"date",order:"DESC"}}}),a.all={text:c.allMediaTypes,props:{type:null,uploadedTo:null,orderby:"date",order:"DESC"},priority:10},this.filters=a}}),d.view.AttachmentsBrowser=d.View.extend({tagName:"div",className:"attachments-browser",initialize:function(){b.defaults(this.options,{filters:!1,search:!0,display:!1,sidebar:!0,showAttachmentFields:getUserSetting("showAttachmentFields",["title","uploadedTo","dateFormatted","mime"]),AttachmentView:d.view.Attachment.Library}),this.createToolbar(),this.updateContent(),this.options.sidebar?this.createSidebar():this.$el.addClass("hide-sidebar"),this.collection.on("add remove reset",this.updateContent,this)},dispose:function(){return this.options.selection.off(null,null,this),d.View.prototype.dispose.apply(this,arguments),this},createToolbar:function(){var e,f,g,h;this.toolbar=new d.view.Toolbar({controller:this.controller}),this.views.add(this.toolbar),b.contains(this.controller.options.mode,"grid")&&(f=d.View.extend({className:"view-switch media-grid-view-switch",template:d.template("media-library-view-switcher")}),this.toolbar.set("libraryViewSwitcher",new f({controller:this.controller,priority:-90}).render()),this.toolbar.set("gridFieldOptions",new d.view.GridFieldOptions({controller:this.controller,priority:-50}).render())),e=this.options.filters,"uploaded"===e?g=d.view.AttachmentFilters.Uploaded:"all"===e?g=d.view.AttachmentFilters.All:"mime-types"===e&&(g=d.view.AttachmentFilters.mimeTypes),g&&(this.toolbar.set("filters",new g({controller:this.controller,model:this.collection.props,priority:-80}).render()),h=a('<label class="screen-reader-text" for="media-attachment-filters">'+c.select+"</label>"),this.toolbar.get("filters").$el.before(h)),this.toolbar.set("spinner",new d.view.Spinner({priority:-70})),this.options.search&&(this.toolbar.set("search",new d.view.Search({controller:this.controller,model:this.collection.props,priority:60}).render()),h=a('<label class="screen-reader-text" for="media-search-input">'+c.search+"</label>"),this.toolbar.get("search").$el.before(h)),this.options.dragInfo&&this.toolbar.set("dragInfo",new d.View({el:a('<div class="instructions">'+c.dragInfo+"</div>")[0],priority:-40})),this.options.suggestedWidth&&this.options.suggestedHeight&&this.toolbar.set("suggestedDimensions",new d.View({el:a('<div class="instructions">'+c.suggestedDimensions+" "+this.options.suggestedWidth+" &times; "+this.options.suggestedHeight+"</div>")[0],priority:-40}))},updateContent:function(){var a=this;this.attachments||this.createAttachments(),this.collection.length?a.toolbar.get("spinner").hide():(this.toolbar.get("spinner").show(),this.collection.more().done(function(){a.collection.length||a.createUploader(),a.toolbar.get("spinner").hide()}))},removeContent:function(){b.each(["attachments","uploader"],function(a){this[a]&&(this[a].remove(),delete this[a])},this)},createUploader:function(){this.removeContent(),this.uploader=new d.view.UploaderInline({controller:this.controller,status:!1,message:c.noItemsFound}),this.views.add(this.uploader)},createAttachments:function(){this.removeContent(),this.attachments=new d.view.Attachments({controller:this.controller