From f078f3e10e4431f9f4fc6e2b094a2af36b637d80 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sun, 9 Mar 2014 10:32:15 +0000 Subject: [PATCH] Video editing in the media modal: * Add a state: `Add Subititles` * Add `text/vtt` to the list of allowed mime-types, files end in `.vtt`. `.srt` files are served as `text/plain`. * The content body of a video shortcode should be used for adding `` elements only. This happens dynamically in the modal. If added by hand, they can still be parsed and managed. See #27016. Built from https://develop.svn.wordpress.org/trunk@27481 git-svn-id: http://core.svn.wordpress.org/trunk@27325 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 1 + wp-includes/js/media-editor.js | 26 +++-- wp-includes/js/media-editor.min.js | 2 +- wp-includes/js/media-views.js | 106 ++++++++++++------ wp-includes/js/media-views.min.js | 6 +- .../js/mediaelement/wp-mediaelement.css | 8 ++ .../js/tinymce/plugins/wpgallery/plugin.js | 13 ++- .../tinymce/plugins/wpgallery/plugin.min.js | 2 +- wp-includes/js/tinymce/wp-tinymce.js.gz | Bin 120955 -> 120959 bytes wp-includes/media-template.php | 34 ++++-- wp-includes/media.php | 7 +- 11 files changed, 138 insertions(+), 67 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 3ac86a3e19..6fa978c099 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1983,6 +1983,7 @@ function wp_get_mime_types() { 'rtx' => 'text/richtext', 'css' => 'text/css', 'htm|html' => 'text/html', + 'vtt' => 'text/vtt', // Audio formats 'mp3|m4a|m4b' => 'audio/mpeg', 'ra|ram' => 'audio/x-realaudio', diff --git a/wp-includes/js/media-editor.js b/wp-includes/js/media-editor.js index f065c0e8b0..bdb72abb32 100644 --- a/wp-includes/js/media-editor.js +++ b/wp-includes/js/media-editor.js @@ -609,26 +609,33 @@ poster : '', loop : false, autoplay : false, - preload : 'metadata' + preload : 'metadata', + content : '' }, edit : function (data) { - var frame, shortcode = wp.shortcode.next( 'video', data ).shortcode; + var frame, + defaults = this.defaults, + shortcode = wp.shortcode.next( 'video', data ).shortcode, + attrs; + + attrs = shortcode.attrs.named; + attrs.content = shortcode.content; + frame = wp.media({ frame: 'video', state: 'video-details', - metadata: _.defaults( - shortcode.attrs.named, - wp.media.video.defaults - ) + metadata: _.defaults( attrs, defaults ) }); return frame; }, shortcode : function (shortcode) { - var self = this; - _.each( wp.media.video.defaults, function( value, key ) { + var self = this, content = shortcode.content; + delete shortcode.content; + + _.each( this.defaults, function( value, key ) { shortcode[ key ] = self.coerce( shortcode, key ); if ( value === shortcode[ key ] ) { @@ -638,7 +645,8 @@ return wp.shortcode.string({ tag: 'video', - attrs: shortcode + attrs: shortcode, + content: content }); } }, wp.media.mixin); diff --git a/wp-includes/js/media-editor.min.js b/wp-includes/js/media-editor.min.js index a951207c53..c003435bd9 100644 --- a/wp-includes/js/media-editor.min.js +++ b/wp-includes/js/media-editor.min.js @@ -1 +1 @@ -!function(a,b){var c={};wp.media.string={props:function(a,c){var d,e,f,g,h,i=wp.media.view.settings.defaultProps;return h=function(a){return"image"!==a.type||a.alt||(a.alt=a.caption||a.title||"",a.alt=a.alt.replace(/<\/?[^>]+>/g,""),a.alt=a.alt.replace(/[\r\n]+/g," ")),a},a=a?b.clone(a):{},c&&c.type&&(a.type=c.type),"image"===a.type&&(a=b.defaults(a||{},{align:i.align||getUserSetting("align","none"),size:i.size||getUserSetting("imgsize","medium"),url:"",classes:[]})),c?(a.title=a.title||c.title,d=a.link||i.link||getUserSetting("urlbutton","file"),"file"===d||"embed"===d?e=c.url:"post"===d?e=c.link:"custom"===d&&(e=a.linkUrl),a.linkUrl=e||"","image"===c.type?(a.classes.push("wp-image-"+c.id),g=c.sizes,f=g&&g[a.size]?g[a.size]:c,b.extend(a,b.pick(c,"align","caption","alt"),{width:f.width,height:f.height,src:f.url,captionId:"attachment_"+c.id})):"video"===c.type||"audio"===c.type?b.extend(a,b.pick(c,"title","type","icon","mime")):(a.title=a.title||c.filename,a.rel=a.rel||"attachment wp-att-"+c.id),h(a)):h(a)},link:function(a,b){var c;return a=wp.media.string.props(a,b),c={tag:"a",content:a.title,attrs:{href:a.linkUrl}},a.rel&&(c.attrs.rel=a.rel),wp.html.string(c)},audio:function(a,b){return wp.media.string._audioVideo("audio",a,b)},video:function(a,b){return wp.media.string._audioVideo("video",a,b)},_audioVideo:function(a,c,d){var e,f,g;return c=wp.media.string.props(c,d),"embed"!==c.link?wp.media.string.link(c):(e={},"video"===a&&(d.width&&(e.width=d.width),d.height&&(e.height=d.height)),g=d.filename.split(".").pop(),b.contains(wp.media.view.settings.embedExts,g)?(e[g]=d.url,f=wp.shortcode.string({tag:a,attrs:e})):wp.media.string.link(c))},image:function(a,c){var d,e,f,g,h={};return a=wp.media.string.props(a,c),e=a.classes||[],h.src=b.isUndefined(c)?a.url:c.url,b.extend(h,b.pick(a,"width","height","alt")),a.align&&!a.caption&&e.push("align"+a.align),a.size&&e.push("size-"+a.size),h["class"]=b.compact(e).join(" "),d={tag:"img",attrs:h,single:!0},a.linkUrl&&(d={tag:"a",attrs:{href:a.linkUrl},content:d}),g=wp.html.string(d),a.caption&&(f={},h.width&&(f.width=h.width),a.captionId&&(f.id=a.captionId),a.align&&(f.align="align"+a.align),g=wp.shortcode.string({tag:"caption",attrs:f,content:g+" "+a.caption})),g}},wp.media.mixin={coerce:function(a,c){return b.isUndefined(a[c])&&!b.isUndefined(this.defaults[c])?a[c]=this.defaults[c]:"true"===a[c]?a[c]=!0:"false"===a[c]&&(a[c]=!1),a[c]}},wp.media.collection=function(a){var c={};return b.extend(a,wp.media.mixin,{attachments:function(a){var d,e,f,g,h=a.string(),i=c[h],j=this;return delete c[h],i?i:(d=b.defaults(a.attrs.named,this.defaults),e=b.pick(d,"orderby","order"),e.type=this.type,e.perPage=-1,void 0!==d.orderby&&(d._orderByField=d.orderby),"rand"===d.orderby&&(d._orderbyRandom=!0),(!d.orderby||/^menu_order(?: ID)?$/i.test(d.orderby))&&(e.orderby="menuOrder"),d.ids?(e.post__in=d.ids.split(","),e.orderby="post__in"):d.include&&(e.post__in=d.include.split(",")),d.exclude&&(e.post__not_in=d.exclude.split(",")),e.post__in||(e.uploadedTo=d.id),g=b.omit(d,"id","ids","include","exclude","orderby","order"),b.each(this.defaults,function(a,b){g[b]=j.coerce(g,b)}),f=wp.media.query(e),f[this.tag]=new Backbone.Model(g),f)},shortcode:function(a){var d,e,f=a.props.toJSON(),g=b.pick(f,"orderby","order"),h=this;return a[this.tag]&&b.extend(g,a[this.tag].toJSON()),g.ids=a.pluck("id"),f.uploadedTo&&(g.id=f.uploadedTo),delete g.orderby,g._orderbyRandom?g.orderby="rand":g._orderByField&&"rand"!=g._orderByField&&(g.orderby=g._orderByField),delete g._orderbyRandom,delete g._orderByField,g.ids&&"post__in"===g.orderby&&delete g.orderby,b.each(this.defaults,function(a,b){g[b]=h.coerce(g,b),a===g[b]&&delete g[b]}),d=new wp.shortcode({tag:this.tag,attrs:g,type:"single"}),e=new wp.media.model.Attachments(a.models,{props:f}),e[this.tag]=a[this.tag],c[d.string()]=e,d},edit:function(a){var c,d,e=wp.shortcode.next(this.tag,a),f=this.defaults.id;if(e&&e.content===a)return e=e.shortcode,b.isUndefined(e.get("id"))&&!b.isUndefined(f)&&e.set("id",f),c=this.attachments(e),d=new wp.media.model.Selection(c.models,{props:c.props.toJSON(),multiple:!0}),d[this.tag]=c[this.tag],d.more().done(function(){d.props.set({query:!1}),d.unmirror(),d.props.unset("orderby")}),this.frame&&this.frame.dispose(),this.frame=wp.media({frame:"post",state:this.tag+"-edit",title:this.editTitle,editing:!0,multiple:!0,selection:d}).open(),this.frame}})},wp.media.gallery=new wp.media.collection({tag:"gallery",type:"image",editTitle:wp.media.view.l10n.editGalleryTitle,defaults:{itemtag:"dl",icontag:"dt",captiontag:"dd",columns:"3",link:"post",size:"thumbnail",order:"ASC",id:wp.media.view.settings.post.id,orderby:"menu_order ID"}}),wp.media.playlist=new wp.media.collection({tag:"playlist",type:"audio",editTitle:wp.media.view.l10n.editPlaylistTitle,defaults:{id:wp.media.view.settings.post.id,style:"light",tracklist:!0,tracknumbers:!0,images:!0,artists:!0}}),wp.media["video-playlist"]=new wp.media.collection({tag:"video-playlist",type:"video",editTitle:wp.media.view.l10n.editVideoPlaylistTitle,defaults:{id:wp.media.view.settings.post.id,style:"light",tracklist:!1,tracknumbers:!1,images:!0}}),wp.media.audio=b.extend({defaults:{id:wp.media.view.settings.post.id,src:"",loop:!1,autoplay:!1,preload:"none"},edit:function(a){var c,d=wp.shortcode.next("audio",a).shortcode;return c=wp.media({frame:"audio",state:"audio-details",metadata:b.defaults(d.attrs.named,wp.media.audio.defaults)})},shortcode:function(a){var c=this;return b.each(wp.media.audio.defaults,function(b,d){a[d]=c.coerce(a,d),b===a[d]&&delete a[d]}),wp.shortcode.string({tag:"audio",attrs:a})}},wp.media.mixin),wp.media.video=b.extend({defaults:{id:wp.media.view.settings.post.id,src:"",poster:"",loop:!1,autoplay:!1,preload:"metadata"},edit:function(a){var c,d=wp.shortcode.next("video",a).shortcode;return c=wp.media({frame:"video",state:"video-details",metadata:b.defaults(d.attrs.named,wp.media.video.defaults)})},shortcode:function(a){var c=this;return b.each(wp.media.video.defaults,function(b,d){a[d]=c.coerce(a,d),b===a[d]&&delete a[d]}),wp.shortcode.string({tag:"video",attrs:a})}},wp.media.mixin),wp.media.featuredImage={get:function(){return wp.media.view.settings.post.featuredImageId},set:function(b){var c=wp.media.view.settings;c.post.featuredImageId=b,wp.media.post("set-post-thumbnail",{json:!0,post_id:c.post.id,thumbnail_id:c.post.featuredImageId,_wpnonce:c.post.nonce}).done(function(b){a(".inside","#postimagediv").html(b)})},frame:function(){return this._frame?this._frame:(this._frame=wp.media({state:"featured-image",states:[new wp.media.controller.FeaturedImage,new wp.media.controller.EditImage]}),this._frame.on("toolbar:create:featured-image",function(a){this.createSelectToolbar(a,{text:wp.media.view.l10n.setFeaturedImage})},this._frame),this._frame.on("content:render:edit-image",function(){var a=this.state("featured-image").get("selection"),b=new wp.media.view.EditImage({model:a.single(),controller:this}).render();this.content.set(b),b.loadEditor()},this._frame),this._frame.state("featured-image").on("select",this.select),this._frame)},select:function(){var a=this.get("selection").single();wp.media.view.settings.post.featuredImageId&&wp.media.featuredImage.set(a?a.id:-1)},init:function(){a("#postimagediv").on("click","#set-post-thumbnail",function(a){a.preventDefault(),a.stopPropagation(),wp.media.featuredImage.frame().open()}).on("click","#remove-post-thumbnail",function(){wp.media.view.settings.post.featuredImageId=-1})}},a(wp.media.featuredImage.init),wp.media.editor={insert:function(a){var c,d=!b.isUndefined(window.tinymce),e=!b.isUndefined(window.QTags),f=window.wpActiveEditor;if(window.send_to_editor)return window.send_to_editor.apply(this,arguments);if(f)d&&(c=tinymce.get(f));else if(d&&tinymce.activeEditor)c=tinymce.activeEditor,f=window.wpActiveEditor=c.id;else if(!e)return!1;if(c&&!c.isHidden()?c.execCommand("mceInsertContent",!1,a):e?QTags.insertContent(a):document.getElementById(f).value+=a,window.tb_remove)try{window.tb_remove()}catch(g){}},add:function(d,e){var f=this.get(d);return f?f:(f=c[d]=wp.media(b.defaults(e||{},{frame:"post",state:"insert",title:wp.media.view.l10n.addMedia,multiple:!0})),f.on("insert",function(c){var d=f.state();c=c||d.get("selection"),c&&a.when.apply(a,c.map(function(a){var b=d.display(a).toJSON();return this.send.attachment(b,a.toJSON())},this)).done(function(){wp.media.editor.insert(b.toArray(arguments).join("\n\n"))})},this),f.state("gallery-edit").on("update",function(a){this.insert(wp.media.gallery.shortcode(a).string())},this),f.state("playlist-edit").on("update",function(a){this.insert(wp.media.playlist.shortcode(a).string())},this),f.state("video-playlist-edit").on("update",function(a){this.insert(wp.media["video-playlist"].shortcode(a).string())},this),f.state("embed").on("select",function(){var a=f.state(),c=a.get("type"),d=a.props.toJSON();d.url=d.url||"","link"===c?(b.defaults(d,{title:d.url,linkUrl:d.url}),this.send.link(d).done(function(a){wp.media.editor.insert(a)})):"image"===c&&(b.defaults(d,{title:d.url,linkUrl:"",align:"none",link:"none"}),"none"===d.link?d.linkUrl="":"file"===d.link&&(d.linkUrl=d.url),this.insert(wp.media.string.image(d)))},this),f.state("featured-image").on("select",wp.media.featuredImage.select),f.setState(f.options.state),f)},id:function(a){return a?a:(a=wpActiveEditor,a||b.isUndefined(window.tinymce)||!tinymce.activeEditor||(a=tinymce.activeEditor.id),a=a||"")},get:function(a){return a=this.id(a),c[a]},remove:function(a){a=this.id(a),delete c[a]},send:{attachment:function(a,c){var d,e,f=c.caption;return wp.media.view.settings.captions||delete c.caption,a=wp.media.string.props(a,c),d={id:c.id,post_content:c.description,post_excerpt:f},a.linkUrl&&(d.url=a.linkUrl),"image"===c.type?(e=wp.media.string.image(a),b.each({align:"align",size:"image-size",alt:"image_alt"},function(b,c){a[c]&&(d[b]=a[c])})):"video"===c.type?e=wp.media.string.video(a,c):"audio"===c.type?e=wp.media.string.audio(a,c):(e=wp.media.string.link(a),d.post_title=a.title),wp.media.post("send-attachment-to-editor",{nonce:wp.media.view.settings.nonce.sendToEditor,attachment:d,html:e,post_id:wp.media.view.settings.post.id})},link:function(a){return wp.media.post("send-link-to-editor",{nonce:wp.media.view.settings.nonce.sendToEditor,src:a.linkUrl,title:a.title,html:wp.media.string.link(a),post_id:wp.media.view.settings.post.id})}},open:function(a,b){var c;return b=b||{},a=this.id(a),c=this.get(a),(!c||c.options&&b.state!==c.options.state)&&(c=this.add(a,b)),c.open()},init:function(){a(document.body).on("click",".insert-media",function(b){var c=a(b.currentTarget),d=c.data("editor"),e={frame:"post",state:"insert",title:wp.media.view.l10n.addMedia,multiple:!0};b.preventDefault(),c.blur(),c.hasClass("gallery")?(e.state="gallery",e.title=wp.media.view.l10n.createGalleryTitle):c.hasClass("playlist")?(e.state="playlist",e.title=wp.media.view.l10n.createPlaylistTitle):c.hasClass("video-playlist")&&(e.state="video-playlist",e.title=wp.media.view.l10n.createVideoPlaylistTitle),wp.media.editor.open(d,e)}),(new wp.media.view.EditorUploader).render()}},b.bindAll(wp.media.editor,"open"),a(wp.media.editor.init)}(jQuery,_); \ No newline at end of file +!function(a,b){var c={};wp.media.string={props:function(a,c){var d,e,f,g,h,i=wp.media.view.settings.defaultProps;return h=function(a){return"image"!==a.type||a.alt||(a.alt=a.caption||a.title||"",a.alt=a.alt.replace(/<\/?[^>]+>/g,""),a.alt=a.alt.replace(/[\r\n]+/g," ")),a},a=a?b.clone(a):{},c&&c.type&&(a.type=c.type),"image"===a.type&&(a=b.defaults(a||{},{align:i.align||getUserSetting("align","none"),size:i.size||getUserSetting("imgsize","medium"),url:"",classes:[]})),c?(a.title=a.title||c.title,d=a.link||i.link||getUserSetting("urlbutton","file"),"file"===d||"embed"===d?e=c.url:"post"===d?e=c.link:"custom"===d&&(e=a.linkUrl),a.linkUrl=e||"","image"===c.type?(a.classes.push("wp-image-"+c.id),g=c.sizes,f=g&&g[a.size]?g[a.size]:c,b.extend(a,b.pick(c,"align","caption","alt"),{width:f.width,height:f.height,src:f.url,captionId:"attachment_"+c.id})):"video"===c.type||"audio"===c.type?b.extend(a,b.pick(c,"title","type","icon","mime")):(a.title=a.title||c.filename,a.rel=a.rel||"attachment wp-att-"+c.id),h(a)):h(a)},link:function(a,b){var c;return a=wp.media.string.props(a,b),c={tag:"a",content:a.title,attrs:{href:a.linkUrl}},a.rel&&(c.attrs.rel=a.rel),wp.html.string(c)},audio:function(a,b){return wp.media.string._audioVideo("audio",a,b)},video:function(a,b){return wp.media.string._audioVideo("video",a,b)},_audioVideo:function(a,c,d){var e,f,g;return c=wp.media.string.props(c,d),"embed"!==c.link?wp.media.string.link(c):(e={},"video"===a&&(d.width&&(e.width=d.width),d.height&&(e.height=d.height)),g=d.filename.split(".").pop(),b.contains(wp.media.view.settings.embedExts,g)?(e[g]=d.url,f=wp.shortcode.string({tag:a,attrs:e})):wp.media.string.link(c))},image:function(a,c){var d,e,f,g,h={};return a=wp.media.string.props(a,c),e=a.classes||[],h.src=b.isUndefined(c)?a.url:c.url,b.extend(h,b.pick(a,"width","height","alt")),a.align&&!a.caption&&e.push("align"+a.align),a.size&&e.push("size-"+a.size),h["class"]=b.compact(e).join(" "),d={tag:"img",attrs:h,single:!0},a.linkUrl&&(d={tag:"a",attrs:{href:a.linkUrl},content:d}),g=wp.html.string(d),a.caption&&(f={},h.width&&(f.width=h.width),a.captionId&&(f.id=a.captionId),a.align&&(f.align="align"+a.align),g=wp.shortcode.string({tag:"caption",attrs:f,content:g+" "+a.caption})),g}},wp.media.mixin={coerce:function(a,c){return b.isUndefined(a[c])&&!b.isUndefined(this.defaults[c])?a[c]=this.defaults[c]:"true"===a[c]?a[c]=!0:"false"===a[c]&&(a[c]=!1),a[c]}},wp.media.collection=function(a){var c={};return b.extend(a,wp.media.mixin,{attachments:function(a){var d,e,f,g,h=a.string(),i=c[h],j=this;return delete c[h],i?i:(d=b.defaults(a.attrs.named,this.defaults),e=b.pick(d,"orderby","order"),e.type=this.type,e.perPage=-1,void 0!==d.orderby&&(d._orderByField=d.orderby),"rand"===d.orderby&&(d._orderbyRandom=!0),(!d.orderby||/^menu_order(?: ID)?$/i.test(d.orderby))&&(e.orderby="menuOrder"),d.ids?(e.post__in=d.ids.split(","),e.orderby="post__in"):d.include&&(e.post__in=d.include.split(",")),d.exclude&&(e.post__not_in=d.exclude.split(",")),e.post__in||(e.uploadedTo=d.id),g=b.omit(d,"id","ids","include","exclude","orderby","order"),b.each(this.defaults,function(a,b){g[b]=j.coerce(g,b)}),f=wp.media.query(e),f[this.tag]=new Backbone.Model(g),f)},shortcode:function(a){var d,e,f=a.props.toJSON(),g=b.pick(f,"orderby","order"),h=this;return a[this.tag]&&b.extend(g,a[this.tag].toJSON()),g.ids=a.pluck("id"),f.uploadedTo&&(g.id=f.uploadedTo),delete g.orderby,g._orderbyRandom?g.orderby="rand":g._orderByField&&"rand"!=g._orderByField&&(g.orderby=g._orderByField),delete g._orderbyRandom,delete g._orderByField,g.ids&&"post__in"===g.orderby&&delete g.orderby,b.each(this.defaults,function(a,b){g[b]=h.coerce(g,b),a===g[b]&&delete g[b]}),d=new wp.shortcode({tag:this.tag,attrs:g,type:"single"}),e=new wp.media.model.Attachments(a.models,{props:f}),e[this.tag]=a[this.tag],c[d.string()]=e,d},edit:function(a){var c,d,e=wp.shortcode.next(this.tag,a),f=this.defaults.id;if(e&&e.content===a)return e=e.shortcode,b.isUndefined(e.get("id"))&&!b.isUndefined(f)&&e.set("id",f),c=this.attachments(e),d=new wp.media.model.Selection(c.models,{props:c.props.toJSON(),multiple:!0}),d[this.tag]=c[this.tag],d.more().done(function(){d.props.set({query:!1}),d.unmirror(),d.props.unset("orderby")}),this.frame&&this.frame.dispose(),this.frame=wp.media({frame:"post",state:this.tag+"-edit",title:this.editTitle,editing:!0,multiple:!0,selection:d}).open(),this.frame}})},wp.media.gallery=new wp.media.collection({tag:"gallery",type:"image",editTitle:wp.media.view.l10n.editGalleryTitle,defaults:{itemtag:"dl",icontag:"dt",captiontag:"dd",columns:"3",link:"post",size:"thumbnail",order:"ASC",id:wp.media.view.settings.post.id,orderby:"menu_order ID"}}),wp.media.playlist=new wp.media.collection({tag:"playlist",type:"audio",editTitle:wp.media.view.l10n.editPlaylistTitle,defaults:{id:wp.media.view.settings.post.id,style:"light",tracklist:!0,tracknumbers:!0,images:!0,artists:!0}}),wp.media["video-playlist"]=new wp.media.collection({tag:"video-playlist",type:"video",editTitle:wp.media.view.l10n.editVideoPlaylistTitle,defaults:{id:wp.media.view.settings.post.id,style:"light",tracklist:!1,tracknumbers:!1,images:!0}}),wp.media.audio=b.extend({defaults:{id:wp.media.view.settings.post.id,src:"",loop:!1,autoplay:!1,preload:"none"},edit:function(a){var c,d=wp.shortcode.next("audio",a).shortcode;return c=wp.media({frame:"audio",state:"audio-details",metadata:b.defaults(d.attrs.named,wp.media.audio.defaults)})},shortcode:function(a){var c=this;return b.each(wp.media.audio.defaults,function(b,d){a[d]=c.coerce(a,d),b===a[d]&&delete a[d]}),wp.shortcode.string({tag:"audio",attrs:a})}},wp.media.mixin),wp.media.video=b.extend({defaults:{id:wp.media.view.settings.post.id,src:"",poster:"",loop:!1,autoplay:!1,preload:"metadata",content:""},edit:function(a){var c,d,e=this.defaults,f=wp.shortcode.next("video",a).shortcode;return d=f.attrs.named,d.content=f.content,c=wp.media({frame:"video",state:"video-details",metadata:b.defaults(d,e)})},shortcode:function(a){var c=this,d=a.content;return delete a.content,b.each(this.defaults,function(b,d){a[d]=c.coerce(a,d),b===a[d]&&delete a[d]}),wp.shortcode.string({tag:"video",attrs:a,content:d})}},wp.media.mixin),wp.media.featuredImage={get:function(){return wp.media.view.settings.post.featuredImageId},set:function(b){var c=wp.media.view.settings;c.post.featuredImageId=b,wp.media.post("set-post-thumbnail",{json:!0,post_id:c.post.id,thumbnail_id:c.post.featuredImageId,_wpnonce:c.post.nonce}).done(function(b){a(".inside","#postimagediv").html(b)})},frame:function(){return this._frame?this._frame:(this._frame=wp.media({state:"featured-image",states:[new wp.media.controller.FeaturedImage,new wp.media.controller.EditImage]}),this._frame.on("toolbar:create:featured-image",function(a){this.createSelectToolbar(a,{text:wp.media.view.l10n.setFeaturedImage})},this._frame),this._frame.on("content:render:edit-image",function(){var a=this.state("featured-image").get("selection"),b=new wp.media.view.EditImage({model:a.single(),controller:this}).render();this.content.set(b),b.loadEditor()},this._frame),this._frame.state("featured-image").on("select",this.select),this._frame)},select:function(){var a=this.get("selection").single();wp.media.view.settings.post.featuredImageId&&wp.media.featuredImage.set(a?a.id:-1)},init:function(){a("#postimagediv").on("click","#set-post-thumbnail",function(a){a.preventDefault(),a.stopPropagation(),wp.media.featuredImage.frame().open()}).on("click","#remove-post-thumbnail",function(){wp.media.view.settings.post.featuredImageId=-1})}},a(wp.media.featuredImage.init),wp.media.editor={insert:function(a){var c,d=!b.isUndefined(window.tinymce),e=!b.isUndefined(window.QTags),f=window.wpActiveEditor;if(window.send_to_editor)return window.send_to_editor.apply(this,arguments);if(f)d&&(c=tinymce.get(f));else if(d&&tinymce.activeEditor)c=tinymce.activeEditor,f=window.wpActiveEditor=c.id;else if(!e)return!1;if(c&&!c.isHidden()?c.execCommand("mceInsertContent",!1,a):e?QTags.insertContent(a):document.getElementById(f).value+=a,window.tb_remove)try{window.tb_remove()}catch(g){}},add:function(d,e){var f=this.get(d);return f?f:(f=c[d]=wp.media(b.defaults(e||{},{frame:"post",state:"insert",title:wp.media.view.l10n.addMedia,multiple:!0})),f.on("insert",function(c){var d=f.state();c=c||d.get("selection"),c&&a.when.apply(a,c.map(function(a){var b=d.display(a).toJSON();return this.send.attachment(b,a.toJSON())},this)).done(function(){wp.media.editor.insert(b.toArray(arguments).join("\n\n"))})},this),f.state("gallery-edit").on("update",function(a){this.insert(wp.media.gallery.shortcode(a).string())},this),f.state("playlist-edit").on("update",function(a){this.insert(wp.media.playlist.shortcode(a).string())},this),f.state("video-playlist-edit").on("update",function(a){this.insert(wp.media["video-playlist"].shortcode(a).string())},this),f.state("embed").on("select",function(){var a=f.state(),c=a.get("type"),d=a.props.toJSON();d.url=d.url||"","link"===c?(b.defaults(d,{title:d.url,linkUrl:d.url}),this.send.link(d).done(function(a){wp.media.editor.insert(a)})):"image"===c&&(b.defaults(d,{title:d.url,linkUrl:"",align:"none",link:"none"}),"none"===d.link?d.linkUrl="":"file"===d.link&&(d.linkUrl=d.url),this.insert(wp.media.string.image(d)))},this),f.state("featured-image").on("select",wp.media.featuredImage.select),f.setState(f.options.state),f)},id:function(a){return a?a:(a=wpActiveEditor,a||b.isUndefined(window.tinymce)||!tinymce.activeEditor||(a=tinymce.activeEditor.id),a=a||"")},get:function(a){return a=this.id(a),c[a]},remove:function(a){a=this.id(a),delete c[a]},send:{attachment:function(a,c){var d,e,f=c.caption;return wp.media.view.settings.captions||delete c.caption,a=wp.media.string.props(a,c),d={id:c.id,post_content:c.description,post_excerpt:f},a.linkUrl&&(d.url=a.linkUrl),"image"===c.type?(e=wp.media.string.image(a),b.each({align:"align",size:"image-size",alt:"image_alt"},function(b,c){a[c]&&(d[b]=a[c])})):"video"===c.type?e=wp.media.string.video(a,c):"audio"===c.type?e=wp.media.string.audio(a,c):(e=wp.media.string.link(a),d.post_title=a.title),wp.media.post("send-attachment-to-editor",{nonce:wp.media.view.settings.nonce.sendToEditor,attachment:d,html:e,post_id:wp.media.view.settings.post.id})},link:function(a){return wp.media.post("send-link-to-editor",{nonce:wp.media.view.settings.nonce.sendToEditor,src:a.linkUrl,title:a.title,html:wp.media.string.link(a),post_id:wp.media.view.settings.post.id})}},open:function(a,b){var c;return b=b||{},a=this.id(a),c=this.get(a),(!c||c.options&&b.state!==c.options.state)&&(c=this.add(a,b)),c.open()},init:function(){a(document.body).on("click",".insert-media",function(b){var c=a(b.currentTarget),d=c.data("editor"),e={frame:"post",state:"insert",title:wp.media.view.l10n.addMedia,multiple:!0};b.preventDefault(),c.blur(),c.hasClass("gallery")?(e.state="gallery",e.title=wp.media.view.l10n.createGalleryTitle):c.hasClass("playlist")?(e.state="playlist",e.title=wp.media.view.l10n.createPlaylistTitle):c.hasClass("video-playlist")&&(e.state="video-playlist",e.title=wp.media.view.l10n.createVideoPlaylistTitle),wp.media.editor.open(d,e)}),(new wp.media.view.EditorUploader).render()}},b.bindAll(wp.media.editor,"open"),a(wp.media.editor.init)}(jQuery,_); \ No newline at end of file diff --git a/wp-includes/js/media-views.js b/wp-includes/js/media-views.js index 1bfe15a305..e0d181c472 100644 --- a/wp-includes/js/media-views.js +++ b/wp-includes/js/media-views.js @@ -1193,41 +1193,16 @@ media.controller.MediaLibrary = media.controller.Library.extend({ defaults: _.defaults({ filterable: 'uploaded', - multiple: false, priority: 80, syncSelection: false, - displaySettings: true + displaySettings: false }, media.controller.Library.prototype.defaults ), initialize: function( options ) { - var library, comparator; - this.media = options.media; this.set( 'library', media.query({ type: options.type }) ); media.controller.Library.prototype.initialize.apply( this, arguments ); - - library = this.get('library'); - comparator = library.comparator; - - // Overload the library's comparator to push items that are not in - // the mirrored query to the front of the aggregate collection. - library.comparator = function( a, b ) { - var aInQuery = !! this.mirroring.get( a.cid ), - bInQuery = !! this.mirroring.get( b.cid ); - - if ( ! aInQuery && bInQuery ) { - return -1; - } else if ( aInQuery && ! bInQuery ) { - return 1; - } else { - return comparator.apply( this, arguments ); - } - }; - - // Add all items in the selection to the library, so any featured - // images that are not initially loaded still appear. - library.observe( this.get('selection') ); } }); @@ -2952,6 +2927,7 @@ this.on( 'toolbar:render:replace-video', this.renderReplaceToolbar, this ); this.on( 'toolbar:render:add-video-source', this.renderAddSourceToolbar, this ); this.on( 'toolbar:render:select-poster-image', this.renderSelectPosterImageToolbar, this ); + this.on( 'toolbar:render:add-track', this.renderAddTrackToolbar, this ); }, createStates: function() { @@ -2987,6 +2963,15 @@ toolbar: 'select-poster-image', media: this.media, menu: 'video-details' + } ), + + new media.controller.MediaLibrary( { + type: 'text', + id: 'add-track', + title: l10n.videoAddTrackTitle, + toolbar: 'add-track', + media: this.media, + menu: 'video-details' } ) ]); }, @@ -3010,6 +2995,43 @@ state.trigger( 'set-poster-image', controller.media.toJSON() ); + // Restore and reset the default state. + controller.setState( controller.options.state ); + controller.reset(); + } + } + } + }) ); + }, + + renderAddTrackToolbar: function() { + this.toolbar.set( new media.view.Toolbar({ + controller: this, + items: { + replace: { + style: 'primary', + text: l10n.videoAddTrackTitle, + priority: 80, + + click: function() { + var controller = this.controller, + state = controller.state(), + selection = state.get( 'selection' ), + attachment = selection.single(), + content = controller.media.get( 'content' ); + + if ( -1 === content.indexOf( attachment.get( 'url' ) ) ) { + content += [ + '' + ].join(''); + + controller.media.set( 'content', content ); + } + + state.trigger( 'add-track', controller.media.toJSON() ); + // Restore and reset the default state. controller.setState( controller.options.state ); controller.reset(); @@ -6366,21 +6388,17 @@ this.on( 'media:setting:remove', this.render ); this.on( 'media:setting:remove', this.setPlayer ); this.events = _.extend( this.events, { - 'click .remove-setting' : 'removeSetting' + 'click .remove-setting' : 'removeSetting', + 'change .content-track' : 'setTracks', + 'click .remove-track' : 'setTracks' } ); media.view.Settings.AttachmentDisplay.prototype.initialize.apply( this, arguments ); }, prepare: function() { - var attachment = false; - - if ( this.model.attachment ) { - attachment = this.model.attachment.toJSON(); - } return _.defaults({ - model: this.model.toJSON(), - attachment: attachment + model: this.model.toJSON() }, this.options ); }, @@ -6404,12 +6422,26 @@ }, removeSetting : function (e) { - var setting = $( e.currentTarget ).parent(); + var wrap = $( e.currentTarget ).parent(), setting; - this.model.unset( setting.find( 'input' ).data( 'setting' ) ); + setting = wrap.find( 'input' ).data( 'setting' ); - setting.remove(); + if ( setting ) { + this.model.unset( setting ); + this.trigger( 'media:setting:remove', this ); + } + wrap.remove(); + }, + + setTracks : function () { + var tracks = ''; + + _.each( this.$('.content-track'), function (track) { + tracks += $( track ).val(); + } ); + + this.model.set( 'content', tracks ); this.trigger( 'media:setting:remove', this ); }, diff --git a/wp-includes/js/media-views.min.js b/wp-includes/js/media-views.min.js index 8eada71d76..45e787fdf9 100644 --- a/wp-includes/js/media-views.min.js +++ b/wp-includes/js/media-views.min.js @@ -1,3 +1,3 @@ -!function(a,b){var c,d=wp.media;c=d.view.l10n="undefined"==typeof _wpMediaViewsL10n?{}:_wpMediaViewsL10n,d.view.settings=c.settings||{},delete c.settings,d.model.settings.post=d.view.settings.post,a.support.transition=function(){var a,c=document.documentElement.style,d={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};return a=b.find(b.keys(d),function(a){return!b.isUndefined(c[a])}),a&&{end:d[a]}}(),d.transition=function(c,d){var e=a.Deferred();return d=d||2e3,a.support.transition?(c instanceof a||(c=a(c)),c.first().one(a.support.transition.end,e.resolve),b.delay(e.resolve,d)):e.resolve(),e.promise()},d.controller.Region=function(a){b.extend(this,b.pick(a||{},"id","view","selector"))},d.controller.Region.extend=Backbone.Model.extend,b.extend(d.controller.Region.prototype,{mode:function(a){return a?a===this._mode?this:(this.trigger("deactivate"),this._mode=a,this.render(a),this.trigger("activate"),this):this._mode},render:function(a){if(a&&a!==this._mode)return this.mode(a);var b,c={view:null};return this.trigger("create",c),b=c.view,this.trigger("render",b),b&&this.set(b),this},get:function(){return this.view.views.first(this.selector)},set:function(a,b){return b&&(b.add=!1),this.view.views.set(this.selector,a,b)},trigger:function(a){var c,d;if(this._mode)return d=b.toArray(arguments),c=this.id+":"+a,d[0]=c+":"+this._mode,this.view.trigger.apply(this.view,d),d[0]=c,this.view.trigger.apply(this.view,d),this}}),d.controller.StateMachine=function(a){this.states=new Backbone.Collection(a)},d.controller.StateMachine.extend=Backbone.Model.extend,b.extend(d.controller.StateMachine.prototype,Backbone.Events,{state:function(a){return this.states=this.states||new Backbone.Collection,a=a||this._state,a&&!this.states.get(a)&&this.states.add({id:a}),this.states.get(a)},setState:function(a){var b=this.state();return b&&a===b.id||!this.states||!this.states.get(a)?this:(b&&(b.trigger("deactivate"),this._lastState=b.id),this._state=a,this.state().trigger("activate"),this)},lastState:function(){return this._lastState?this.state(this._lastState):void 0}}),b.each(["on","off","trigger"],function(a){d.controller.StateMachine.prototype[a]=function(){return this.states=this.states||new Backbone.Collection,this.states[a].apply(this.states,arguments),this}}),d.controller.State=Backbone.Model.extend({constructor:function(){this.on("activate",this._preActivate,this),this.on("activate",this.activate,this),this.on("activate",this._postActivate,this),this.on("deactivate",this._deactivate,this),this.on("deactivate",this.deactivate,this),this.on("reset",this.reset,this),this.on("ready",this._ready,this),this.on("ready",this.ready,this),Backbone.Model.apply(this,arguments),this.on("change:menu",this._updateMenu,this)},ready:function(){},activate:function(){},deactivate:function(){},reset:function(){},_ready:function(){this._updateMenu()},_preActivate:function(){this.active=!0},_postActivate:function(){this.on("change:menu",this._menu,this),this.on("change:titleMode",this._title,this),this.on("change:content",this._content,this),this.on("change:toolbar",this._toolbar,this),this.frame.on("title:render:default",this._renderTitle,this),this._title(),this._menu(),this._toolbar(),this._content(),this._router()},_deactivate:function(){this.active=!1,this.frame.off("title:render:default",this._renderTitle,this),this.off("change:menu",this._menu,this),this.off("change:titleMode",this._title,this),this.off("change:content",this._content,this),this.off("change:toolbar",this._toolbar,this)},_title:function(){this.frame.title.render(this.get("titleMode")||"default")},_renderTitle:function(a){a.$el.text(this.get("title")||"")},_router:function(){var a,b=this.frame.router,c=this.get("router");this.frame.$el.toggleClass("hide-router",!c),c&&(this.frame.router.render(c),a=b.get(),a&&a.select&&a.select(this.frame.content.mode()))},_menu:function(){var a,b=this.frame.menu,c=this.get("menu");c&&(b.mode(c),a=b.get(),a&&a.select&&a.select(this.id))},_updateMenu:function(){var a=this.previous("menu"),b=this.get("menu");a&&this.frame.off("menu:render:"+a,this._renderMenu,this),b&&this.frame.on("menu:render:"+b,this._renderMenu,this)},_renderMenu:function(a){var b=this.get("menuItem"),c=this.get("title"),d=this.get("priority");!b&&c&&(b={text:c},d&&(b.priority=d)),b&&a.set(this.id,b)}}),b.each(["toolbar","content"],function(a){d.controller.State.prototype["_"+a]=function(){var b=this.get(a);b&&this.frame[a].render(b)}}),d.selectionSync={syncSelection:function(){var a=this.get("selection"),c=this.frame._selection;this.get("syncSelection")&&c&&a&&(a.multiple&&(a.reset([],{silent:!0}),a.validateAll(c.attachments),c.difference=b.difference(c.attachments.models,a.models)),a.single(c.single))},recordSelection:function(){var a=this.get("selection"),b=this.frame._selection;this.get("syncSelection")&&b&&a&&(a.multiple?(b.attachments.reset(a.toArray().concat(b.difference)),b.difference=[]):b.attachments.add(a.toArray()),b.single=a._single)}},d.controller.Library=d.controller.State.extend({defaults:{id:"library",multiple:!1,describe:!1,toolbar:"select",sidebar:"settings",content:"upload",router:"browse",menu:"default",searchable:!0,filterable:!1,sortable:!0,title:c.mediaLibraryTitle,contentUserSetting:!0,syncSelection:!0},initialize:function(){var a,c=this.get("selection");this.get("library")||this.set("library",d.query()),c instanceof d.model.Selection||(a=c,a||(a=this.get("library").props.toJSON(),a=b.omit(a,"orderby","query")),this.set("selection",new d.model.Selection(null,{multiple:this.get("multiple"),props:a}))),this.get("edge")||this.set("edge",120),this.get("gutter")||this.set("gutter",8),this.resetDisplays()},activate:function(){this.syncSelection(),wp.Uploader.queue.on("add",this.uploading,this),this.get("selection").on("add remove reset",this.refreshContent,this),this.get("contentUserSetting")&&(this.frame.on("content:activate",this.saveContentMode,this),this.set("content",getUserSetting("libraryContent",this.get("content"))))},deactivate:function(){this.recordSelection(),this.frame.off("content:activate",this.saveContentMode,this),this.get("selection").off(null,null,this),wp.Uploader.queue.off(null,null,this)},reset:function(){this.get("selection").reset(),this.resetDisplays(),this.refreshContent()},resetDisplays:function(){var a=d.view.settings.defaultProps;this._displays=[],this._defaultDisplaySettings={align:a.align||getUserSetting("align","none"),size:a.size||getUserSetting("imgsize","medium"),link:a.link||getUserSetting("urlbutton","file")}},display:function(a){var b=this._displays;return b[a.cid]||(b[a.cid]=new Backbone.Model(this.defaultDisplaySettings(a))),b[a.cid]},defaultDisplaySettings:function(a){var b=this._defaultDisplaySettings;return(b.canEmbed=this.canEmbed(a))&&(b.link="embed"),b},canEmbed:function(a){if(!a.get("uploading")){var c=a.get("type");if("audio"!==c&&"video"!==c)return!1}return b.contains(d.view.settings.embedExts,a.get("filename").split(".").pop())},refreshContent:function(){var a=this.get("selection"),b=this.frame,c=b.router.get(),d=b.content.mode();this.active&&!a.length&&c&&!c.get(d)&&this.frame.content.render(this.get("content"))},uploading:function(a){var b=this.frame.content;"upload"===b.mode()&&this.frame.content.mode("browse"),this.get("selection").add(a)},saveContentMode:function(){if("browse"===this.get("router")){var a=this.frame.content.mode(),b=this.frame.router.get();b&&b.get(a)&&setUserSetting("libraryContent",a)}}}),b.extend(d.controller.Library.prototype,d.selectionSync),d.controller.ImageDetails=d.controller.State.extend({defaults:b.defaults({id:"image-details",toolbar:"image-details",title:c.imageDetailsTitle,content:"image-details",menu:"image-details",router:!1,attachment:!1,priority:60,editing:!1},d.controller.Library.prototype.defaults),initialize:function(a){this.image=a.image,d.controller.State.prototype.initialize.apply(this,arguments)}}),d.controller.AudioDetails=d.controller.State.extend({defaults:b.defaults({id:"audio-details",toolbar:"audio-details",title:c.audioDetailsTitle,content:"audio-details",menu:"audio-details",router:!1,attachment:!1,priority:60,editing:!1},d.controller.Library.prototype.defaults),initialize:function(a){this.media=a.media,d.controller.State.prototype.initialize.apply(this,arguments)}}),d.controller.VideoDetails=d.controller.State.extend({defaults:b.defaults({id:"video-details",toolbar:"video-details",title:c.videoDetailsTitle,content:"video-details",menu:"video-details",router:!1,attachment:!1,priority:60,editing:!1},d.controller.Library.prototype.defaults),initialize:function(a){this.media=a.media,d.controller.State.prototype.initialize.apply(this,arguments)}}),d.controller.CollectionEdit=d.controller.Library.extend({defaults:{multiple:!1,describe:!0,edge:199,editing:!1,sortable:!0,searchable:!1,content:"browse",priority:60,dragInfo:!0,SettingsView:!1,syncSelection:!1},initialize:function(){var a=this.get("collectionType");this.set("id",a+"-edit"),this.set("toolbar",a+"-edit"),this.get("library")||this.set("library",new d.model.Selection),this.get("AttachmentView")||this.set("AttachmentView",d.view.Attachment.EditLibrary),d.controller.Library.prototype.initialize.apply(this,arguments)},activate:function(){var a=this.get("library");a.props.set("type",this.get("type")),this.get("library").observe(wp.Uploader.queue),this.frame.on("content:render:browse",this.renderSettings,this),d.controller.Library.prototype.activate.apply(this,arguments)},deactivate:function(){this.get("library").unobserve(wp.Uploader.queue),this.frame.off("content:render:browse",this.renderSettings,this),d.controller.Library.prototype.deactivate.apply(this,arguments)},renderSettings:function(b){var e=this.get("library"),f=this.get("collectionType"),g=this.get("dragInfoText"),h=this.get("SettingsView"),i={};e&&b&&(e[f]=e[f]||new Backbone.Model,i[f]=new h({controller:this,model:e[f],priority:40}),b.sidebar.set(i),g&&b.toolbar.set("dragInfo",new d.View({el:a('
'+g+"
")[0],priority:-40})),b.toolbar.set("reverse",{text:c.reverseOrder,priority:80,click:function(){e.reset(e.toArray().reverse())}}))}}),d.controller.CollectionAdd=d.controller.Library.extend({defaults:b.defaults({filterable:"uploaded",multiple:"add",priority:100,syncSelection:!1},d.controller.Library.prototype.defaults),initialize:function(){var a=this.get("collectionType");this.set("id",a+"-library"),this.set("toolbar",a+"-add"),this.set("menu",a),this.get("library")||this.set("library",d.query({type:this.get("type")})),d.controller.Library.prototype.initialize.apply(this,arguments)},activate:function(){var a=this.get("library"),b=this.get("editLibrary"),c=this.frame.state(this.get("collectionType")+"-edit").get("library");b&&b!==c&&a.unobserve(b),a.validator=function(a){return!!this.mirroring.get(a.cid)&&!c.get(a.cid)&&d.model.Selection.prototype.validator.apply(this,arguments)},a.reset(a.mirroring.models,{silent:!0}),a.observe(c),this.set("editLibrary",c),d.controller.Library.prototype.activate.apply(this,arguments)}}),d.controller.FeaturedImage=d.controller.Library.extend({defaults:b.defaults({id:"featured-image",filterable:"uploaded",multiple:!1,toolbar:"featured-image",title:c.setFeaturedImageTitle,priority:60,syncSelection:!0},d.controller.Library.prototype.defaults),initialize:function(){var a,b;this.get("library")||this.set("library",d.query({type:"image"})),d.controller.Library.prototype.initialize.apply(this,arguments),a=this.get("library"),b=a.comparator,a.comparator=function(a,c){var d=!!this.mirroring.get(a.cid),e=!!this.mirroring.get(c.cid);return!d&&e?-1:d&&!e?1:b.apply(this,arguments)},a.observe(this.get("selection"))},activate:function(){this.updateSelection(),this.frame.on("open",this.updateSelection,this),d.controller.Library.prototype.activate.apply(this,arguments)},deactivate:function(){this.frame.off("open",this.updateSelection,this),d.controller.Library.prototype.deactivate.apply(this,arguments)},updateSelection:function(){var a,b=this.get("selection"),c=d.view.settings.post.featuredImageId;""!==c&&-1!==c&&(a=d.model.Attachment.get(c),a.fetch()),b.reset(a?[a]:[])}}),d.controller.ReplaceImage=d.controller.Library.extend({defaults:b.defaults({id:"replace-image",filterable:"uploaded",multiple:!1,toolbar:"replace",title:c.replaceImageTitle,priority:60,syncSelection:!0},d.controller.Library.prototype.defaults),initialize:function(a){var b,c;this.image=a.image,this.get("library")||this.set("library",d.query({type:"image"})),d.controller.Library.prototype.initialize.apply(this,arguments),b=this.get("library"),c=b.comparator,b.comparator=function(a,b){var d=!!this.mirroring.get(a.cid),e=!!this.mirroring.get(b.cid);return!d&&e?-1:d&&!e?1:c.apply(this,arguments)},b.observe(this.get("selection"))},activate:function(){this.updateSelection(),d.controller.Library.prototype.activate.apply(this,arguments)},updateSelection:function(){var a=this.get("selection"),b=this.image.attachment;a.reset(b?[b]:[])}}),d.controller.EditImage=d.controller.State.extend({defaults:{id:"edit-image",url:"",menu:!1,toolbar:"edit-image",title:c.editImage,content:"edit-image",syncSelection:!0},activate:function(){this.get("selection")||this.set("selection",new d.model.Selection),this.listenTo(this.frame,"toolbar:render:edit-image",this.toolbar),this.syncSelection()},deactivate:function(){this.stopListening(this.frame)},toolbar:function(){var a=this.frame,b=a.lastState(),e=b&&b.id;a.toolbar.set(new d.view.Toolbar({controller:a,items:{back:{style:"primary",text:c.back,priority:20,click:function(){e?a.setState(e):a.close()}}}}))}}),b.extend(d.controller.EditImage.prototype,d.selectionSync),d.controller.MediaLibrary=d.controller.Library.extend({defaults:b.defaults({filterable:"uploaded",multiple:!1,priority:80,syncSelection:!1,displaySettings:!0},d.controller.Library.prototype.defaults),initialize:function(a){var b,c;this.media=a.media,this.set("library",d.query({type:a.type})),d.controller.Library.prototype.initialize.apply(this,arguments),b=this.get("library"),c=b.comparator,b.comparator=function(a,b){var d=!!this.mirroring.get(a.cid),e=!!this.mirroring.get(b.cid);return!d&&e?-1:d&&!e?1:c.apply(this,arguments)},b.observe(this.get("selection"))}}),d.controller.Embed=d.controller.State.extend({defaults:{id:"embed",url:"",menu:"default",content:"embed",toolbar:"main-embed",type:"link",title:c.insertFromUrlTitle,priority:120},sensitivity:200,initialize:function(){this.debouncedScan=b.debounce(b.bind(this.scan,this),this.sensitivity),this.props=new Backbone.Model({url:""}),this.props.on("change:url",this.debouncedScan,this),this.props.on("change:url",this.refresh,this),this.on("scan",this.scanImage,this)},scan:function(){var b,c=this,d={type:"link",scanners:[]};this.props.get("url")&&this.trigger("scan",d),d.scanners.length?(b=d.scanners=a.when.apply(a,d.scanners),b.always(function(){c.get("scanners")===b&&c.set("loading",!1)})):d.scanners=null,d.loading=!!d.scanners,this.set(d)},scanImage:function(b){var c=this.frame,d=this,e=this.props.get("url"),f=new Image,g=a.Deferred();b.scanners.push(g.promise()),f.onload=function(){g.resolve(),d===c.state()&&e===d.props.get("url")&&(d.set({type:"image"}),d.props.set({width:f.width,height:f.height}))},f.onerror=g.reject,f.src=e},refresh:function(){this.frame.toolbar.get().refresh()},reset:function(){this.props.clear().set({url:""}),this.active&&this.refresh()}}),d.View=wp.Backbone.View.extend({constructor:function(a){a&&a.controller&&(this.controller=a.controller),wp.Backbone.View.apply(this,arguments)},dispose:function(){return this.undelegateEvents(),this.model&&this.model.off&&this.model.off(null,null,this),this.collection&&this.collection.off&&this.collection.off(null,null,this),this.controller&&this.controller.off&&this.controller.off(null,null,this),this},remove:function(){return this.dispose(),wp.Backbone.View.prototype.remove.apply(this,arguments)}}),d.view.Frame=d.View.extend({initialize:function(){this._createRegions(),this._createStates()},_createRegions:function(){this.regions=this.regions?this.regions.slice():[],b.each(this.regions,function(a){this[a]=new d.controller.Region({view:this,id:a,selector:".media-frame-"+a})},this)},_createStates:function(){this.states=new Backbone.Collection(null,{model:d.controller.State}),this.states.on("add",function(a){a.frame=this,a.trigger("ready")},this),this.options.states&&this.states.add(this.options.states)},reset:function(){return this.states.invoke("trigger","reset"),this}}),b.extend(d.view.Frame.prototype,d.controller.StateMachine.prototype),d.view.MediaFrame=d.view.Frame.extend({className:"media-frame",template:d.template("media-frame"),regions:["menu","title","content","toolbar","router"],initialize:function(){d.view.Frame.prototype.initialize.apply(this,arguments),b.defaults(this.options,{title:"",modal:!0,uploader:!0}),this.$el.addClass("wp-core-ui"),this.options.modal&&(this.modal=new d.view.Modal({controller:this,title:this.options.title}),this.modal.content(this)),(wp.Uploader.limitExceeded||!wp.Uploader.browser.supported)&&(this.options.uploader=!1),this.options.uploader&&(this.uploader=new d.view.UploaderWindow({controller:this,uploader:{dropzone:this.modal?this.modal.$el:this.$el,container:this.$el}}),this.views.set(".media-frame-uploader",this.uploader)),this.on("attach",b.bind(this.views.ready,this.views),this),this.on("title:create:default",this.createTitle,this),this.title.mode("default"),this.on("menu:create:default",this.createMenu,this)},render:function(){return!this.state()&&this.options.state&&this.setState(this.options.state),d.view.Frame.prototype.render.apply(this,arguments)},createTitle:function(a){a.view=new d.View({controller:this,tagName:"h1"})},createMenu:function(a){a.view=new d.view.Menu({controller:this})},createToolbar:function(a){a.view=new d.view.Toolbar({controller:this})},createRouter:function(a){a.view=new d.view.Router({controller:this})},createIframeStates:function(c){var e,f=d.view.settings,g=f.tabs,h=f.tabUrl;g&&h&&(e=a("#post_ID"),e.length&&(h+="&post_id="+e.val()),b.each(g,function(a,d){this.state("iframe:"+d).set(b.defaults({tab:d,src:h+"&tab="+d,title:a,content:"iframe",menu:"default"},c))},this),this.on("content:create:iframe",this.iframeContent,this),this.on("menu:render:default",this.iframeMenu,this),this.on("open",this.hijackThickbox,this),this.on("close",this.restoreThickbox,this))},iframeContent:function(a){this.$el.addClass("hide-toolbar"),a.view=new d.view.Iframe({controller:this})},iframeMenu:function(a){var c={};a&&(b.each(d.view.settings.tabs,function(a,b){c["iframe:"+b]={text:this.state("iframe:"+b).get("title"),priority:200}},this),a.set(c))},hijackThickbox:function(){var a=this;window.tb_remove&&!this._tb_remove&&(this._tb_remove=window.tb_remove,window.tb_remove=function(){a.close(),a.reset(),a.setState(a.options.state),a._tb_remove.call(window)})},restoreThickbox:function(){this._tb_remove&&(window.tb_remove=this._tb_remove,delete this._tb_remove)}}),b.each(["open","close","attach","detach","escape"],function(a){d.view.MediaFrame.prototype[a]=function(){return this.modal&&this.modal[a].apply(this.modal,arguments),this}}),d.view.MediaFrame.Select=d.view.MediaFrame.extend({initialize:function(){d.view.MediaFrame.prototype.initialize.apply(this,arguments),b.defaults(this.options,{selection:[],library:{},multiple:!1,state:"library"}),this.createSelection(),this.createStates(),this.bindHandlers()},createSelection:function(){var a=this.options.selection;a instanceof d.model.Selection||(this.options.selection=new d.model.Selection(a,{multiple:this.options.multiple})),this._selection={attachments:new d.model.Attachments,difference:[]}},createStates:function(){var a=this.options;this.options.states||this.states.add([new d.controller.Library({library:d.query(a.library),multiple:a.multiple,title:a.title,priority:20})])},bindHandlers:function(){this.on("router:create:browse",this.createRouter,this),this.on("router:render:browse",this.browseRouter,this),this.on("content:create:browse",this.browseContent,this),this.on("content:render:upload",this.uploadContent,this),this.on("toolbar:create:select",this.createSelectToolbar,this)},browseRouter:function(a){a.set({upload:{text:c.uploadFilesTitle,priority:20},browse:{text:c.mediaLibraryTitle,priority:40}})},browseContent:function(a){var b=this.state();this.$el.removeClass("hide-toolbar"),a.view=new d.view.AttachmentsBrowser({controller:this,collection:b.get("library"),selection:b.get("selection"),model:b,sortable:b.get("sortable"),search:b.get("searchable"),filters:b.get("filterable"),display:b.get("displaySettings"),dragInfo:b.get("dragInfo"),AttachmentView:b.get("AttachmentView")})},uploadContent:function(){this.$el.removeClass("hide-toolbar"),this.content.set(new d.view.UploaderInline({controller:this}))},createSelectToolbar:function(a,b){b=b||this.options.button||{},b.controller=this,a.view=new d.view.Toolbar.Select(b)}}),d.view.MediaFrame.Post=d.view.MediaFrame.Select.extend({initialize:function(){b.defaults(this.options,{multiple:!0,editing:!1,state:"insert"}),d.view.MediaFrame.Select.prototype.initialize.apply(this,arguments),this.createIframeStates()},createStates:function(){var a=this.options;this.states.add([new d.controller.Library({id:"insert",title:c.insertMediaTitle,priority:20,toolbar:"main-insert",filterable:"all",library:d.query(a.library),multiple:a.multiple?"reset":!1,editable:!0,allowLocalEdits:!0,displaySettings:!0,displayUserSettings:!0}),new d.controller.Library({id:"gallery",title:c.createGalleryTitle,priority:40,toolbar:"main-gallery",filterable:"uploaded",multiple:"add",editable:!1,library:d.query(b.defaults({type:"image"},a.library))}),new d.controller.Embed,new d.controller.EditImage({selection:a.selection}),new d.controller.CollectionEdit({type:"image",collectionType:"gallery",title:c.editGalleryTitle,SettingsView:d.view.Settings.Gallery,library:a.selection,editing:a.editing,menu:"gallery"}),new d.controller.CollectionAdd({type:"image",collectionType:"gallery",title:c.addToGalleryTitle}),new d.controller.Library({id:"playlist",title:c.createPlaylistTitle,priority:60,toolbar:"main-playlist",filterable:"uploaded",multiple:"add",editable:!1,library:d.query(b.defaults({type:"audio"},a.library))}),new d.controller.CollectionEdit({type:"audio",collectionType:"playlist",title:c.editPlaylistTitle,SettingsView:d.view.Settings.Playlist,library:a.selection,editing:a.editing,menu:"playlist",dragInfoText:c.playlistDragInfo,dragInfo:!1}),new d.controller.CollectionAdd({type:"audio",collectionType:"playlist",title:c.addToPlaylistTitle}),new d.controller.Library({id:"video-playlist",title:c.createVideoPlaylistTitle,priority:60,toolbar:"main-video-playlist",filterable:"uploaded",multiple:"add",editable:!1,library:d.query(b.defaults({type:"video"},a.library))}),new d.controller.CollectionEdit({type:"video",collectionType:"video-playlist",title:c.editVideoPlaylistTitle,SettingsView:d.view.Settings.Playlist,library:a.selection,editing:a.editing,menu:"video-playlist",dragInfoText:c.videoPlaylistDragInfo,dragInfo:!1}),new d.controller.CollectionAdd({type:"video",collectionType:"video-playlist",title:c.addToVideoPlaylistTitle})]),d.view.settings.post.featuredImageId&&this.states.add(new d.controller.FeaturedImage)},bindHandlers:function(){d.view.MediaFrame.Select.prototype.bindHandlers.apply(this,arguments),this.on("menu:create:gallery",this.createMenu,this),this.on("menu:create:playlist",this.createMenu,this),this.on("menu:create:video-playlist",this.createMenu,this),this.on("toolbar:create:main-insert",this.createToolbar,this),this.on("toolbar:create:main-gallery",this.createToolbar,this),this.on("toolbar:create:main-playlist",this.createToolbar,this),this.on("toolbar:create:main-video-playlist",this.createToolbar,this),this.on("toolbar:create:featured-image",this.featuredImageToolbar,this),this.on("toolbar:create:main-embed",this.mainEmbedToolbar,this);var a={menu:{"default":"mainMenu",gallery:"galleryMenu",playlist:"playlistMenu","video-playlist":"videoPlaylistMenu"},content:{embed:"embedContent","edit-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"}};b.each(a,function(a,c){b.each(a,function(a,b){this.on(c+":render:"+b,this[a],this)},this)},this)},mainMenu:function(a){a.set({"library-separator":new d.View({className:"separator",priority:100})})},galleryMenu:function(a){var b=this.lastState(),e=b&&b.id,f=this;a.set({cancel:{text:c.cancelGalleryTitle,priority:20,click:function(){e?f.setState(e):f.close()}},separateCancel:new d.View({className:"separator",priority:40})})},playlistMenu:function(a){var b=this.lastState(),e=b&&b.id,f=this;a.set({cancel:{text:c.cancelPlaylistTitle,priority:20,click:function(){e?f.setState(e):f.close()}},separateCancel:new d.View({className:"separator",priority:40})})},videoPlaylistMenu:function(a){var b=this.lastState(),e=b&&b.id,f=this;a.set({cancel:{text:c.cancelVideoPlaylistTitle,priority:20,click:function(){e?f.setState(e):f.close()}},separateCancel:new d.View({className:"separator",priority:40})})},embedContent:function(){var a=new d.view.Embed({controller:this,model:this.state()}).render();this.content.set(a),a.url.focus()},editSelectionContent:function(){var a,b=this.state(),e=b.get("selection");a=new d.view.AttachmentsBrowser({controller:this,collection:e,selection:e,model:b,sortable:!0,search:!1,dragInfo:!0,AttachmentView:d.view.Attachment.EditSelection}).render(),a.toolbar.set("backToLibrary",{text:c.returnToLibrary,priority:-100,click:function(){this.controller.content.mode("browse")}}),this.content.set(a)},editImageContent:function(){var a=this.state().get("selection"),b=new d.view.EditImage({model:a.single(),controller:this}).render();this.content.set(b),b.loadEditor()},selectionStatusToolbar:function(a){var b=this.state().get("editable");a.set("selection",new d.view.Selection({controller:this,collection:this.state().get("selection"),priority:-40,editable:b&&function(){this.controller.content.mode("edit-selection")}}).render())},mainInsertToolbar:function(a){var b=this;this.selectionStatusToolbar(a),a.set("insert",{style:"primary",priority:80,text:c.insertIntoPost,requires:{selection:!0},click:function(){var a=b.state(),c=a.get("selection");b.close(),a.trigger("insert",c).reset()}})},mainGalleryToolbar:function(a){var b=this;this.selectionStatusToolbar(a),a.set("gallery",{style:"primary",text:c.createNewGallery,priority:60,requires:{selection:!0},click:function(){var a=b.state().get("selection"),c=b.state("gallery-edit"),e=a.where({type:"image"});c.set("library",new d.model.Selection(e,{props:a.props.toJSON(),multiple:!0})),this.controller.setState("gallery-edit")}})},mainPlaylistToolbar:function(a){var b=this;this.selectionStatusToolbar(a),a.set("playlist",{style:"primary",text:c.createNewPlaylist,priority:100,requires:{selection:!0},click:function(){var a=b.state().get("selection"),c=b.state("playlist-edit"),e=a.where({type:"audio"});c.set("library",new d.model.Selection(e,{props:a.props.toJSON(),multiple:!0})),this.controller.setState("playlist-edit")}})},mainVideoPlaylistToolbar:function(a){var b=this;this.selectionStatusToolbar(a),a.set("video-playlist",{style:"primary",text:c.createNewVideoPlaylist,priority:100,requires:{selection:!0},click:function(){var a=b.state().get("selection"),c=b.state("video-playlist-edit"),e=a.where({type:"video"});c.set("library",new d.model.Selection(e,{props:a.props.toJSON(),multiple:!0})),this.controller.setState("video-playlist-edit")}})},featuredImageToolbar:function(a){this.createSelectToolbar(a,{text:c.setFeaturedImage,state:this.options.state})},mainEmbedToolbar:function(a){a.view=new d.view.Toolbar.Embed({controller:this})},galleryEditToolbar:function(){var a=this.state().get("editing");this.toolbar.set(new d.view.Toolbar({controller:this,items:{insert:{style:"primary",text:a?c.updateGallery:c.insertGallery,priority:80,requires:{library:!0},click:function(){var a=this.controller,b=a.state();a.close(),b.trigger("update",b.get("library")),a.setState(a.options.state),a.reset()}}}}))},galleryAddToolbar:function(){this.toolbar.set(new d.view.Toolbar({controller:this,items:{insert:{style:"primary",text:c.addToGallery,priority:80,requires:{selection:!0},click:function(){var a=this.controller,b=a.state(),c=a.state("gallery-edit");c.get("library").add(b.get("selection").models),b.trigger("reset"),a.setState("gallery-edit")}}}}))},playlistEditToolbar:function(){var a=this.state().get("editing");this.toolbar.set(new d.view.Toolbar({controller:this,items:{insert:{style:"primary",text:a?c.updatePlaylist:c.insertPlaylist,priority:80,requires:{library:!0},click:function(){var a=this.controller,b=a.state();a.close(),b.trigger("update",b.get("library")),a.setState(a.options.state),a.reset()}}}}))},playlistAddToolbar:function(){this.toolbar.set(new d.view.Toolbar({controller:this,items:{insert:{style:"primary",text:c.addToPlaylist,priority:80,requires:{selection:!0},click:function(){var a=this.controller,b=a.state(),c=a.state("playlist-edit");c.get("library").add(b.get("selection").models),b.trigger("reset"),a.setState("playlist-edit")}}}}))},videoPlaylistEditToolbar:function(){var a=this.state().get("editing");this.toolbar.set(new d.view.Toolbar({controller:this,items:{insert:{style:"primary",text:a?c.updateVideoPlaylist:c.insertVideoPlaylist,priority:140,requires:{library:!0},click:function(){var a=this.controller,b=a.state();a.close(),b.trigger("update",b.get("library")),a.setState(a.options.state),a.reset()}}}}))},videoPlaylistAddToolbar:function(){this.toolbar.set(new d.view.Toolbar({controller:this,items:{insert:{style:"primary",text:c.addToVideoPlaylist,priority:140,requires:{selection:!0},click:function(){var a=this.controller,b=a.state(),c=a.state("video-playlist-edit");c.get("library").add(b.get("selection").models),b.trigger("reset"),a.setState("video-playlist-edit")}}}}))}}),d.view.MediaFrame.ImageDetails=d.view.MediaFrame.Select.extend({defaults:{id:"image",url:"",menu:"image-details",content:"image-details",toolbar:"image-details",type:"link",title:c.imageDetailsTitle,priority:120},initialize:function(a){this.image=new d.model.PostImage(a.metadata),this.options.selection=new d.model.Selection(this.image.attachment,{multiple:!1}),d.view.MediaFrame.Select.prototype.initialize.apply(this,arguments)},bindHandlers:function(){d.view.MediaFrame.Select.prototype.bindHandlers.apply(this,arguments),this.on("menu:create:image-details",this.createMenu,this),this.on("content:render:image-details",this.renderImageDetailsContent,this),this.on("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 d.controller.ImageDetails({image:this.image,editable:!1,menu:"image-details"}),new d.controller.ReplaceImage({id:"replace-image",library:d.query({type:"image"}),image:this.image,multiple:!1,title:c.imageReplaceTitle,menu:"image-details",toolbar:"replace",priority:80,displaySettings:!0}),new d.controller.EditImage({image:this.image,selection:this.options.selection})])},renderImageDetailsContent:function(){var a=new d.view.ImageDetails({controller:this,model:this.state().image,attachment:this.state().image.attachment}).render();this.content.set(a)},editImageContent:function(){var a,b,c=this.state(),e=c.get("image").attachment;e&&(a=c.get("selection").single(),a||(a=e),b=new d.view.EditImage({model:a,controller:this}).render(),this.content.set(b),b.loadEditor()) -},renderMenu:function(a){var b=this.lastState(),e=b&&b.id,f=this;a.set({cancel:{text:c.imageDetailsCancel,priority:20,click:function(){e?f.setState(e):f.close()}},separateCancel:new d.View({className:"separator",priority:40})})},renderImageDetailsToolbar:function(){this.toolbar.set(new d.view.Toolbar({controller:this,items:{select:{style:"primary",text:c.update,priority:80,click:function(){var a=this.controller,b=a.state();a.close(),b.trigger("update",a.image.toJSON()),a.setState(a.options.state),a.reset()}}}}))},renderReplaceImageToolbar:function(){this.toolbar.set(new d.view.Toolbar({controller:this,items:{replace:{style:"primary",text:c.replace,priority:80,click:function(){var a=this.controller,b=a.state(),c=b.get("selection"),d=c.single();a.close(),a.image.changeAttachment(d,b.display(d)),b.trigger("replace",a.image.toJSON()),a.setState(a.options.state),a.reset()}}}}))}}),d.view.MediaFrame.MediaDetails=d.view.MediaFrame.Select.extend({defaults:{id:"media",url:"",menu:"media-details",content:"media-details",toolbar:"media-details",type:"link",priority:120},initialize:function(a){this.DetailsView=a.DetailsView,this.cancelText=a.cancelText,this.addText=a.addText,this.media=new d.model.PostMedia(a.metadata),this.options.selection=new d.model.Selection(this.media.attachment,{multiple:!1}),d.view.MediaFrame.Select.prototype.initialize.apply(this,arguments)},bindHandlers:function(){var a=this.defaults.menu;d.view.MediaFrame.Select.prototype.bindHandlers.apply(this,arguments),this.on("menu:create:"+a,this.createMenu,this),this.on("content:render:"+a,this.renderDetailsContent,this),this.on("menu:render:"+a,this.renderMenu,this),this.on("toolbar:render:"+a,this.renderDetailsToolbar,this)},renderDetailsContent:function(){var a=new this.DetailsView({controller:this,model:this.state().media,attachment:this.state().media.attachment}).render();this.content.set(a)},renderMenu:function(a){var b=this.lastState(),c=b&&b.id,e=this;a.set({cancel:{text:this.cancelText,priority:20,click:function(){c?e.setState(c):e.close()}},separateCancel:new d.View({className:"separator",priority:40})})},renderDetailsToolbar:function(){this.toolbar.set(new d.view.Toolbar({controller:this,items:{select:{style:"primary",text:c.update,priority:80,click:function(){var a=this.controller,b=a.state();a.close(),b.trigger("update",a.media.toJSON()),a.setState(a.options.state),a.reset()}}}}))},renderReplaceToolbar:function(){this.toolbar.set(new d.view.Toolbar({controller:this,items:{replace:{style:"primary",text:c.replace,priority:80,click:function(){var a=this.controller,b=a.state(),c=b.get("selection"),d=c.single();a.media.changeAttachment(d),b.trigger("replace",a.media.toJSON()),a.setState(a.options.state),a.reset()}}}}))},renderAddSourceToolbar:function(){this.toolbar.set(new d.view.Toolbar({controller:this,items:{replace:{style:"primary",text:this.addText,priority:80,click:function(){var a=this.controller,b=a.state(),c=b.get("selection"),d=c.single();a.media.setSource(d),b.trigger("add-source",a.media.toJSON()),a.setState(a.options.state),a.reset()}}}}))}}),d.view.MediaFrame.AudioDetails=d.view.MediaFrame.MediaDetails.extend({defaults:{id:"audio",url:"",menu:"audio-details",content:"audio-details",toolbar:"audio-details",type:"link",title:c.audioDetailsTitle,priority:120},initialize:function(a){a.DetailsView=d.view.AudioDetails,a.cancelText=c.audioDetailsCancel,a.addText=c.audioAddSourceTitle,d.view.MediaFrame.MediaDetails.prototype.initialize.call(this,a)},bindHandlers:function(){d.view.MediaFrame.MediaDetails.prototype.bindHandlers.apply(this,arguments),this.on("toolbar:render:replace-audio",this.renderReplaceToolbar,this),this.on("toolbar:render:add-audio-source",this.renderAddSourceToolbar,this)},createStates:function(){this.states.add([new d.controller.AudioDetails({media:this.media,editable:!1,menu:"audio-details"}),new d.controller.MediaLibrary({type:"audio",id:"replace-audio",title:c.audioReplaceTitle,toolbar:"replace-audio",media:this.media,menu:"audio-details"}),new d.controller.MediaLibrary({type:"audio",id:"add-audio-source",title:c.audioAddSourceTitle,toolbar:"add-audio-source",media:this.media,menu:"audio-details"})])}}),d.view.MediaFrame.VideoDetails=d.view.MediaFrame.MediaDetails.extend({defaults:{id:"video",url:"",menu:"video-details",content:"video-details",toolbar:"video-details",type:"link",title:c.videoDetailsTitle,priority:120},initialize:function(a){a.DetailsView=d.view.VideoDetails,a.cancelText=c.videoDetailsCancel,a.addText=c.videoAddSourceTitle,d.view.MediaFrame.MediaDetails.prototype.initialize.call(this,a)},bindHandlers:function(){d.view.MediaFrame.MediaDetails.prototype.bindHandlers.apply(this,arguments),this.on("toolbar:render:replace-video",this.renderReplaceToolbar,this),this.on("toolbar:render:add-video-source",this.renderAddSourceToolbar,this),this.on("toolbar:render:select-poster-image",this.renderSelectPosterImageToolbar,this)},createStates:function(){this.states.add([new d.controller.VideoDetails({media:this.media,editable:!1,menu:"video-details"}),new d.controller.MediaLibrary({type:"video",id:"replace-video",title:c.videoReplaceTitle,toolbar:"replace-video",media:this.media,menu:"video-details"}),new d.controller.MediaLibrary({type:"video",id:"add-video-source",title:c.videoAddSourceTitle,toolbar:"add-video-source",media:this.media,menu:"video-details"}),new d.controller.MediaLibrary({type:"image",id:"select-poster-image",title:c.videoSelectPosterImageTitle,toolbar:"select-poster-image",media:this.media,menu:"video-details"})])},renderSelectPosterImageToolbar:function(){this.toolbar.set(new d.view.Toolbar({controller:this,items:{replace:{style:"primary",text:c.videoSelectPosterImageTitle,priority:80,click:function(){var a=this.controller,b=a.state(),c=b.get("selection"),d=c.single();a.media.set("poster",d.get("url")),b.trigger("set-poster-image",a.media.toJSON()),a.setState(a.options.state),a.reset()}}}}))}}),d.view.Modal=d.View.extend({tagName:"div",template:d.template("media-modal"),attributes:{tabindex:0},events:{"click .media-modal-backdrop, .media-modal-close":"escapeHandler",keydown:"keydown"},initialize:function(){b.defaults(this.options,{container:document.body,title:"",propagate:!0,freeze:!0})},prepare:function(){return{title:this.options.title}},attach:function(){return this.views.attached?this:(this.views.rendered||this.render(),this.$el.appendTo(this.options.container),this.views.attached=!0,this.views.ready(),this.propagate("attach"))},detach:function(){return this.$el.is(":visible")&&this.close(),this.$el.detach(),this.views.attached=!1,this.propagate("detach")},open:function(){var b=this.$el,c=this.options;return b.is(":visible")?this:(this.views.attached||this.attach(),c.freeze&&(this._freeze={scrollTop:a(window).scrollTop()}),b.show().focus(),this.propagate("open"))},close:function(b){var c=this._freeze;return this.views.attached&&this.$el.is(":visible")?(this.$el.hide(),this.propagate("close"),c&&a(window).scrollTop(c.scrollTop),b&&b.escape&&this.propagate("escape"),this):this},escape:function(){return this.close({escape:!0})},escapeHandler:function(a){a.preventDefault(),this.escape()},content:function(a){return this.views.set(".media-modal-content",a),this},propagate:function(a){return this.trigger(a),this.options.propagate&&this.controller.trigger(a),this},keydown:function(a){27===a.which&&this.$el.is(":visible")&&(this.escape(),a.stopImmediatePropagation())}}),d.view.FocusManager=d.View.extend({events:{keydown:"recordTab",focusin:"updateIndex"},focus:function(){b.isUndefined(this.index)||(this.$tabbables=this.$(":tabbable"),this.$tabbables.eq(this.index).focus())},recordTab:function(a){if(9===a.keyCode&&(b.isUndefined(this.index)&&this.updateIndex(a),!b.isUndefined(this.index))){var c=this.index+(a.shiftKey?-1:1);c>=0&&c').hide().appendTo("body"),c=this.options.uploader=b.defaults(this.options.uploader||{},{dropzone:this.$el,browser:this.$browser,params:{}}),!c.dropzone||c.dropzone instanceof a||(c.dropzone=a(c.dropzone)),this.controller.on("activate",this.refresh,this),this.controller.on("detach",function(){this.$browser.remove()},this)},refresh:function(){this.uploader&&this.uploader.refresh()},ready:function(){var c,e=d.view.settings.post.id;this.uploader||(e&&(this.options.uploader.params.post_id=e),this.uploader=new wp.Uploader(this.options.uploader),c=this.uploader.dropzone,c.on("dropzone:enter",b.bind(this.show,this)),c.on("dropzone:leave",b.bind(this.hide,this)),a(this.uploader).on("uploader:ready",b.bind(this._ready,this)))},_ready:function(){this.controller.trigger("uploader:ready")},show:function(){var a=this.$el.show();b.defer(function(){a.css({opacity:1})})},hide:function(){var a=this.$el.css({opacity:0});d.transition(a).done(function(){"0"===a.css("opacity")&&a.hide()})}}),d.view.EditorUploader=d.View.extend({tagName:"div",className:"uploader-editor",template:d.template("uploader-editor"),initialize:function(){return this.initialized=!1,this.browserSupport()?(this.$document=a(document),this.dropzones=[],this.files=[],this.$document.on("drop",".uploader-editor",b.bind(this.drop,this)),this.$document.on("dragover",".uploader-editor",b.bind(this.dropzoneDragover,this)),this.$document.on("dragleave",".uploader-editor",b.bind(this.dropzoneDragleave,this)),this.$document.on("dragover",b.bind(this.containerDragover,this)),this.$document.on("dragleave",b.bind(this.containerDragleave,this)),this.initialized=!0,this):this},browserSupport:function(){var a=!1,b=document.createElement("div");return a="draggable"in b||"ondragstart"in b&&"ondrop"in b,a=a&&!!(window.File&&window.FileList&&window.FileReader)},refresh:function(c){var d;for(d in this.dropzones)this.dropzones[d].toggle(this.overContainer||this.overDropzone);return b.isUndefined(c)||a(c.target).closest(".uploader-editor").toggleClass("droppable",this.overDropzone),this},render:function(){return this.initialized?(d.View.prototype.render.apply(this,arguments),a(".wp-editor-wrap").each(b.bind(this.attach,this)),this):this},attach:function(b,c){var d=this.$el.clone();return this.dropzones.push(d),a(c).append(d),this},drop:function(b){var c=null;return this.files=b.originalEvent.dataTransfer.files,this.files.length<1?void 0:(this.containerDragleave(b),this.dropzoneDragleave(b),c=a(b.target).parents(".wp-editor-wrap"),c.length>0&&(window.wpActiveEditor=c[0].id.slice(3,-5)),this.workflow?(this.workflow.state().reset(),this.addFiles.apply(this),this.workflow.open()):(this.workflow=wp.media.editor.open("content",{frame:"post",state:"insert",title:wp.media.view.l10n.addMedia,multiple:!0}),this.workflow.on("uploader:ready",this.addFiles,this)),!1)},addFiles:function(){return this.files.length&&(this.workflow.uploader.uploader.uploader.addFile(b.toArray(this.files)),this.files=[]),this},containerDragover:function(){this.overContainer=!0,this.refresh()},containerDragleave:function(){this.overContainer=!1,b.delay(b.bind(this.refresh,this),50)},dropzoneDragover:function(a){return this.overDropzone=!0,this.refresh(a),!1},dropzoneDragleave:function(a){this.overDropzone=!1,b.delay(b.bind(this.refresh,this,a),50)}}),d.view.UploaderInline=d.View.extend({tagName:"div",className:"uploader-inline",template:d.template("uploader-inline"),initialize:function(){b.defaults(this.options,{message:"",status:!0}),!this.options.$browser&&this.controller.uploader&&(this.options.$browser=this.controller.uploader.$browser),b.isUndefined(this.options.postId)&&(this.options.postId=d.view.settings.post.id),this.options.status&&this.views.set(".upload-inline-status",new d.view.UploaderStatus({controller:this.controller}))},dispose:function(){return this.disposing?d.View.prototype.dispose.apply(this,arguments):(this.disposing=!0,this.remove())},remove:function(){var a=d.View.prototype.remove.apply(this,arguments);return b.defer(b.bind(this.refresh,this)),a},refresh:function(){var a=this.controller.uploader;a&&a.refresh()},ready:function(){var a,b=this.options.$browser;if(this.controller.uploader){if(a=this.$(".browser"),a[0]===b[0])return;b.detach().text(a.text()),b[0].className=a[0].className,a.replaceWith(b.show())}return this.refresh(),this}}),d.view.UploaderStatus=d.View.extend({className:"media-uploader-status",template:d.template("uploader-status"),events:{"click .upload-dismiss-errors":"dismiss"},initialize:function(){this.queue=wp.Uploader.queue,this.queue.on("add remove reset",this.visibility,this),this.queue.on("add remove reset change:percent",this.progress,this),this.queue.on("add remove reset change:uploading",this.info,this),this.errors=wp.Uploader.errors,this.errors.reset(),this.errors.on("add remove reset",this.visibility,this),this.errors.on("add",this.error,this)},dispose:function(){return wp.Uploader.queue.off(null,null,this),d.View.prototype.dispose.apply(this,arguments),this},visibility:function(){this.$el.toggleClass("uploading",!!this.queue.length),this.$el.toggleClass("errors",!!this.errors.length),this.$el.toggle(!!this.queue.length||!!this.errors.length)},ready:function(){b.each({$bar:".media-progress-bar div",$index:".upload-index",$total:".upload-total",$filename:".upload-filename"},function(a,b){this[b]=this.$(a)},this),this.visibility(),this.progress(),this.info()},progress:function(){var a=this.queue,c=this.$bar;c&&a.length&&c.width(a.reduce(function(a,c){if(!c.get("uploading"))return a+100;var d=c.get("percent");return a+(b.isNumber(d)?d:100)},0)/a.length+"%")},info:function(){var a,b=this.queue,c=0;b.length&&(a=this.queue.find(function(a,b){return c=b,a.get("uploading")}),this.$index.text(c+1),this.$total.text(b.length),this.$filename.html(a?this.filename(a.get("filename")):""))},filename:function(a){return d.truncate(b.escape(a),24)},error:function(a){this.views.add(".upload-errors",new d.view.UploaderStatusError({filename:this.filename(a.get("file").name),message:a.get("message")}),{at:0})},dismiss:function(a){var c=this.views.get(".upload-errors");a.preventDefault(),c&&b.invoke(c,"remove"),wp.Uploader.errors.reset()}}),d.view.UploaderStatusError=d.View.extend({className:"upload-error",template:d.template("uploader-status-error")}),d.view.Toolbar=d.View.extend({tagName:"div",className:"media-toolbar",initialize:function(){var a=this.controller.state(),b=this.selection=a.get("selection"),c=this.library=a.get("library");this._views={},this.primary=new d.view.PriorityList,this.secondary=new d.view.PriorityList,this.primary.$el.addClass("media-toolbar-primary"),this.secondary.$el.addClass("media-toolbar-secondary"),this.views.set([this.secondary,this.primary]),this.options.items&&this.set(this.options.items,{silent:!0}),this.options.silent||this.render(),b&&b.on("add remove reset",this.refresh,this),c&&c.on("add remove reset",this.refresh,this)},dispose:function(){return this.selection&&this.selection.off(null,null,this),this.library&&this.library.off(null,null,this),d.View.prototype.dispose.apply(this,arguments)},ready:function(){this.refresh()},set:function(a,c,e){var f;return e=e||{},b.isObject(a)?b.each(a,function(a,b){this.set(b,a,{silent:!0})},this):(c instanceof Backbone.View||(c.classes=["media-button-"+a].concat(c.classes||[]),c=new d.view.Button(c).render()),c.controller=c.controller||this.controller,this._views[a]=c,f=c.options.priority<0?"secondary":"primary",this[f].set(a,c,e)),e.silent||this.refresh(),this},get:function(a){return this._views[a]},unset:function(a,b){return delete this._views[a],this.primary.unset(a,b),this.secondary.unset(a,b),b&&b.silent||this.refresh(),this},refresh:function(){var a=this.controller.state(),c=a.get("library"),d=a.get("selection");b.each(this._views,function(a){if(a.model&&a.options&&a.options.requires){var e=a.options.requires,f=!1;f=b.some(d.models,function(a){return a.get("uploading")===!0}),e.selection&&d&&!d.length?f=!0:e.library&&c&&!c.length&&(f=!0),a.model.set("disabled",f)}})}}),d.view.Toolbar.Select=d.view.Toolbar.extend({initialize:function(){var a=this.options;b.bindAll(this,"clickSelect"),b.defaults(a,{event:"select",state:!1,reset:!0,close:!0,text:c.select,requires:{selection:!0}}),a.items=b.defaults(a.items||{},{select:{style:"primary",text:a.text,priority:80,click:this.clickSelect,requires:a.requires}}),d.view.Toolbar.prototype.initialize.apply(this,arguments)},clickSelect:function(){var a=this.options,b=this.controller;a.close&&b.close(),a.event&&b.state().trigger(a.event),a.state&&b.setState(a.state),a.reset&&b.reset()}}),d.view.Toolbar.Embed=d.view.Toolbar.Select.extend({initialize:function(){b.defaults(this.options,{text:c.insertIntoPost,requires:!1}),d.view.Toolbar.Select.prototype.initialize.apply(this,arguments)},refresh:function(){var a=this.controller.state().props.get("url");this.get("select").model.set("disabled",!a||"http://"===a),d.view.Toolbar.Select.prototype.refresh.apply(this,arguments)}}),d.view.Button=d.View.extend({tagName:"a",className:"media-button",attributes:{href:"#"},events:{click:"click"},defaults:{text:"",style:"",size:"large",disabled:!1},initialize:function(){this.model=new Backbone.Model(this.defaults),b.each(this.defaults,function(a,c){var d=this.options[c];b.isUndefined(d)||(this.model.set(c,d),delete this.options[c])},this),this.model.on("change",this.render,this)},render:function(){var a=["button",this.className],c=this.model.toJSON();return c.style&&a.push("button-"+c.style),c.size&&a.push("button-"+c.size),a=b.uniq(a.concat(this.options.classes)),this.el.className=a.join(" "),this.$el.attr("disabled",c.disabled),this.$el.text(this.model.get("text")),this},click:function(a){"#"===this.attributes.href&&a.preventDefault(),this.options.click&&!this.model.get("disabled")&&this.options.click.apply(this,arguments)}}),d.view.ButtonGroup=d.View.extend({tagName:"div",className:"button-group button-large media-button-group",initialize:function(){this.buttons=b.map(this.options.buttons||[],function(a){return a instanceof Backbone.View?a:new d.view.Button(a).render()}),delete this.options.buttons,this.options.classes&&this.$el.addClass(this.options.classes)},render:function(){return this.$el.html(a(b.pluck(this.buttons,"el")).detach()),this}}),d.view.PriorityList=d.View.extend({tagName:"div",initialize:function(){this._views={},this.set(b.extend({},this._views,this.options.views),{silent:!0}),delete this.options.views,this.options.silent||this.render()},set:function(a,c,d){var e,f,g;return d=d||{},b.isObject(a)?(b.each(a,function(a,b){this.set(b,a)},this),this):(c instanceof Backbone.View||(c=this.toView(c,a,d)),c.controller=c.controller||this.controller,this.unset(a),e=c.options.priority||10,f=this.views.get()||[],b.find(f,function(a,b){return a.options.priority>e?(g=b,!0):void 0}),this._views[a]=c,this.views.add(c,{at:b.isNumber(g)?g:f.length||0}),this)},get:function(a){return this._views[a]},unset:function(a){var b=this.get(a);return b&&b.remove(),delete this._views[a],this},toView:function(a){return new d.View(a)}}),d.view.MenuItem=d.View.extend({tagName:"a",className:"media-menu-item",attributes:{href:"#"},events:{click:"_click"},_click:function(a){var b=this.options.click;a&&a.preventDefault(),b?b.call(this):this.click()},click:function(){var a=this.options.state;a&&this.controller.setState(a)},render:function(){var a=this.options;return a.text?this.$el.text(a.text):a.html&&this.$el.html(a.html),this}}),d.view.Menu=d.view.PriorityList.extend({tagName:"div",className:"media-menu",property:"state",ItemView:d.view.MenuItem,region:"menu",toView:function(a,b){return a=a||{},a[this.property]=a[this.property]||b,new this.ItemView(a).render()},ready:function(){d.view.PriorityList.prototype.ready.apply(this,arguments),this.visibility()},set:function(){d.view.PriorityList.prototype.set.apply(this,arguments),this.visibility()},unset:function(){d.view.PriorityList.prototype.unset.apply(this,arguments),this.visibility()},visibility:function(){var a=this.region,b=this.controller[a].get(),c=this.views.get(),d=!c||c.length<2;this===b&&this.controller.$el.toggleClass("hide-"+a,d)},select:function(a){var b=this.get(a);b&&(this.deselect(),b.$el.addClass("active"))},deselect:function(){this.$el.children().removeClass("active")}}),d.view.RouterItem=d.view.MenuItem.extend({click:function(){var a=this.options.contentMode;a&&this.controller.content.mode(a)}}),d.view.Router=d.view.Menu.extend({tagName:"div",className:"media-router",property:"contentMode",ItemView:d.view.RouterItem,region:"router",initialize:function(){this.controller.on("content:render",this.update,this),d.view.Menu.prototype.initialize.apply(this,arguments)},update:function(){var a=this.controller.content.mode();a&&this.select(a)}}),d.view.Sidebar=d.view.PriorityList.extend({className:"media-sidebar"}),d.view.Attachment=d.View.extend({tagName:"li",className:"attachment",template:d.template("attachment"),events:{"click .attachment-preview":"toggleSelectionHandler","change [data-setting]":"updateSetting","change [data-setting] input":"updateSetting","change [data-setting] select":"updateSetting","change [data-setting] textarea":"updateSetting","click .close":"removeFromLibrary","click .check":"removeFromSelection","click a":"preventDefault"},buttons:{},initialize:function(){var a=this.options.selection;this.model.on("change:sizes change:uploading",this.render,this),this.model.on("change:title",this._syncTitle,this),this.model.on("change:caption",this._syncCaption,this),this.model.on("change:percent",this.progress,this),this.model.on("add",this.select,this),this.model.on("remove",this.deselect,this),a&&a.on("reset",this.updateSelect,this),this.model.on("selection:single selection:unsingle",this.details,this),this.details(this.model,this.controller.state().get("selection"))},dispose:function(){var a=this.options.selection;return this.updateAll(),a&&a.off(null,null,this),d.View.prototype.dispose.apply(this,arguments),this},render:function(){var a=b.defaults(this.model.toJSON(),{orientation:"landscape",uploading:!1,type:"",subtype:"",icon:"",filename:"",caption:"",title:"",dateFormatted:"",width:"",height:"",compat:!1,alt:"",description:""});return a.buttons=this.buttons,a.describe=this.controller.state().get("describe"),"image"===a.type&&(a.size=this.imageSize()),a.can={},a.nonces&&(a.can.remove=!!a.nonces["delete"],a.can.save=!!a.nonces.update),this.controller.state().get("allowLocalEdits")&&(a.allowLocalEdits=!0),this.views.detach(),this.$el.html(this.template(a)),this.$el.toggleClass("uploading",a.uploading),a.uploading?this.$bar=this.$(".media-progress-bar div"):delete this.$bar,this.updateSelect(),this.updateSave(),this.views.render(),this},progress:function(){this.$bar&&this.$bar.length&&this.$bar.width(this.model.get("percent")+"%")},toggleSelectionHandler:function(a){var b;a.shiftKey?b="between":(a.ctrlKey||a.metaKey)&&(b="toggle"),this.toggleSelection({method:b})},toggleSelection:function(a){var c,d,e,f,g=this.collection,h=this.options.selection,i=this.model,j=a&&a.method;if(h){if(c=h.single(),j=b.isUndefined(j)?h.multiple:j,"between"===j&&c&&h.multiple){if(c===i)return;return e=g.indexOf(c),f=g.indexOf(this.model),d=f>e?g.models.slice(e,f+1):g.models.slice(f,e+1),h.add(d),void h.single(i)}if("toggle"===j)return h[this.selected()?"remove":"add"](i),void h.single(i);"add"!==j&&(j="reset"),this.selected()?h[c===i?"remove":"single"](i):(h[j](i),h.single(i))}},updateSelect:function(){this[this.selected()?"select":"deselect"]()},selected:function(){var a=this.options.selection;return a?!!a.get(this.model.cid):void 0},select:function(a,b){var c=this.options.selection;!c||b&&b!==c||this.$el.addClass("selected")},deselect:function(a,b){var c=this.options.selection;!c||b&&b!==c||this.$el.removeClass("selected")},details:function(a,b){var c,d=this.options.selection;d===b&&(c=d.single(),this.$el.toggleClass("details",c===this.model))},preventDefault:function(a){a.preventDefault()},imageSize:function(a){var c=this.model.get("sizes");return a=a||"medium",c&&c[a]?b.clone(c[a]):{url:this.model.get("url"),width:this.model.get("width"),height:this.model.get("height"),orientation:this.model.get("orientation")}},updateSetting:function(b){var c,d,e=a(b.target).closest("[data-setting]");e.length&&(c=e.data("setting"),d=b.target.value,this.model.get(c)!==d&&this.save(c,d))},save:function(){var b=this,c=this._save=this._save||{status:"ready"},d=this.model.save.apply(this.model,arguments),e=c.requests?a.when(d,c.requests):d;c.savedTimer&&clearTimeout(c.savedTimer),this.updateSave("waiting"),c.requests=e,e.always(function(){c.requests===e&&(b.updateSave("resolved"===e.state()?"complete":"error"),c.savedTimer=setTimeout(function(){b.updateSave("ready"),delete c.savedTimer},2e3))})},updateSave:function(a){var b=this._save=this._save||{status:"ready"};return a&&a!==b.status&&(this.$el.removeClass("save-"+b.status),b.status=a),this.$el.addClass("save-"+b.status),this},updateAll:function(){var c,d=this.$("[data-setting]"),e=this.model;c=b.chain(d).map(function(b){var c,d,f=a("input, textarea, select, [value]",b);if(f.length)return c=a(b).data("setting"),d=f.val(),e.get(c)!==d?[c,d]:void 0}).compact().object().value(),b.isEmpty(c)||e.save(c)},removeFromLibrary:function(a){a.stopPropagation(),this.collection.remove(this.model)},removeFromSelection:function(a){var b=this.options.selection;b&&(a.stopPropagation(),b.remove(this.model))}}),b.each({caption:"_syncCaption",title:"_syncTitle"},function(a,b){d.view.Attachment.prototype[a]=function(a,c){var d=this.$('[data-setting="'+b+'"]');return d.length?c===d.find("input, textarea, select, [value]").val()?this:this.render():this}}),d.view.Attachment.Library=d.view.Attachment.extend({buttons:{check:!0}}),d.view.Attachment.EditLibrary=d.view.Attachment.extend({buttons:{close:!0}}),d.view.Attachments=d.View.extend({tagName:"ul",className:"attachments",cssTemplate:d.template("attachments-css"),events:{scroll:"scroll"},initialize:function(){this.el.id=b.uniqueId("__attachments-view-"),b.defaults(this.options,{refreshSensitivity:200,refreshThreshold:3,AttachmentView:d.view.Attachment,sortable:!1,resize:!0}),this._viewsByCid={},this.collection.on("add",function(a){this.views.add(this.createAttachmentView(a),{at:this.collection.indexOf(a)})},this),this.collection.on("remove",function(a){var b=this._viewsByCid[a.cid];delete this._viewsByCid[a.cid],b&&b.remove()},this),this.collection.on("reset",this.render,this),this.scroll=b.chain(this.scroll).bind(this).throttle(this.options.refreshSensitivity).value(),this.initSortable(),b.bindAll(this,"css"),this.model.on("change:edge change:gutter",this.css,this),this._resizeCss=b.debounce(b.bind(this.css,this),this.refreshSensitivity),this.options.resize&&a(window).on("resize.attachments",this._resizeCss),this.css()},dispose:function(){this.collection.props.off(null,null,this),a(window).off("resize.attachments",this._resizeCss),d.View.prototype.dispose.apply(this,arguments)},css:function(){var b=a("#"+this.el.id+"-css");b.length&&b.remove(),d.view.Attachments.$head().append(this.cssTemplate({id:this.el.id,edge:this.edge(),gutter:this.model.get("gutter")}))},edge:function(){var a,b,c,d=this.model.get("edge");return this.$el.is(":visible")?(a=2*this.model.get("gutter"),b=this.$el.width()-a,c=Math.ceil(b/(d+a)),d=Math.floor((b-c*a)/c)):d},initSortable:function(){var c=this.collection;this.options.sortable&&a.fn.sortable&&(this.$el.sortable(b.extend({disabled:!!c.comparator,containment:this.$el,tolerance:"pointer",start:function(a,b){b.item.data("sortableIndexStart",b.item.index())},update:function(a,b){var d=c.at(b.item.data("sortableIndexStart")),e=c.comparator;delete c.comparator,c.remove(d,{silent:!0}),c.add(d,{silent:!0,at:b.item.index()}),c.comparator=e,c.trigger("reset",c),c.saveMenuOrder()}},this.options.sortable)),c.props.on("change:orderby",function(){this.$el.sortable("option","disabled",!!c.comparator)},this),this.collection.props.on("change:orderby",this.refreshSortable,this),this.refreshSortable())},refreshSortable:function(){if(this.options.sortable&&a.fn.sortable){var b=this.collection,c=b.props.get("orderby"),d="menuOrder"===c||!b.comparator;this.$el.sortable("option","disabled",!d)}},createAttachmentView:function(a){var b=new this.options.AttachmentView({controller:this.controller,model:a,collection:this.collection,selection:this.options.selection});return this._viewsByCid[a.cid]=b},prepare:function(){this.collection.length?this.views.set(this.collection.map(this.createAttachmentView,this)):(this.views.unset(),this.collection.more().done(this.scroll))},ready:function(){this.scroll()},scroll:function(){this.$el.is(":visible")&&this.collection.hasMore()&&this.el.scrollHeight").val(c).text(b.text)[0],priority:b.priority||50}},this).sortBy("priority").pluck("el").value()),this.model.on("change",this.select,this),this.select()},createFilters:function(){this.filters={}},change:function(){var a=this.filters[this.el.value];a&&this.model.set(a.props)},select:function(){var a=this.model,c="all",d=a.toJSON();b.find(this.filters,function(a,e){var f=b.all(a.props,function(a,c){return a===(b.isUndefined(d[c])?null:d[c])});return f?c=e:void 0}),this.$el.val(c)}}),d.view.AttachmentFilters.Uploaded=d.view.AttachmentFilters.extend({createFilters:function(){var a,b=this.model.get("type"),e=d.view.settings.mimeTypes;e&&b&&(a=e[b]),this.filters={all:{text:a||c.allMediaItems,props:{uploadedTo:null,orderby:"date",order:"DESC"},priority:10},uploaded:{text:c.uploadedToThisPost,props:{uploadedTo:d.view.settings.post.id,orderby:"menuOrder",order:"ASC"},priority:20}}}}),d.view.AttachmentFilters.All=d.view.AttachmentFilters.extend({createFilters:function(){var a={};b.each(d.view.settings.mimeTypes||{},function(b,c){a[c]={text:b,props:{type:c,uploadedTo:null,orderby:"date",order:"DESC"}}}),a.all={text:c.allMediaItems,props:{type:null,uploadedTo:null,orderby:"date",order:"DESC"},priority:10},a.uploaded={text:c.uploadedToThisPost,props:{type:null,uploadedTo:d.view.settings.post.id,orderby:"menuOrder",order:"ASC"},priority:20},this.filters=a}}),d.view.AttachmentsBrowser=d.View.extend({tagName:"div",className:"attachments-browser",initialize:function(){b.defaults(this.options,{filters:!1,search:!0,display:!1,AttachmentView:d.view.Attachment.Library}),this.createToolbar(),this.updateContent(),this.createSidebar(),this.collection.on("add remove reset",this.updateContent,this)},toggleSpinner:function(a){a?this.spinnerTimeout=b.delay(function(a){a.toolbar.get("spinner").show()},600,this):(this.toolbar.get("spinner").hide(),clearTimeout(this.spinnerTimeout))},dispose:function(){return this.options.selection.off(null,null,this),d.View.prototype.dispose.apply(this,arguments),this},createToolbar:function(){var b,e;this.toolbar=new d.view.Toolbar({controller:this.controller}),this.views.add(this.toolbar),b=this.options.filters,"uploaded"===b?e=d.view.AttachmentFilters.Uploaded:"all"===b&&(e=d.view.AttachmentFilters.All),e&&this.toolbar.set("filters",new e({controller:this.controller,model:this.collection.props,priority:-80}).render()),this.toolbar.set("spinner",new d.view.Spinner({priority:-70})),this.options.search&&this.toolbar.set("search",new d.view.Search({controller:this.controller,model:this.collection.props,priority:60}).render()),this.options.dragInfo&&this.toolbar.set("dragInfo",new d.View({el:a('
'+c.dragInfo+"
")[0],priority:-40})) -},updateContent:function(){var a=this;this.attachments||this.createAttachments(),this.collection.length||(this.toggleSpinner(!0),this.collection.more().done(function(){a.collection.length||a.createUploader(),a.toggleSpinner(!1)}))},removeContent:function(){b.each(["attachments","uploader"],function(a){this[a]&&(this[a].remove(),delete this[a])},this)},createUploader:function(){this.removeContent(),this.uploader=new d.view.UploaderInline({controller:this.controller,status:!1,message:c.noItemsFound}),this.views.add(this.uploader)},createAttachments:function(){this.removeContent(),this.attachments=new d.view.Attachments({controller:this.controller,collection:this.collection,selection:this.options.selection,model:this.model,sortable:this.options.sortable,AttachmentView:this.options.AttachmentView}),this.views.add(this.attachments)},createSidebar:function(){var a=this.options,b=a.selection,c=this.sidebar=new d.view.Sidebar({controller:this.controller});this.views.add(c),this.controller.uploader&&c.set("uploads",new d.view.UploaderStatus({controller:this.controller,priority:40})),b.on("selection:single",this.createSingle,this),b.on("selection:unsingle",this.disposeSingle,this),b.single()&&this.createSingle()},createSingle:function(){var a=this.sidebar,b=this.options.selection.single();a.set("details",new d.view.Attachment.Details({controller:this.controller,model:b,priority:80})),a.set("compat",new d.view.AttachmentCompat({controller:this.controller,model:b,priority:120})),this.options.display&&a.set("display",new d.view.Settings.AttachmentDisplay({controller:this.controller,model:this.model.display(b),attachment:b,priority:160,userSettings:this.model.get("displayUserSettings")}))},disposeSingle:function(){var a=this.sidebar;a.unset("details"),a.unset("compat"),a.unset("display")}}),d.view.Selection=d.View.extend({tagName:"div",className:"media-selection",template:d.template("media-selection"),events:{"click .edit-selection":"edit","click .clear-selection":"clear"},initialize:function(){b.defaults(this.options,{editable:!1,clearable:!0}),this.attachments=new d.view.Attachments.Selection({controller:this.controller,collection:this.collection,selection:this.collection,model:new Backbone.Model({edge:40,gutter:5})}),this.views.set(".selection-view",this.attachments),this.collection.on("add remove reset",this.refresh,this),this.controller.on("content:activate",this.refresh,this)},ready:function(){this.refresh()},refresh:function(){if(this.$el.children().length){var a=this.collection,b="edit-selection"===this.controller.content.mode();this.$el.toggleClass("empty",!a.length),this.$el.toggleClass("one",1===a.length),this.$el.toggleClass("editing",b),this.$(".count").text(c.selected.replace("%d",a.length))}},edit:function(a){a.preventDefault(),this.options.editable&&this.options.editable.call(this,this.collection)},clear:function(a){a.preventDefault(),this.collection.reset()}}),d.view.Attachment.Selection=d.view.Attachment.extend({className:"attachment selection",toggleSelection:function(){this.options.selection.single(this.model)}}),d.view.Attachments.Selection=d.view.Attachments.extend({events:{},initialize:function(){return b.defaults(this.options,{sortable:!0,resize:!1,AttachmentView:d.view.Attachment.Selection}),d.view.Attachments.prototype.initialize.apply(this,arguments)}}),d.view.Attachment.EditSelection=d.view.Attachment.Selection.extend({buttons:{close:!0}}),d.view.Settings=d.View.extend({events:{"click button":"updateHandler","change input":"updateHandler","change select":"updateHandler","change textarea":"updateHandler"},initialize:function(){this.model=this.model||new Backbone.Model,this.model.on("change",this.updateChanges,this)},prepare:function(){return b.defaults({model:this.model.toJSON()},this.options)},render:function(){return d.View.prototype.render.apply(this,arguments),b(this.model.attributes).chain().keys().each(this.update,this),this},update:function(a){var b,c,d=this.model.get(a),e=this.$('[data-setting="'+a+'"]');e.length&&(e.is("select")?(c=e.find('[value="'+d+'"]'),c.length?(e.find("option").prop("selected",!1),c.prop("selected",!0)):this.model.set(a,e.find(":selected").val())):e.hasClass("button-group")?(b=e.find("button").removeClass("active"),b.filter('[value="'+d+'"]').addClass("active")):e.is('input[type="text"], textarea')?e.is(":focus")||e.val(d):e.is('input[type="checkbox"]')&&e.prop("checked",!!d))},updateHandler:function(b){var c,d=a(b.target).closest("[data-setting]"),e=b.target.value;b.preventDefault(),d.length&&(d.is('input[type="checkbox"]')&&(e=d[0].checked),this.model.set(d.data("setting"),e),(c=d.data("userSetting"))&&setUserSetting(c,e))},updateChanges:function(a){a.hasChanged()&&b(a.changed).chain().keys().each(this.update,this)}}),d.view.Settings.AttachmentDisplay=d.view.Settings.extend({className:"attachment-display-settings",template:d.template("attachment-display-settings"),initialize:function(){var a=this.options.attachment;b.defaults(this.options,{userSettings:!1}),d.view.Settings.prototype.initialize.apply(this,arguments),this.model.on("change:link",this.updateLinkTo,this),a&&a.on("change:uploading",this.render,this)},dispose:function(){var a=this.options.attachment;a&&a.off(null,null,this),d.view.Settings.prototype.dispose.apply(this,arguments)},render:function(){var a=this.options.attachment;return a&&b.extend(this.options,{sizes:a.get("sizes"),type:a.get("type")}),d.view.Settings.prototype.render.call(this),this.updateLinkTo(),this},updateLinkTo:function(){var a=this.model.get("link"),b=this.$(".link-to-custom"),c=this.options.attachment;return"none"===a||"embed"===a||!c&&"custom"!==a?void b.addClass("hidden"):(c&&("post"===a?b.val(c.get("link")):"file"===a?b.val(c.get("url")):this.model.get("linkUrl")||b.val("http://"),b.prop("readonly","custom"!==a)),b.removeClass("hidden"),void(b.is(":visible")&&b.focus()[0].select()))}}),d.view.Settings.Gallery=d.view.Settings.extend({className:"collection-settings gallery-settings",template:d.template("gallery-settings")}),d.view.Settings.Playlist=d.view.Settings.extend({className:"collection-settings playlist-settings",template:d.template("playlist-settings")}),d.view.Attachment.Details=d.view.Attachment.extend({tagName:"div",className:"attachment-details",template:d.template("attachment-details"),events:{"change [data-setting]":"updateSetting","change [data-setting] input":"updateSetting","change [data-setting] select":"updateSetting","change [data-setting] textarea":"updateSetting","click .delete-attachment":"deleteAttachment","click .trash-attachment":"trashAttachment","click .edit-attachment":"editAttachment","click .refresh-attachment":"refreshAttachment"},initialize:function(){this.focusManager=new d.view.FocusManager({el:this.el}),d.view.Attachment.prototype.initialize.apply(this,arguments)},render:function(){return d.view.Attachment.prototype.render.apply(this,arguments),this.focusManager.focus(),this},deleteAttachment:function(a){a.preventDefault(),confirm(c.warnDelete)&&this.model.destroy()},trashAttachment:function(a){a.preventDefault(),this.model.destroy()},editAttachment:function(a){a.preventDefault(),this.controller.setState("edit-image")},refreshAttachment:function(a){this.$el.removeClass("needs-refresh"),a.preventDefault(),this.model.fetch()}}),d.view.AttachmentCompat=d.View.extend({tagName:"form",className:"compat-item",events:{submit:"preventDefault","change input":"save","change select":"save","change textarea":"save"},initialize:function(){this.focusManager=new d.view.FocusManager({el:this.el}),this.model.on("change:compat",this.render,this)},dispose:function(){return this.$(":focus").length&&this.save(),d.View.prototype.dispose.apply(this,arguments)},render:function(){var a=this.model.get("compat");if(a&&a.item)return this.views.detach(),this.$el.html(a.item),this.views.render(),this.focusManager.focus(),this},preventDefault:function(a){a.preventDefault()},save:function(a){var c={};a&&a.preventDefault(),b.each(this.$el.serializeArray(),function(a){c[a.name]=a.value}),this.model.saveCompat(c)}}),d.view.Iframe=d.View.extend({className:"media-iframe",render:function(){return this.views.detach(),this.$el.html('