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

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