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

1 line
24 KiB
JavaScript
Raw Normal View History

(function(e){var f=wp.media,d=f.model.Attachment,c=f.model.Attachments,a=f.model.Query,b;b=f.view.l10n=_.isUndefined(_wpMediaViewsL10n)?{}:_wpMediaViewsL10n;e.support.transition=(function(){var g=document.documentElement.style,h={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"},i;i=_.find(_.keys(h),function(j){return !_.isUndefined(g[j])});return i&&{end:h[i]}}());f.transition=function(g){var h=e.Deferred();if(e.support.transition){if(!(g instanceof e)){g=e(g)}g.first().one(e.support.transition.end,h.resolve)}else{h.resolve()}return h.promise()};f.controller.StateMachine=function(g){this.states=new Backbone.Collection(g)};f.controller.StateMachine.extend=Backbone.Model.extend;_.extend(f.controller.StateMachine.prototype,{get:function(g){this.states=this.states||new Backbone.Collection();if(!this.states.get(g)){this.states.add({id:g})}return this.states.get(g)},state:function(h){var g;if(h){if(g=this.state()){g.trigger("deactivate")}this._state=h;return this.state().trigger("activate")}if(this._state){return this.get(this._state)}}});_.each(["on","off","trigger"],function(g){f.controller.StateMachine.prototype[g]=function(){this.states=this.states||new Backbone.Collection();this.states[g].apply(this.states,arguments);return this}});f.controller.Library=Backbone.Model.extend({defaults:{id:"library",multiple:false,describe:false,title:b.mediaLibraryTitle},initialize:function(){if(!this.get("selection")){this.set("selection",new f.model.Selection(null,{multiple:this.get("multiple")}))}if(!this.get("library")){this.set("library",f.query())}if(!this.get("edge")){this.set("edge",120)}if(!this.get("gutter")){this.set("gutter",8)}this.on("activate",this.activate,this);this.on("deactivate",this.deactivate,this)},activate:function(){this.toolbar();this.sidebar();this.content();if(this.get("multiple")){wp.Uploader.queue.on("add",this.selectUpload,this)}this.get("selection").on("selection:single",this.buildDetails,this);this.get("selection").on("selection:unsingle",this.clearDetails,this)},deactivate:function(){var g=this._postLibraryToolbar;if(g){this.get("selection").off("add remove",g.visibility,g)}wp.Uploader.queue.off("add",this.selectUpload,this);this.get("selection").off("selection:single",this.buildDetails,this);this.get("selection").off("selection:unsingle",this.clearDetails,this)},toolbar:function(){var h=this.frame,g;g=this._postLibraryToolbar=new f.view.Toolbar.PostLibrary({controller:h,state:this});h.toolbar(g);this.get("selection").on("add remove",g.visibility,g)},sidebar:function(){var g=this.frame;g.sidebar(new f.view.Sidebar({controller:g}));this.details();g.sidebar().add({search:new f.view.Search({controller:g,model:this.get("library").props,priority:20}),selection:new f.view.SelectionPreview({controller:g,collection:this.get("selection"),priority:40})})},content:function(){var g=this.frame;g.content(new f.view.Attachments({controller:g,collection:this.get("library"),AttachmentView:f.view.Attachment.Library}).render())},selectUpload:function(g){this.get("selection").add(g)},details:function(){var g=this.get("selection").single();this[g?"buildDetails":"clearDetails"](g)},buildDetails:function(g){this.frame.sidebar().add("details",new f.view.Attachment.Details({controller:this.frame,model:g,priority:80}).render());return this},clearDetails:function(g){if(this.get("selection").single()){return this}this.frame.sidebar().add("details",new Backbone.View({priority:80}).render());return this},toggleSelection:function(g){var h=this.get("selection");if(h.has(g)){h[h.single()===g?"remove":"single"](g)}else{h.add(g).single()}return this}});f.controller.Gallery=f.controller.Library.extend({defaults:{id:"gallery",multiple:false,describe:true,title:b.createGalleryTitle,edge:199,editing:false},toolbar:function(){this.frame.toolbar(new f.view.Toolbar.Gallery({controller:this.frame,state:this}))},sidebar:function(){var g=this.frame;g.sidebar(new f.view.Sidebar({controller:g}));this.details();g.sidebar().add({settings:new f.view.Settings.Galle