From bd4085fac3bab7529061b67e0151b39dcedbcee2 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Fri, 14 Mar 2014 14:36:14 +0000 Subject: [PATCH] The `canPlayType` property for audio and video in JS is so bad that the official valid responses are "probably" and "maybe". There are many cases where we might want to know if an audio|video tag is gonna blow up in our face before even attempting to make a `MediaElementPlayer` instance out of it. The best (and most cautious) way to tackle this is to whitelist types by browser. Imagine that one implemented MEjs in TinyMCE's rich editor mode, this would be very helpful. Add `isCompatible( $media )` to `wp.media.mixin`. Future features will use this. See #27389. Built from https://develop.svn.wordpress.org/trunk@27539 git-svn-id: http://core.svn.wordpress.org/trunk@27382 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/media-editor.js | 65 ++++++++++++++++++++++++++++++ wp-includes/js/media-editor.min.js | 2 +- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/wp-includes/js/media-editor.js b/wp-includes/js/media-editor.js index a8458fb178..1c82c6f54e 100644 --- a/wp-includes/js/media-editor.js +++ b/wp-includes/js/media-editor.js @@ -307,6 +307,71 @@ } }, + isCompatible: function ( media ) { + if ( ! media.find( 'source' ).length ) { + return false; + } + + var ua = window.navigator.userAgent.toLowerCase(), + ff, chrome, opera, safari, + isIE = ua.match(/MSIE/gi) !== null, + isOpera = window.navigator.userAgent.match(/OPR/) !== null, + isOldIE = ua.match(/MSIE [6-8]/gi) !== null, + isChrome = ua.match(/safari/gi) && ua.match(/chrome/gi) !== null, + isFirefox = ua.match(/firefox/gi) !== null, + isSafari = ua.match(/safari/gi) !== null && ua.match(/chrome/gi) === null; + + if ( isOldIE || isIE ) { + return false; + } + + if ( isOpera ) { + opera = false; + media.find( 'source' ).each(function (i, elem) { + if ( elem.type.match(/video\/(ogv|webm)/gi) !== null || + ( elem.type.match(/audio\/(ogg|wav)/gi) !== null ) ) { + opera = true; + } + }); + + return opera; + } else if ( isChrome ) { + chrome = false; + media.find( 'source' ).each(function (i, elem) { + if ( elem.type.match(/video\/(mp4|m4v|mpeg|webm|ogg)/gi) !== null || + elem.type.match(/audio\/(ogg|mpeg|x-ms-wma)/gi) !== null ) { + chrome = true; + } + }); + + return chrome; + + } else if ( isFirefox ) { + ff = false; + media.find( 'source' ).each(function (i, elem) { + if ( elem.type.match(/video\/(ogg|webm)/gi) !== null || + ( elem.type.match(/audio\/(ogg|mpeg)/gi) !== null && -1 === elem.src.indexOf('.m4a') ) ) { + ff = true; + } + }); + + return ff; + + } else if ( isSafari ) { + safari = false; + media.find( 'source' ).each(function (i, elem) { + if ( elem.type.match(/video\/(mp4|m4v|mpeg|x-ms-wmv|quicktime)/gi) !== null || + ( elem.type.match(/audio\/(mpeg|wav)/gi) !== null ) ) { + safari = true; + } + }); + + return safari; + } + + return false; + }, + /** * Override the MediaElement method for removing a player. * MediaElement tries to pull the audio/video tag out of diff --git a/wp-includes/js/media-editor.min.js b/wp-includes/js/media-editor.min.js index 285625fdb0..a02a633644 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]},pauseAllPlayers:function(){var a;if(window.mejs&&window.mejs.players)for(a in window.mejs.players)window.mejs.players[a].pause()},removePlayer:function(){var a,b,c=this.player;for(a in c.options.features)if(b=c.options.features[a],c["clean"+b])try{c["clean"+b](c)}catch(d){}c.isDynamic||c.$node.remove(),"native"!==c.media.pluginType&&c.media.remove(),delete window.mejs.players[c.id],c.container.remove(),c.globalUnbind(),delete c.node.player},unsetPlayer:function(){this.player&&(wp.media.mixin.pauseAllPlayers(),wp.media.mixin.removePlayer.apply(this),this.player=!1)}},wp.media.collection=function(a){var c={};return b.extend(a,{coerce:wp.media.mixin.coerce,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={coerce:wp.media.mixin.coerce,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.video={coerce:wp.media.mixin.coerce,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.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)}).on("click",".wp-switch-editor",wp.media.mixin.pauseAllPlayers),(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]},pauseAllPlayers:function(){var a;if(window.mejs&&window.mejs.players)for(a in window.mejs.players)window.mejs.players[a].pause()},isCompatible:function(a){if(!a.find("source").length)return!1;var b,c,d,e,f=window.navigator.userAgent.toLowerCase(),g=null!==f.match(/MSIE/gi),h=null!==window.navigator.userAgent.match(/OPR/),i=null!==f.match(/MSIE [6-8]/gi),j=f.match(/safari/gi)&&null!==f.match(/chrome/gi),k=null!==f.match(/firefox/gi),l=null!==f.match(/safari/gi)&&null===f.match(/chrome/gi);return i||g?!1:h?(d=!1,a.find("source").each(function(a,b){(null!==b.type.match(/video\/(ogv|webm)/gi)||null!==b.type.match(/audio\/(ogg|wav)/gi))&&(d=!0)}),d):j?(c=!1,a.find("source").each(function(a,b){(null!==b.type.match(/video\/(mp4|m4v|mpeg|webm|ogg)/gi)||null!==b.type.match(/audio\/(ogg|mpeg|x-ms-wma)/gi))&&(c=!0)}),c):k?(b=!1,a.find("source").each(function(a,c){(null!==c.type.match(/video\/(ogg|webm)/gi)||null!==c.type.match(/audio\/(ogg|mpeg)/gi)&&-1===c.src.indexOf(".m4a"))&&(b=!0)}),b):l?(e=!1,a.find("source").each(function(a,b){(null!==b.type.match(/video\/(mp4|m4v|mpeg|x-ms-wmv|quicktime)/gi)||null!==b.type.match(/audio\/(mpeg|wav)/gi))&&(e=!0)}),e):!1},removePlayer:function(){var a,b,c=this.player;for(a in c.options.features)if(b=c.options.features[a],c["clean"+b])try{c["clean"+b](c)}catch(d){}c.isDynamic||c.$node.remove(),"native"!==c.media.pluginType&&c.media.remove(),delete window.mejs.players[c.id],c.container.remove(),c.globalUnbind(),delete c.node.player},unsetPlayer:function(){this.player&&(wp.media.mixin.pauseAllPlayers(),wp.media.mixin.removePlayer.apply(this),this.player=!1)}},wp.media.collection=function(a){var c={};return b.extend(a,{coerce:wp.media.mixin.coerce,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={coerce:wp.media.mixin.coerce,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.video={coerce:wp.media.mixin.coerce,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.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)}).on("click",".wp-switch-editor",wp.media.mixin.pauseAllPlayers),(new wp.media.view.EditorUploader).render()}},b.bindAll(wp.media.editor,"open"),a(wp.media.editor.init)}(jQuery,_); \ No newline at end of file