diff --git a/wp-includes/js/media-models.min.js b/wp-includes/js/media-models.min.js index 88ec8f6448..323a7a6ed9 100644 --- a/wp-includes/js/media-models.min.js +++ b/wp-includes/js/media-models.min.js @@ -1 +1 @@ -window.wp=window.wp||{};(function(f){var d,c,a,e,b;media=wp.media=function(g){var h=media.view.MediaFrame,i;if(!h){return}g=_.defaults(g||{},{frame:"select"});if("select"===g.frame&&h.Select){i=new h.Select(g)}else{if("post"===g.frame&&h.Post){i=new h.Post(g)}}delete g.frame;i.setState(i.options.state);return i.render().attach().open()};_.extend(media,{model:{},view:{},controller:{}});b=media.model.l10n=typeof _wpMediaModelsL10n==="undefined"?{}:_wpMediaModelsL10n;media.model.settings=b.settings||{};delete b.settings;e=function(h,g,i,j){if(_.isEqual(h,g)){return i===j?0:(i>j?-1:1)}else{return h>g?-1:1}};_.extend(media,{template:_.memoize(function(i){var h,g={evaluate:/<#([\s\S]+?)#>/g,interpolate:/\{\{\{([\s\S]+?)\}\}\}/g,escape:/\{\{([^\}]+?)\}\}(?!\})/g,variable:"data"};return function(j){h=h||_.template(f("#tmpl-"+i).html(),null,g);return h(j)}}),post:function(h,g){return media.ajax({data:_.isObject(h)?h:_.extend(g||{},{action:h})})},ajax:function(h,g){if(_.isObject(h)){g=h}else{g=g||{};g.data=_.extend(g.data||{},{action:h})}g=_.defaults(g||{},{type:"POST",url:media.model.settings.ajaxurl,context:this});return f.Deferred(function(i){if(g.success){i.done(g.success)}if(g.error){i.fail(g.error)}delete g.success;delete g.error;f.ajax(g).done(function(j){if(_.isObject(j)&&!_.isUndefined(j.success)){i[j.success?"resolveWith":"rejectWith"](this,[j.data])}else{i.rejectWith(this,[j])}}).fail(function(){i.rejectWith(this,arguments)})}).promise()},fit:function(k){var h=k.width,g=k.height,j=k.maxWidth,i=k.maxHeight,l;if(!_.isUndefined(j)&&!_.isUndefined(i)){l=(h/g>j/i)?"width":"height"}else{if(_.isUndefined(i)){l="width"}else{if(_.isUndefined(j)&&g>i){l="height"}}}if("width"===l&&h>j){return{width:j,height:Math.round(j*g/h)}}else{if("height"===l&&g>i){return{width:Math.round(i*h/g),height:i}}else{return{width:h,height:g}}}},truncate:function(g,i,h){i=i||30;h=h||"…";if(g.length<=i){return g}return g.substr(0,i/2)+h+g.substr(-1*i/2)}});d=media.model.Attachment=Backbone.Model.extend({sync:function(i,h,g){if(_.isUndefined(this.id)){return f.Deferred().reject().promise()}if("read"===i){g=g||{};g.context=this;g.data=_.extend(g.data||{},{action:"get-attachment",id:this.id});return media.ajax(g)}else{if("update"===i){g=g||{};g.context=this;g.data=_.extend(g.data||{},{action:"save-attachment",id:this.id,nonce:this.get("nonces").update,post_id:media.model.settings.postId});if(g.changes){_.each(g.changes,function(k,j){g.changes[j]=this.get(j)},this);g.data.changes=g.changes;delete g.changes}return media.ajax(g)}else{if("delete"===i){g=g||{};g.context=this;g.data=_.extend(g.data||{},{action:"delete-post",id:this.id,_wpnonce:this.get("nonces")["delete"]});return media.ajax(g)}}}},parse:function(h,g){if(!h){return h}h.date=new Date(h.date);h.modified=new Date(h.modified);return h},saveCompat:function(i,h){var g=this;return media.post("save-attachment-compat",_.defaults({id:this.id,nonce:this.get("nonces").update,post_id:media.model.settings.postId},i)).done(function(l,j,k){g.set(g.parse(l,k),h)})}},{create:function(g){return c.all.push(g)},get:_.memoize(function(h,g){return c.all.push(g||{id:h})})});c=media.model.Attachments=Backbone.Collection.extend({model:d,initialize:function(h,g){g=g||{};this.props=new Backbone.Model();this.filters=g.filters||{};this.props.on("change",this._changeFilteredProps,this);this.props.on("change:order",this._changeOrder,this);this.props.on("change:orderby",this._changeOrderby,this);this.props.on("change:query",this._changeQuery,this);this.props.set(_.defaults(g.props||{}));if(g.observe){this.observe(g.observe)}},_changeOrder:function(h,g){if(this.comparator){this.sort()}},_changeOrderby:function(g,h){if(this.comparator&&this.comparator!==c.comparator){return}if(h&&"post__in"!==h){this.comparator=c.comparator}else{delete this.comparator}},_changeQuery:function(g,h){if(h){this.props.on("change",this._requery,this);this._requery()}else{this.props.off("change",this._requery,this)}},_changeFilteredProps:function(h,g){if(this.props.get("query")){return}var i=_.chain(g.changes).map(function(k,m){var l=c.filters[m],j=h.get(m);if(!l){return}if(j&&!this.filters[m]){this.filters[m]=l}else{if(!j&&this.filters[m]===l){delete this.filters[m]}else{return}}return true},this).any().value();if(!i){return}if(!this._source){this._source=new c(this.models)}this.reset(this._source.filter(this.validator,this))},validator:function(g){return _.all(this.filters,function(i,h){return !!i.call(this,g)},this)},validate:function(j,h){var i=this.validator(j),g=!!this.getByCid(j.cid);if(!i&&g){this.remove(j,h)}else{if(i&&!g){this.add(j,h)}}return this},validateAll:function(g,h){h=h||{};_.each(g.models,function(i){this.validate(i,{silent:true})},this);if(!h.silent){this.trigger("reset",this,h)}return this},observe:function(g){this.observers=this.observers||[];this.observers.push(g);g.on("add change remove",this._validateHandler,this);g.on("reset",this._validateAllHandler,this);this.validateAll(g);return this},unobserve:function(g){if(g){g.off(null,null,this);this.observers=_.without(this.observers,g)}else{_.each(this.observers,function(h){h.off(null,null,this)},this);delete this.observers}return this},_validateHandler:function(i,g,h){h=g===this.mirroring?h:{silent:h&&h.silent};return this.validate(i,h)},_validateAllHandler:function(g,h){return this.validateAll(g,h)},mirror:function(g){if(this.mirroring&&this.mirroring===g){return this}this.unmirror();this.mirroring=g;this.reset([],{silent:true});this.observe(g);return this},unmirror:function(){if(!this.mirroring){return}this.unobserve(this.mirroring);delete this.mirroring},more:function(i){var h=f.Deferred(),j=this.mirroring,g=this;if(!j||!j.more){return h.resolveWith(this).promise()}j.more(i).done(function(){if(this===g.mirroring){h.resolveWith(this)}});return h.promise()},hasMore:function(){return this.mirroring?this.mirroring.hasMore():false},parse:function(h,g){return _.map(h,function(i){var j=d.get(i.id);return j.set(j.parse(i,g))})},_requery:function(){if(this.props.get("query")){this.mirror(a.get(this.props.toJSON()))}}},{comparator:function(i,h,j){var k=this.props.get("orderby"),g=this.props.get("order")||"DESC",l=i.cid,m=h.cid;i=i.get(k);h=h.get(k);if("date"===k||"modified"===k){i=i||new Date();h=h||new Date()}if(j&&j.ties){l=m=null}return("DESC"===g)?e(i,h,l,m):e(h,i,m,l)},filters:{search:function(g){if(!this.props.get("search")){return true}return _.any(["title","filename","description","caption","name"],function(h){var i=g.get(h);return i&&-1!==i.search(this.props.get("search"))},this)},type:function(h){var g=this.props.get("type");return !g||-1!==g.indexOf(h.get("type"))},uploadedTo:function(h){var g=this.props.get("uploadedTo");if(_.isUndefined(g)){return true}return g===h.get("uploadedTo")}}});c.all=new c();media.query=function(g){return new c(null,{props:_.extend(_.defaults(g||{},{orderby:"date"}),{query:true})})};a=media.model.Query=c.extend({initialize:function(i,g){var h;g=g||{};c.prototype.initialize.apply(this,arguments);this.args=g.args;this._hasMore=true;this.created=new Date();this.filters.order=function(l){var k=this.props.get("orderby"),j=this.props.get("order");if(!this.comparator){return true}if(this.length){return 1!==this.comparator(l,this.last(),{ties:true})}else{if("DESC"===j&&("date"===k||"modified"===k)){return l.get(k)>=this.created}else{if("ASC"===j&&"menuOrder"===k){return l.get(k)===0}}}return false};h=["s","order","orderby","posts_per_page","post_mime_type","post_parent"];if(wp.Uploader&&_(this.args).chain().keys().difference(h).isEmpty().value()){this.observe(wp.Uploader.queue)}},hasMore:function(){return this._hasMore},more:function(g){var h=this;if(this._more&&"pending"===this._more.state()){return this._more}if(!this.hasMore()){return f.Deferred().resolveWith(this).promise()}g=g||{};g.add=true;return this._more=this.fetch(g).done(function(i){if(_.isEmpty(i)||-1===this.args.posts_per_page||i.lengthk?-1:1)}else{return i>h?-1:1}};_.extend(g,{template:_.memoize(function(j){var i,h={evaluate:/<#([\s\S]+?)#>/g,interpolate:/\{\{\{([\s\S]+?)\}\}\}/g,escape:/\{\{([^\}]+?)\}\}(?!\})/g,variable:"data"};return function(k){i=i||_.template(f("#tmpl-"+j).html(),null,h);return i(k)}}),post:function(i,h){return g.ajax({data:_.isObject(i)?i:_.extend(h||{},{action:i})})},ajax:function(i,h){if(_.isObject(i)){h=i}else{h=h||{};h.data=_.extend(h.data||{},{action:i})}h=_.defaults(h||{},{type:"POST",url:g.model.settings.ajaxurl,context:this});return f.Deferred(function(j){if(h.success){j.done(h.success)}if(h.error){j.fail(h.error)}delete h.success;delete h.error;f.ajax(h).done(function(k){if(_.isObject(k)&&!_.isUndefined(k.success)){j[k.success?"resolveWith":"rejectWith"](this,[k.data])}else{j.rejectWith(this,[k])}}).fail(function(){j.rejectWith(this,arguments)})}).promise()},fit:function(l){var i=l.width,h=l.height,k=l.maxWidth,j=l.maxHeight,m;if(!_.isUndefined(k)&&!_.isUndefined(j)){m=(i/h>k/j)?"width":"height"}else{if(_.isUndefined(j)){m="width"}else{if(_.isUndefined(k)&&h>j){m="height"}}}if("width"===m&&i>k){return{width:k,height:Math.round(k*h/i)}}else{if("height"===m&&h>j){return{width:Math.round(j*i/h),height:j}}else{return{width:i,height:h}}}},truncate:function(h,j,i){j=j||30;i=i||"…";if(h.length<=j){return h}return h.substr(0,j/2)+i+h.substr(-1*j/2)}});d=g.model.Attachment=Backbone.Model.extend({sync:function(j,i,h){if(_.isUndefined(this.id)){return f.Deferred().reject().promise()}if("read"===j){h=h||{};h.context=this;h.data=_.extend(h.data||{},{action:"get-attachment",id:this.id});return g.ajax(h)}else{if("update"===j){h=h||{};h.context=this;h.data=_.extend(h.data||{},{action:"save-attachment",id:this.id,nonce:this.get("nonces").update,post_id:g.model.settings.postId});if(h.changes){_.each(h.changes,function(l,k){h.changes[k]=this.get(k)},this);h.data.changes=h.changes;delete h.changes}return g.ajax(h)}else{if("delete"===j){h=h||{};h.context=this;h.data=_.extend(h.data||{},{action:"delete-post",id:this.id,_wpnonce:this.get("nonces")["delete"]});return g.ajax(h)}}}},parse:function(i,h){if(!i){return i}i.date=new Date(i.date);i.modified=new Date(i.modified);return i},saveCompat:function(j,i){var h=this;return g.post("save-attachment-compat",_.defaults({id:this.id,nonce:this.get("nonces").update,post_id:g.model.settings.postId},j)).done(function(m,k,l){h.set(h.parse(m,l),i)})}},{create:function(h){return c.all.push(h)},get:_.memoize(function(i,h){return c.all.push(h||{id:i})})});c=g.model.Attachments=Backbone.Collection.extend({model:d,initialize:function(i,h){h=h||{};this.props=new Backbone.Model();this.filters=h.filters||{};this.props.on("change",this._changeFilteredProps,this);this.props.on("change:order",this._changeOrder,this);this.props.on("change:orderby",this._changeOrderby,this);this.props.on("change:query",this._changeQuery,this);this.props.set(_.defaults(h.props||{}));if(h.observe){this.observe(h.observe)}},_changeOrder:function(i,h){if(this.comparator){this.sort()}},_changeOrderby:function(h,i){if(this.comparator&&this.comparator!==c.comparator){return}if(i&&"post__in"!==i){this.comparator=c.comparator}else{delete this.comparator}},_changeQuery:function(h,i){if(i){this.props.on("change",this._requery,this);this._requery()}else{this.props.off("change",this._requery,this)}},_changeFilteredProps:function(i,h){if(this.props.get("query")){return}var j=_.chain(h.changes).map(function(l,n){var m=c.filters[n],k=i.get(n);if(!m){return}if(k&&!this.filters[n]){this.filters[n]=m}else{if(!k&&this.filters[n]===m){delete this.filters[n]}else{return}}return true},this).any().value();if(!j){return}if(!this._source){this._source=new c(this.models)}this.reset(this._source.filter(this.validator,this))},validator:function(h){return _.all(this.filters,function(j,i){return !!j.call(this,h)},this)},validate:function(k,i){var j=this.validator(k),h=!!this.getByCid(k.cid);if(!j&&h){this.remove(k,i)}else{if(j&&!h){this.add(k,i)}}return this},validateAll:function(h,i){i=i||{};_.each(h.models,function(j){this.validate(j,{silent:true})},this);if(!i.silent){this.trigger("reset",this,i)}return this},observe:function(h){this.observers=this.observers||[];this.observers.push(h);h.on("add change remove",this._validateHandler,this);h.on("reset",this._validateAllHandler,this);this.validateAll(h);return this},unobserve:function(h){if(h){h.off(null,null,this);this.observers=_.without(this.observers,h)}else{_.each(this.observers,function(i){i.off(null,null,this)},this);delete this.observers}return this},_validateHandler:function(j,h,i){i=h===this.mirroring?i:{silent:i&&i.silent};return this.validate(j,i)},_validateAllHandler:function(h,i){return this.validateAll(h,i)},mirror:function(h){if(this.mirroring&&this.mirroring===h){return this}this.unmirror();this.mirroring=h;this.reset([],{silent:true});this.observe(h);return this},unmirror:function(){if(!this.mirroring){return}this.unobserve(this.mirroring);delete this.mirroring},more:function(j){var i=f.Deferred(),k=this.mirroring,h=this;if(!k||!k.more){return i.resolveWith(this).promise()}k.more(j).done(function(){if(this===h.mirroring){i.resolveWith(this)}});return i.promise()},hasMore:function(){return this.mirroring?this.mirroring.hasMore():false},parse:function(i,h){return _.map(i,function(j){var k=d.get(j.id);return k.set(k.parse(j,h))})},_requery:function(){if(this.props.get("query")){this.mirror(a.get(this.props.toJSON()))}},saveMenuOrder:function(){if("menuOrder"!==this.props.get("orderby")){return}var h=this.chain().filter(function(i){return !_.isUndefined(i.id)}).map(function(j,i){i=i+1;j.set("menuOrder",i);return[j.id,i]}).object().value();if(_.isEmpty(h)){return}return g.post("save-attachment-order",{nonce:g.model.settings.updatePostNonce,post_id:g.model.settings.postId,attachments:h})}},{comparator:function(j,i,k){var l=this.props.get("orderby"),h=this.props.get("order")||"DESC",m=j.cid,n=i.cid;j=j.get(l);i=i.get(l);if("date"===l||"modified"===l){j=j||new Date();i=i||new Date()}if(k&&k.ties){m=n=null}return("DESC"===h)?e(j,i,m,n):e(i,j,n,m)},filters:{search:function(h){if(!this.props.get("search")){return true}return _.any(["title","filename","description","caption","name"],function(i){var j=h.get(i);return j&&-1!==j.search(this.props.get("search"))},this)},type:function(i){var h=this.props.get("type");return !h||-1!==h.indexOf(i.get("type"))},uploadedTo:function(i){var h=this.props.get("uploadedTo");if(_.isUndefined(h)){return true}return h===i.get("uploadedTo")}}});c.all=new c();g.query=function(h){return new c(null,{props:_.extend(_.defaults(h||{},{orderby:"date"}),{query:true})})};a=g.model.Query=c.extend({initialize:function(j,h){var i;h=h||{};c.prototype.initialize.apply(this,arguments);this.args=h.args;this._hasMore=true;this.created=new Date();this.filters.order=function(m){var l=this.props.get("orderby"),k=this.props.get("order");if(!this.comparator){return true}if(this.length){return 1!==this.comparator(m,this.last(),{ties:true})}else{if("DESC"===k&&("date"===l||"modified"===l)){return m.get(l)>=this.created}else{if("ASC"===k&&"menuOrder"===l){return m.get(l)===0}}}return false};i=["s","order","orderby","posts_per_page","post_mime_type","post_parent"];if(wp.Uploader&&_(this.args).chain().keys().difference(i).isEmpty().value()){this.observe(wp.Uploader.queue)}},hasMore:function(){return this._hasMore},more:function(h){var i=this;if(this._more&&"pending"===this._more.state()){return this._more}if(!this.hasMore()){return f.Deferred().resolveWith(this).promise()}h=h||{};h.add=true;return this._more=this.fetch(h).done(function(j){if(_.isEmpty(j)||-1===this.args.posts_per_page||j.lengthg){i.eq(g).before(k)}else{h.append(k)}return this},ready:function(){this.view.trigger("ready");_.chain(this.all()).map(function(g){return g.views}).flatten().where({attached:true}).invoke("ready")},_attach:function(g,h,i){var k=g?this.view.$(g):this.view.$el,j;if(!k.length){return this}j=_.chain(h).pluck("views").flatten().value();_.each(j,function(l){if(l.rendered){return}l.view.render();l.rendered=true},this);this[i.add?"insert":"replace"](k,_.pluck(h,"el"),i);_.each(j,function(l){l.attached=true;if(i.ready){l.ready()}},this);return this},_isReady:function(){var g=this.view.el;while(g){if(g===document.body){return true}g=g.parentNode}return false}});f.View=Backbone.View.extend({Views:f.Views,constructor:function(){this.views=new this.Views(this,this.views);this.on("ready",this.ready,this);Backbone.View.apply(this,arguments)},dispose:function(){this.undelegateEvents();if(this.model&&this.model.off){this.model.off(null,null,this)}if(this.collection&&this.collection.off){this.collection.off(null,null,this)}if(this.controller&&this.controller.off){this.controller.off(null,null,this)}if(this.views){this.views.dispose()}return this},remove:function(){this.dispose();return Backbone.View.prototype.remove.apply(this,arguments)},render:function(){var g;if(this.prepare){g=this.prepare()}this.views.detach();if(this.template){g=g||{};this.trigger("prepare",g);this.$el.html(this.template(g))}this.views.render();return this},prepare:function(){return this.options},ready:function(){}});f.view.Frame=f.View.extend({initialize:function(){this._createRegions();this._createStates()},_createRegions:function(){this.regions=this.regions?this.regions.slice():[];_.each(this.regions,function(g){this[g]=new f.controller.Region({controller:this,id:g,selector:".media-frame-"+g})},this)},_createStates:function(){this.states=new Backbone.Collection(null,{model:f.controller.State});this.states.on("add",function(g){g.frame=this},this)},reset:function(){this.states.invoke("trigger","reset");return this}});_.extend(f.view.Frame.prototype,f.controller.StateMachine.prototype);f.view.MediaFrame=f.view.Frame.extend({className:"media-frame",template:f.template("media-frame"),regions:["menu","content","toolbar"],initialize:function(){f.view.Frame.prototype.initialize.apply(this,arguments);_.defaults(this.options,{title:"",modal:true,uploader:true});this.$el.addClass("wp-core-ui");if(this.options.modal){this.modal=new f.view.Modal({controller:this,$content:this.$el,title:this.options.title})}if(wp.Uploader.limitExceeded||!wp.Uploader.browser.supported){this.options.uploader=false}if(this.options.uploader){this.uploader=new f.view.UploaderWindow({controller:this,uploader:{dropzone:this.modal?this.modal.$el:this.$el,container:this.$el}});this.views.set(".media-frame-uploader",this.uploader)}this.on("attach",_.bind(this.views.ready,this.views),this)},render:function(){if(this.modal){this.modal.render()}f.view.Frame.prototype.render.apply(this,arguments);return this},createIframeStates:function(g){var j=f.view.settings,i=j.tabs,k=j.tabUrl,h;if(!i||!k){return}h=e("#post_ID");if(h.length){k+="&post_id="+h.val()}_.each(i,function(m,n){var l=this.state("iframe:"+n).set(_.defaults({tab:n,src:k+"&tab="+n,title:m,content:"iframe",menu:"main"},g))},this);this.content.on("activate:iframe",this.iframeContent,this);this.menu.on("activate:main",this.iframeMenu,this);this.on("open",this.hijackThickbox,this);this.on("close",this.restoreThickbox,this)},iframeContent:function(){this.$el.addClass("hide-toolbar");this.content.view(new f.view.Iframe({controller:this}).render())},iframeMenu:function(){var g={};_.each(f.view.settings.tabs,function(h,i){g["iframe:"+i]={text:this.state("iframe:"+i).get("title"),priority:200}},this);this.menu.view().set(g)},hijackThickbox:function(){var g=this;if(!window.tb_remove||this._tb_remove){return}this._tb_remove=window.tb_remove;window.tb_remove=function(){g.close();g.reset();g.setState(g.options.state);g._tb_remove.call(window)}},restoreThickbox:function(){if(!this._tb_remove){return}window.tb_remove=this._tb_remove;delete this._tb_remove}});_.each(["open","close","attach","detach"],function(g){f.view.MediaFrame.prototype[g]=function(h){if(this.modal){this.modal[g].apply(this.modal,arguments)}return this}});f.view.MediaFrame.Select=f.view.MediaFrame.extend({initialize:function(){f.view.MediaFrame.prototype.initialize.apply(this,arguments);_.defaults(this.options,{state:"upload",selection:[],library:{},multiple:false});this.createSelection();this.createStates();this.bindHandlers()},createSelection:function(){var g=this,h=this.options.selection;if(!(h instanceof f.model.Selection)){this.options.selection=new f.model.Selection(h,{multiple:this.options.multiple})}},createStates:function(){var g=this.options;this.states.add([new f.controller.Library({selection:g.selection,library:f.query(g.library),multiple:this.options.multiple,menu:"main",toolbar:"select"}),new f.controller.Upload({menu:"main"})])},bindHandlers:function(){this.menu.on("activate:main",this.mainMenu,this);this.content.on("activate:browse",this.browseContent,this);this.content.on("activate:upload",this.uploadContent,this);this.toolbar.on("activate:select",this.selectToolbar,this);this.on("refresh:selection",this.refreshSelectToolbar,this)},mainMenu:function(g){this.menu.view(new f.view.Menu({controller:this,silent:g&&g.silent,views:{upload:{text:b.uploadFilesTitle,priority:20},library:{text:b.mediaLibraryTitle,priority:40}}}))},browseContent:function(){var g=this.state();this.$el.removeClass("hide-toolbar");this.content.view(new f.view.AttachmentsBrowser({controller:this,collection:g.get("library"),selection:g.get("selection"),model:g,sortable:g.get("sortable"),search:g.get("searchable"),uploads:g.get("uploads"),filters:g.get("filterable"),display:g.get("displaySettings"),AttachmentView:g.get("AttachmentView")}))},uploadContent:function(){this.$el.addClass("hide-toolbar");this.content.view(new f.view.UploaderInline({controller:this}))},selectToolbar:function(g){g=_.defaults(g||{},{event:"select",silent:false,state:false});this.toolbar.view(new f.view.Toolbar({controller:this,silent:g.silent,items:{select:{style:"primary",text:b.select,priority:80,click:function(){var h=this.controller;h.close();h.state().trigger(g.event);h.reset();if(g.state){h.setState(g.state)}}}}}))},refreshSelectToolbar:function(){var g=this.state().get("selection");if(!g||"select"!==this.toolbar.mode()){return}this.toolbar.view().get("select").model.set("disabled",!g.length)}});f.view.MediaFrame.Post=f.view.MediaFrame.Select.extend({initialize:function(){_.defaults(this.options,{state:"upload",multiple:true,editing:false});f.view.MediaFrame.Select.prototype.initialize.apply(this,arguments);this.createIframeStates()},createStates:function(){var g=this.options;this.states.add([new f.controller.Library({selection:g.selection,library:f.query(g.library),editable:true,filterable:"all",multiple:this.options.multiple,menu:"main",displaySettings:true,displayUserSettings:true}),new f.controller.Upload({menu:"main"}),new f.controller.Embed(),new f.controller.Gallery({library:g.selection,editing:g.editing,menu:"gallery"}),new f.controller.Library({id:"gallery-library",library:f.query({type:"image"}),filterable:"uploaded",multiple:true,menu:"gallery",toolbar:"gallery-add",excludeState:"gallery-edit"}),new f.controller.Upload({id:"gallery-upload",menu:"gallery",libraryState:"gallery-edit"})])},bindHandlers:function(){f.view.MediaFrame.Select.prototype.bindHandlers.apply(this,arguments);var g={menu:{gallery:"galleryMenu"},content:{embed:"embedContent","edit-selection":"editSelectionContent"},toolbar:{"main-attachments":"mainAttachmentsToolbar","main-embed":"mainEmbedToolbar","gallery-edit":"galleryEditToolbar","gallery-add":"galleryAddToolbar"}};_.each(g,function(i,h){_.each(i,function(k,j){this[h].on("activate:"+j,this[k],this)},this)},this)},mainMenu:function(){f.view.MediaFrame.Select.prototype.mainMenu.call(this,{silent:true});this.menu.view().set({separateLibrary:new f.View({className:"separator",priority:60}),embed:{text:b.fromUrlTitle,priority:80}})},galleryMenu:function(){var g=this.lastState(),h=g&&g.id,i=this;this.menu.view(new f.view.Menu({controller:this,views:{cancel:{text:b.cancelGalleryTitle,priority:20,click:function(){if(h){i.setState(h)}else{i.close()}}},separateCancel:new f.View({className:"separator",priority:40}),"gallery-edit":{text:b.editGalleryTitle,priority:60},"gallery-upload":{text:b.uploadImagesTitle,priority:80},"gallery-library":{text:b.mediaLibraryTitle,priority:100}}}))},embedContent:function(){var g=new f.view.Embed({controller:this,model:this.state()}).render();this.content.view(g);g.url.focus()},editSelectionContent:function(){var i=this.state(),h=i.get("selection"),g;g=new f.view.AttachmentsBrowser({controller:this,collection:h,selection:h,model:i,sortable:true,search:false,AttachmentView:f.view.Attachment.EditSelection}).render();g.toolbar.set("backToLibrary",{text:b.returnToLibrary,priority:-100,click:function(){this.controller.content.mode("browse")}});this.content.view(g)},onSidebarGallerySettings:function(h){var g=this.state().get("library");if(!g){return}g.gallery=g.gallery||new Backbone.Model();this.sidebar.view().set({gallery:new f.view.Settings.Gallery({controller:this,model:g.gallery,priority:40}).render()},h)},mainAttachmentsToolbar:function(){this.toolbar.view(new f.view.Toolbar.Insert({controller:this,editable:this.state().get("editable")}))},mainEmbedToolbar:function(){this.toolbar.view(new f.view.Toolbar.Embed({controller:this}));this.$el.removeClass("hide-toolbar")},galleryEditToolbar:function(){var g=this.state().get("editing");this.toolbar.view(new f.view.Toolbar({controller:this,items:{insert:{style:"primary",text:g?b.updateGallery:b.insertGallery,priority:80,click:function(){var h=this.controller,i=h.state();h.close();i.trigger("update",i.get("library"));h.reset();h.setState("upload")}}}}))},galleryAddToolbar:function(){this.toolbar.view(new f.view.Toolbar({controller:this,items:{insert:{style:"primary",text:b.addToGallery,priority:80,click:function(){var g=this.controller,i=g.state(),h=g.state("gallery-edit");h.get("library").add(i.get("selection").models);i.trigger("reset");g.state("gallery-edit")}}}}))}});f.view.Modal=f.View.extend({tagName:"div",template:f.template("media-modal"),attributes:{tabindex:0},events:{"click .media-modal-backdrop, .media-modal-close":"closeHandler",keydown:"keydown"},initialize:function(){this.controller=this.options.controller;_.defaults(this.options,{container:document.body,title:"",propagate:true})},render:function(){this.options.$content=this.options.$content||e("
");this.options.$content.detach();this.$el.html(this.template({title:this.options.title}));this.options.$content.addClass("media-modal-content");this.$(".media-modal").append(this.options.$content);return this},attach:function(){this.$el.appendTo(this.options.container);return this.propagate("attach")},detach:function(){this.$el.detach();return this.propagate("detach")},open:function(){this.$el.show().focus();return this.propagate("open")},close:function(){this.$el.hide();return this.propagate("close")},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()},propagate:function(g){this.trigger(g);if(this.options.propagate){this.controller.trigger(g)}return this},keydown:function(g){if(27===g.which){g.preventDefault();this.close();return}}});f.view.UploaderWindow=f.View.extend({tagName:"div",className:"uploader-window",template:f.template("uploader-window"),initialize:function(){var g;this.controller=this.options.controller;this.$browser=e('').hide().appendTo("body");g=this.options.uploader=_.defaults(this.options.uploader||{},{dropzone:this.$el,browser:this.$browser,params:{}});if(g.dropzone&&!(g.dropzone instanceof e)){g.dropzone=e(g.dropzone)}this.controller.on("activate",this.refresh,this)},refresh:function(){if(this.uploader){this.uploader.refresh()}},ready:function(){var h=f.view.settings.postId,g;if(this.uploader){return}if(h){this.options.uploader.params.post_id=h}this.uploader=new wp.Uploader(this.options.uploader);g=this.uploader.dropzone;g.on("dropzone:enter",_.bind(this.show,this));g.on("dropzone:leave",_.bind(this.hide,this))},show:function(){var g=this.$el.show();_.defer(function(){g.css({opacity:1})})},hide:function(){var g=this.$el.css({opacity:0});f.transition(g).done(function(){if("0"===g.css("opacity")){g.hide()}})}});f.view.UploaderInline=f.View.extend({tagName:"div",className:"uploader-inline",template:f.template("uploader-inline"),initialize:function(){this.controller=this.options.controller;if(!this.options.$browser&&this.controller.uploader){this.options.$browser=this.controller.uploader.$browser}if(_.isUndefined(this.options.postId)){this.options.postId=f.view.settings.postId}this.views.set(".upload-inline-status",new f.view.UploaderStatus({controller:this.controller}))},ready:function(){var g=this.options.$browser,h;if(this.controller.uploader){h=this.$(".browser");g.detach().text(h.text());g[0].className=h[0].className;h.replaceWith(g.show())}return this}});f.view.UploaderStatus=f.View.extend({className:"media-uploader-status",template:f.template("uploader-status"),events:{"click .upload-dismiss-errors":"dismiss"},initialize:function(){this.controller=this.options.controller;this.queue=wp.Uploader.queue;this.queue.on("add remove reset",this.visibility,this);this.queue.on("add remove reset change:percent",this.progress,this);this.queue.on("add remove reset change:uploading",this.info,this);this.errors=wp.Uploader.errors;this.errors.reset();this.errors.on("add remove reset",this.visibility,this);this.errors.on("add",this.error,this)},dispose:function(){wp.Uploader.queue.off(null,null,this);f.View.prototype.dispose.apply(this,arguments);return this},visibility:function(){this.$el.toggleClass("uploading",!!this.queue.length);this.$el.toggleClass("errors",!!this.errors.length);this.$el.toggle(!!this.queue.length||!!this.errors.length)},ready:function(){_.each({"$bar":".media-progress-bar div","$index":".upload-index","$total":".upload-total","$filename":".upload-filename"},function(g,h){this[h]=this.$(g)},this);this.visibility();this.progress();this.info()},progress:function(){var g=this.queue,i=this.$bar,h=0;if(!i||!g.length){return}i.width((g.reduce(function(j,l){if(!l.get("uploading")){return j+100}var k=l.get("percent");return j+(_.isNumber(k)?k:100)},0)/g.length)+"%")},info:function(){var g=this.queue,h=0,i;if(!g.length){return}i=this.queue.find(function(k,j){h=j;return k.get("uploading")});this.$index.text(h+1);this.$total.text(g.length);this.$filename.html(i?this.filename(i.get("filename")):"")},filename:function(g){return f.truncate(_.escape(g),24)},error:function(g){this.views.add(".upload-errors",new f.view.UploaderStatusError({filename:this.filename(g.get("file").name),message:g.get("message")}),{at:0})},dismiss:function(g){var h=this.views.get(".upload-errors");g.preventDefault();if(h){_.invoke(h,"remove")}wp.Uploader.errors.reset()}});f.view.UploaderStatusError=f.View.extend({className:"upload-error",template:f.template("uploader-status-error")});f.view.Toolbar=f.View.extend({tagName:"div",className:"media-toolbar",initialize:function(){this.controller=this.options.controller;this._views={};this.$primary=e('
').prependTo(this.$el);this.$secondary=e('
').prependTo(this.$el);if(this.options.items){this.set(this.options.items,{silent:true})}if(!this.options.silent){this.render()}},destroy:function(){this.remove();if(this.model){this.model.off(null,null,this)}if(this.collection){this.collection.off(null,null,this)}this.controller.off(null,null,this);_.each(this._views,function(g){if(g.destroy){g.destroy()}})},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"));this.refresh();return this},set:function(i,g,h){h=h||{};if(_.isObject(i)){_.each(i,function(j,k){this.set(k,j,{silent:true})},this)}else{if(!(g instanceof Backbone.View)){g.classes=["media-button-"+i].concat(g.classes||[]);g=new f.view.Button(g).render()}g.controller=g.controller||this.controller;this._views[i]=g}if(!h.silent){this.render()}return this},get:function(g){return this._views[g]},unset:function(h,g){delete this._views[h];if(!g||!g.silent){this.render()}return this},refresh:function(){}});f.view.Toolbar.Select=f.view.Toolbar.extend({initialize:function(){var h=this.options,g=h.controller,i=g.state().get("selection");_.bindAll(this,"clickSelect");_.defaults(h,{event:"select",state:false,reset:true,close:true,text:b.select});h.items=_.defaults(h.items||{},{select:{style:"primary",text:h.text,priority:80,click:this.clickSelect}});f.view.Toolbar.prototype.initialize.apply(this,arguments)},clickSelect:function(){var h=this.options,g=this.controller;if(h.close){g.close()}if(h.event){g.state().trigger(h.event)}if(h.reset){g.reset()}if(h.state){g.setState(h.state)}}});f.view.Toolbar.Embed=f.view.Toolbar.Select.extend({initialize:function(){var g=this.options.controller;_.defaults(this.options,{text:b.insertIntoPost});f.view.Toolbar.Select.prototype.initialize.apply(this,arguments);g.on("change:url",this.refresh,this)},refresh:function(){var g=this.controller.state().get("url");this.get("select").model.set("disabled",!g||/^https?:\/\/$/.test(g))}});f.view.Toolbar.Insert=f.view.Toolbar.extend({initialize:function(){var g=this.options.controller,i=g.state().get("selection"),h;h=function(k,j){return function(){var l=this.controller,m=l.state().get("selection"),n=l.state(k),o=j?j(m):m.models;n.set("library",new f.model.Selection(o,{props:m.props.toJSON(),multiple:true}));this.controller.setState(k)}};this.options.items=_.defaults(this.options.items||{},{selection:new f.view.Selection({controller:g,collection:i,priority:-40,editable:this.options.editable&&function(){this.controller.content.mode("edit-selection")}}).render(),insert:{style:"primary",priority:80,text:b.insertIntoPost,click:function(){g.close();g.state().trigger("insert",i).reset()}},gallery:{text:b.createNewGallery,priority:40,click:h("gallery-edit",function(j){return j.where({type:"image"})})}});f.view.Toolbar.prototype.initialize.apply(this,arguments)},refresh:function(){var g=this.controller.state().get("selection"),h=g.length;this.get("insert").model.set("disabled",!g.length);this.get("gallery").$el.toggle(h>1&&g.any(function(i){return"image"===i.get("type")}))}});f.view.Button=f.View.extend({tagName:"a",className:"media-button",attributes:{href:"#"},events:{click:"click"},defaults:{text:"",style:"",size:"large",disabled:false},initialize:function(){this.model=new Backbone.Model(this.defaults);_.each(this.defaults,function(i,g){var h=this.options[g];if(_.isUndefined(h)){return}this.model.set(g,h);delete this.options[g]},this);this.model.on("change",this.render,this)},render:function(){var h=["button",this.className],g=this.model.toJSON();if(g.style){h.push("button-"+g.style)}if(g.size){h.push("button-"+g.size)}h=_.uniq(h.concat(this.options.classes));this.el.className=h.join(" ");this.$el.attr("disabled",g.disabled);this.$el.text(this.model.get("text"));return this},click:function(g){if("#"===this.attributes.href){g.preventDefault()}if(this.options.click&&!this.model.get("disabled")){this.options.click.apply(this,arguments)}}});f.view.ButtonGroup=f.View.extend({tagName:"div",className:"button-group button-large media-button-group",initialize:function(){this.buttons=_.map(this.options.buttons||[],function(g){if(g instanceof Backbone.View){return g}else{return new f.view.Button(g).render()}});delete this.options.buttons;if(this.options.classes){this.$el.addClass(this.options.classes)}},render:function(){this.$el.html(e(_.pluck(this.buttons,"el")).detach());return this}});f.view.PriorityList=f.View.extend({tagName:"div",initialize:function(){this.controller=this.options.controller;this._views={};this.set(_.extend({},this._views,this.options.views),{silent:true});delete this.options.views;if(!this.options.silent){this.render()}},destroy:this.dispose,set:function(l,h,j){var k,g,i;j=j||{};if(_.isObject(l)){_.each(l,function(m,n){this.set(n,m)},this);return this}if(!(h instanceof Backbone.View)){h=this.toView(h,l,j)}h.controller=h.controller||this.controller;this.unset(l);k=h.options.priority||10;g=this.views.get()||[];_.find(g,function(n,m){if(n.options.priority>k){i=m;return true}});this._views[l]=h;this.views.add(h,{at:_.isNumber(i)?i:g.length||0});return this},get:function(g){return this._views[g]},unset:function(h){var g=this.get(h);if(g){g.remove()}delete this._views[h];return this},toView:function(g){return new f.View(g)}});f.view.Menu=f.view.PriorityList.extend({tagName:"ul",className:"media-menu",toView:function(g,h){g=g||{};g.state=g.state||h;return new f.view.MenuItem(g).render()},select:function(h){var g=this.get(h);if(!g){return}this.deselect();g.$el.addClass("active")},deselect:function(){this.$el.children().removeClass("active")}});f.view.MenuItem=f.View.extend({tagName:"li",className:"media-menu-item",events:{click:"click"},click:function(){var g=this.options;if(g.click){g.click.call(this)}else{if(g.state){this.controller.setState(g.state)}}},render:function(){var g=this.options;if(g.text){this.$el.text(g.text)}else{if(g.html){this.$el.html(g.html)}}return this}});f.view.Sidebar=f.view.PriorityList.extend({className:"media-sidebar"});f.view.Attachment=f.View.extend({tagName:"li",className:"attachment",template:f.template("attachment"),events:{"click .attachment-preview":"toggleSelection","change [data-setting]":"updateSetting","change [data-setting] input":"updateSetting","change [data-setting] select":"updateSetting","change [data-setting] textarea":"updateSetting","click .close":"removeFromLibrary","click .check":"removeFromSelection","click a":"preventDefault"},buttons:{},initialize:function(){this.controller=this.options.controller;this.model.on("change:sizes change:uploading change:caption change:title",this.render,this);this.model.on("change:percent",this.progress,this);this.model.on("add",this.select,this);this.model.on("remove",this.deselect,this);this.model.on("selection:single selection:unsingle",this.details,this);this.details(this.model,this.controller.state().get("selection"))},dispose:function(){this.updateAll();f.View.prototype.dispose.apply(this,arguments);return this},render:function(){var h=this.model.toJSON(),g=_.defaults(this.model.toJSON(),{orientation:"landscape",uploading:false,type:"",subtype:"",icon:"",filename:"",caption:"",title:"",dateFormatted:"",width:"",height:"",compat:false,alt:""});g.buttons=this.buttons;g.describe=this.controller.state().get("describe");if("image"===g.type){g.size=this.imageSize()}this.views.detach();this.$el.html(this.template(g));this.$el.toggleClass("uploading",g.uploading);if(g.uploading){this.$bar=this.$(".media-progress-bar div")}else{delete this.$bar}if(this.selected()){this.select()}this.views.render();return this},progress:function(){if(this.$bar&&this.$bar.length){this.$bar.width(this.model.get("percent")+"%")}},toggleSelection:function(i){var h=this.options.selection,g=this.model;if(!h){return}if(h.has(g)){h[h.single()===g?"remove":"single"](g)}else{h.add(g).single(g)}},selected:function(){var g=this.options.selection;if(g){return g.has(this.model)}},select:function(g,i){var h=this.options.selection;if(!h||(i&&i!==h)){return}this.$el.addClass("selected")},deselect:function(g,i){var h=this.options.selection;if(!h||(i&&i!==h)){return}this.$el.removeClass("selected")},details:function(g,j){var i=this.options.selection,h;if(i!==j){return}h=i.single();this.$el.toggleClass("details",h===this.model)},preventDefault:function(g){g.preventDefault()},imageSize:function(g){var h=this.model.get("sizes");g=g||"medium";if(h&&h[g]){return _.clone(h[g])}else{return{url:this.model.get("url"),width:this.model.get("width"),height:this.model.get("height"),orientation:this.model.get("orientation")}}},updateSetting:function(i){var g=e(i.target).closest("[data-setting]"),h,j;if(!g.length){return}h=g.data("setting");j=i.target.value;if(this.model.get(h)!==j){this.model.save(h,j)}},updateAll:function(){var h=this.$("[data-setting]"),g=this.model,i;i=_.chain(h).map(function(k){var m=e("input, textarea, select, [value]",k),j,l;if(!m.length){return}j=e(k).data("setting");l=m.val();if(g.get(j)!==l){return[j,l]}}).compact().object().value();if(!_.isEmpty(i)){g.save(i)}},removeFromLibrary:function(g){g.stopPropagation();this.collection.remove(this.model)},removeFromSelection:function(h){var g=this.options.selection;if(!g){return}h.stopPropagation();g.remove(this.model)}});f.view.Attachment.Library=f.view.Attachment.extend({buttons:{check:true}});f.view.Attachment.EditLibrary=f.view.Attachment.extend({buttons:{close:true}});f.view.Attachments=f.View.extend({tagName:"ul",className:"attachments",cssTemplate:f.template("attachments-css"),events:{scroll:"scroll"},initialize:function(){this.controller=this.options.controller;this.el.id=_.uniqueId("__attachments-view-");_.defaults(this.options,{refreshSensitivity:200,refreshThreshold:3,AttachmentView:f.view.Attachment,sortable:false});this._viewsByCid={};this.collection.on("add",function(i,g,h){this.views.add(this.createAttachmentView(i),{at:h.index})},this);this.collection.on("remove",function(j,g,i){var h=this._viewsByCid[j.cid];delete this._viewsByCid[j.cid];if(h){h.remove()}},this);this.collection.on("reset",this.render,this);this.scroll=_.chain(this.scroll).bind(this).throttle(this.options.refreshSensitivity).value();this.initSortable();this.collection.props.on("change:orderby",this.refreshSortable,this);_.bindAll(this,"css");this.model.on("change:edge change:gutter",this.css,this);this._resizeCss=_.debounce(_.bind(this.css,this),this.refreshSensitivity);e(window).on("resize.attachments",this._resizeCss);this.css()},dispose:function(){this.collection.props.off(null,null,this);e(window).off("resize.attachments",this._resizeCss);f.View.prototype.dispose.apply(this,arguments)},css:function(){var g=e("#"+this.el.id+"-css");if(g.length){g.remove()}f.view.Attachments.$head().append(this.cssTemplate({id:this.el.id,edge:this.edge(),gutter:this.model.get("gutter")}))},edge:function(){var i=this.model.get("edge"),j,h,g;if(!this.$el.is(":visible")){return i}j=this.model.get("gutter")*2;h=this.$el.width()-j;g=Math.ceil(h/(i+j));i=Math.floor((h-(g*j))/g);return i},initSortable:function(){var g=this.collection,h;if(!this.options.sortable||!e.fn.sortable){return}this.$el.sortable({disabled:!!g.comparator,containment:this.$el,tolerance:"pointer",start:function(i,j){h=j.item.index()},update:function(j,k){var i=g.at(h);g.remove(i,{silent:true}).add(i,{at:k.item.index(),silent:true})}});g.props.on("change:orderby",function(){this.$el.sortable("option","disabled",!!g.comparator)},this)},refreshSortable:function(){if(!this.options.sortable||!e.fn.sortable){return}this.$el.sortable("option","disabled",!!this.collection.comparator)},createAttachmentView:function(h){var g=new this.options.AttachmentView({controller:this.controller,model:h,collection:this.collection,selection:this.options.selection});return this._viewsByCid[h.cid]=g},prepare:function(){if(this.collection.length){this.views.set(this.collection.map(this.createAttachmentView,this))}else{this.views.unset();this.collection.more().done(this.scroll)}},ready:function(){this.scroll()},scroll:function(g){if(!this.$el.is(":visible")){return}if(this.collection.hasMore()&&this.el.scrollHeight'+b.dragInfo+"
")[0],priority:-40}))}},updateContent:function(){var g=this;if(!this.attachments){this.createAttachments()}if(!this.collection.length){this.collection.more().done(function(){if(!g.collection.length){g.createUploader()}})}},removeContent:function(){_.each(["attachments","uploader"],function(g){if(this[g]){this[g].remove();delete this[g]}},this)},createUploader:function(){this.removeContent();this.uploader=new f.view.UploaderInline({controller:this.controller});this.views.add(this.uploader)},createAttachments:function(){this.removeContent();this.attachments=new f.view.Attachments({controller:this.controller,collection:this.collection,selection:this.options.selection,model:this.model,sortable:this.options.sortable,AttachmentView:this.options.AttachmentView});this.views.add(this.attachments)},createSidebar:function(){var g=this.options,h=g.selection,i=this.sidebar=new f.view.Sidebar({controller:this.controller});this.views.add(i);if(g.uploads&&this.controller.uploader){i.set("uploads",new f.view.UploaderStatus({controller:this.controller,priority:40}))}h.on("selection:single",this.createSingle,this);h.on("selection:unsingle",this.disposeSingle,this);if(h.single()){this.createSingle()}},createSingle:function(){var h=this.sidebar,i=this.options.selection.single(),g={};h.set("details",new f.view.Attachment.Details({controller:this.controller,model:i,priority:80}));h.set("compat",new f.view.AttachmentCompat({controller:this.controller,model:i,priority:120}));if(this.options.display){h.set("display",new f.view.Settings.AttachmentDisplay({controller:this.controller,model:this.model.display(i),attachment:i,priority:160,userSettings:this.model.get("displayUserSettings")}))}},disposeSingle:function(){var g=this.sidebar;g.unset("details");g.unset("compat");g.unset("display")}});f.view.SelectionPreview=f.View.extend({tagName:"div",className:"selection-preview",template:f.template("media-selection-preview"),events:{"click .clear-selection":"clear"},initialize:function(){_.defaults(this.options,{clearable:true});this.controller=this.options.controller;this.collection.on("add change:url remove",this.render,this);this.render()},render:function(){var g=_.clone(this.options),j,i,h;if(!this.collection.length){this.$el.empty();return this}g.count=this.collection.length;j=this.collection.last();i=j.get("sizes");if("image"===j.get("type")){g.thumbnail=(i&&i.thumbnail)?i.thumbnail.url:j.get("url")}else{g.thumbnail=j.get("icon")}this.$el.html(this.template(g));return this},clear:function(g){g.preventDefault();this.collection.clear()}});f.view.Selection=f.View.extend({tagName:"div",className:"media-selection",template:f.template("media-selection"),events:{"click .edit-selection":"edit","click .clear-selection":"clear"},initialize:function(){_.defaults(this.options,{editable:false,clearable:true});this.controller=this.options.controller;this.attachments=new f.view.Attachments({controller:this.controller,collection:this.collection,selection:this.collection,sortable:true,model:new Backbone.Model({edge:40,gutter:5}),AttachmentView:f.view.Attachment.Selection});this.collection.on("add remove reset",this.refresh,this)},destroy:function(){this.remove();this.collection.off("add remove reset",this.refresh,this);this.attachments.destroy()},render:function(){this.attachments.$el.detach();this.attachments.render();this.$el.html(this.template(this.options));this.$(".selection-view").replaceWith(this.attachments.$el);this.refresh();return this},refresh:function(){if(!this.$el.children().length){return}this.$el.toggleClass("empty",!this.collection.length);this.$(".count").text(this.collection.length+" "+b.selected)},edit:function(g){g.preventDefault();if(this.options.editable){this.options.editable.call(this,this.collection)}},clear:function(g){g.preventDefault();this.collection.clear()}});f.view.Attachment.Selection=f.view.Attachment.extend({className:"attachment selection",toggleSelection:function(){this.options.selection.single(this.model)}});f.view.Attachment.EditSelection=f.view.Attachment.Selection.extend({buttons:{close:true}});f.view.Settings=f.View.extend({events:{"click button":"updateHandler","change input":"updateHandler","change select":"updateHandler","change textarea":"updateHandler"},initialize:function(){this.model=this.model||new Backbone.Model();this.model.on("change",this.updateChanges,this)},destroy:function(){this.model.off(null,null,this)},render:function(){this.$el.html(this.template(_.defaults({model:this.model.toJSON()},this.options)));_(this.model.attributes).chain().keys().each(this.update,this);return this},update:function(i){var j=this.model.get(i),h=this.$('[data-setting="'+i+'"]'),g;if(!h.length){return}if(h.is("select")){h.find('[value="'+j+'"]').attr("selected",true)}else{if(h.hasClass("button-group")){g=h.find("button").removeClass("active");g.filter('[value="'+j+'"]').addClass("active")}else{if(h.is('input[type="text"], textarea')){if(!h.is(":focus")){h.val(j)}}}}},updateHandler:function(i){var h=e(i.target).closest("[data-setting]"),j=i.target.value,g;i.preventDefault();if(!h.length){return}this.model.set(h.data("setting"),j);if(g=h.data("userSetting")){setUserSetting(g,j)}},updateChanges:function(h,g){if(g.changes){_(g.changes).chain().keys().each(this.update,this)}}});f.view.Settings.AttachmentDisplay=f.view.Settings.extend({className:"attachment-display-settings",template:f.template("attachment-display-settings"),initialize:function(){var g=this.options.attachment;_.defaults(this.options,{userSettings:false});f.view.Settings.prototype.initialize.apply(this,arguments);this.model.on("change:link",this.updateLinkTo,this);if(g){g.on("change:uploading",this.render,this)}},dispose:function(){var g=this.options.attachment;if(g){g.off(null,null,this)}f.view.Settings.prototype.dispose.apply(this,arguments)},render:function(){var g=this.options.attachment;if(g){_.extend(this.options,{sizes:g.get("sizes"),type:g.get("type")})}f.view.Settings.prototype.render.call(this);this.updateLinkTo();return this},updateLinkTo:function(){var h=this.model.get("link"),i=this.$(".link-to-custom"),g=this.options.attachment;if("none"===h){i.hide();return}i.show();if("post"==h){i.val(g.get("link"))}else{if("file"==h){i.val(g.get("url"))}else{if(!this.model.get("linkUrl")){i.val("http://")}}}i.prop("readonly","custom"!==h);if(i.is(":visible")){i.focus()[0].select()}}});f.view.Settings.Gallery=f.view.Settings.extend({className:"gallery-settings",template:f.template("gallery-settings")});f.view.Attachment.Details=f.view.Attachment.extend({tagName:"div",className:"attachment-details",template:f.template("attachment-details"),events:{"change [data-setting]":"updateSetting","change [data-setting] input":"updateSetting","change [data-setting] select":"updateSetting","change [data-setting] textarea":"updateSetting","click .delete-attachment":"deleteAttachment"},deleteAttachment:function(g){g.preventDefault();if(confirm(b.warnDelete)){this.model.destroy()}}});f.view.AttachmentCompat=f.View.extend({tagName:"form",className:"compat-item",events:{submit:"preventDefault","change input":"save","change select":"save","change textarea":"save"},initialize:function(){this.model.on("change:compat",this.render,this)},destroy:function(){this.model.off(null,null,this)},render:function(){var g=this.model.get("compat");if(!g||!g.item){return}this.$el.html(g.item);return this},preventDefault:function(g){g.preventDefault()},save:function(g){var h={};g.preventDefault();_.each(this.$el.serializeArray(),function(i){h[i.name]=i.value});this.model.saveCompat(h)}});f.view.Iframe=f.View.extend({className:"media-iframe",initialize:function(){this.controller=this.options.controller},render:function(){this.$el.html('