diff --git a/wp-includes/js/media-views.js b/wp-includes/js/media-views.js index 862ec7bf59..1a9328d1ef 100644 --- a/wp-includes/js/media-views.js +++ b/wp-includes/js/media-views.js @@ -6280,7 +6280,7 @@ template: media.template('video-details'), initialize: function() { - _.bindAll(this, 'player'); + _.bindAll(this, 'success'); this.listenTo( this.controller, 'close', this.close ); @@ -6301,15 +6301,16 @@ close : function() { this.mejs.pause(); + this.player.remove(); }, - player : function (mejs) { + success : function (mejs) { this.mejs = mejs; }, render: function() { var video, self = this, settings = { - success : this.player + success : this.success }; if ( ! _.isUndefined( window._wpmejsSettings ) ) { @@ -6326,7 +6327,7 @@ (new Date()).getTime() ].join(''); - new MediaElementPlayer( video, settings ); + this.player = new MediaElementPlayer( video, settings ); return this; }, diff --git a/wp-includes/js/media-views.min.js b/wp-includes/js/media-views.min.js index 948b936c5f..d85d9275ee 100644 --- a/wp-includes/js/media-views.min.js +++ b/wp-includes/js/media-views.min.js @@ -1,3 +1,3 @@ !function(a,b){var c,d=wp.media;c=d.view.l10n="undefined"==typeof _wpMediaViewsL10n?{}:_wpMediaViewsL10n,d.view.settings=c.settings||{},delete c.settings,d.model.settings.post=d.view.settings.post,a.support.transition=function(){var a,c=document.documentElement.style,d={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};return a=b.find(b.keys(d),function(a){return!b.isUndefined(c[a])}),a&&{end:d[a]}}(),d.transition=function(c,d){var e=a.Deferred();return d=d||2e3,a.support.transition?(c instanceof a||(c=a(c)),c.first().one(a.support.transition.end,e.resolve),b.delay(e.resolve,d)):e.resolve(),e.promise()},d.controller.Region=function(a){b.extend(this,b.pick(a||{},"id","view","selector"))},d.controller.Region.extend=Backbone.Model.extend,b.extend(d.controller.Region.prototype,{mode:function(a){return a?a===this._mode?this:(this.trigger("deactivate"),this._mode=a,this.render(a),this.trigger("activate"),this):this._mode},render:function(a){if(a&&a!==this._mode)return this.mode(a);var b,c={view:null};return this.trigger("create",c),b=c.view,this.trigger("render",b),b&&this.set(b),this},get:function(){return this.view.views.first(this.selector)},set:function(a,b){return b&&(b.add=!1),this.view.views.set(this.selector,a,b)},trigger:function(a){var c,d;if(this._mode)return d=b.toArray(arguments),c=this.id+":"+a,d[0]=c+":"+this._mode,this.view.trigger.apply(this.view,d),d[0]=c,this.view.trigger.apply(this.view,d),this}}),d.controller.StateMachine=function(a){this.states=new Backbone.Collection(a)},d.controller.StateMachine.extend=Backbone.Model.extend,b.extend(d.controller.StateMachine.prototype,Backbone.Events,{state:function(a){return this.states=this.states||new Backbone.Collection,a=a||this._state,a&&!this.states.get(a)&&this.states.add({id:a}),this.states.get(a)},setState:function(a){var b=this.state();return b&&a===b.id||!this.states||!this.states.get(a)?this:(b&&(b.trigger("deactivate"),this._lastState=b.id),this._state=a,this.state().trigger("activate"),this)},lastState:function(){return this._lastState?this.state(this._lastState):void 0}}),b.each(["on","off","trigger"],function(a){d.controller.StateMachine.prototype[a]=function(){return this.states=this.states||new Backbone.Collection,this.states[a].apply(this.states,arguments),this}}),d.controller.State=Backbone.Model.extend({constructor:function(){this.on("activate",this._preActivate,this),this.on("activate",this.activate,this),this.on("activate",this._postActivate,this),this.on("deactivate",this._deactivate,this),this.on("deactivate",this.deactivate,this),this.on("reset",this.reset,this),this.on("ready",this._ready,this),this.on("ready",this.ready,this),Backbone.Model.apply(this,arguments),this.on("change:menu",this._updateMenu,this)},ready:function(){},activate:function(){},deactivate:function(){},reset:function(){},_ready:function(){this._updateMenu()},_preActivate:function(){this.active=!0},_postActivate:function(){this.on("change:menu",this._menu,this),this.on("change:titleMode",this._title,this),this.on("change:content",this._content,this),this.on("change:toolbar",this._toolbar,this),this.frame.on("title:render:default",this._renderTitle,this),this._title(),this._menu(),this._toolbar(),this._content(),this._router()},_deactivate:function(){this.active=!1,this.frame.off("title:render:default",this._renderTitle,this),this.off("change:menu",this._menu,this),this.off("change:titleMode",this._title,this),this.off("change:content",this._content,this),this.off("change:toolbar",this._toolbar,this)},_title:function(){this.frame.title.render(this.get("titleMode")||"default")},_renderTitle:function(a){a.$el.text(this.get("title")||"")},_router:function(){var a,b=this.frame.router,c=this.get("router");this.frame.$el.toggleClass("hide-router",!c),c&&(this.frame.router.render(c),a=b.get(),a&&a.select&&a.select(this.frame.content.mode()))},_menu:function(){var a,b=this.frame.menu,c=this.get("menu");c&&(b.mode(c),a=b.get(),a&&a.select&&a.select(this.id))},_updateMenu:function(){var a=this.previous("menu"),b=this.get("menu");a&&this.frame.off("menu:render:"+a,this._renderMenu,this),b&&this.frame.on("menu:render:"+b,this._renderMenu,this)},_renderMenu:function(a){var b=this.get("menuItem"),c=this.get("title"),d=this.get("priority");!b&&c&&(b={text:c},d&&(b.priority=d)),b&&a.set(this.id,b)}}),b.each(["toolbar","content"],function(a){d.controller.State.prototype["_"+a]=function(){var b=this.get(a);b&&this.frame[a].render(b)}}),d.controller.Library=d.controller.State.extend({defaults:{id:"library",multiple:!1,describe:!1,toolbar:"select",sidebar:"settings",content:"upload",router:"browse",menu:"default",searchable:!0,filterable:!1,sortable:!0,title:c.mediaLibraryTitle,contentUserSetting:!0,syncSelection:!0},initialize:function(){var a,c=this.get("selection");this.get("library")||this.set("library",d.query()),c instanceof d.model.Selection||(a=c,a||(a=this.get("library").props.toJSON(),a=b.omit(a,"orderby","query")),this.set("selection",new d.model.Selection(null,{multiple:this.get("multiple"),props:a}))),this.get("edge")||this.set("edge",120),this.get("gutter")||this.set("gutter",8),this.resetDisplays()},activate:function(){this.syncSelection(),wp.Uploader.queue.on("add",this.uploading,this),this.get("selection").on("add remove reset",this.refreshContent,this),this.get("contentUserSetting")&&(this.frame.on("content:activate",this.saveContentMode,this),this.set("content",getUserSetting("libraryContent",this.get("content"))))},deactivate:function(){this.recordSelection(),this.frame.off("content:activate",this.saveContentMode,this),this.get("selection").off(null,null,this),wp.Uploader.queue.off(null,null,this)},reset:function(){this.get("selection").reset(),this.resetDisplays(),this.refreshContent()},resetDisplays:function(){var a=d.view.settings.defaultProps;this._displays=[],this._defaultDisplaySettings={align:a.align||getUserSetting("align","none"),size:a.size||getUserSetting("imgsize","medium"),link:a.link||getUserSetting("urlbutton","file")}},display:function(a){var b=this._displays;return b[a.cid]||(b[a.cid]=new Backbone.Model(this.defaultDisplaySettings(a))),b[a.cid]},defaultDisplaySettings:function(a){var b=this._defaultDisplaySettings;return(b.canEmbed=this.canEmbed(a))&&(b.link="embed"),b},canEmbed:function(a){if(!a.get("uploading")){var c=a.get("type");if("audio"!==c&&"video"!==c)return!1}return b.contains(d.view.settings.embedExts,a.get("filename").split(".").pop())},syncSelection:function(){var a=this.get("selection"),c=this.frame._selection;this.get("syncSelection")&&c&&a&&(a.multiple&&(a.reset([],{silent:!0}),a.validateAll(c.attachments),c.difference=b.difference(c.attachments.models,a.models)),a.single(c.single))},recordSelection:function(){var a=this.get("selection"),b=this.frame._selection;this.get("syncSelection")&&b&&a&&(a.multiple?(b.attachments.reset(a.toArray().concat(b.difference)),b.difference=[]):b.attachments.add(a.toArray()),b.single=a._single)},refreshContent:function(){var a=this.get("selection"),b=this.frame,c=b.router.get(),d=b.content.mode();this.active&&!a.length&&c&&!c.get(d)&&this.frame.content.render(this.get("content"))},uploading:function(a){var b=this.frame.content;"upload"===b.mode()&&this.frame.content.mode("browse"),this.get("selection").add(a)},saveContentMode:function(){if("browse"===this.get("router")){var a=this.frame.content.mode(),b=this.frame.router.get();b&&b.get(a)&&setUserSetting("libraryContent",a)}}}),d.controller.ImageDetails=d.controller.State.extend({defaults:b.defaults({id:"image-details",toolbar:"image-details",title:c.imageDetailsTitle,content:"image-details",menu:"image-details",router:!1,attachment:!1,priority:60,editing:!1},d.controller.Library.prototype.defaults),initialize:function(a){this.image=a.image,d.controller.State.prototype.initialize.apply(this,arguments)}}),d.controller.AudioDetails=d.controller.State.extend({defaults:b.defaults({id:"audio-details",toolbar:"audio-details",title:c.audioDetailsTitle,content:"audio-details",menu:"audio-details",router:!1,attachment:!1,priority:60,editing:!1},d.controller.Library.prototype.defaults),initialize:function(a){this.audio=a.audio,d.controller.State.prototype.initialize.apply(this,arguments)}}),d.controller.VideoDetails=d.controller.State.extend({defaults:b.defaults({id:"video-details",toolbar:"video-details",title:c.videoDetailsTitle,content:"video-details",menu:"video-details",router:!1,attachment:!1,priority:60,editing:!1},d.controller.Library.prototype.defaults),initialize:function(a){this.video=a.video,d.controller.State.prototype.initialize.apply(this,arguments)}}),d.controller.CollectionEdit=d.controller.Library.extend({defaults:{multiple:!1,describe:!0,edge:199,editing:!1,sortable:!0,searchable:!1,content:"browse",priority:60,dragInfo:!0,SettingsView:!1,syncSelection:!1},initialize:function(){var a=this.get("collectionType");this.set("id",a+"-edit"),this.set("toolbar",a+"-edit"),this.get("library")||this.set("library",new d.model.Selection),this.get("AttachmentView")||this.set("AttachmentView",d.view.Attachment.EditLibrary),d.controller.Library.prototype.initialize.apply(this,arguments)},activate:function(){var a=this.get("library");a.props.set("type",this.get("type")),this.get("library").observe(wp.Uploader.queue),this.frame.on("content:render:browse",this.renderSettings,this),d.controller.Library.prototype.activate.apply(this,arguments)},deactivate:function(){this.get("library").unobserve(wp.Uploader.queue),this.frame.off("content:render:browse",this.renderSettings,this),d.controller.Library.prototype.deactivate.apply(this,arguments)},renderSettings:function(b){var e=this.get("library"),f=this.get("collectionType"),g=this.get("dragInfoText"),h=this.get("SettingsView"),i={};e&&b&&(e[f]=e[f]||new Backbone.Model,i[f]=new h({controller:this,model:e[f],priority:40}),b.sidebar.set(i),g&&b.toolbar.set("dragInfo",new d.View({el:a('
'+g+"
")[0],priority:-40})),b.toolbar.set("reverse",{text:c.reverseOrder,priority:80,click:function(){e.reset(e.toArray().reverse())}}))}}),d.controller.CollectionAdd=d.controller.Library.extend({defaults:b.defaults({filterable:"uploaded",multiple:"add",priority:100,syncSelection:!1},d.controller.Library.prototype.defaults),initialize:function(){var a=this.get("collectionType");this.set("id",a+"-library"),this.set("toolbar",a+"-add"),this.set("menu",a),this.get("library")||this.set("library",d.query({type:this.get("type")})),d.controller.Library.prototype.initialize.apply(this,arguments)},activate:function(){var a=this.get("library"),b=this.get("editLibrary"),c=this.frame.state(this.get("collectionType")+"-edit").get("library");b&&b!==c&&a.unobserve(b),a.validator=function(a){return!!this.mirroring.get(a.cid)&&!c.get(a.cid)&&d.model.Selection.prototype.validator.apply(this,arguments)},a.reset(a.mirroring.models,{silent:!0}),a.observe(c),this.set("editLibrary",c),d.controller.Library.prototype.activate.apply(this,arguments)}}),d.controller.FeaturedImage=d.controller.Library.extend({defaults:b.defaults({id:"featured-image",filterable:"uploaded",multiple:!1,toolbar:"featured-image",title:c.setFeaturedImageTitle,priority:60,syncSelection:!1},d.controller.Library.prototype.defaults),initialize:function(){var a,b;this.get("library")||this.set("library",d.query({type:"image"})),d.controller.Library.prototype.initialize.apply(this,arguments),a=this.get("library"),b=a.comparator,a.comparator=function(a,c){var d=!!this.mirroring.get(a.cid),e=!!this.mirroring.get(c.cid);return!d&&e?-1:d&&!e?1:b.apply(this,arguments)},a.observe(this.get("selection"))},activate:function(){this.updateSelection(),this.frame.on("open",this.updateSelection,this),d.controller.Library.prototype.activate.apply(this,arguments)},deactivate:function(){this.frame.off("open",this.updateSelection,this),d.controller.Library.prototype.deactivate.apply(this,arguments)},updateSelection:function(){var a,b=this.get("selection"),c=d.view.settings.post.featuredImageId;""!==c&&-1!==c&&(a=d.model.Attachment.get(c),a.fetch()),b.reset(a?[a]:[])}}),d.controller.ReplaceImage=d.controller.Library.extend({defaults:b.defaults({id:"replace-image",filterable:"uploaded",multiple:!1,toolbar:"replace",title:c.replaceImageTitle,priority:60,syncSelection:!1},d.controller.Library.prototype.defaults),initialize:function(a){var b,c;this.image=a.image,this.get("library")||this.set("library",d.query({type:"image"})),d.controller.Library.prototype.initialize.apply(this,arguments),b=this.get("library"),c=b.comparator,b.comparator=function(a,b){var d=!!this.mirroring.get(a.cid),e=!!this.mirroring.get(b.cid);return!d&&e?-1:d&&!e?1:c.apply(this,arguments)},b.observe(this.get("selection"))},activate:function(){this.updateSelection(),d.controller.Library.prototype.activate.apply(this,arguments)},updateSelection:function(){var a=this.get("selection"),b=this.image.attachment;a.reset(b?[b]:[])}}),d.controller.ReplaceVideo=d.controller.Library.extend({defaults:b.defaults({id:"replace-video",filterable:"uploaded",multiple:!1,toolbar:"replace",title:c.replaceVideoTitle,priority:60,syncSelection:!1},d.controller.Library.prototype.defaults),initialize:function(a){var b,c;this.video=a.video,this.get("library")||this.set("library",d.query({type:"video"})),d.controller.Library.prototype.initialize.apply(this,arguments),b=this.get("library"),c=b.comparator,b.comparator=function(a,b){var d=!!this.mirroring.get(a.cid),e=!!this.mirroring.get(b.cid);return!d&&e?-1:d&&!e?1:c.apply(this,arguments)},b.observe(this.get("selection"))},activate:function(){this.updateSelection(),d.controller.Library.prototype.activate.apply(this,arguments)},updateSelection:function(){var a=this.get("selection"),b=this.video.attachment;a.reset(b?[b]:[])}}),d.controller.ReplaceAudio=d.controller.Library.extend({defaults:b.defaults({id:"replace-audio",filterable:"uploaded",multiple:!1,toolbar:"replace",title:c.replaceAudioTitle,priority:60,syncSelection:!1},d.controller.Library.prototype.defaults),initialize:function(a){var b,c;this.audio=a.audio,this.get("library")||this.set("library",d.query({type:"audio"})),d.controller.Library.prototype.initialize.apply(this,arguments),b=this.get("library"),c=b.comparator,b.comparator=function(a,b){var d=!!this.mirroring.get(a.cid),e=!!this.mirroring.get(b.cid);return!d&&e?-1:d&&!e?1:c.apply(this,arguments)},b.observe(this.get("selection"))},activate:function(){this.updateSelection(),d.controller.Library.prototype.activate.apply(this,arguments)},updateSelection:function(){var a=this.get("selection"),b=this.audio.attachment;a.reset(b?[b]:[])}}),d.controller.Embed=d.controller.State.extend({defaults:{id:"embed",url:"",menu:"default",content:"embed",toolbar:"main-embed",type:"link",title:c.insertFromUrlTitle,priority:120},sensitivity:200,initialize:function(){this.debouncedScan=b.debounce(b.bind(this.scan,this),this.sensitivity),this.props=new Backbone.Model({url:""}),this.props.on("change:url",this.debouncedScan,this),this.props.on("change:url",this.refresh,this),this.on("scan",this.scanImage,this)},scan:function(){var b,c=this,d={type:"link",scanners:[]};this.props.get("url")&&this.trigger("scan",d),d.scanners.length?(b=d.scanners=a.when.apply(a,d.scanners),b.always(function(){c.get("scanners")===b&&c.set("loading",!1)})):d.scanners=null,d.loading=!!d.scanners,this.set(d)},scanImage:function(b){var c=this.frame,d=this,e=this.props.get("url"),f=new Image,g=a.Deferred();b.scanners.push(g.promise()),f.onload=function(){g.resolve(),d===c.state()&&e===d.props.get("url")&&(d.set({type:"image"}),d.props.set({width:f.width,height:f.height}))},f.onerror=g.reject,f.src=e},refresh:function(){this.frame.toolbar.get().refresh()},reset:function(){this.props.clear().set({url:""}),this.active&&this.refresh()}}),d.View=wp.Backbone.View.extend({constructor:function(a){a&&a.controller&&(this.controller=a.controller),wp.Backbone.View.apply(this,arguments)},dispose:function(){return this.undelegateEvents(),this.model&&this.model.off&&this.model.off(null,null,this),this.collection&&this.collection.off&&this.collection.off(null,null,this),this.controller&&this.controller.off&&this.controller.off(null,null,this),this},remove:function(){return this.dispose(),wp.Backbone.View.prototype.remove.apply(this,arguments)}}),d.view.Frame=d.View.extend({initialize:function(){this._createRegions(),this._createStates()},_createRegions:function(){this.regions=this.regions?this.regions.slice():[],b.each(this.regions,function(a){this[a]=new d.controller.Region({view:this,id:a,selector:".media-frame-"+a})},this)},_createStates:function(){this.states=new Backbone.Collection(null,{model:d.controller.State}),this.states.on("add",function(a){a.frame=this,a.trigger("ready")},this),this.options.states&&this.states.add(this.options.states)},reset:function(){return this.states.invoke("trigger","reset"),this}}),b.extend(d.view.Frame.prototype,d.controller.StateMachine.prototype),d.view.MediaFrame=d.view.Frame.extend({className:"media-frame",template:d.template("media-frame"),regions:["menu","title","content","toolbar","router"],initialize:function(){d.view.Frame.prototype.initialize.apply(this,arguments),b.defaults(this.options,{title:"",modal:!0,uploader:!0}),this.$el.addClass("wp-core-ui"),this.options.modal&&(this.modal=new d.view.Modal({controller:this,title:this.options.title}),this.modal.content(this)),(wp.Uploader.limitExceeded||!wp.Uploader.browser.supported)&&(this.options.uploader=!1),this.options.uploader&&(this.uploader=new d.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",b.bind(this.views.ready,this.views),this),this.on("title:create:default",this.createTitle,this),this.title.mode("default"),this.on("menu:create:default",this.createMenu,this)},render:function(){return!this.state()&&this.options.state&&this.setState(this.options.state),d.view.Frame.prototype.render.apply(this,arguments)},createTitle:function(a){a.view=new d.View({controller:this,tagName:"h1"})},createMenu:function(a){a.view=new d.view.Menu({controller:this})},createToolbar:function(a){a.view=new d.view.Toolbar({controller:this})},createRouter:function(a){a.view=new d.view.Router({controller:this})},createIframeStates:function(c){var e,f=d.view.settings,g=f.tabs,h=f.tabUrl;g&&h&&(e=a("#post_ID"),e.length&&(h+="&post_id="+e.val()),b.each(g,function(a,d){this.state("iframe:"+d).set(b.defaults({tab:d,src:h+"&tab="+d,title:a,content:"iframe",menu:"default"},c))},this),this.on("content:create:iframe",this.iframeContent,this),this.on("menu:render:default",this.iframeMenu,this),this.on("open",this.hijackThickbox,this),this.on("close",this.restoreThickbox,this))},iframeContent:function(a){this.$el.addClass("hide-toolbar"),a.view=new d.view.Iframe({controller:this})},iframeMenu:function(a){var c={};a&&(b.each(d.view.settings.tabs,function(a,b){c["iframe:"+b]={text:this.state("iframe:"+b).get("title"),priority:200}},this),a.set(c))},hijackThickbox:function(){var a=this;window.tb_remove&&!this._tb_remove&&(this._tb_remove=window.tb_remove,window.tb_remove=function(){a.close(),a.reset(),a.setState(a.options.state),a._tb_remove.call(window)})},restoreThickbox:function(){this._tb_remove&&(window.tb_remove=this._tb_remove,delete this._tb_remove)}}),b.each(["open","close","attach","detach","escape"],function(a){d.view.MediaFrame.prototype[a]=function(){return this.modal&&this.modal[a].apply(this.modal,arguments),this}}),d.view.MediaFrame.Select=d.view.MediaFrame.extend({initialize:function(){d.view.MediaFrame.prototype.initialize.apply(this,arguments),b.defaults(this.options,{selection:[],library:{},multiple:!1,state:"library"}),this.createSelection(),this.createStates(),this.bindHandlers()},createSelection:function(){var a=this.options.selection;a instanceof d.model.Selection||(this.options.selection=new d.model.Selection(a,{multiple:this.options.multiple})),this._selection={attachments:new d.model.Attachments,difference:[]}},createStates:function(){var a=this.options;this.options.states||this.states.add([new d.controller.Library({library:d.query(a.library),multiple:a.multiple,title:a.title,priority:20})])},bindHandlers:function(){this.on("router:create:browse",this.createRouter,this),this.on("router:render:browse",this.browseRouter,this),this.on("content:create:browse",this.browseContent,this),this.on("content:render:upload",this.uploadContent,this),this.on("toolbar:create:select",this.createSelectToolbar,this)},browseRouter:function(a){a.set({upload:{text:c.uploadFilesTitle,priority:20},browse:{text:c.mediaLibraryTitle,priority:40}})},browseContent:function(a){var b=this.state();this.$el.removeClass("hide-toolbar"),a.view=new d.view.AttachmentsBrowser({controller:this,collection:b.get("library"),selection:b.get("selection"),model:b,sortable:b.get("sortable"),search:b.get("searchable"),filters:b.get("filterable"),display:b.get("displaySettings"),dragInfo:b.get("dragInfo"),AttachmentView:b.get("AttachmentView")})},uploadContent:function(){this.$el.removeClass("hide-toolbar"),this.content.set(new d.view.UploaderInline({controller:this}))},createSelectToolbar:function(a,b){b=b||this.options.button||{},b.controller=this,a.view=new d.view.Toolbar.Select(b)}}),d.view.MediaFrame.Post=d.view.MediaFrame.Select.extend({initialize:function(){b.defaults(this.options,{multiple:!0,editing:!1,state:"insert"}),d.view.MediaFrame.Select.prototype.initialize.apply(this,arguments),this.createIframeStates()},createStates:function(){var a=this.options;this.states.add([new d.controller.Library({id:"insert",title:c.insertMediaTitle,priority:20,toolbar:"main-insert",filterable:"all",library:d.query(a.library),multiple:a.multiple?"reset":!1,editable:!0,allowLocalEdits:!0,displaySettings:!0,displayUserSettings:!0}),new d.controller.Library({id:"gallery",title:c.createGalleryTitle,priority:40,toolbar:"main-gallery",filterable:"uploaded",multiple:"add",editable:!1,library:d.query(b.defaults({type:"image"},a.library))}),new d.controller.Embed,new d.controller.CollectionEdit({type:"image",collectionType:"gallery",title:c.editGalleryTitle,SettingsView:d.view.Settings.Gallery,library:a.selection,editing:a.editing,menu:"gallery"}),new d.controller.CollectionAdd({type:"image",collectionType:"gallery",title:c.addToGalleryTitle}),new d.controller.Library({id:"playlist",title:c.createPlaylistTitle,priority:60,toolbar:"main-playlist",filterable:"uploaded",multiple:"add",editable:!1,library:d.query(b.defaults({type:"audio"},a.library))}),new d.controller.CollectionEdit({type:"audio",collectionType:"playlist",title:c.editPlaylistTitle,SettingsView:d.view.Settings.Playlist,library:a.selection,editing:a.editing,menu:"playlist",dragInfoText:c.playlistDragInfo,dragInfo:!1}),new d.controller.CollectionAdd({type:"audio",collectionType:"playlist",title:c.addToPlaylistTitle}),new d.controller.Library({id:"video-playlist",title:c.createVideoPlaylistTitle,priority:60,toolbar:"main-video-playlist",filterable:"uploaded",multiple:"add",editable:!1,library:d.query(b.defaults({type:"video"},a.library))}),new d.controller.CollectionEdit({type:"video",collectionType:"video-playlist",title:c.editVideoPlaylistTitle,SettingsView:d.view.Settings.Playlist,library:a.selection,editing:a.editing,menu:"video-playlist",dragInfoText:c.videoPlaylistDragInfo,dragInfo:!1}),new d.controller.CollectionAdd({type:"video",collectionType:"video-playlist",title:c.addToVideoPlaylistTitle})]),d.view.settings.post.featuredImageId&&this.states.add(new d.controller.FeaturedImage)},bindHandlers:function(){d.view.MediaFrame.Select.prototype.bindHandlers.apply(this,arguments),this.on("menu:create:gallery",this.createMenu,this),this.on("menu:create:playlist",this.createMenu,this),this.on("menu:create:video-playlist",this.createMenu,this),this.on("toolbar:create:main-insert",this.createToolbar,this),this.on("toolbar:create:main-gallery",this.createToolbar,this),this.on("toolbar:create:main-playlist",this.createToolbar,this),this.on("toolbar:create:main-video-playlist",this.createToolbar,this),this.on("toolbar:create:featured-image",this.featuredImageToolbar,this),this.on("toolbar:create:main-embed",this.mainEmbedToolbar,this);var a={menu:{"default":"mainMenu",gallery:"galleryMenu",playlist:"playlistMenu","video-playlist":"videoPlaylistMenu"},content:{embed:"embedContent","edit-selection":"editSelectionContent"},toolbar:{"main-insert":"mainInsertToolbar","main-gallery":"mainGalleryToolbar","gallery-edit":"galleryEditToolbar","gallery-add":"galleryAddToolbar","main-playlist":"mainPlaylistToolbar","playlist-edit":"playlistEditToolbar","playlist-add":"playlistAddToolbar","main-video-playlist":"mainVideoPlaylistToolbar","video-playlist-edit":"videoPlaylistEditToolbar","video-playlist-add":"videoPlaylistAddToolbar"}};b.each(a,function(a,c){b.each(a,function(a,b){this.on(c+":render:"+b,this[a],this)},this)},this)},mainMenu:function(a){a.set({"library-separator":new d.View({className:"separator",priority:100})})},galleryMenu:function(a){var b=this.lastState(),e=b&&b.id,f=this;a.set({cancel:{text:c.cancelGalleryTitle,priority:20,click:function(){e?f.setState(e):f.close()}},separateCancel:new d.View({className:"separator",priority:40})})},playlistMenu:function(a){var b=this.lastState(),e=b&&b.id,f=this;a.set({cancel:{text:c.cancelPlaylistTitle,priority:20,click:function(){e?f.setState(e):f.close()}},separateCancel:new d.View({className:"separator",priority:40})})},videoPlaylistMenu:function(a){var b=this.lastState(),e=b&&b.id,f=this;a.set({cancel:{text:c.cancelVideoPlaylistTitle,priority:20,click:function(){e?f.setState(e):f.close()}},separateCancel:new d.View({className:"separator",priority:40})})},embedContent:function(){var a=new d.view.Embed({controller:this,model:this.state()}).render();this.content.set(a),a.url.focus()},editSelectionContent:function(){var a,b=this.state(),e=b.get("selection");a=new d.view.AttachmentsBrowser({controller:this,collection:e,selection:e,model:b,sortable:!0,search:!1,dragInfo:!0,AttachmentView:d.view.Attachment.EditSelection}).render(),a.toolbar.set("backToLibrary",{text:c.returnToLibrary,priority:-100,click:function(){this.controller.content.mode("browse")}}),this.content.set(a)},selectionStatusToolbar:function(a){var b=this.state().get("editable");a.set("selection",new d.view.Selection({controller:this,collection:this.state().get("selection"),priority:-40,editable:b&&function(){this.controller.content.mode("edit-selection")}}).render())},mainInsertToolbar:function(a){var b=this;this.selectionStatusToolbar(a),a.set("insert",{style:"primary",priority:80,text:c.insertIntoPost,requires:{selection:!0},click:function(){var a=b.state(),c=a.get("selection");b.close(),a.trigger("insert",c).reset()}})},mainGalleryToolbar:function(a){var b=this;this.selectionStatusToolbar(a),a.set("gallery",{style:"primary",text:c.createNewGallery,priority:60,requires:{selection:!0},click:function(){var a=b.state().get("selection"),c=b.state("gallery-edit"),e=a.where({type:"image"});c.set("library",new d.model.Selection(e,{props:a.props.toJSON(),multiple:!0})),this.controller.setState("gallery-edit")}})},mainPlaylistToolbar:function(a){var b=this;this.selectionStatusToolbar(a),a.set("playlist",{style:"primary",text:c.createNewPlaylist,priority:100,requires:{selection:!0},click:function(){var a=b.state().get("selection"),c=b.state("playlist-edit"),e=a.where({type:"audio"});c.set("library",new d.model.Selection(e,{props:a.props.toJSON(),multiple:!0})),this.controller.setState("playlist-edit")}})},mainVideoPlaylistToolbar:function(a){var b=this;this.selectionStatusToolbar(a),a.set("video-playlist",{style:"primary",text:c.createNewVideoPlaylist,priority:100,requires:{selection:!0},click:function(){var a=b.state().get("selection"),c=b.state("video-playlist-edit"),e=a.where({type:"video"});c.set("library",new d.model.Selection(e,{props:a.props.toJSON(),multiple:!0})),this.controller.setState("video-playlist-edit")}})},featuredImageToolbar:function(a){this.createSelectToolbar(a,{text:c.setFeaturedImage,state:this.options.state})},mainEmbedToolbar:function(a){a.view=new d.view.Toolbar.Embed({controller:this})},galleryEditToolbar:function(){var a=this.state().get("editing");this.toolbar.set(new d.view.Toolbar({controller:this,items:{insert:{style:"primary",text:a?c.updateGallery:c.insertGallery,priority:80,requires:{library:!0},click:function(){var a=this.controller,b=a.state();a.close(),b.trigger("update",b.get("library")),a.setState(a.options.state),a.reset()}}}}))},galleryAddToolbar:function(){this.toolbar.set(new d.view.Toolbar({controller:this,items:{insert:{style:"primary",text:c.addToGallery,priority:80,requires:{selection:!0},click:function(){var a=this.controller,b=a.state(),c=a.state("gallery-edit");c.get("library").add(b.get("selection").models),b.trigger("reset"),a.setState("gallery-edit")}}}}))},playlistEditToolbar:function(){var a=this.state().get("editing");this.toolbar.set(new d.view.Toolbar({controller:this,items:{insert:{style:"primary",text:a?c.updatePlaylist:c.insertPlaylist,priority:80,requires:{library:!0},click:function(){var a=this.controller,b=a.state();a.close(),b.trigger("update",b.get("library")),a.setState(a.options.state),a.reset()}}}}))},playlistAddToolbar:function(){this.toolbar.set(new d.view.Toolbar({controller:this,items:{insert:{style:"primary",text:c.addToPlaylist,priority:80,requires:{selection:!0},click:function(){var a=this.controller,b=a.state(),c=a.state("playlist-edit");c.get("library").add(b.get("selection").models),b.trigger("reset"),a.setState("playlist-edit")}}}}))},videoPlaylistEditToolbar:function(){var a=this.state().get("editing");this.toolbar.set(new d.view.Toolbar({controller:this,items:{insert:{style:"primary",text:a?c.updateVideoPlaylist:c.insertVideoPlaylist,priority:140,requires:{library:!0},click:function(){var a=this.controller,b=a.state();a.close(),b.trigger("update",b.get("library")),a.setState(a.options.state),a.reset()}}}}))},videoPlaylistAddToolbar:function(){this.toolbar.set(new d.view.Toolbar({controller:this,items:{insert:{style:"primary",text:c.addToVideoPlaylist,priority:140,requires:{selection:!0},click:function(){var a=this.controller,b=a.state(),c=a.state("video-playlist-edit");c.get("library").add(b.get("selection").models),b.trigger("reset"),a.setState("video-playlist-edit")}}}}))}}),d.view.MediaFrame.ImageDetails=d.view.MediaFrame.Select.extend({defaults:{id:"image",url:"",menu:"image-details",content:"image-details",toolbar:"image-details",type:"link",title:c.imageDetailsTitle,priority:120},initialize:function(a){this.image=new d.model.PostImage(a.metadata),this.options.selection=new d.model.Selection(this.image.attachment,{multiple:!1}),d.view.MediaFrame.Select.prototype.initialize.apply(this,arguments)},bindHandlers:function(){d.view.MediaFrame.Select.prototype.bindHandlers.apply(this,arguments),this.on("menu:create:image-details",this.createMenu,this),this.on("content:render:image-details",this.renderImageDetailsContent,this),this.on("menu:render:image-details",this.renderMenu,this),this.on("toolbar:render:image-details",this.renderImageDetailsToolbar,this),this.on("toolbar:render:replace",this.renderReplaceImageToolbar,this)},createStates:function(){this.states.add([new d.controller.ImageDetails({image:this.image,editable:!1,menu:"image-details"}),new d.controller.ReplaceImage({id:"replace-image",library:d.query({type:"image"}),image:this.image,multiple:!1,title:c.imageReplaceTitle,menu:"image-details",toolbar:"replace",priority:80,displaySettings:!0})])},renderImageDetailsContent:function(){var a=new d.view.ImageDetails({controller:this,model:this.state().image,attachment:this.state().image.attachment}).render();this.content.set(a)},renderMenu:function(a){var b=this.lastState(),e=b&&b.id,f=this;a.set({cancel:{text:c.imageDetailsCancel,priority:20,click:function(){e?f.setState(e):f.close()}},separateCancel:new d.View({className:"separator",priority:40})}) },renderImageDetailsToolbar:function(){this.toolbar.set(new d.view.Toolbar({controller:this,items:{select:{style:"primary",text:c.update,priority:80,click:function(){var a=this.controller,b=a.state();a.close(),b.trigger("update",a.image.toJSON()),a.setState(a.options.state),a.reset()}}}}))},renderReplaceImageToolbar:function(){this.toolbar.set(new d.view.Toolbar({controller:this,items:{replace:{style:"primary",text:c.replace,priority:80,click:function(){var a=this.controller,b=a.state(),c=b.get("selection"),d=c.single();a.close(),a.image.changeAttachment(d,b.display(d)),b.trigger("replace",a.image.toJSON()),a.setState(a.options.state),a.reset()}}}}))}}),d.view.MediaFrame.AudioDetails=d.view.MediaFrame.Select.extend({defaults:{id:"audio",url:"",menu:"audio-details",content:"audio-details",toolbar:"audio-details",type:"link",title:c.audioDetailsTitle,priority:120},initialize:function(a){this.audio=new d.model.PostAudio(a.metadata),this.options.selection=new d.model.Selection(this.audio.attachment,{multiple:!1}),d.view.MediaFrame.Select.prototype.initialize.apply(this,arguments)},bindHandlers:function(){d.view.MediaFrame.Select.prototype.bindHandlers.apply(this,arguments),this.on("menu:create:audio-details",this.createMenu,this),this.on("content:render:audio-details",this.renderAudioDetailsContent,this),this.on("menu:render:audio-details",this.renderMenu,this),this.on("toolbar:render:audio-details",this.renderAudioDetailsToolbar,this),this.on("toolbar:render:replace",this.renderReplaceAudioToolbar,this)},createStates:function(){this.states.add([new d.controller.AudioDetails({audio:this.audio,editable:!1,menu:"audio-details"}),new d.controller.ReplaceAudio({id:"replace-audio",library:d.query({type:"audio"}),audio:this.audio,multiple:!1,title:c.audioReplaceTitle,menu:"audio-details",toolbar:"replace",priority:80,displaySettings:!0})])},renderAudioDetailsContent:function(){var a=new d.view.AudioDetails({controller:this,model:this.state().audio,attachment:this.state().audio.attachment}).render();this.content.set(a)},renderMenu:function(a){var b=this.lastState(),e=b&&b.id,f=this;a.set({cancel:{text:c.audioDetailsCancel,priority:20,click:function(){e?f.setState(e):f.close()}},separateCancel:new d.View({className:"separator",priority:40})})},renderAudioDetailsToolbar:function(){this.toolbar.set(new d.view.Toolbar({controller:this,items:{select:{style:"primary",text:c.update,priority:80,click:function(){var a=this.controller,b=a.state();a.close(),b.trigger("update",a.audio.toJSON()),a.setState(a.options.state),a.reset()}}}}))},renderReplaceAudioToolbar:function(){this.toolbar.set(new d.view.Toolbar({controller:this,items:{replace:{style:"primary",text:c.replace,priority:80,click:function(){var a=this.controller,b=a.state(),c=b.get("selection"),d=c.single();a.audio.changeAttachment(d,b.display(d)),b.trigger("replace",a.audio.toJSON()),a.setState(a.options.state),a.reset()}}}}))}}),d.view.MediaFrame.VideoDetails=d.view.MediaFrame.Select.extend({defaults:{id:"video",url:"",menu:"video-details",content:"video-details",toolbar:"video-details",type:"link",title:c.videoDetailsTitle,priority:120},initialize:function(a){this.video=new d.model.PostVideo(a.metadata),this.options.selection=new d.model.Selection(this.video.attachment,{multiple:!1}),d.view.MediaFrame.Select.prototype.initialize.apply(this,arguments)},bindHandlers:function(){d.view.MediaFrame.Select.prototype.bindHandlers.apply(this,arguments),this.on("menu:create:video-details",this.createMenu,this),this.on("content:render:video-details",this.renderVideoDetailsContent,this),this.on("menu:render:video-details",this.renderMenu,this),this.on("toolbar:render:video-details",this.renderVideoDetailsToolbar,this),this.on("toolbar:render:replace",this.renderReplaceVideoToolbar,this)},createStates:function(){this.states.add([new d.controller.VideoDetails({video:this.video,editable:!1,menu:"video-details"}),new d.controller.ReplaceVideo({id:"replace-video",library:d.query({type:"video"}),video:this.video,multiple:!1,title:c.videoReplaceTitle,menu:"video-details",toolbar:"replace",priority:80,displaySettings:!0})])},renderVideoDetailsContent:function(){var a=new d.view.VideoDetails({controller:this,model:this.state().video,attachment:this.state().video.attachment}).render();this.content.set(a)},renderMenu:function(a){var b=this.lastState(),e=b&&b.id,f=this;a.set({cancel:{text:c.videoDetailsCancel,priority:20,click:function(){e?f.setState(e):f.close()}},separateCancel:new d.View({className:"separator",priority:40})})},renderVideoDetailsToolbar:function(){this.toolbar.set(new d.view.Toolbar({controller:this,items:{select:{style:"primary",text:c.update,priority:80,click:function(){var a=this.controller,b=a.state();a.close(),b.trigger("update",a.video.toJSON()),a.setState(a.options.state),a.reset()}}}}))},renderReplaceVideoToolbar:function(){this.toolbar.set(new d.view.Toolbar({controller:this,items:{replace:{style:"primary",text:c.replace,priority:80,click:function(){var a=this.controller,b=a.state(),c=b.get("selection"),d=c.single();a.video.changeAttachment(d,b.display(d)),b.trigger("replace",a.video.toJSON()),a.setState(a.options.state),a.reset()}}}}))}}),d.view.Modal=d.View.extend({tagName:"div",template:d.template("media-modal"),attributes:{tabindex:0},events:{"click .media-modal-backdrop, .media-modal-close":"escapeHandler",keydown:"keydown"},initialize:function(){b.defaults(this.options,{container:document.body,title:"",propagate:!0,freeze:!0})},prepare:function(){return{title:this.options.title}},attach:function(){return this.views.attached?this:(this.views.rendered||this.render(),this.$el.appendTo(this.options.container),this.views.attached=!0,this.views.ready(),this.propagate("attach"))},detach:function(){return this.$el.is(":visible")&&this.close(),this.$el.detach(),this.views.attached=!1,this.propagate("detach")},open:function(){var b=this.$el,c=this.options;return b.is(":visible")?this:(this.views.attached||this.attach(),c.freeze&&(this._freeze={scrollTop:a(window).scrollTop()}),b.show().focus(),this.propagate("open"))},close:function(b){var c=this._freeze;return this.views.attached&&this.$el.is(":visible")?(this.$el.hide(),this.propagate("close"),c&&a(window).scrollTop(c.scrollTop),b&&b.escape&&this.propagate("escape"),this):this},escape:function(){return this.close({escape:!0})},escapeHandler:function(a){a.preventDefault(),this.escape()},content:function(a){return this.views.set(".media-modal-content",a),this},propagate:function(a){return this.trigger(a),this.options.propagate&&this.controller.trigger(a),this},keydown:function(a){27===a.which&&this.$el.is(":visible")&&(this.escape(),a.stopImmediatePropagation())}}),d.view.FocusManager=d.View.extend({events:{keydown:"recordTab",focusin:"updateIndex"},focus:function(){b.isUndefined(this.index)||(this.$tabbables=this.$(":tabbable"),this.$tabbables.eq(this.index).focus())},recordTab:function(a){if(9===a.keyCode&&(b.isUndefined(this.index)&&this.updateIndex(a),!b.isUndefined(this.index))){var c=this.index+(a.shiftKey?-1:1);c>=0&&c').hide().appendTo("body"),c=this.options.uploader=b.defaults(this.options.uploader||{},{dropzone:this.$el,browser:this.$browser,params:{}}),!c.dropzone||c.dropzone instanceof a||(c.dropzone=a(c.dropzone)),this.controller.on("activate",this.refresh,this),this.controller.on("detach",function(){this.$browser.remove()},this)},refresh:function(){this.uploader&&this.uploader.refresh()},ready:function(){var c,e=d.view.settings.post.id;this.uploader||(e&&(this.options.uploader.params.post_id=e),this.uploader=new wp.Uploader(this.options.uploader),c=this.uploader.dropzone,c.on("dropzone:enter",b.bind(this.show,this)),c.on("dropzone:leave",b.bind(this.hide,this)),a(this.uploader).on("uploader:ready",b.bind(this._ready,this)))},_ready:function(){this.controller.trigger("uploader:ready")},show:function(){var a=this.$el.show();b.defer(function(){a.css({opacity:1})})},hide:function(){var a=this.$el.css({opacity:0});d.transition(a).done(function(){"0"===a.css("opacity")&&a.hide()})}}),d.view.EditorUploader=d.View.extend({tagName:"div",className:"uploader-editor",template:d.template("uploader-editor"),initialize:function(){return this.$document=a(document),this.dropzones=[],this.files=[],this.$document.on("drop",".uploader-editor",b.bind(this.drop,this)),this.$document.on("dragover",".uploader-editor",b.bind(this.dropzoneDragover,this)),this.$document.on("dragleave",".uploader-editor",b.bind(this.dropzoneDragleave,this)),this.$document.on("dragover",b.bind(this.containerDragover,this)),this.$document.on("dragleave",b.bind(this.containerDragleave,this)),this},refresh:function(){var a;for(a in this.dropzones)this.dropzones[a].toggle(this.overContainer||this.overDropzone);return this},render:function(){return d.View.prototype.render.apply(this,arguments),a(".wp-editor-wrap").each(b.bind(this.attach,this)),this},attach:function(b,c){var d=this.$el.clone();return this.dropzones.push(d),a(c).append(d),this},drop:function(b){var c=null;return this.files=b.originalEvent.dataTransfer.files,this.files.length<1?void 0:(this.containerDragleave(b),this.dropzoneDragleave(b),c=a(b.target).parents(".wp-editor-wrap"),c.length>0&&(window.wpActiveEditor=c[0].id.slice(3,-5)),this.workflow?(this.workflow.state().reset(),this.addFiles.apply(this),this.workflow.open()):(this.workflow=wp.media.editor.open("content",{frame:"post",state:"insert",title:wp.media.view.l10n.addMedia,multiple:!0}),this.workflow.on("uploader:ready",this.addFiles,this)),!1)},addFiles:function(){return this.files.length&&(this.workflow.uploader.uploader.uploader.addFile(b.toArray(this.files)),this.files=[]),this},containerDragover:function(){this.overContainer=!0,this.refresh()},containerDragleave:function(){this.overContainer=!1,b.delay(b.bind(this.refresh,this),50)},dropzoneDragover:function(c){return a(c.target).addClass("droppable"),this.overDropzone=!0,b.defer(b.bind(this.refresh,this)),!1},dropzoneDragleave:function(b){a(b.target).removeClass("droppable"),this.overDropzone=!1,this.refresh()}}),d.view.UploaderInline=d.View.extend({tagName:"div",className:"uploader-inline",template:d.template("uploader-inline"),initialize:function(){b.defaults(this.options,{message:"",status:!0}),!this.options.$browser&&this.controller.uploader&&(this.options.$browser=this.controller.uploader.$browser),b.isUndefined(this.options.postId)&&(this.options.postId=d.view.settings.post.id),this.options.status&&this.views.set(".upload-inline-status",new d.view.UploaderStatus({controller:this.controller}))},dispose:function(){return this.disposing?d.View.prototype.dispose.apply(this,arguments):(this.disposing=!0,this.remove())},remove:function(){var a=d.View.prototype.remove.apply(this,arguments);return b.defer(b.bind(this.refresh,this)),a},refresh:function(){var a=this.controller.uploader;a&&a.refresh()},ready:function(){var a,b=this.options.$browser;if(this.controller.uploader){if(a=this.$(".browser"),a[0]===b[0])return;b.detach().text(a.text()),b[0].className=a[0].className,a.replaceWith(b.show())}return this.refresh(),this}}),d.view.UploaderStatus=d.View.extend({className:"media-uploader-status",template:d.template("uploader-status"),events:{"click .upload-dismiss-errors":"dismiss"},initialize:function(){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(){return wp.Uploader.queue.off(null,null,this),d.View.prototype.dispose.apply(this,arguments),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(){b.each({$bar:".media-progress-bar div",$index:".upload-index",$total:".upload-total",$filename:".upload-filename"},function(a,b){this[b]=this.$(a)},this),this.visibility(),this.progress(),this.info()},progress:function(){var a=this.queue,c=this.$bar;c&&a.length&&c.width(a.reduce(function(a,c){if(!c.get("uploading"))return a+100;var d=c.get("percent");return a+(b.isNumber(d)?d:100)},0)/a.length+"%")},info:function(){var a,b=this.queue,c=0;b.length&&(a=this.queue.find(function(a,b){return c=b,a.get("uploading")}),this.$index.text(c+1),this.$total.text(b.length),this.$filename.html(a?this.filename(a.get("filename")):""))},filename:function(a){return d.truncate(b.escape(a),24)},error:function(a){this.views.add(".upload-errors",new d.view.UploaderStatusError({filename:this.filename(a.get("file").name),message:a.get("message")}),{at:0})},dismiss:function(a){var c=this.views.get(".upload-errors");a.preventDefault(),c&&b.invoke(c,"remove"),wp.Uploader.errors.reset()}}),d.view.UploaderStatusError=d.View.extend({className:"upload-error",template:d.template("uploader-status-error")}),d.view.Toolbar=d.View.extend({tagName:"div",className:"media-toolbar",initialize:function(){var a=this.controller.state(),b=this.selection=a.get("selection"),c=this.library=a.get("library");this._views={},this.primary=new d.view.PriorityList,this.secondary=new d.view.PriorityList,this.primary.$el.addClass("media-toolbar-primary"),this.secondary.$el.addClass("media-toolbar-secondary"),this.views.set([this.secondary,this.primary]),this.options.items&&this.set(this.options.items,{silent:!0}),this.options.silent||this.render(),b&&b.on("add remove reset",this.refresh,this),c&&c.on("add remove reset",this.refresh,this)},dispose:function(){return this.selection&&this.selection.off(null,null,this),this.library&&this.library.off(null,null,this),d.View.prototype.dispose.apply(this,arguments)},ready:function(){this.refresh()},set:function(a,c,e){var f;return e=e||{},b.isObject(a)?b.each(a,function(a,b){this.set(b,a,{silent:!0})},this):(c instanceof Backbone.View||(c.classes=["media-button-"+a].concat(c.classes||[]),c=new d.view.Button(c).render()),c.controller=c.controller||this.controller,this._views[a]=c,f=c.options.priority<0?"secondary":"primary",this[f].set(a,c,e)),e.silent||this.refresh(),this},get:function(a){return this._views[a]},unset:function(a,b){return delete this._views[a],this.primary.unset(a,b),this.secondary.unset(a,b),b&&b.silent||this.refresh(),this},refresh:function(){var a=this.controller.state(),c=a.get("library"),d=a.get("selection");b.each(this._views,function(a){if(a.model&&a.options&&a.options.requires){var e=a.options.requires,f=!1;f=b.some(d.models,function(a){return a.get("uploading")===!0}),e.selection&&d&&!d.length?f=!0:e.library&&c&&!c.length&&(f=!0),a.model.set("disabled",f)}})}}),d.view.Toolbar.Select=d.view.Toolbar.extend({initialize:function(){var a=this.options;b.bindAll(this,"clickSelect"),b.defaults(a,{event:"select",state:!1,reset:!0,close:!0,text:c.select,requires:{selection:!0}}),a.items=b.defaults(a.items||{},{select:{style:"primary",text:a.text,priority:80,click:this.clickSelect,requires:a.requires}}),d.view.Toolbar.prototype.initialize.apply(this,arguments)},clickSelect:function(){var a=this.options,b=this.controller;a.close&&b.close(),a.event&&b.state().trigger(a.event),a.state&&b.setState(a.state),a.reset&&b.reset()}}),d.view.Toolbar.Embed=d.view.Toolbar.Select.extend({initialize:function(){b.defaults(this.options,{text:c.insertIntoPost,requires:!1}),d.view.Toolbar.Select.prototype.initialize.apply(this,arguments)},refresh:function(){var a=this.controller.state().props.get("url");this.get("select").model.set("disabled",!a||"http://"===a),d.view.Toolbar.Select.prototype.refresh.apply(this,arguments)}}),d.view.Button=d.View.extend({tagName:"a",className:"media-button",attributes:{href:"#"},events:{click:"click"},defaults:{text:"",style:"",size:"large",disabled:!1},initialize:function(){this.model=new Backbone.Model(this.defaults),b.each(this.defaults,function(a,c){var d=this.options[c];b.isUndefined(d)||(this.model.set(c,d),delete this.options[c])},this),this.model.on("change",this.render,this)},render:function(){var a=["button",this.className],c=this.model.toJSON();return c.style&&a.push("button-"+c.style),c.size&&a.push("button-"+c.size),a=b.uniq(a.concat(this.options.classes)),this.el.className=a.join(" "),this.$el.attr("disabled",c.disabled),this.$el.text(this.model.get("text")),this},click:function(a){"#"===this.attributes.href&&a.preventDefault(),this.options.click&&!this.model.get("disabled")&&this.options.click.apply(this,arguments)}}),d.view.ButtonGroup=d.View.extend({tagName:"div",className:"button-group button-large media-button-group",initialize:function(){this.buttons=b.map(this.options.buttons||[],function(a){return a instanceof Backbone.View?a:new d.view.Button(a).render()}),delete this.options.buttons,this.options.classes&&this.$el.addClass(this.options.classes)},render:function(){return this.$el.html(a(b.pluck(this.buttons,"el")).detach()),this}}),d.view.PriorityList=d.View.extend({tagName:"div",initialize:function(){this._views={},this.set(b.extend({},this._views,this.options.views),{silent:!0}),delete this.options.views,this.options.silent||this.render()},set:function(a,c,d){var e,f,g;return d=d||{},b.isObject(a)?(b.each(a,function(a,b){this.set(b,a)},this),this):(c instanceof Backbone.View||(c=this.toView(c,a,d)),c.controller=c.controller||this.controller,this.unset(a),e=c.options.priority||10,f=this.views.get()||[],b.find(f,function(a,b){return a.options.priority>e?(g=b,!0):void 0}),this._views[a]=c,this.views.add(c,{at:b.isNumber(g)?g:f.length||0}),this)},get:function(a){return this._views[a]},unset:function(a){var b=this.get(a);return b&&b.remove(),delete this._views[a],this},toView:function(a){return new d.View(a)}}),d.view.MenuItem=d.View.extend({tagName:"a",className:"media-menu-item",attributes:{href:"#"},events:{click:"_click"},_click:function(a){var b=this.options.click;a&&a.preventDefault(),b?b.call(this):this.click()},click:function(){var a=this.options.state;a&&this.controller.setState(a)},render:function(){var a=this.options;return a.text?this.$el.text(a.text):a.html&&this.$el.html(a.html),this}}),d.view.Menu=d.view.PriorityList.extend({tagName:"div",className:"media-menu",property:"state",ItemView:d.view.MenuItem,region:"menu",toView:function(a,b){return a=a||{},a[this.property]=a[this.property]||b,new this.ItemView(a).render()},ready:function(){d.view.PriorityList.prototype.ready.apply(this,arguments),this.visibility()},set:function(){d.view.PriorityList.prototype.set.apply(this,arguments),this.visibility()},unset:function(){d.view.PriorityList.prototype.unset.apply(this,arguments),this.visibility()},visibility:function(){var a=this.region,b=this.controller[a].get(),c=this.views.get(),d=!c||c.length<2;this===b&&this.controller.$el.toggleClass("hide-"+a,d)},select:function(a){var b=this.get(a);b&&(this.deselect(),b.$el.addClass("active"))},deselect:function(){this.$el.children().removeClass("active")}}),d.view.RouterItem=d.view.MenuItem.extend({click:function(){var a=this.options.contentMode;a&&this.controller.content.mode(a)}}),d.view.Router=d.view.Menu.extend({tagName:"div",className:"media-router",property:"contentMode",ItemView:d.view.RouterItem,region:"router",initialize:function(){this.controller.on("content:render",this.update,this),d.view.Menu.prototype.initialize.apply(this,arguments)},update:function(){var a=this.controller.content.mode();a&&this.select(a)}}),d.view.Sidebar=d.view.PriorityList.extend({className:"media-sidebar"}),d.view.Attachment=d.View.extend({tagName:"li",className:"attachment",template:d.template("attachment"),events:{"click .attachment-preview":"toggleSelectionHandler","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(){var a=this.options.selection;this.model.on("change:sizes change:uploading",this.render,this),this.model.on("change:title",this._syncTitle,this),this.model.on("change:caption",this._syncCaption,this),this.model.on("change:percent",this.progress,this),this.model.on("add",this.select,this),this.model.on("remove",this.deselect,this),a&&a.on("reset",this.updateSelect,this),this.model.on("selection:single selection:unsingle",this.details,this),this.details(this.model,this.controller.state().get("selection"))},dispose:function(){var a=this.options.selection;return this.updateAll(),a&&a.off(null,null,this),d.View.prototype.dispose.apply(this,arguments),this},render:function(){var a=b.defaults(this.model.toJSON(),{orientation:"landscape",uploading:!1,type:"",subtype:"",icon:"",filename:"",caption:"",title:"",dateFormatted:"",width:"",height:"",compat:!1,alt:"",description:""});return a.buttons=this.buttons,a.describe=this.controller.state().get("describe"),"image"===a.type&&(a.size=this.imageSize()),a.can={},a.nonces&&(a.can.remove=!!a.nonces["delete"],a.can.save=!!a.nonces.update),this.controller.state().get("allowLocalEdits")&&(a.allowLocalEdits=!0),this.views.detach(),this.$el.html(this.template(a)),this.$el.toggleClass("uploading",a.uploading),a.uploading?this.$bar=this.$(".media-progress-bar div"):delete this.$bar,this.updateSelect(),this.updateSave(),this.views.render(),this},progress:function(){this.$bar&&this.$bar.length&&this.$bar.width(this.model.get("percent")+"%")},toggleSelectionHandler:function(a){var b;a.shiftKey?b="between":(a.ctrlKey||a.metaKey)&&(b="toggle"),this.toggleSelection({method:b})},toggleSelection:function(a){var c,d,e,f,g=this.collection,h=this.options.selection,i=this.model,j=a&&a.method;if(h){if(c=h.single(),j=b.isUndefined(j)?h.multiple:j,"between"===j&&c&&h.multiple){if(c===i)return;return e=g.indexOf(c),f=g.indexOf(this.model),d=f>e?g.models.slice(e,f+1):g.models.slice(f,e+1),h.add(d),void h.single(i)}if("toggle"===j)return h[this.selected()?"remove":"add"](i),void h.single(i);"add"!==j&&(j="reset"),this.selected()?h[c===i?"remove":"single"](i):(h[j](i),h.single(i))}},updateSelect:function(){this[this.selected()?"select":"deselect"]()},selected:function(){var a=this.options.selection;return a?!!a.get(this.model.cid):void 0},select:function(a,b){var c=this.options.selection;!c||b&&b!==c||this.$el.addClass("selected")},deselect:function(a,b){var c=this.options.selection;!c||b&&b!==c||this.$el.removeClass("selected")},details:function(a,b){var c,d=this.options.selection;d===b&&(c=d.single(),this.$el.toggleClass("details",c===this.model))},preventDefault:function(a){a.preventDefault()},imageSize:function(a){var c=this.model.get("sizes");return a=a||"medium",c&&c[a]?b.clone(c[a]):{url:this.model.get("url"),width:this.model.get("width"),height:this.model.get("height"),orientation:this.model.get("orientation")}},updateSetting:function(b){var c,d,e=a(b.target).closest("[data-setting]");e.length&&(c=e.data("setting"),d=b.target.value,this.model.get(c)!==d&&this.save(c,d))},save:function(){var b=this,c=this._save=this._save||{status:"ready"},d=this.model.save.apply(this.model,arguments),e=c.requests?a.when(d,c.requests):d;c.savedTimer&&clearTimeout(c.savedTimer),this.updateSave("waiting"),c.requests=e,e.always(function(){c.requests===e&&(b.updateSave("resolved"===e.state()?"complete":"error"),c.savedTimer=setTimeout(function(){b.updateSave("ready"),delete c.savedTimer},2e3))})},updateSave:function(a){var b=this._save=this._save||{status:"ready"};return a&&a!==b.status&&(this.$el.removeClass("save-"+b.status),b.status=a),this.$el.addClass("save-"+b.status),this},updateAll:function(){var c,d=this.$("[data-setting]"),e=this.model;c=b.chain(d).map(function(b){var c,d,f=a("input, textarea, select, [value]",b);if(f.length)return c=a(b).data("setting"),d=f.val(),e.get(c)!==d?[c,d]:void 0}).compact().object().value(),b.isEmpty(c)||e.save(c)},removeFromLibrary:function(a){a.stopPropagation(),this.collection.remove(this.model)},removeFromSelection:function(a){var b=this.options.selection;b&&(a.stopPropagation(),b.remove(this.model))}}),b.each({caption:"_syncCaption",title:"_syncTitle"},function(a,b){d.view.Attachment.prototype[a]=function(a,c){var d=this.$('[data-setting="'+b+'"]');return d.length?c===d.find("input, textarea, select, [value]").val()?this:this.render():this}}),d.view.Attachment.Library=d.view.Attachment.extend({buttons:{check:!0}}),d.view.Attachment.EditLibrary=d.view.Attachment.extend({buttons:{close:!0}}),d.view.Attachments=d.View.extend({tagName:"ul",className:"attachments",cssTemplate:d.template("attachments-css"),events:{scroll:"scroll"},initialize:function(){this.el.id=b.uniqueId("__attachments-view-"),b.defaults(this.options,{refreshSensitivity:200,refreshThreshold:3,AttachmentView:d.view.Attachment,sortable:!1,resize:!0}),this._viewsByCid={},this.collection.on("add",function(a){this.views.add(this.createAttachmentView(a),{at:this.collection.indexOf(a)})},this),this.collection.on("remove",function(a){var b=this._viewsByCid[a.cid];delete this._viewsByCid[a.cid],b&&b.remove()},this),this.collection.on("reset",this.render,this),this.scroll=b.chain(this.scroll).bind(this).throttle(this.options.refreshSensitivity).value(),this.initSortable(),b.bindAll(this,"css"),this.model.on("change:edge change:gutter",this.css,this),this._resizeCss=b.debounce(b.bind(this.css,this),this.refreshSensitivity),this.options.resize&&a(window).on("resize.attachments",this._resizeCss),this.css()},dispose:function(){this.collection.props.off(null,null,this),a(window).off("resize.attachments",this._resizeCss),d.View.prototype.dispose.apply(this,arguments)},css:function(){var b=a("#"+this.el.id+"-css");b.length&&b.remove(),d.view.Attachments.$head().append(this.cssTemplate({id:this.el.id,edge:this.edge(),gutter:this.model.get("gutter")}))},edge:function(){var a,b,c,d=this.model.get("edge");return this.$el.is(":visible")?(a=2*this.model.get("gutter"),b=this.$el.width()-a,c=Math.ceil(b/(d+a)),d=Math.floor((b-c*a)/c)):d},initSortable:function(){var c=this.collection;this.options.sortable&&a.fn.sortable&&(this.$el.sortable(b.extend({disabled:!!c.comparator,containment:this.$el,tolerance:"pointer",start:function(a,b){b.item.data("sortableIndexStart",b.item.index())},update:function(a,b){var d=c.at(b.item.data("sortableIndexStart")),e=c.comparator;delete c.comparator,c.remove(d,{silent:!0}),c.add(d,{silent:!0,at:b.item.index()}),c.comparator=e,c.trigger("reset",c),c.saveMenuOrder()}},this.options.sortable)),c.props.on("change:orderby",function(){this.$el.sortable("option","disabled",!!c.comparator)},this),this.collection.props.on("change:orderby",this.refreshSortable,this),this.refreshSortable())},refreshSortable:function(){if(this.options.sortable&&a.fn.sortable){var b=this.collection,c=b.props.get("orderby"),d="menuOrder"===c||!b.comparator;this.$el.sortable("option","disabled",!d)}},createAttachmentView:function(a){var b=new this.options.AttachmentView({controller:this.controller,model:a,collection:this.collection,selection:this.options.selection});return this._viewsByCid[a.cid]=b},prepare:function(){this.collection.length?this.views.set(this.collection.map(this.createAttachmentView,this)):(this.views.unset(),this.collection.more().done(this.scroll))},ready:function(){this.scroll()},scroll:function(){this.$el.is(":visible")&&this.collection.hasMore()&&this.el.scrollHeight").val(c).text(b.text)[0],priority:b.priority||50}},this).sortBy("priority").pluck("el").value()),this.model.on("change",this.select,this),this.select()},createFilters:function(){this.filters={}},change:function(){var a=this.filters[this.el.value];a&&this.model.set(a.props)},select:function(){var a=this.model,c="all",d=a.toJSON();b.find(this.filters,function(a,e){var f=b.all(a.props,function(a,c){return a===(b.isUndefined(d[c])?null:d[c])});return f?c=e:void 0}),this.$el.val(c)}}),d.view.AttachmentFilters.Uploaded=d.view.AttachmentFilters.extend({createFilters:function(){var a,b=this.model.get("type"),e=d.view.settings.mimeTypes;e&&b&&(a=e[b]),this.filters={all:{text:a||c.allMediaItems,props:{uploadedTo:null,orderby:"date",order:"DESC"},priority:10},uploaded:{text:c.uploadedToThisPost,props:{uploadedTo:d.view.settings.post.id,orderby:"menuOrder",order:"ASC"},priority:20}}}}),d.view.AttachmentFilters.All=d.view.AttachmentFilters.extend({createFilters:function(){var a={};b.each(d.view.settings.mimeTypes||{},function(b,c){a[c]={text:b,props:{type:c,uploadedTo:null,orderby:"date",order:"DESC"}}}),a.all={text:c.allMediaItems,props:{type:null,uploadedTo:null,orderby:"date",order:"DESC"},priority:10},a.uploaded={text:c.uploadedToThisPost,props:{type:null,uploadedTo:d.view.settings.post.id,orderby:"menuOrder",order:"ASC"},priority:20},this.filters=a}}),d.view.AttachmentsBrowser=d.View.extend({tagName:"div",className:"attachments-browser",initialize:function(){b.defaults(this.options,{filters:!1,search:!0,display:!1,AttachmentView:d.view.Attachment.Library}),this.createToolbar(),this.updateContent(),this.createSidebar(),this.collection.on("add remove reset",this.updateContent,this)},toggleSpinner:function(a){a?this.spinnerTimeout=b.delay(function(a){a.toolbar.get("spinner").show()},600,this):(this.toolbar.get("spinner").hide(),clearTimeout(this.spinnerTimeout))},dispose:function(){return this.options.selection.off(null,null,this),d.View.prototype.dispose.apply(this,arguments),this},createToolbar:function(){var b,e;this.toolbar=new d.view.Toolbar({controller:this.controller}),this.views.add(this.toolbar),b=this.options.filters,"uploaded"===b?e=d.view.AttachmentFilters.Uploaded:"all"===b&&(e=d.view.AttachmentFilters.All),e&&this.toolbar.set("filters",new e({controller:this.controller,model:this.collection.props,priority:-80}).render()),this.toolbar.set("spinner",new d.view.Spinner({priority:-70})),this.options.search&&this.toolbar.set("search",new d.view.Search({controller:this.controller,model:this.collection.props,priority:60}).render()),this.options.dragInfo&&this.toolbar.set("dragInfo",new d.View({el:a('
'+c.dragInfo+"
")[0],priority:-40}))},updateContent:function(){var a=this;this.attachments||this.createAttachments(),this.collection.length||(this.toggleSpinner(!0),this.collection.more().done(function(){a.collection.length||a.createUploader(),a.toggleSpinner(!1)}))},removeContent:function(){b.each(["attachments","uploader"],function(a){this[a]&&(this[a].remove(),delete this[a])},this)},createUploader:function(){this.removeContent(),this.uploader=new d.view.UploaderInline({controller:this.controller,status:!1,message:c.noItemsFound}),this.views.add(this.uploader)},createAttachments:function(){this.removeContent(),this.attachments=new d.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 a=this.options,b=a.selection,c=this.sidebar=new d.view.Sidebar({controller:this.controller});this.views.add(c),this.controller.uploader&&c.set("uploads",new d.view.UploaderStatus({controller:this.controller,priority:40})),b.on("selection:single",this.createSingle,this),b.on("selection:unsingle",this.disposeSingle,this),b.single()&&this.createSingle()},createSingle:function(){var a=this.sidebar,b=this.options.selection.single();a.set("details",new d.view.Attachment.Details({controller:this.controller,model:b,priority:80})),a.set("compat",new d.view.AttachmentCompat({controller:this.controller,model:b,priority:120})),this.options.display&&a.set("display",new d.view.Settings.AttachmentDisplay({controller:this.controller,model:this.model.display(b),attachment:b,priority:160,userSettings:this.model.get("displayUserSettings")}))},disposeSingle:function(){var a=this.sidebar;a.unset("details"),a.unset("compat"),a.unset("display")}}),d.view.Selection=d.View.extend({tagName:"div",className:"media-selection",template:d.template("media-selection"),events:{"click .edit-selection":"edit","click .clear-selection":"clear"},initialize:function(){b.defaults(this.options,{editable:!1,clearable:!0}),this.attachments=new d.view.Attachments.Selection({controller:this.controller,collection:this.collection,selection:this.collection,model:new Backbone.Model({edge:40,gutter:5})}),this.views.set(".selection-view",this.attachments),this.collection.on("add remove reset",this.refresh,this),this.controller.on("content:activate",this.refresh,this)},ready:function(){this.refresh()},refresh:function(){if(this.$el.children().length){var a=this.collection,b="edit-selection"===this.controller.content.mode();this.$el.toggleClass("empty",!a.length),this.$el.toggleClass("one",1===a.length),this.$el.toggleClass("editing",b),this.$(".count").text(c.selected.replace("%d",a.length))}},edit:function(a){a.preventDefault(),this.options.editable&&this.options.editable.call(this,this.collection)},clear:function(a){a.preventDefault(),this.collection.reset()}}),d.view.Attachment.Selection=d.view.Attachment.extend({className:"attachment selection",toggleSelection:function(){this.options.selection.single(this.model)}}),d.view.Attachments.Selection=d.view.Attachments.extend({events:{},initialize:function(){return b.defaults(this.options,{sortable:!0,resize:!1,AttachmentView:d.view.Attachment.Selection}),d.view.Attachments.prototype.initialize.apply(this,arguments)}}),d.view.Attachment.EditSelection=d.view.Attachment.Selection.extend({buttons:{close:!0}}),d.view.Settings=d.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)},prepare:function(){return b.defaults({model:this.model.toJSON()},this.options)},render:function(){return d.View.prototype.render.apply(this,arguments),b(this.model.attributes).chain().keys().each(this.update,this),this},update:function(a){var b,c,d=this.model.get(a),e=this.$('[data-setting="'+a+'"]');e.length&&(e.is("select")?(c=e.find('[value="'+d+'"]'),c.length?(e.find("option").prop("selected",!1),c.prop("selected",!0)):this.model.set(a,e.find(":selected").val())):e.hasClass("button-group")?(b=e.find("button").removeClass("active"),b.filter('[value="'+d+'"]').addClass("active")):e.is('input[type="text"], textarea')?e.is(":focus")||e.val(d):e.is('input[type="checkbox"]')&&e.prop("checked",!!d))},updateHandler:function(b){var c,d=a(b.target).closest("[data-setting]"),e=b.target.value;b.preventDefault(),d.length&&(d.is('input[type="checkbox"]')&&(e=d[0].checked),this.model.set(d.data("setting"),e),(c=d.data("userSetting"))&&setUserSetting(c,e))},updateChanges:function(a){a.hasChanged()&&b(a.changed).chain().keys().each(this.update,this)}}),d.view.Settings.AttachmentDisplay=d.view.Settings.extend({className:"attachment-display-settings",template:d.template("attachment-display-settings"),initialize:function(){var a=this.options.attachment;b.defaults(this.options,{userSettings:!1}),d.view.Settings.prototype.initialize.apply(this,arguments),this.model.on("change:link",this.updateLinkTo,this),a&&a.on("change:uploading",this.render,this)},dispose:function(){var a=this.options.attachment;a&&a.off(null,null,this),d.view.Settings.prototype.dispose.apply(this,arguments)},render:function(){var a=this.options.attachment;return a&&b.extend(this.options,{sizes:a.get("sizes"),type:a.get("type")}),d.view.Settings.prototype.render.call(this),this.updateLinkTo(),this},updateLinkTo:function(){var a=this.model.get("link"),b=this.$(".link-to-custom"),c=this.options.attachment;return"none"===a||"embed"===a||!c&&"custom"!==a?void b.addClass("hidden"):(c&&("post"===a?b.val(c.get("link")):"file"===a?b.val(c.get("url")):this.model.get("linkUrl")||b.val("http://"),b.prop("readonly","custom"!==a)),b.removeClass("hidden"),void(b.is(":visible")&&b.focus()[0].select()))}}),d.view.Settings.Gallery=d.view.Settings.extend({className:"collection-settings gallery-settings",template:d.template("gallery-settings")}),d.view.Settings.Playlist=d.view.Settings.extend({className:"collection-settings playlist-settings",template:d.template("playlist-settings")}),d.view.Attachment.Details=d.view.Attachment.extend({tagName:"div",className:"attachment-details",template:d.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","click .edit-attachment":"editAttachment","click .refresh-attachment":"refreshAttachment"},initialize:function(){this.focusManager=new d.view.FocusManager({el:this.el}),d.view.Attachment.prototype.initialize.apply(this,arguments)},render:function(){return d.view.Attachment.prototype.render.apply(this,arguments),this.focusManager.focus(),this},deleteAttachment:function(a){a.preventDefault(),confirm(c.warnDelete)&&this.model.destroy()},editAttachment:function(){this.$el.addClass("needs-refresh")},refreshAttachment:function(a){this.$el.removeClass("needs-refresh"),a.preventDefault(),this.model.fetch()}}),d.view.AttachmentCompat=d.View.extend({tagName:"form",className:"compat-item",events:{submit:"preventDefault","change input":"save","change select":"save","change textarea":"save"},initialize:function(){this.focusManager=new d.view.FocusManager({el:this.el}),this.model.on("change:compat",this.render,this)},dispose:function(){return this.$(":focus").length&&this.save(),d.View.prototype.dispose.apply(this,arguments)},render:function(){var a=this.model.get("compat");if(a&&a.item)return this.views.detach(),this.$el.html(a.item),this.views.render(),this.focusManager.focus(),this},preventDefault:function(a){a.preventDefault()},save:function(a){var c={};a&&a.preventDefault(),b.each(this.$el.serializeArray(),function(a){c[a.name]=a.value}),this.model.saveCompat(c)}}),d.view.Iframe=d.View.extend({className:"media-iframe",render:function(){return this.views.detach(),this.$el.html('