1 line
78 KiB
JavaScript
1 line
78 KiB
JavaScript
!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('<div class="instructions">'+s+"</div>")[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<this.$tabbables.length?this.index=t:delete this.index))},updateIndex:function(t){this.$tabbables=this.$(":tabbable");t=this.$tabbables.index(t.target);-1===t?delete this.index:this.index=t}}),l.view.UploaderWindow=l.View.extend({tagName:"div",className:"uploader-window",template:l.template("uploader-window"),initialize:function(){var t;this.$browser=r('<a href="#" class="browser" />').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=-1<a.indexOf(t.originalEvent.dataTransfer.types,"Files")&&-1===a.indexOf(t.originalEvent.dataTransfer.types,"text/plain"),this.draggingFile)},refresh:function(t){for(var e in this.dropzones)this.dropzones[e].toggle(this.overContainer||this.overDropzone);return a.isUndefined(t)||r(t.target).closest(".uploader-editor").toggleClass("droppable",this.overDropzone),this.overContainer||this.overDropzone||(this.draggingFile=null),this},render:function(){return this.initialized&&(l.View.prototype.render.apply(this,arguments),r(".wp-editor-wrap, #wp-fullscreen-body").each(a.bind(this.attach,this))),this},attach:function(t,e){var i=this.$el.clone();return this.dropzones.push(i),r(e).append(i),this},drop:function(t){var e=null;if(this.containerDragleave(t),this.dropzoneDragleave(t),this.files=t.originalEvent.dataTransfer.files,!(this.files.length<1))return 0<(e=r(t.target).parents(".wp-editor-wrap")).length&&e[0].id&&(window.wpActiveEditor=e[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(a.toArray(this.files)),this.files=[]),this},containerDragover:function(t){!this.localDrag&&this.isDraggingFile(t)&&(this.overContainer=!0,this.refresh())},containerDragleave:function(){this.overContainer=!1,a.delay(a.bind(this.refresh,this),50)},dropzoneDragover:function(t){if(!this.localDrag&&this.isDraggingFile(t))return this.overDropzone=!0,this.refresh(t),!1},dropzoneDragleave:function(t){this.overDropzone=!1,a.delay(a.bind(this.refresh,this,t),50)},click:function(t){this.containerDragleave(t),this.dropzoneDragleave(t),this.localDrag=!1}}),l.view.UploaderInline=l.View.extend({tagName:"div",className:"uploader-inline",template:l.template("uploader-inline"),initialize:function(){a.defaults(this.options,{message:"",status:!0}),!this.options.$browser&&this.controller.uploader&&(this.options.$browser=this.controller.uploader.$browser),a.isUndefined(this.options.postId)&&(this.options.postId=l.view.settings.post.id),this.options.status&&this.views.set(".upload-inline-status",new l.view.UploaderStatus({controller:this.controller}))},prepare:function(){var t=this.controller.state().get("suggestedWidth"),e=this.controller.state().get("suggestedHeight");if(t&&e)return{suggestedWidth:t,suggestedHeight:e}},dispose:function(){return this.disposing?l.View.prototype.dispose.apply(this,arguments):(this.disposing=!0,this.remove())},remove:function(){var t=l.View.prototype.remove.apply(this,arguments);return a.defer(a.bind(this.refresh,this)),t},refresh:function(){var t=this.controller.uploader;t&&t.refresh()},ready:function(){var t,e=this.options.$browser;if(this.controller.uploader){if((t=this.$(".browser"))[0]===e[0])return;e.detach().text(t.text()),e[0].className=t[0].className,t.replaceWith(e.show())}return this.refresh(),this}}),l.view.UploaderStatus=l.View.extend({className:"media-uploader-status",template:l.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),l.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(){a.each({$bar:".media-progress-bar div",$index:".upload-index",$total:".upload-total",$filename:".upload-filename"},function(t,e){this[e]=this.$(t)},this),this.visibility(),this.progress(),this.info()},progress:function(){var t=this.queue,e=this.$bar;e&&t.length&&e.width(t.reduce(function(t,e){if(!e.get("uploading"))return t+100;e=e.get("percent");return t+(a.isNumber(e)?e:100)},0)/t.length+"%")},info:function(){var t,e=this.queue,i=0;e.length&&(t=this.queue.find(function(t,e){return i=e,t.get("uploading")}),this.$index.text(i+1),this.$total.text(e.length),this.$filename.html(t?this.filename(t.get("filename")):""))},filename:function(t){return l.truncate(a.escape(t),24)},error:function(t){this.views.add(".upload-errors",new l.view.UploaderStatusError({filename:this.filename(t.get("file").name),message:t.get("message")}),{at:0})},dismiss:function(t){var e=this.views.get(".upload-errors");t.preventDefault(),e&&a.invoke(e,"remove"),wp.Uploader.errors.reset()}}),l.view.UploaderStatusError=l.View.extend({className:"upload-error",template:l.template("uploader-status-error")}),l.view.Toolbar=l.View.extend({tagName:"div",className:"media-toolbar",initialize:function(){var t=this.controller.state(),e=this.selection=t.get("selection"),t=this.library=t.get("library");this._views={},this.primary=new l.view.PriorityList,this.secondary=new l.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(),e&&e.on("add remove reset",this.refresh,this),t&&t.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),l.View.prototype.dispose.apply(this,arguments)},ready:function(){this.refresh()},set:function(t,e,i){return i=i||{},a.isObject(t)?a.each(t,function(t,e){this.set(e,t,{silent:!0})},this):(e instanceof Backbone.View||(e.classes=["media-button-"+t].concat(e.classes||[]),e=new l.view.Button(e).render()),e.controller=e.controller||this.controller,this._views[t]=e,this[e.options.priority<0?"secondary":"primary"].set(t,e,i)),i.silent||this.refresh(),this},get:function(t){return this._views[t]},unset:function(t,e){return delete this._views[t],this.primary.unset(t,e),this.secondary.unset(t,e),e&&e.silent||this.refresh(),this},refresh:function(){var t=this.controller.state(),s=t.get("library"),o=t.get("selection");a.each(this._views,function(t){var e,i;t.model&&t.options&&t.options.requires&&(e=t.options.requires,i=!1,i=a.some(o.models,function(t){return!0===t.get("uploading")}),(e.selection&&o&&!o.length||e.library&&s&&!s.length)&&(i=!0),t.model.set("disabled",i))})}}),l.view.Toolbar.Select=l.view.Toolbar.extend({initialize:function(){var t=this.options;a.bindAll(this,"clickSelect"),a.defaults(t,{event:"select",state:!1,reset:!0,close:!0,text:h.select,requires:{selection:!0}}),t.items=a.defaults(t.items||{},{select:{style:"primary",text:t.text,priority:80,click:this.clickSelect,requires:t.requires}}),l.view.Toolbar.prototype.initialize.apply(this,arguments)},clickSelect:function(){var t=this.options,e=this.controller;t.close&&e.close(),t.event&&e.state().trigger(t.event),t.state&&e.setState(t.state),t.reset&&e.reset()}}),l.view.Toolbar.Embed=l.view.Toolbar.Select.extend({initialize:function(){a.defaults(this.options,{text:h.insertIntoPost,requires:!1}),l.view.Toolbar.Select.prototype.initialize.apply(this,arguments)},refresh:function(){var t=this.controller.state().props.get("url");this.get("select").model.set("disabled",!t||"http://"===t),l.view.Toolbar.Select.prototype.refresh.apply(this,arguments)}}),l.view.Button=l.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),a.each(this.defaults,function(t,e){var i=this.options[e];a.isUndefined(i)||(this.model.set(e,i),delete this.options[e])},this),this.model.on("change",this.render,this)},render:function(){var t=["button",this.className],e=this.model.toJSON();return e.style&&t.push("button-"+e.style),e.size&&t.push("button-"+e.size),t=a.uniq(t.concat(this.options.classes)),this.el.className=t.join(" "),this.$el.attr("disabled",e.disabled),this.$el.text(this.model.get("text")),this},click:function(t){"#"===this.attributes.href&&t.preventDefault(),this.options.click&&!this.model.get("disabled")&&this.options.click.apply(this,arguments)}}),l.view.ButtonGroup=l.View.extend({tagName:"div",className:"button-group button-large media-button-group",initialize:function(){this.buttons=a.map(this.options.buttons||[],function(t){return t instanceof Backbone.View?t:new l.view.Button(t).render()}),delete this.options.buttons,this.options.classes&&this.$el.addClass(this.options.classes)},render:function(){return this.$el.html(r(a.pluck(this.buttons,"el")).detach()),this}}),l.view.PriorityList=l.View.extend({tagName:"div",initialize:function(){this._views={},this.set(a.extend({},this._views,this.options.views),{silent:!0}),delete this.options.views,this.options.silent||this.render()},set:function(t,e,i){var s,o;return i=i||{},a.isObject(t)?a.each(t,function(t,e){this.set(e,t)},this):((e=!(e instanceof Backbone.View)?this.toView(e,t,i):e).controller=e.controller||this.controller,this.unset(t),s=e.options.priority||10,i=this.views.get()||[],a.find(i,function(t,e){if(t.options.priority>s)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)<this.el.clientHeight/3&&t.get("spinner").show(),this.el.scrollHeight<this.el.scrollTop+this.el.clientHeight*this.options.refreshThreshold&&this.collection.more().done(function(){e.scroll(),t.get("spinner").hide()}))}},{$head:function(){return s=s||r("head")}}),l.view.Search=l.View.extend({tagName:"input",className:"search",attributes:{type:"search",placeholder:h.search},events:{input:"search",keyup:"search",change:"search",search:"search"},render:function(){return this.el.value=this.model.escape("search"),this},search:function(t){t.target.value?this.model.set("search",t.target.value):this.model.unset("search")}}),l.view.AttachmentFilters=l.View.extend({tagName:"select",className:"attachment-filters",events:{change:"change"},keys:[],initialize:function(){this.createFilters(),a.extend(this.filters,this.options.filters),this.$el.html(a.chain(this.filters).map(function(t,e){return{el:r("<option></option>").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('<div class="instructions">'+h.dragInfo+"</div>")[0],priority:-40})),this.options.suggestedWidth&&this.options.suggestedHeight&&this.toolbar.set("suggestedDimensions",new l.View({el:r('<div class="instructions">'+h.suggestedDimensions+" "+this.options.suggestedWidth+" × "+this.options.suggestedHeight+"</div>")[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('<iframe src="'+this.controller.state().get("src")+'" />'),this.views.render(),this}}),l.view.Embed=l.View.extend({className:"media-embed",initialize:function(){this.url=new l.view.EmbedUrl({controller:this.controller,model:this.model.props}).render(),this.views.set([this.url]),this.refresh(),this.model.on("change:type",this.refresh,this),this.model.on("change:loading",this.loading,this)},settings:function(t){this._settings&&this._settings.remove(),this._settings=t,this.views.add(t)},refresh:function(){var t,e=this.model.get("type");if("image"===e)t=l.view.EmbedImage;else{if("link"!==e)return;t=l.view.EmbedLink}this.settings(new t({controller:this.controller,model:this.model.props,priority:40}))},loading:function(){this.$el.toggleClass("embed-loading",this.model.get("loading"))}}),l.view.EmbedUrl=l.View.extend({tagName:"label",className:"embed-url",events:{input:"url",keyup:"url",change:"url"},initialize:function(){this.$input=r("<input/>").attr("type","text").val(this.model.get("url")),this.input=this.$input[0],this.spinner=r('<span class="spinner" />')[0],this.$el.append([this.input,this.spinner]),this.model.on("change:url",this.render,this)},render:function(){if(!this.$input.is(":focus"))return this.input.value=this.model.get("url")||"http://",l.View.prototype.render.apply(this,arguments),this},ready:function(){this.focus()},url:function(t){this.model.set("url",t.target.value)},focus:function(){var t=this.$input;t.is(":visible")&&t.focus()[0].select()}}),l.view.EmbedLink=l.view.Settings.extend({className:"embed-link-settings",template:l.template("embed-link-settings")}),l.view.EmbedImage=l.view.Settings.AttachmentDisplay.extend({className:"embed-media-settings",template:l.template("embed-image-settings"),initialize:function(){l.view.Settings.AttachmentDisplay.prototype.initialize.apply(this,arguments),this.model.on("change:url",this.updateImage,this)},updateImage:function(){this.$("img").attr("src",this.model.get("url"))}}),l.view.ImageDetails=l.view.Settings.AttachmentDisplay.extend({className:"image-details",template:l.template("image-details"),events:a.defaults(l.view.Settings.AttachmentDisplay.prototype.events,{"click .edit-attachment":"editAttachment","click .replace-attachment":"replaceAttachment","click .advanced-toggle":"onToggleAdvanced",'change [data-setting="customWidth"]':"onCustomSize",'change [data-setting="customHeight"]':"onCustomSize",'keyup [data-setting="customWidth"]':"onCustomSize",'keyup [data-setting="customHeight"]':"onCustomSize"}),initialize:function(){this.options.attachment=this.model.attachment,this.listenTo(this.model,"change:url",this.updateUrl),this.listenTo(this.model,"change:link",this.toggleLinkSettings),this.listenTo(this.model,"change:size",this.toggleCustomSize),l.view.Settings.AttachmentDisplay.prototype.initialize.apply(this,arguments)},prepare:function(){var t=!1;return this.model.attachment&&(t=this.model.attachment.toJSON()),a.defaults({model:this.model.toJSON(),attachment:t},this.options)},render:function(){var t=this,e=arguments;return this.model.attachment&&"pending"===this.model.dfd.state()?this.model.dfd.done(function(){l.view.Settings.AttachmentDisplay.prototype.render.apply(t,e),t.postRender()}).fail(function(){t.model.attachment=!1,l.view.Settings.AttachmentDisplay.prototype.render.apply(t,e),t.postRender()}):(l.view.Settings.AttachmentDisplay.prototype.render.apply(this,arguments),this.postRender()),this},postRender:function(){setTimeout(a.bind(this.resetFocus,this),10),this.toggleLinkSettings(),"show"===getUserSetting("advImgDetails")&&this.toggleAdvanced(!0),this.trigger("post-render")},resetFocus:function(){this.$(".link-to-custom").blur(),this.$(".embed-media-settings").scrollTop(0)},updateUrl:function(){this.$(".image img").attr("src",this.model.get("url")),this.$(".url").val(this.model.get("url"))},toggleLinkSettings:function(){"none"===this.model.get("link")?this.$(".link-settings").addClass("hidden"):this.$(".link-settings").removeClass("hidden")},toggleCustomSize:function(){"custom"!==this.model.get("size")?this.$(".custom-size").addClass("hidden"):this.$(".custom-size").removeClass("hidden")},onCustomSize:function(t){var e,i=r(t.target).data("setting"),s=r(t.target).val();!/^\d+/.test(s)||parseInt(s,10)<1?t.preventDefault():"customWidth"===i?(e=Math.round(1/this.model.get("aspectRatio")*s),this.model.set("customHeight",e,{silent:!0}),this.$('[data-setting="customHeight"]').val(e)):(e=Math.round(this.model.get("aspectRatio")*s),this.model.set("customWidth",e,{silent:!0}),this.$('[data-setting="customWidth"]').val(e))},onToggleAdvanced:function(t){t.preventDefault(),this.toggleAdvanced()},toggleAdvanced:function(t){var e=this.$el.find(".advanced-section"),e=e.hasClass("advanced-visible")||!1===t?(e.removeClass("advanced-visible"),e.find(".advanced-settings").addClass("hidden"),"hide"):(e.addClass("advanced-visible"),e.find(".advanced-settings").removeClass("hidden"),"show");setUserSetting("advImgDetails",e)},editAttachment:function(t){var e=this.controller.states.get("edit-image");window.imageEdit&&e&&(t.preventDefault(),e.set("image",this.model.attachment),this.controller.setState("edit-image"))},replaceAttachment:function(t){t.preventDefault(),this.controller.setState("replace-image")}}),l.view.Cropper=l.View.extend({className:"crop-content",template:l.template("crop-content"),initialize:function(){a.bindAll(this,"onImageLoad")},ready:function(){this.controller.frame.on("content:error:crop",this.onError,this),this.$image=this.$el.find(".crop-image"),this.$image.on("load",this.onImageLoad),r(window).on("resize.cropper",a.debounce(this.onImageLoad,250))},remove:function(){r(window).off("resize.cropper"),this.$el.remove(),this.$el.off(),wp.media.View.prototype.remove.apply(this,arguments)},prepare:function(){return{title:h.cropYourImage,url:this.options.attachment.get("url")}},onImageLoad:function(){var t=this.controller.get("imgSelectOptions");"function"==typeof t&&(t=t(this.options.attachment,this.controller)),t=a.extend(t,{parent:this.$el}),this.trigger("image-loaded"),this.controller.imgSelect=this.$image.imgAreaSelect(t)},onError:function(){var t=this.options.attachment.get("filename");this.views.add(".upload-errors",new l.view.UploaderStatusError({filename:l.view.UploaderStatus.prototype.filename(t),message:_wpMediaViewsL10n.cropError}),{at:0})}}),l.view.EditImage=l.View.extend({className:"image-editor",template:l.template("image-editor"),initialize:function(t){this.editor=window.imageEdit,this.controller=t.controller,l.View.prototype.initialize.apply(this,arguments)},prepare:function(){return this.model.toJSON()},render:function(){return l.View.prototype.render.apply(this,arguments),this},loadEditor:function(){this.editor.open(this.model.get("id"),this.model.get("nonces").edit,this)},back:function(){var t=this.controller.lastState();this.controller.setState(t)},refresh:function(){this.model.fetch()},save:function(){var t=this,e=this.controller.lastState();this.model.fetch().done(function(){t.controller.setState(e)})}}),l.view.Spinner=l.View.extend({tagName:"span",className:"spinner",spinnerTimeout:!1,delay:400,show:function(){return this.spinnerTimeout||(this.spinnerTimeout=a.delay(function(t){t.show()},this.delay,this.$el)),this},hide:function(){return this.$el.hide(),this.spinnerTimeout=clearTimeout(this.spinnerTimeout),this}})}(jQuery,_); |