!function(r,a){var e,t,i,s,l=wp.media,h=l.view.l10n="undefined"==typeof _wpMediaViewsL10n?{}:_wpMediaViewsL10n;l.view.settings=h.settings||{},delete h.settings,l.model.settings.post=l.view.settings.post,r.support.transition=(e=document.documentElement.style,t={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"},(i=a.find(a.keys(t),function(t){return!a.isUndefined(e[t])}))&&{end:t[i]}),l.events=a.extend({},Backbone.Events),l.transition=function(t,e){var i=r.Deferred();return e=e||2e3,r.support.transition?((t=!(t instanceof r)?r(t):t).first().one(r.support.transition.end,i.resolve),a.delay(i.resolve,e)):i.resolve(),i.promise()},l.controller.Region=function(t){a.extend(this,a.pick(t||{},"id","view","selector"))},l.controller.Region.extend=Backbone.Model.extend,a.extend(l.controller.Region.prototype,{mode:function(t){return t?(t===this._mode||(this.trigger("deactivate"),this._mode=t,this.render(t),this.trigger("activate")),this):this._mode},render:function(t){if(t&&t!==this._mode)return this.mode(t);t={view:null};return this.trigger("create",t),t=t.view,this.trigger("render",t),t&&this.set(t),this},get:function(){return this.view.views.first(this.selector)},set:function(t,e){return e&&(e.add=!1),this.view.views.set(this.selector,t,e)},trigger:function(t){var e,i;if(this._mode)return i=a.toArray(arguments),e=this.id+":"+t,i[0]=e+":"+this._mode,this.view.trigger.apply(this.view,i),i[0]=e,this.view.trigger.apply(this.view,i),this}}),l.controller.StateMachine=function(t){this.states=new Backbone.Collection(t)},l.controller.StateMachine.extend=Backbone.Model.extend,a.extend(l.controller.StateMachine.prototype,Backbone.Events,{state:function(t){return this.states=this.states||new Backbone.Collection,(t=t||this._state)&&!this.states.get(t)&&this.states.add({id:t}),this.states.get(t)},setState:function(t){var e=this.state();return e&&t===e.id||!this.states||!this.states.get(t)||(e&&(e.trigger("deactivate"),this._lastState=e.id),this._state=t,this.state().trigger("activate")),this},lastState:function(){if(this._lastState)return this.state(this._lastState)}}),a.each(["on","off","trigger"],function(t){l.controller.StateMachine.prototype[t]=function(){return this.states=this.states||new Backbone.Collection,this.states[t].apply(this.states,arguments),this}}),l.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(t){t.$el.text(this.get("title")||"")},_router:function(){var t=this.frame.router,e=this.get("router");this.frame.$el.toggleClass("hide-router",!e),e&&(this.frame.router.render(e),(t=t.get())&&t.select&&t.select(this.frame.content.mode()))},_menu:function(){var t=this.frame.menu,e=this.get("menu");e&&(t.mode(e),(t=t.get())&&t.select&&t.select(this.id))},_updateMenu:function(){var t=this.previous("menu"),e=this.get("menu");t&&this.frame.off("menu:render:"+t,this._renderMenu,this),e&&this.frame.on("menu:render:"+e,this._renderMenu,this)},_renderMenu:function(t){var e=this.get("menuItem"),i=this.get("title"),s=this.get("priority");!e&&i&&(e={text:i},s&&(e.priority=s)),e&&t.set(this.id,e)}}),a.each(["toolbar","content"],function(e){l.controller.State.prototype["_"+e]=function(){var t=this.get(e);t&&this.frame[e].render(t)}}),l.selectionSync={syncSelection:function(){var t=this.get("selection"),e=this.frame._selection;this.get("syncSelection")&&e&&t&&(t.multiple&&(t.reset([],{silent:!0}),t.validateAll(e.attachments),e.difference=a.difference(e.attachments.models,t.models)),t.single(e.single))},recordSelection:function(){var t=this.get("selection"),e=this.frame._selection;this.get("syncSelection")&&e&&t&&(t.multiple?(e.attachments.reset(t.toArray().concat(e.difference)),e.difference=[]):e.attachments.add(t.toArray()),e.single=t._single)}},l.controller.Library=l.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:h.mediaLibraryTitle,contentUserSetting:!0,syncSelection:!0},initialize:function(){var t=this.get("selection");this.get("library")||this.set("library",l.query()),t instanceof l.model.Selection||((t=t)||(t=this.get("library").props.toJSON(),t=a.omit(t,"orderby","query")),this.set("selection",new l.model.Selection(null,{multiple:this.get("multiple"),props:t}))),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 t=l.view.settings.defaultProps;this._displays=[],this._defaultDisplaySettings={align:t.align||getUserSetting("align","none"),size:t.size||getUserSetting("imgsize","medium"),link:t.link||getUserSetting("urlbutton","file")}},display:function(t){var e=this._displays;return e[t.cid]||(e[t.cid]=new Backbone.Model(this.defaultDisplaySettings(t))),e[t.cid]},defaultDisplaySettings:function(t){var e=this._defaultDisplaySettings;return(e.canEmbed=this.canEmbed(t))&&(e.link="embed"),e},canEmbed:function(t){if(!t.get("uploading")){var e=t.get("type");if("audio"!==e&&"video"!==e)return!1}return a.contains(l.view.settings.embedExts,t.get("filename").split(".").pop())},refreshContent:function(){var t=this.get("selection"),e=this.frame,i=e.router.get(),e=e.content.mode();this.active&&!t.length&&i&&!i.get(e)&&this.frame.content.render(this.get("content"))},uploading:function(t){"upload"===this.frame.content.mode()&&this.frame.content.mode("browse"),this.get("selection").add(t)},saveContentMode:function(){var t,e;"browse"===this.get("router")&&(t=this.frame.content.mode(),(e=this.frame.router.get())&&e.get(t)&&setUserSetting("libraryContent",t))}}),a.extend(l.controller.Library.prototype,l.selectionSync),l.controller.ImageDetails=l.controller.State.extend({defaults:a.defaults({id:"image-details",toolbar:"image-details",title:h.imageDetailsTitle,content:"image-details",menu:"image-details",router:!1,attachment:!1,priority:60,editing:!1},l.controller.Library.prototype.defaults),initialize:function(t){this.image=t.image,l.controller.State.prototype.initialize.apply(this,arguments)},activate:function(){this.frame.modal.$el.addClass("image-details")}}),l.controller.GalleryEdit=l.controller.Library.extend({defaults:{id:"gallery-edit",multiple:!1,describe:!0,edge:199,editing:!1,sortable:!0,searchable:!1,toolbar:"gallery-edit",content:"browse",title:h.editGalleryTitle,priority:60,dragInfo:!0,syncSelection:!1},initialize:function(){this.get("library")||this.set("library",new l.model.Selection),this.get("AttachmentView")||this.set("AttachmentView",l.view.Attachment.EditLibrary),l.controller.Library.prototype.initialize.apply(this,arguments)},activate:function(){this.get("library").props.set("type","image"),this.get("library").observe(wp.Uploader.queue),this.frame.on("content:render:browse",this.gallerySettings,this),l.controller.Library.prototype.activate.apply(this,arguments)},deactivate:function(){this.get("library").unobserve(wp.Uploader.queue),this.frame.off("content:render:browse",this.gallerySettings,this),l.controller.Library.prototype.deactivate.apply(this,arguments)},gallerySettings:function(t){var e=this.get("library");e&&t&&(e.gallery=e.gallery||new Backbone.Model,t.sidebar.set({gallery:new l.view.Settings.Gallery({controller:this,model:e.gallery,priority:40})}),t.toolbar.set("reverse",{text:h.reverseOrder,priority:80,click:function(){e.reset(e.toArray().reverse())}}))}}),l.controller.GalleryAdd=l.controller.Library.extend({defaults:a.defaults({id:"gallery-library",filterable:"uploaded",multiple:"add",menu:"gallery",toolbar:"gallery-add",title:h.addToGalleryTitle,priority:100,syncSelection:!1},l.controller.Library.prototype.defaults),initialize:function(){this.get("library")||this.set("library",l.query({type:"image"})),l.controller.Library.prototype.initialize.apply(this,arguments)},activate:function(){var t=this.get("library"),e=this.frame.state("gallery-edit").get("library");this.editLibrary&&this.editLibrary!==e&&t.unobserve(this.editLibrary),t.validator=function(t){return!!this.mirroring.get(t.cid)&&!e.get(t.cid)&&l.model.Selection.prototype.validator.apply(this,arguments)},t.reset(t.mirroring.models,{silent:!0}),t.observe(e),this.editLibrary=e,l.controller.Library.prototype.activate.apply(this,arguments)}}),l.controller.CollectionEdit=l.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 t=this.get("collectionType");"video"===this.get("type")&&(t="video-"+t),this.set("id",t+"-edit"),this.set("toolbar",t+"-edit"),this.get("library")||this.set("library",new l.model.Selection),this.get("AttachmentView")||this.set("AttachmentView",l.view.Attachment.EditLibrary),l.controller.Library.prototype.initialize.apply(this,arguments)},activate:function(){this.get("library").props.set("type",this.get("type")),this.get("library").observe(wp.Uploader.queue),this.frame.on("content:render:browse",this.renderSettings,this),l.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),l.controller.Library.prototype.deactivate.apply(this,arguments)},renderSettings:function(t){var e=this.get("library"),i=this.get("collectionType"),s=this.get("dragInfoText"),o=this.get("SettingsView"),n={};e&&t&&(e[i]=e[i]||new Backbone.Model,n[i]=new o({controller:this,model:e[i],priority:40}),t.sidebar.set(n),s&&t.toolbar.set("dragInfo",new l.View({el:r('
'+s+"
")[0],priority:-40})),t.toolbar.set("reverse",{text:h.reverseOrder,priority:80,click:function(){e.reset(e.toArray().reverse())}}))}}),l.controller.CollectionAdd=l.controller.Library.extend({defaults:a.defaults({filterable:"uploaded",multiple:"add",priority:100,syncSelection:!1},l.controller.Library.prototype.defaults),initialize:function(){var t=this.get("collectionType");"video"===this.get("type")&&(t="video-"+t),this.set("id",t+"-library"),this.set("toolbar",t+"-add"),this.set("menu",t),this.get("library")||this.set("library",l.query({type:this.get("type")})),l.controller.Library.prototype.initialize.apply(this,arguments)},activate:function(){var t=this.get("library"),e=this.get("editLibrary"),i=this.frame.state(this.get("collectionType")+"-edit").get("library");e&&e!==i&&t.unobserve(e),t.validator=function(t){return!!this.mirroring.get(t.cid)&&!i.get(t.cid)&&l.model.Selection.prototype.validator.apply(this,arguments)},t.reset(t.mirroring.models,{silent:!0}),t.observe(i),this.set("editLibrary",i),l.controller.Library.prototype.activate.apply(this,arguments)}}),l.controller.FeaturedImage=l.controller.Library.extend({defaults:a.defaults({id:"featured-image",filterable:"uploaded",multiple:!1,toolbar:"featured-image",title:h.setFeaturedImageTitle,priority:60,syncSelection:!0},l.controller.Library.prototype.defaults),initialize:function(){var t,o;this.get("library")||this.set("library",l.query({type:"image"})),l.controller.Library.prototype.initialize.apply(this,arguments),t=this.get("library"),o=t.comparator,t.comparator=function(t,e){var i=!!this.mirroring.get(t.cid),s=!!this.mirroring.get(e.cid);return!i&&s?-1:i&&!s?1:o.apply(this,arguments)},t.observe(this.get("selection"))},activate:function(){this.updateSelection(),this.frame.on("open",this.updateSelection,this),l.controller.Library.prototype.activate.apply(this,arguments)},deactivate:function(){this.frame.off("open",this.updateSelection,this),l.controller.Library.prototype.deactivate.apply(this,arguments)},updateSelection:function(){var t,e=this.get("selection"),i=l.view.settings.post.featuredImageId;""!==i&&-1!==i&&(t=l.model.Attachment.get(i)).fetch(),e.reset(t?[t]:[])}}),l.controller.ReplaceImage=l.controller.Library.extend({defaults:a.defaults({id:"replace-image",filterable:"uploaded",multiple:!1,toolbar:"replace",title:h.replaceImageTitle,priority:60,syncSelection:!0},l.controller.Library.prototype.defaults),initialize:function(t){var e,o;this.image=t.image,this.get("library")||this.set("library",l.query({type:"image"})),l.controller.Library.prototype.initialize.apply(this,arguments),e=this.get("library"),o=e.comparator,e.comparator=function(t,e){var i=!!this.mirroring.get(t.cid),s=!!this.mirroring.get(e.cid);return!i&&s?-1:i&&!s?1:o.apply(this,arguments)},e.observe(this.get("selection"))},activate:function(){this.updateSelection(),l.controller.Library.prototype.activate.apply(this,arguments)},updateSelection:function(){var t=this.get("selection"),e=this.image.attachment;t.reset(e?[e]:[])}}),l.controller.EditImage=l.controller.State.extend({defaults:{id:"edit-image",url:"",menu:!1,toolbar:"edit-image",title:h.editImage,content:"edit-image"},activate:function(){this.listenTo(this.frame,"toolbar:render:edit-image",this.toolbar)},deactivate:function(){this.stopListening(this.frame)},toolbar:function(){var t=this.frame,e=t.lastState(),i=e&&e.id;t.toolbar.set(new l.view.Toolbar({controller:t,items:{back:{style:"primary",text:h.back,priority:20,click:function(){i?t.setState(i):t.close()}}}}))}}),l.controller.MediaLibrary=l.controller.Library.extend({defaults:a.defaults({filterable:"uploaded",priority:80,syncSelection:!1,displaySettings:!1},l.controller.Library.prototype.defaults),initialize:function(t){this.media=t.media,this.type=t.type,this.set("library",l.query({type:this.type})),l.controller.Library.prototype.initialize.apply(this,arguments)},activate:function(){l.frame.lastMime&&(this.set("library",l.query({type:l.frame.lastMime})),delete l.frame.lastMime),l.controller.Library.prototype.activate.apply(this,arguments)}}),l.controller.Embed=l.controller.State.extend({defaults:{id:"embed",url:"",menu:"default",content:"embed",toolbar:"main-embed",type:"link",title:h.insertFromUrlTitle,priority:120},sensitivity:200,initialize:function(){this.debouncedScan=a.debounce(a.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 t,e=this,i={type:"link",scanners:[]};this.props.get("url")&&this.trigger("scan",i),i.scanners.length?(t=i.scanners=r.when.apply(r,i.scanners)).always(function(){e.get("scanners")===t&&e.set("loading",!1)}):i.scanners=null,i.loading=!!i.scanners,this.set(i)},scanImage:function(t){var e=this.frame,i=this,s=this.props.get("url"),o=new Image,n=r.Deferred();t.scanners.push(n.promise()),o.onload=function(){n.resolve(),i===e.state()&&s===i.props.get("url")&&(i.set({type:"image"}),i.props.set({width:o.width,height:o.height}))},o.onerror=n.reject,o.src=s},refresh:function(){this.frame.toolbar.get().refresh()},reset:function(){this.props.clear().set({url:""}),this.active&&this.refresh()}}),l.controller.Cropper=l.controller.State.extend({defaults:{id:"cropper",title:h.cropImage,toolbar:"crop",content:"crop",router:!1,canSkipCrop:!1},activate:function(){this.frame.on("content:create:crop",this.createCropContent,this),this.frame.on("close",this.removeCropper,this),this.set("selection",new Backbone.Collection(this.frame._selection.single))},deactivate:function(){this.frame.toolbar.mode("browse")},createCropContent:function(){this.cropperView=new wp.media.view.Cropper({controller:this,attachment:this.get("selection").first()}),this.cropperView.on("image-loaded",this.createCropToolbar,this),this.frame.content.set(this.cropperView)},removeCropper:function(){this.imgSelect.cancelSelection(),this.imgSelect.setOptions({remove:!0}),this.imgSelect.update(),this.cropperView.remove()},createCropToolbar:function(){var t=this.get("canSkipCrop")||!1,e={controller:this.frame,items:{insert:{style:"primary",text:h.cropImage,priority:80,requires:{library:!1,selection:!1},click:function(){var e=this,t=this.controller.state().get("selection").first();t.set({cropDetails:this.controller.state().imgSelect.getSelection()}),this.$el.text(h.cropping),this.$el.attr("disabled",!0),this.controller.state().doCrop(t).done(function(t){e.controller.trigger("cropped",t),e.controller.close()}).fail(function(){e.controller.trigger("content:error:crop")})}}}};t&&a.extend(e.items,{skip:{style:"secondary",text:h.skipCropping,priority:70,requires:{library:!1,selection:!1},click:function(){var t=this.controller.state().get("selection").first();this.controller.state().cropperView.remove(),this.controller.trigger("skippedcrop",t),this.controller.close()}}}),this.frame.toolbar.set(new wp.media.view.Toolbar(e))},doCrop:function(t){return wp.ajax.post("custom-header-crop",{nonce:t.get("nonces").edit,id:t.get("id"),cropDetails:t.get("cropDetails")})}}),l.View=wp.Backbone.View.extend({constructor:function(t){t&&t.controller&&(this.controller=t.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)}}),l.view.Frame=l.View.extend({initialize:function(){this._createRegions(),this._createStates()},_createRegions:function(){this.regions=this.regions?this.regions.slice():[],a.each(this.regions,function(t){this[t]=new l.controller.Region({view:this,id:t,selector:".media-frame-"+t})},this)},_createStates:function(){this.states=new Backbone.Collection(null,{model:l.controller.State}),this.states.on("add",function(t){t.frame=this,t.trigger("ready")},this),this.options.states&&this.states.add(this.options.states)},reset:function(){return this.states.invoke("trigger","reset"),this}}),a.extend(l.view.Frame.prototype,l.controller.StateMachine.prototype),l.view.MediaFrame=l.view.Frame.extend({className:"media-frame",template:l.template("media-frame"),regions:["menu","title","content","toolbar","router"],initialize:function(){l.view.Frame.prototype.initialize.apply(this,arguments),a.defaults(this.options,{title:"",modal:!0,uploader:!0}),this.$el.addClass("wp-core-ui"),this.options.modal&&(this.modal=new l.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 l.view.UploaderWindow({controller:this,uploader:{dropzone:(this.modal||this).$el,container:this.$el}}),this.views.set(".media-frame-uploader",this.uploader)),this.on("attach",a.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),l.view.Frame.prototype.render.apply(this,arguments)},createTitle:function(t){t.view=new l.View({controller:this,tagName:"h1"})},createMenu:function(t){t.view=new l.view.Menu({controller:this})},createToolbar:function(t){t.view=new l.view.Toolbar({controller:this})},createRouter:function(t){t.view=new l.view.Router({controller:this})},createIframeStates:function(i){var t=l.view.settings,e=t.tabs,s=t.tabUrl;e&&s&&((t=r("#post_ID")).length&&(s+="&post_id="+t.val()),a.each(e,function(t,e){this.state("iframe:"+e).set(a.defaults({tab:e,src:s+"&tab="+e,title:t,content:"iframe",menu:"default"},i))},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(t){this.$el.addClass("hide-toolbar"),t.view=new l.view.Iframe({controller:this})},iframeMenu:function(t){var i={};t&&(a.each(l.view.settings.tabs,function(t,e){i["iframe:"+e]={text:this.state("iframe:"+e).get("title"),priority:200}},this),t.set(i))},hijackThickbox:function(){var t=this;window.tb_remove&&!this._tb_remove&&(this._tb_remove=window.tb_remove,window.tb_remove=function(){t.close(),t.reset(),t.setState(t.options.state),t._tb_remove.call(window)})},restoreThickbox:function(){this._tb_remove&&(window.tb_remove=this._tb_remove,delete this._tb_remove)}}),a.each(["open","close","attach","detach","escape"],function(t){l.view.MediaFrame.prototype[t]=function(){return this.modal&&this.modal[t].apply(this.modal,arguments),this}}),l.view.MediaFrame.Select=l.view.MediaFrame.extend({initialize:function(){l.view.MediaFrame.prototype.initialize.apply(this,arguments),a.defaults(this.options,{selection:[],library:{},multiple:!1,state:"library"}),this.createSelection(),this.createStates(),this.bindHandlers()},createSelection:function(){var t=this.options.selection;t instanceof l.model.Selection||(this.options.selection=new l.model.Selection(t,{multiple:this.options.multiple})),this._selection={attachments:new l.model.Attachments,difference:[]}},createStates:function(){var t=this.options;this.options.states||this.states.add([new l.controller.Library({library:l.query(t.library),multiple:t.multiple,title:t.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(t){t.set({upload:{text:h.uploadFilesTitle,priority:20},browse:{text:h.mediaLibraryTitle,priority:40}})},browseContent:function(t){var e=this.state();this.$el.removeClass("hide-toolbar"),t.view=new l.view.AttachmentsBrowser({controller:this,collection:e.get("library"),selection:e.get("selection"),model:e,sortable:e.get("sortable"),search:e.get("searchable"),filters:e.get("filterable"),display:e.get("displaySettings"),dragInfo:e.get("dragInfo"),suggestedWidth:e.get("suggestedWidth"),suggestedHeight:e.get("suggestedHeight"),AttachmentView:e.get("AttachmentView")})},uploadContent:function(){this.$el.removeClass("hide-toolbar"),this.content.set(new l.view.UploaderInline({controller:this}))},createSelectToolbar:function(t,e){(e=e||this.options.button||{}).controller=this,t.view=new l.view.Toolbar.Select(e)}}),l.view.MediaFrame.Post=l.view.MediaFrame.Select.extend({initialize:function(){this.counts={audio:{count:l.view.settings.attachmentCounts.audio,state:"playlist"},video:{count:l.view.settings.attachmentCounts.video,state:"video-playlist"}},a.defaults(this.options,{multiple:!0,editing:!1,state:"insert"}),l.view.MediaFrame.Select.prototype.initialize.apply(this,arguments),this.createIframeStates()},createStates:function(){var t=this.options;this.states.add([new l.controller.Library({id:"insert",title:h.insertMediaTitle,priority:20,toolbar:"main-insert",filterable:"all",library:l.query(t.library),multiple:!!t.multiple&&"reset",editable:!0,allowLocalEdits:!0,displaySettings:!0,displayUserSettings:!0}),new l.controller.Library({id:"gallery",title:h.createGalleryTitle,priority:40,toolbar:"main-gallery",filterable:"uploaded",multiple:"add",editable:!1,library:l.query(a.defaults({type:"image"},t.library))}),new l.controller.Embed,new l.controller.EditImage({model:t.editImage}),new l.controller.GalleryEdit({library:t.selection,editing:t.editing,menu:"gallery"}),new l.controller.GalleryAdd,new l.controller.Library({id:"playlist",title:h.createPlaylistTitle,priority:60,toolbar:"main-playlist",filterable:"uploaded",multiple:"add",editable:!1,library:l.query(a.defaults({type:"audio"},t.library))}),new l.controller.CollectionEdit({type:"audio",collectionType:"playlist",title:h.editPlaylistTitle,SettingsView:l.view.Settings.Playlist,library:t.selection,editing:t.editing,menu:"playlist",dragInfoText:h.playlistDragInfo,dragInfo:!1}),new l.controller.CollectionAdd({type:"audio",collectionType:"playlist",title:h.addToPlaylistTitle}),new l.controller.Library({id:"video-playlist",title:h.createVideoPlaylistTitle,priority:60,toolbar:"main-video-playlist",filterable:"uploaded",multiple:"add",editable:!1,library:l.query(a.defaults({type:"video"},t.library))}),new l.controller.CollectionEdit({type:"video",collectionType:"playlist",title:h.editVideoPlaylistTitle,SettingsView:l.view.Settings.Playlist,library:t.selection,editing:t.editing,menu:"video-playlist",dragInfoText:h.videoPlaylistDragInfo,dragInfo:!1}),new l.controller.CollectionAdd({type:"video",collectionType:"playlist",title:h.addToVideoPlaylistTitle})]),l.view.settings.post.featuredImageId&&this.states.add(new l.controller.FeaturedImage)},bindHandlers:function(){var t;l.view.MediaFrame.Select.prototype.bindHandlers.apply(this,arguments),this.on("activate",this.activate,this),void 0!==a.find(this.counts,function(t){return 0===t.count})&&this.listenTo(l.model.Attachments.all,"change:type",this.mediaTypeCounts),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),t={menu:{"default":"mainMenu",gallery:"galleryMenu",playlist:"playlistMenu","video-playlist":"videoPlaylistMenu"},content:{embed:"embedContent","edit-image":"editImageContent","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"}},a.each(t,function(t,i){a.each(t,function(t,e){this.on(i+":render:"+e,this[t],this)},this)},this)},activate:function(){a.each(this.counts,function(t){t.count<1&&this.menuItemVisibility(t.state,"hide")},this)},mediaTypeCounts:function(t,e){void 0!==this.counts[e]&&this.counts[e].count<1&&(this.counts[e].count++,this.menuItemVisibility(this.counts[e].state,"show"))},mainMenu:function(t){t.set({"library-separator":new l.View({className:"separator",priority:100})})},menuItemVisibility:function(t,e){var i=this.menu.get();"hide"===e?i.hide(t):"show"===e&&i.show(t)},galleryMenu:function(t){var e=this.lastState(),i=e&&e.id,s=this;t.set({cancel:{text:h.cancelGalleryTitle,priority:20,click:function(){i?s.setState(i):s.close()}},separateCancel:new l.View({className:"separator",priority:40})})},playlistMenu:function(t){var e=this.lastState(),i=e&&e.id,s=this;t.set({cancel:{text:h.cancelPlaylistTitle,priority:20,click:function(){i?s.setState(i):s.close()}},separateCancel:new l.View({className:"separator",priority:40})})},videoPlaylistMenu:function(t){var e=this.lastState(),i=e&&e.id,s=this;t.set({cancel:{text:h.cancelVideoPlaylistTitle,priority:20,click:function(){i?s.setState(i):s.close()}},separateCancel:new l.View({className:"separator",priority:40})})},embedContent:function(){var t=new l.view.Embed({controller:this,model:this.state()}).render();this.content.set(t),t.url.focus()},editSelectionContent:function(){var t=this.state(),e=t.get("selection"),t=new l.view.AttachmentsBrowser({controller:this,collection:e,selection:e,model:t,sortable:!0,search:!1,dragInfo:!0,AttachmentView:l.view.Attachment.EditSelection}).render();t.toolbar.set("backToLibrary",{text:h.returnToLibrary,priority:-100,click:function(){this.controller.content.mode("browse")}}),this.content.set(t)},editImageContent:function(){var t=this.state().get("image"),t=new l.view.EditImage({model:t,controller:this}).render();this.content.set(t),t.loadEditor()},selectionStatusToolbar:function(t){var e=this.state().get("editable");t.set("selection",new l.view.Selection({controller:this,collection:this.state().get("selection"),priority:-40,editable:e&&function(){this.controller.content.mode("edit-selection")}}).render())},mainInsertToolbar:function(t){var i=this;this.selectionStatusToolbar(t),t.set("insert",{style:"primary",priority:80,text:h.insertIntoPost,requires:{selection:!0},click:function(){var t=i.state(),e=t.get("selection");i.close(),t.trigger("insert",e).reset()}})},mainGalleryToolbar:function(t){var s=this;this.selectionStatusToolbar(t),t.set("gallery",{style:"primary",text:h.createNewGallery,priority:60,requires:{selection:!0},click:function(){var t=s.state().get("selection"),e=s.state("gallery-edit"),i=t.where({type:"image"});e.set("library",new l.model.Selection(i,{props:t.props.toJSON(),multiple:!0})),this.controller.setState("gallery-edit")}})},mainPlaylistToolbar:function(t){var s=this;this.selectionStatusToolbar(t),t.set("playlist",{style:"primary",text:h.createNewPlaylist,priority:100,requires:{selection:!0},click:function(){var t=s.state().get("selection"),e=s.state("playlist-edit"),i=t.where({type:"audio"});e.set("library",new l.model.Selection(i,{props:t.props.toJSON(),multiple:!0})),this.controller.setState("playlist-edit")}})},mainVideoPlaylistToolbar:function(t){var s=this;this.selectionStatusToolbar(t),t.set("video-playlist",{style:"primary",text:h.createNewVideoPlaylist,priority:100,requires:{selection:!0},click:function(){var t=s.state().get("selection"),e=s.state("video-playlist-edit"),i=t.where({type:"video"});e.set("library",new l.model.Selection(i,{props:t.props.toJSON(),multiple:!0})),this.controller.setState("video-playlist-edit")}})},featuredImageToolbar:function(t){this.createSelectToolbar(t,{text:h.setFeaturedImage,state:this.options.state})},mainEmbedToolbar:function(t){t.view=new l.view.Toolbar.Embed({controller:this})},galleryEditToolbar:function(){var t=this.state().get("editing");this.toolbar.set(new l.view.Toolbar({controller:this,items:{insert:{style:"primary",text:t?h.updateGallery:h.insertGallery,priority:80,requires:{library:!0},click:function(){var t=this.controller,e=t.state();t.close(),e.trigger("update",e.get("library")),t.setState(t.options.state),t.reset()}}}}))},galleryAddToolbar:function(){this.toolbar.set(new l.view.Toolbar({controller:this,items:{insert:{style:"primary",text:h.addToGallery,priority:80,requires:{selection:!0},click:function(){var t=this.controller,e=t.state();t.state("gallery-edit").get("library").add(e.get("selection").models),e.trigger("reset"),t.setState("gallery-edit")}}}}))},playlistEditToolbar:function(){var t=this.state().get("editing");this.toolbar.set(new l.view.Toolbar({controller:this,items:{insert:{style:"primary",text:t?h.updatePlaylist:h.insertPlaylist,priority:80,requires:{library:!0},click:function(){var t=this.controller,e=t.state();t.close(),e.trigger("update",e.get("library")),t.setState(t.options.state),t.reset()}}}}))},playlistAddToolbar:function(){this.toolbar.set(new l.view.Toolbar({controller:this,items:{insert:{style:"primary",text:h.addToPlaylist,priority:80,requires:{selection:!0},click:function(){var t=this.controller,e=t.state();t.state("playlist-edit").get("library").add(e.get("selection").models),e.trigger("reset"),t.setState("playlist-edit")}}}}))},videoPlaylistEditToolbar:function(){var t=this.state().get("editing");this.toolbar.set(new l.view.Toolbar({controller:this,items:{insert:{style:"primary",text:t?h.updateVideoPlaylist:h.insertVideoPlaylist,priority:140,requires:{library:!0},click:function(){var t=this.controller,e=t.state(),i=e.get("library");i.type="video",t.close(),e.trigger("update",i),t.setState(t.options.state),t.reset()}}}}))},videoPlaylistAddToolbar:function(){this.toolbar.set(new l.view.Toolbar({controller:this,items:{insert:{style:"primary",text:h.addToVideoPlaylist,priority:140,requires:{selection:!0},click:function(){var t=this.controller,e=t.state();t.state("video-playlist-edit").get("library").add(e.get("selection").models),e.trigger("reset"),t.setState("video-playlist-edit")}}}}))}}),l.view.MediaFrame.ImageDetails=l.view.MediaFrame.Select.extend({defaults:{id:"image",url:"",menu:"image-details",content:"image-details",toolbar:"image-details",type:"link",title:h.imageDetailsTitle,priority:120},initialize:function(t){this.image=new l.model.PostImage(t.metadata),this.options.selection=new l.model.Selection(this.image.attachment,{multiple:!1}),l.view.MediaFrame.Select.prototype.initialize.apply(this,arguments)},bindHandlers:function(){l.view.MediaFrame.Select.prototype.bindHandlers.apply(this,arguments),this.on("menu:create:image-details",this.createMenu,this),this.on("content:create:image-details",this.imageDetailsContent,this),this.on("content:render:edit-image",this.editImageContent,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 l.controller.ImageDetails({image:this.image,editable:!1,menu:"image-details"}),new l.controller.ReplaceImage({id:"replace-image",library:l.query({type:"image"}),image:this.image,multiple:!1,title:h.imageReplaceTitle,menu:"image-details",toolbar:"replace",priority:80,displaySettings:!0}),new l.controller.EditImage({image:this.image,selection:this.options.selection})])},imageDetailsContent:function(t){t.view=new l.view.ImageDetails({controller:this,model:this.state().image,attachment:this.state().image.attachment})},editImageContent:function(){var t=this.state().get("image");t&&(t=new l.view.EditImage({model:t,controller:this}).render(),this.content.set(t),t.loadEditor())},renderMenu:function(t){var e=this.lastState(),i=e&&e.id,s=this;t.set({cancel:{text:h.imageDetailsCancel,priority:20,click:function(){i?s.setState(i):s.close()}},separateCancel:new l.View({className:"separator",priority:40})})},renderImageDetailsToolbar:function(){this.toolbar.set(new l.view.Toolbar({controller:this,items:{select:{style:"primary",text:h.update,priority:80,click:function(){var t=this.controller,e=t.state();t.close(),e.trigger("update",t.image.toJSON()),t.setState(t.options.state),t.reset()}}}}))},renderReplaceImageToolbar:function(){var t=this,e=t.lastState(),i=e&&e.id;this.toolbar.set(new l.view.Toolbar({controller:this,items:{back:{text:h.back,priority:20,click:function(){i?t.setState(i):t.close()}},replace:{style:"primary",text:h.replace,priority:80,click:function(){var t=this.controller,e=t.state(),i=e.get("selection").single();t.close(),t.image.changeAttachment(i,e.display(i)),e.trigger("replace",t.image.toJSON()),t.setState(t.options.state),t.reset()}}}}))}}),l.view.Modal=l.View.extend({tagName:"div",template:l.template("media-modal"),attributes:{tabindex:0},events:{"click .media-modal-backdrop, .media-modal-close":"escapeHandler",keydown:"keydown"},initialize:function(){a.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 t=this.$el,e=this.options;return t.is(":visible")?this:(this.views.attached||this.attach(),e.freeze&&(this._freeze={scrollTop:r(window).scrollTop()}),t.show().focus(),this.propagate("open"))},close:function(t){var e=this._freeze;return this.views.attached&&this.$el.is(":visible")&&(this.$el.hide(),this.propagate("close"),e&&r(window).scrollTop(e.scrollTop),t&&t.escape&&this.propagate("escape")),this},escape:function(){return this.close({escape:!0})},escapeHandler:function(t){t.preventDefault(),this.escape()},content:function(t){return this.views.set(".media-modal-content",t),this},propagate:function(t){return this.trigger(t),this.options.propagate&&this.controller.trigger(t),this},keydown:function(t){27===t.which&&this.$el.is(":visible")&&(this.escape(),t.stopImmediatePropagation())}}),l.view.FocusManager=l.View.extend({events:{keydown:"recordTab",focusin:"updateIndex"},focus:function(){a.isUndefined(this.index)||(this.$tabbables=this.$(":tabbable"),this.$tabbables.eq(this.index).focus())},recordTab:function(t){9===t.keyCode&&(a.isUndefined(this.index)&&this.updateIndex(t),a.isUndefined(this.index)||(0<=(t=this.index+(t.shiftKey?-1:1))&&t').hide().appendTo("body"),!(t=this.options.uploader=a.defaults(this.options.uploader||{},{dropzone:this.$el,browser:this.$browser,params:{}})).dropzone||t.dropzone instanceof r||(t.dropzone=r(t.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 t=l.view.settings.post.id;this.uploader||(t&&(this.options.uploader.params.post_id=t),this.uploader=new wp.Uploader(this.options.uploader),(t=this.uploader.dropzone).on("dropzone:enter",a.bind(this.show,this)),t.on("dropzone:leave",a.bind(this.hide,this)),r(this.uploader).on("uploader:ready",a.bind(this._ready,this)))},_ready:function(){this.controller.trigger("uploader:ready")},show:function(){var t=this.$el.show();a.defer(function(){t.css({opacity:1})})},hide:function(){var t=this.$el.css({opacity:0});l.transition(t).done(function(){"0"===t.css("opacity")&&t.hide()})}}),l.view.EditorUploader=l.View.extend({tagName:"div",className:"uploader-editor",template:l.template("uploader-editor"),localDrag:!1,overContainer:!1,overDropzone:!1,draggingFile:null,initialize:function(){var e=this;return this.initialized=!1,window.tinyMCEPreInit&&window.tinyMCEPreInit.dragDropUpload&&this.browserSupport()&&(this.$document=r(document),this.dropzones=[],this.files=[],this.$document.on("drop",".uploader-editor",a.bind(this.drop,this)),this.$document.on("dragover",".uploader-editor",a.bind(this.dropzoneDragover,this)),this.$document.on("dragleave",".uploader-editor",a.bind(this.dropzoneDragleave,this)),this.$document.on("click",".uploader-editor",a.bind(this.click,this)),this.$document.on("dragover",a.bind(this.containerDragover,this)),this.$document.on("dragleave",a.bind(this.containerDragleave,this)),this.$document.on("dragstart dragend drop",function(t){e.localDrag="dragstart"===t.type}),this.initialized=!0),this},browserSupport:function(){var t=document.createElement("div");return("draggable"in t||"ondragstart"in t&&"ondrop"in t)&&!!(window.File&&window.FileList&&window.FileReader)},isDraggingFile:function(t){return null!==this.draggingFile?this.draggingFile:!a.isUndefined(t.originalEvent)&&!a.isUndefined(t.originalEvent.dataTransfer)&&(this.draggingFile=-1s)return o=e,!0}),this._views[t]=e,this.views.add(e,{at:a.isNumber(o)?o:i.length||0})),this},get:function(t){return this._views[t]},unset:function(t){var e=this.get(t);return e&&e.remove(),delete this._views[t],this},toView:function(t){return new l.View(t)}}),l.view.MenuItem=l.View.extend({tagName:"a",className:"media-menu-item",attributes:{href:"#"},events:{click:"_click"},_click:function(t){var e=this.options.click;t&&t.preventDefault(),e?e.call(this):this.click()},click:function(){var t=this.options.state;t&&this.controller.setState(t)},render:function(){var t=this.options;return t.text?this.$el.text(t.text):t.html&&this.$el.html(t.html),this}}),l.view.Menu=l.view.PriorityList.extend({tagName:"div",className:"media-menu",property:"state",ItemView:l.view.MenuItem,region:"menu",toView:function(t,e){return(t=t||{})[this.property]=t[this.property]||e,new this.ItemView(t).render()},ready:function(){l.view.PriorityList.prototype.ready.apply(this,arguments),this.visibility()},set:function(){l.view.PriorityList.prototype.set.apply(this,arguments),this.visibility()},unset:function(){l.view.PriorityList.prototype.unset.apply(this,arguments),this.visibility()},visibility:function(){var t=this.region,e=this.controller[t].get(),i=this.views.get(),i=!i||i.length<2;this===e&&this.controller.$el.toggleClass("hide-"+t,i)},select:function(t){t=this.get(t);t&&(this.deselect(),t.$el.addClass("active"))},deselect:function(){this.$el.children().removeClass("active")},hide:function(t){t=this.get(t);t&&t.$el.addClass("hidden")},show:function(t){t=this.get(t);t&&t.$el.removeClass("hidden")}}),l.view.RouterItem=l.view.MenuItem.extend({click:function(){var t=this.options.contentMode;t&&this.controller.content.mode(t)}}),l.view.Router=l.view.Menu.extend({tagName:"div",className:"media-router",property:"contentMode",ItemView:l.view.RouterItem,region:"router",initialize:function(){this.controller.on("content:render",this.update,this),l.view.Menu.prototype.initialize.apply(this,arguments)},update:function(){var t=this.controller.content.mode();t&&this.select(t)}}),l.view.Sidebar=l.view.PriorityList.extend({className:"media-sidebar"}),l.view.Attachment=l.View.extend({tagName:"li",className:"attachment",template:l.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 t=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),t&&t.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 t=this.options.selection;return this.updateAll(),t&&t.off(null,null,this),l.View.prototype.dispose.apply(this,arguments),this},render:function(){var t=a.defaults(this.model.toJSON(),{orientation:"landscape",uploading:!1,type:"",subtype:"",icon:"",filename:"",caption:"",title:"",dateFormatted:"",width:"",height:"",compat:!1,alt:"",description:""});return t.buttons=this.buttons,t.describe=this.controller.state().get("describe"),"image"===t.type&&(t.size=this.imageSize()),t.can={},t.nonces&&(t.can.remove=!!t.nonces["delete"],t.can.save=!!t.nonces.update),this.controller.state().get("allowLocalEdits")&&(t.allowLocalEdits=!0),this.views.detach(),this.$el.html(this.template(t)),this.$el.toggleClass("uploading",t.uploading),t.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(t){var e;t.shiftKey?e="between":(t.ctrlKey||t.metaKey)&&(e="toggle"),this.toggleSelection({method:e})},toggleSelection:function(t){var e,i,s=this.collection,o=this.options.selection,n=this.model,r=t&&t.method;if(o)return e=o.single(),"between"===(r=a.isUndefined(r)?o.multiple:r)&&e&&o.multiple?e===n?void 0:(i=(i=s.indexOf(e))<(t=s.indexOf(this.model))?s.models.slice(i,t+1):s.models.slice(t,i+1),o.add(i),void o.single(n)):"toggle"===r?(o[this.selected()?"remove":"add"](n),void o.single(n)):("add"!==r&&(r="reset"),void(this.selected()?o[e===n?"remove":"single"](n):(o[r](n),o.single(n))))},updateSelect:function(){this[this.selected()?"select":"deselect"]()},selected:function(){var t=this.options.selection;if(t)return!!t.get(this.model.cid)},select:function(t,e){var i=this.options.selection;!i||e&&e!==i||this.$el.addClass("selected")},deselect:function(t,e){var i=this.options.selection;!i||e&&e!==i||this.$el.removeClass("selected")},details:function(t,e){var i=this.options.selection;i===e&&(i=i.single(),this.$el.toggleClass("details",i===this.model))},preventDefault:function(t){t.preventDefault()},imageSize:function(t){var e=this.model.get("sizes");return t=t||"medium",e&&e[t]?a.clone(e[t]):{url:this.model.get("url"),width:this.model.get("width"),height:this.model.get("height"),orientation:this.model.get("orientation")}},updateSetting:function(t){var e=r(t.target).closest("[data-setting]");e.length&&(e=e.data("setting"),t=t.target.value,this.model.get(e)!==t&&this.save(e,t))},save:function(){var t=this,e=this._save=this._save||{status:"ready"},i=this.model.save.apply(this.model,arguments),s=e.requests?r.when(i,e.requests):i;e.savedTimer&&clearTimeout(e.savedTimer),this.updateSave("waiting"),(e.requests=s).always(function(){e.requests===s&&(t.updateSave("resolved"===s.state()?"complete":"error"),e.savedTimer=setTimeout(function(){t.updateSave("ready"),delete e.savedTimer},2e3))})},updateSave:function(t){var e=this._save=this._save||{status:"ready"};return t&&t!==e.status&&(this.$el.removeClass("save-"+e.status),e.status=t),this.$el.addClass("save-"+e.status),this},updateAll:function(){var t=this.$("[data-setting]"),i=this.model,t=a.chain(t).map(function(t){var e=r("input, textarea, select, [value]",t);if(e.length)return t=r(t).data("setting"),e=e.val(),i.get(t)!==e?[t,e]:void 0}).compact().object().value();a.isEmpty(t)||i.save(t)},removeFromLibrary:function(t){t.stopPropagation(),this.collection.remove(this.model)},removeFromSelection:function(t){var e=this.options.selection;e&&(t.stopPropagation(),e.remove(this.model))}}),a.each({caption:"_syncCaption",title:"_syncTitle"},function(t,s){l.view.Attachment.prototype[t]=function(t,e){var i=this.$('[data-setting="'+s+'"]');return!i.length||e===i.find("input, textarea, select, [value]").val()?this:this.render()}}),l.view.Attachment.Library=l.view.Attachment.extend({buttons:{check:!0}}),l.view.Attachment.EditLibrary=l.view.Attachment.extend({buttons:{close:!0}}),l.view.Attachments=l.View.extend({tagName:"ul",className:"attachments",cssTemplate:l.template("attachments-css"),events:{scroll:"scroll"},initialize:function(){this.el.id=a.uniqueId("__attachments-view-"),a.defaults(this.options,{refreshSensitivity:200,refreshThreshold:3,AttachmentView:l.view.Attachment,sortable:!1,resize:!0}),this._viewsByCid={},this.collection.on("add",function(t){this.views.add(this.createAttachmentView(t),{at:this.collection.indexOf(t)})},this),this.collection.on("remove",function(t){var e=this._viewsByCid[t.cid];delete this._viewsByCid[t.cid],e&&e.remove()},this),this.collection.on("reset",this.render,this),this.scroll=a.chain(this.scroll).bind(this).throttle(this.options.refreshSensitivity).value(),this.initSortable(),a.bindAll(this,"css"),this.model.on("change:edge change:gutter",this.css,this),this._resizeCss=a.debounce(a.bind(this.css,this),this.refreshSensitivity),this.options.resize&&r(window).on("resize.attachments",this._resizeCss),this.css()},dispose:function(){this.collection.props.off(null,null,this),r(window).off("resize.attachments",this._resizeCss),l.View.prototype.dispose.apply(this,arguments)},css:function(){var t=r("#"+this.el.id+"-css");t.length&&t.remove(),l.view.Attachments.$head().append(this.cssTemplate({id:this.el.id,edge:this.edge(),gutter:this.model.get("gutter")}))},edge:function(){var t,e,i,s=this.model.get("edge");return this.$el.is(":visible")?(t=2*this.model.get("gutter"),e=this.$el.width()-t,i=Math.ceil(e/(s+t)),s=Math.floor((e-i*t)/i)):s},initSortable:function(){var o=this.collection;this.options.sortable&&r.fn.sortable&&(this.$el.sortable(a.extend({disabled:!!o.comparator,containment:this.$el,tolerance:"pointer",start:function(t,e){e.item.data("sortableIndexStart",e.item.index())},update:function(t,e){var i=o.at(e.item.data("sortableIndexStart")),s=o.comparator;delete o.comparator,o.remove(i,{silent:!0}),o.add(i,{silent:!0,at:e.item.index()}),o.comparator=s,o.trigger("reset",o),o.saveMenuOrder()}},this.options.sortable)),o.props.on("change:orderby",function(){this.$el.sortable("option","disabled",!!o.comparator)},this),this.collection.props.on("change:orderby",this.refreshSortable,this),this.refreshSortable())},refreshSortable:function(){var t;this.options.sortable&&r.fn.sortable&&(t="menuOrder"===(t=this.collection).props.get("orderby")||!t.comparator,this.$el.sortable("option","disabled",!t))},createAttachmentView:function(t){var e=new this.options.AttachmentView({controller:this.controller,model:t,collection:this.collection,selection:this.options.selection});return this._viewsByCid[t.cid]=e},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(){var t,e=this;this.$el.is(":visible")&&this.collection.hasMore()&&(t=this.views.parent.toolbar,this.el.scrollHeight-(this.el.scrollTop+this.el.clientHeight)").val(e).html(t.text)[0],priority:t.priority||50}},this).sortBy("priority").pluck("el").value()),this.model.on("change",this.select,this),this.select()},createFilters:function(){this.filters={}},change:function(){var t=this.filters[this.el.value];t&&this.model.set(t.props)},select:function(){var t=this.model,i="all",s=t.toJSON();a.find(this.filters,function(t,e){if(a.all(t.props,function(t,e){return t===(a.isUndefined(s[e])?null:s[e])}))return i=e}),this.$el.val(i)}}),l.view.AttachmentFilters.Uploaded=l.view.AttachmentFilters.extend({createFilters:function(){var t,e=this.model.get("type"),i=l.view.settings.mimeTypes;i&&e&&(t=i[e]),this.filters={all:{text:t||h.allMediaItems,props:{uploadedTo:null,orderby:"date",order:"DESC"},priority:10},uploaded:{text:h.uploadedToThisPost,props:{uploadedTo:l.view.settings.post.id,orderby:"menuOrder",order:"ASC"},priority:20}}}}),l.view.AttachmentFilters.All=l.view.AttachmentFilters.extend({createFilters:function(){var i={};a.each(l.view.settings.mimeTypes||{},function(t,e){i[e]={text:t,props:{type:e,uploadedTo:null,orderby:"date",order:"DESC"}}}),i.all={text:h.allMediaItems,props:{type:null,uploadedTo:null,orderby:"date",order:"DESC"},priority:10},i.uploaded={text:h.uploadedToThisPost,props:{type:null,uploadedTo:l.view.settings.post.id,orderby:"menuOrder",order:"ASC"},priority:20},this.filters=i}}),l.view.AttachmentsBrowser=l.View.extend({tagName:"div",className:"attachments-browser",initialize:function(){a.defaults(this.options,{filters:!1,search:!0,display:!1,AttachmentView:l.view.Attachment.Library}),this.createToolbar(),this.updateContent(),this.createSidebar(),this.collection.on("add remove reset",this.updateContent,this)},dispose:function(){return this.options.selection.off(null,null,this),l.View.prototype.dispose.apply(this,arguments),this},createToolbar:function(){var t,e;this.toolbar=new l.view.Toolbar({controller:this.controller}),this.views.add(this.toolbar),"uploaded"===(t=this.options.filters)?e=l.view.AttachmentFilters.Uploaded:"all"===t&&(e=l.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 l.view.Spinner({priority:-70})),this.options.search&&this.toolbar.set("search",new l.view.Search({controller:this.controller,model:this.collection.props,priority:60}).render()),this.options.dragInfo&&this.toolbar.set("dragInfo",new l.View({el:r('
'+h.dragInfo+"
")[0],priority:-40})),this.options.suggestedWidth&&this.options.suggestedHeight&&this.toolbar.set("suggestedDimensions",new l.View({el:r('
'+h.suggestedDimensions+" "+this.options.suggestedWidth+" × "+this.options.suggestedHeight+"
")[0],priority:-40}))},updateContent:function(){var t=this;this.attachments||this.createAttachments(),this.collection.length?t.toolbar.get("spinner").hide():(this.toolbar.get("spinner").show(),this.collection.more().done(function(){t.collection.length||t.createUploader(),t.toolbar.get("spinner").hide()}))},removeContent:function(){a.each(["attachments","uploader"],function(t){this[t]&&(this[t].remove(),delete this[t])},this)},createUploader:function(){this.removeContent(),this.uploader=new l.view.UploaderInline({controller:this.controller,status:!1,message:h.noItemsFound}),this.views.add(this.uploader)},createAttachments:function(){this.removeContent(),this.attachments=new l.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 t=this.options.selection,e=this.sidebar=new l.view.Sidebar({controller:this.controller});this.views.add(e),this.controller.uploader&&e.set("uploads",new l.view.UploaderStatus({controller:this.controller,priority:40})),t.on("selection:single",this.createSingle,this),t.on("selection:unsingle",this.disposeSingle,this),t.single()&&this.createSingle()},createSingle:function(){var t=this.sidebar,e=this.options.selection.single();t.set("details",new l.view.Attachment.Details({controller:this.controller,model:e,priority:80})),t.set("compat",new l.view.AttachmentCompat({controller:this.controller,model:e,priority:120})),this.options.display&&t.set("display",new l.view.Settings.AttachmentDisplay({controller:this.controller,model:this.model.display(e),attachment:e,priority:160,userSettings:this.model.get("displayUserSettings")}))},disposeSingle:function(){var t=this.sidebar;t.unset("details"),t.unset("compat"),t.unset("display")}}),l.view.Selection=l.View.extend({tagName:"div",className:"media-selection",template:l.template("media-selection"),events:{"click .edit-selection":"edit","click .clear-selection":"clear"},initialize:function(){a.defaults(this.options,{editable:!1,clearable:!0}),this.attachments=new l.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(){var t,e;this.$el.children().length&&(t=this.collection,e="edit-selection"===this.controller.content.mode(),this.$el.toggleClass("empty",!t.length),this.$el.toggleClass("one",1===t.length),this.$el.toggleClass("editing",e),this.$(".count").text(h.selected.replace("%d",t.length)))},edit:function(t){t.preventDefault(),this.options.editable&&this.options.editable.call(this,this.collection)},clear:function(t){t.preventDefault(),this.collection.reset()}}),l.view.Attachment.Selection=l.view.Attachment.extend({className:"attachment selection",toggleSelection:function(){this.options.selection.single(this.model)}}),l.view.Attachments.Selection=l.view.Attachments.extend({events:{},initialize:function(){return a.defaults(this.options,{sortable:!0,resize:!1,AttachmentView:l.view.Attachment.Selection}),l.view.Attachments.prototype.initialize.apply(this,arguments)}}),l.view.Attachment.EditSelection=l.view.Attachment.Selection.extend({buttons:{close:!0}}),l.view.Settings=l.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 a.defaults({model:this.model.toJSON()},this.options)},render:function(){return l.View.prototype.render.apply(this,arguments),a(this.model.attributes).chain().keys().each(this.update,this),this},update:function(t){var e,i=this.model.get(t),s=this.$('[data-setting="'+t+'"]');s.length&&(s.is("select")?(e=s.find('[value="'+i+'"]')).length?(s.find("option").prop("selected",!1),e.prop("selected",!0)):this.model.set(t,s.find(":selected").val()):s.hasClass("button-group")?s.find("button").removeClass("active").filter('[value="'+i+'"]').addClass("active"):s.is('input[type="text"], textarea')?s.is(":focus")||s.val(i):s.is('input[type="checkbox"]')&&s.prop("checked",!!i))},updateHandler:function(t){var e=r(t.target).closest("[data-setting]"),i=t.target.value;t.preventDefault(),e.length&&(e.is('input[type="checkbox"]')&&(i=e[0].checked),this.model.set(e.data("setting"),i),(e=e.data("userSetting"))&&setUserSetting(e,i))},updateChanges:function(t){t.hasChanged()&&a(t.changed).chain().keys().each(this.update,this)}}),l.view.Settings.AttachmentDisplay=l.view.Settings.extend({className:"attachment-display-settings",template:l.template("attachment-display-settings"),initialize:function(){var t=this.options.attachment;a.defaults(this.options,{userSettings:!1}),l.view.Settings.prototype.initialize.apply(this,arguments),this.model.on("change:link",this.updateLinkTo,this),t&&t.on("change:uploading",this.render,this)},dispose:function(){var t=this.options.attachment;t&&t.off(null,null,this),l.view.Settings.prototype.dispose.apply(this,arguments)},render:function(){var t=this.options.attachment;return t&&a.extend(this.options,{sizes:t.get("sizes"),type:t.get("type")}),l.view.Settings.prototype.render.call(this),this.updateLinkTo(),this},updateLinkTo:function(){var t=this.model.get("link"),e=this.$(".link-to-custom"),i=this.options.attachment;"none"===t||"embed"===t||!i&&"custom"!==t?e.addClass("hidden"):(i&&("post"===t?e.val(i.get("link")):"file"===t?e.val(i.get("url")):this.model.get("linkUrl")||e.val("http://"),e.prop("readonly","custom"!==t)),e.removeClass("hidden"),e.is(":visible")&&e.focus()[0].select())}}),l.view.Settings.Gallery=l.view.Settings.extend({className:"collection-settings gallery-settings",template:l.template("gallery-settings")}),l.view.Settings.Playlist=l.view.Settings.extend({className:"collection-settings playlist-settings",template:l.template("playlist-settings")}),l.view.Attachment.Details=l.view.Attachment.extend({tagName:"div",className:"attachment-details",template:l.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 .trash-attachment":"trashAttachment","click .edit-attachment":"editAttachment","click .refresh-attachment":"refreshAttachment"},initialize:function(){this.focusManager=new l.view.FocusManager({el:this.el}),l.view.Attachment.prototype.initialize.apply(this,arguments)},render:function(){return l.view.Attachment.prototype.render.apply(this,arguments),this.focusManager.focus(),this},deleteAttachment:function(t){t.preventDefault(),confirm(h.warnDelete)&&this.model.destroy()},trashAttachment:function(t){t.preventDefault(),this.model.destroy()},editAttachment:function(t){var e=this.controller.states.get("edit-image");window.imageEdit&&e?(t.preventDefault(),e.set("image",this.model),this.controller.setState("edit-image")):this.$el.addClass("needs-refresh")},refreshAttachment:function(t){this.$el.removeClass("needs-refresh"),t.preventDefault(),this.model.fetch()}}),l.view.AttachmentCompat=l.View.extend({tagName:"form",className:"compat-item",events:{submit:"preventDefault","change input":"save","change select":"save","change textarea":"save"},initialize:function(){this.focusManager=new l.view.FocusManager({el:this.el}),this.model.on("change:compat",this.render,this)},dispose:function(){return this.$(":focus").length&&this.save(),l.View.prototype.dispose.apply(this,arguments)},render:function(){var t=this.model.get("compat");if(t&&t.item)return this.views.detach(),this.$el.html(t.item),this.views.render(),this.focusManager.focus(),this},preventDefault:function(t){t.preventDefault()},save:function(t){var e={};t&&t.preventDefault(),a.each(this.$el.serializeArray(),function(t){e[t.name]=t.value}),this.model.saveCompat(e)}}),l.view.Iframe=l.View.extend({className:"media-iframe",render:function(){return this.views.detach(),this.$el.html('