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

1 line
29 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){return this._state?this.get(this._state):null}g=this.state();if(g&&h===g.id||!this.states.get(h)){return}if(g){g.trigger("deactivate")}this._state=h;this.state().trigger("activate")}});_.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.State=Backbone.Model.extend({initialize:function(){this.on("activate",this._activate,this);this.on("activate",this.activate,this);this.on("deactivate",this._deactivate,this);this.on("deactivate",this.deactivate,this)},activate:function(){},_activate:function(){this.active=true;this.menu();this.toolbar();this.sidebar();this.content()},deactivate:function(){},_deactivate:function(){this.active=false},menu:function(){var g=this.get("menu");if(!g){return}this.frame.menu(g);g.select(this.id)},toolbar:function(){},sidebar:function(){},content:function(){}});f.controller.Library=f.controller.State.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)}f.controller.State.prototype.initialize.apply(this,arguments)},activate:function(){var g=this.get("selection");if(this.get("multiple")){wp.Uploader.queue.on("add",this.selectUpload,this)}g.on("selection:single",this.buildDetails,this);g.on("selection:unsingle",this.clearDetails,this);g.on("add remove reset",this.updateToolbarVisibility,this);this._updateEmpty();this.get("library").on("add remove reset",this._updateEmpty,this);this.on("change:empty",this.refresh,this);this.refresh()},deactivate:function(){wp.Uploader.queue.off("add",this.selectUpload,this);this.get("selection").off(null,null,this);this.get("library").off("add remove reset",this._updateEmpty,this);this.off("change:empty",this.refresh,this)},toolbar:function(){var g=this.frame;g.toolbar(new f.view.Toolbar.PostLibrary({controller:g}))},sidebar:function(){var g=this.frame;g.sidebar(new f.view.Sidebar({controller:g}));this.details()},content:function(){var i=this.frame,h=this.get("library"),g;if(this.get("empty")){h.more();g=new f.view.UploaderInline({controller:i})}else{g=new f.view.AttachmentsBrowser({controller:i,collection:h,model:this})}i.content(g.render())},refresh:function(){this.frame.$el.toggleClass("hide-sidebar hide-toolbar",this.get("empty"));this.content()},_updateEmpty:function(){this.set("empty",!this.get("library").length)},updateToolbarVisibility:function(){this.frame.toolbar().visibility()},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.ge