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

1 line
10 KiB
JavaScript
Raw Normal View History

(function(d){var e=wp.media,c=e.model.Attachment,b=e.model.Attachments,a=e.model.Query;e.controller.Workflow=Backbone.Model.extend({defaults:{multiple:false,view:"library",library:{},selection:[]},initialize:function(){this.createSelection();this._views={};this._pendingViews={};this.modal=new e.view.Modal({controller:this});this.add("library",e.view.Workspace.Library,{collection:e.query(this.get("library"))});this.unset("library");this.add("gallery",e.view.Workspace.Gallery,{collection:this.selection})},add:function(h,g,f){this.remove(h);this._pendingViews[h]={view:g,options:f};this.trigger("add add:"+h,g,f);return this},view:function(g){var f;g=g||this.get("view");f=this._pendingViews[g];if(!this._views[g]&&f){this._views[g]=new f.view(_.extend({controller:this},f.options||{}));delete this._pendingViews[g];this.trigger("init init:"+g,this._views[g])}return this._views[g]},remove:function(f){delete this._views[f];delete this._pendingViews[f];this.trigger("remove remove:"+f);return this},render:function(i,h,g){var f;i=i||this.get("view");if(h){this.add(i,h,g)}f=this.view(i);if(!f){return this}f.render();this.modal.content(f);return this},createSelection:function(){var f=this;this.selection=new b(this.get("selection"));this.unset("selection");_.extend(this.selection,{add:function(h,g){if(!f.get("multiple")){h=_.isArray(h)?_.first(h):h;this.clear(g)}return b.prototype.add.call(this,h,g)},clear:function(g){return this.remove(this.models,g)},reset:function(h,g){return this.clear(g).add(h,g)},has:function(g){return !!(this.getByCid(g.cid)||this.get(g.id))}})}});_.each(["attach","detach","open","close"],function(f){e.controller.Workflow.prototype[f]=function(){this.modal[f].apply(this.modal,arguments);return this}});e.view.Modal=Backbone.View.extend({tagName:"div",template:e.template("media-modal"),events:{"click .media-modal-backdrop, .media-modal-close":"closeHandler"},initialize:function(){this.controller=this.options.controller;_.defaults(this.options,{title:"",container:document.body})},render:function(){this.options.$content=this.options.$content||d("<div />");this.options.$content.detach();this.$el.html(this.template(this.options));this.$(".media-modal-content").append(this.options.$content);return this},attach:function(){this.$el.appendTo(this.options.container)},detach:function(){this.$el.detach()},open:function(){this.$el.show()},close:function(){this.$el.hide()},closeHandler:function(f){f.preventDefault();this.close()},content:function(f){if(this.options.$content){this.options.$content.detach()}this.options.$content=(f instanceof Backbone.View)?f.$el:f;return this.render()},title:function(f){this.options.title=f;return this.render()}});e.view.Toolbar=Backbone.View.extend({tagName:"div",className:"media-toolbar",initialize:function(){this._views={};this.$primary=d('<div class="media-toolbar-primary" />').prependTo(this.$el);this.$secondary=d('<div class="media-toolbar-secondary" />').prependTo(this.$el);if(this.options.items){_.each(this.options.items,function(f,g){this.add(g,f,{silent:true})},this);this.render()}},render:function(){var f=_.chain(this._views).sortBy(function(g){return g.options.priority||10}).groupBy(function(g){return(g.options.priority||10)>0?"primary":"secondary"}).value();d(_.pluck(this._views,"el")).detach();this.$primary.html(_.pluck(f.primary,"el"));this.$secondary.html(_.pluck(f.secondary,"el"));return this},add:function(h,f,g){if(!(f instanceof Backbone.View)){f.classes=[h].concat(f.classes||[]);f=new e.view.Button(f).render()}this._views[h]=f;if(!g||!g.silent){this.render()}return this},remove:function(g,f){delete this._views[g];if(!f||!f.silent){this.render()}return this}});e.view.Button=Backbone.View.extend({tagName:"a",className:"media-button",attributes:{href:"#"},events:{click:"click"},initialize:function(){_.defaults(this.options,{text:"",classes:[]})},render:function(){var f=["button",this.className];if(this.options.style){f.push("button-"+this.options.style)}if(this.options.size){f.push("button-"+this.options.size)}f=f.concat(this.options.classes);this.el.className=f.join(" ");this.