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

1 line
22 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.mediaLibrary},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);this.on("change:details",this.details,this)},activate:function(){this.toolbar();this.sidebar();this.content();if(this.get("multiple")){wp.Uploader.queue.on("add",this.selectUpload,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)},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({silent:true});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(i){var h=this.get("details"),g;if(h){g=new f.view.Attachment.Details({controller:this.frame,model:h,priority:80})}else{g=new Backbone.View()}if(!i||!i.silent){g.render()}this.frame.sidebar().add("details",g,i)},toggleSelection:function(g){var h=this.get("details"),j=this.get("selection"),i=j.has(g);if(!j){return}if(!i){j.add(g)}if(h!==g){this.set("details",g);return}j.remove(g);if(j.length){this.set("details",j.last())}else{this.unset("details")}}});f.controller.Gallery=f.controller.Library.extend({defaults:{id:"gallery",multiple:false,describe:true,title:b.createGallery,edge:199},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()},content:function(){this.frame.content(new f.view.Attachments({controller:this.frame,collection:this.get("library"),sortable:true,AttachmentView:f.view.Attachment.Gallery}).render())}});f.view.Frame=Backbone.View.extend({tagName:"div",className:"media-frame",template:f.template("media-frame"),initialize:function(){_.defaults(this.options,{state:"library",title:"",selection:[],library:{}