diff --git a/wp-includes/js/mce-view.js b/wp-includes/js/mce-view.js index 73e33c9cfb..34dc0d2a61 100644 --- a/wp-includes/js/mce-view.js +++ b/wp-includes/js/mce-view.js @@ -317,4 +317,362 @@ window.wp = window.wp || {}; }; wp.mce.views.register( 'gallery', wp.mce.gallery ); + + /** + * Tiny MCE Views for Audio / Video + * + */ + + /** + * These are base methods that are shared by each shortcode's MCE controller + * + * @mixin + */ + wp.mce.media = { + /** + * @global wp.shortcode + * + * @param {string} content + * @returns {Object} + */ + toView: function( content ) { + var match = wp.shortcode.next( this.shortcode, content ); + + if ( ! match ) { + return; + } + + return { + index: match.index, + content: match.content, + options: { + shortcode: match.shortcode + } + }; + }, + + /** + * Called when a TinyMCE view is clicked for editing. + * - Parses the shortcode out of the element's data attribute + * - Calls the `edit` method on the shortcode model + * - Launches the model window + * - Bind's an `update` callback which updates the element's data attribute + * re-renders the view + * + * @param {HTMLElement} node + */ + edit: function( node ) { + var media = wp.media[ this.shortcode ], + self = this, + frame, data; + + wp.media.mixin.pauseAllPlayers(); + + data = window.decodeURIComponent( $( node ).attr('data-wpview-text') ); + frame = media.edit( data ); + frame.on( 'close', function() { + frame.detach(); + } ); + frame.state( self.state ).on( 'update', function( selection ) { + var shortcode = wp.media[ self.shortcode ].shortcode( selection ).string(); + $( node ).attr( 'data-wpview-text', window.encodeURIComponent( shortcode ) ); + wp.mce.views.refreshView( self, shortcode ); + frame.detach(); + } ); + frame.open(); + } + }; + + /** + * Base View class for audio and video shortcodes + * + * @constructor + * @augments wp.mce.View + * @mixes wp.media.mixin + */ + wp.mce.media.View = wp.mce.View.extend({ + initialize: function( options ) { + this.shortcode = options.shortcode; + _.bindAll( this, 'setPlayer' ); + $(this).on( 'ready', this.setPlayer ); + }, + + /** + * Creates the player instance for the current node + * + * @global MediaElementPlayer + * @global _wpmejsSettings + * + * @param {Event} e + * @param {HTMLElement} node + */ + setPlayer: function(e, node) { + // if the ready event fires on an empty node + if ( ! node ) { + return; + } + + var self = this, + media, + firefox = this.ua.is( 'ff' ), + className = '.wp-' + this.shortcode.tag + '-shortcode'; + + if ( this.player ) { + this.unsetPlayer(); + } + + media = $( node ).find( className ); + + if ( ! this.isCompatible( media ) ) { + media.closest( '.wpview-wrap' ).addClass( 'wont-play' ); + if ( ! media.parent().hasClass( 'wpview-wrap' ) ) { + media.parent().replaceWith( media ); + } + media.replaceWith( '

' + media.find( 'source' ).eq(0).prop( 'src' ) + '

' ); + return; + } else { + media.closest( '.wpview-wrap' ).removeClass( 'wont-play' ); + if ( firefox ) { + media.prop( 'preload', 'metadata' ); + } else { + media.prop( 'preload', 'none' ); + } + } + + media = wp.media.view.MediaDetails.prepareSrc( media.get(0) ); + + // Thanks, Firefox! + if ( firefox ) { + setTimeout( function() { + self.player = new MediaElementPlayer( media, this.mejsSettings ); + }, 50 ); + } else { + this.player = new MediaElementPlayer( media, this.mejsSettings ); + } + }, + + /** + * Pass data to the View's Underscore template and return the compiled output + * + * @returns {string} + */ + getHtml: function() { + var attrs = _.defaults( + this.shortcode.attrs.named, + wp.media[ this.shortcode.tag ].defaults + ); + return this.template({ model: attrs }); + } + }); + _.extend( wp.mce.media.View.prototype, wp.media.mixin ); + + /** + * TinyMCE handler for the video shortcode + * + * @mixes wp.mce.media + */ + wp.mce.video = _.extend( {}, wp.mce.media, { + shortcode: 'video', + state: 'video-details', + View: wp.mce.media.View.extend({ + className: 'editor-video', + template: media.template('editor-video') + }) + } ); + wp.mce.views.register( 'video', wp.mce.video ); + + /** + * TinyMCE handler for the audio shortcode + * + * @mixes wp.mce.media + */ + wp.mce.audio = _.extend( {}, wp.mce.media, { + shortcode: 'audio', + state: 'audio-details', + View: wp.mce.media.View.extend({ + className: 'editor-audio', + template: media.template('editor-audio') + }) + } ); + wp.mce.views.register( 'audio', wp.mce.audio ); + + /** + * Base View class for playlist shortcodes + * + * @constructor + * @augments wp.mce.View + * @mixes wp.media.mixin + */ + wp.mce.media.PlaylistView = wp.mce.View.extend({ + className: 'editor-playlist', + template: media.template('editor-playlist'), + + initialize: function( options ) { + this.data = {}; + this.attachments = []; + this.shortcode = options.shortcode; + _.bindAll( this, 'setPlayer' ); + $(this).on('ready', this.setNode); + }, + + /** + * Set the element context for the view, and then fetch the playlist's + * associated attachments. + * + * @param {Event} e + * @param {HTMLElement} node + */ + setNode: function(e, node) { + this.node = node; + this.fetch(); + }, + + /** + * Asynchronously fetch the shortcode's attachments + */ + fetch: function() { + this.attachments = wp.media[ this.shortcode.tag ].attachments( this.shortcode ); + this.attachments.more().done( this.setPlayer ); + }, + + /** + * Get the HTML for the view (which also set's the data), replace the + * current HTML, and then invoke the WPPlaylistView instance to render + * the playlist in the editor + * + * @global WPPlaylistView + * @global tinymce.editors + */ + setPlayer: function() { + var p, + html = this.getHtml(), + t = this.encodedText, + self = this; + + this.unsetPlayer(); + + _.each( tinymce.editors, function( editor ) { + var doc; + if ( editor.plugins.wpview ) { + doc = editor.getDoc(); + $( doc ).find( '[data-wpview-text="' + t + '"]' ).each(function(i, elem) { + var node = $( elem ); + node.html( html ); + self.node = elem; + }); + } + }, this ); + + p = new WPPlaylistView({ + el: $( self.node ).find( '.wp-playlist' ).get(0), + metadata: this.data + }); + + this.player = p._player; + }, + + /** + * Set the data that will be used to compile the Underscore template, + * compile the template, and then return it. + * + * @returns {string} + */ + getHtml: function() { + var data = this.shortcode.attrs.named, + model = wp.media[ this.shortcode.tag ], + type = 'playlist' === this.shortcode.tag ? 'audio' : 'video', + options, + attachments, + tracks = []; + + if ( ! this.attachments.length ) { + return; + } + + _.each( model.defaults, function( value, key ) { + data[ key ] = model.coerce( data, key ); + }); + + attachments = this.attachments.toJSON(); + + options = { + type: type, + style: data.style, + tracklist: data.tracklist, + tracknumbers: data.tracknumbers, + images: data.images, + artists: data.artists + }; + + _.each( attachments, function( attachment ) { + var size = {}, resize = {}, track = { + src : attachment.url, + type : attachment.mime, + title : attachment.title, + caption : attachment.caption, + description : attachment.description, + meta : attachment.meta + }; + + if ( 'video' === type ) { + size.width = attachment.width; + size.height = attachment.height; + if ( media.view.settings.contentWidth ) { + resize.width = media.view.settings.contentWidth - 22; + resize.height = Math.ceil( ( size.height * resize.width ) / size.width ); + if ( ! options.width ) { + options.width = resize.width; + options.height = resize.height; + } + } else { + if ( ! options.width ) { + options.width = attachment.width; + options.height = attachment.height; + } + } + track.dimensions = { + original : size, + resized : _.isEmpty( resize ) ? size : resize + }; + } else { + options.width = 400; + } + + track.image = attachment.image; + track.thumb = attachment.thumb; + + tracks.push( track ); + } ); + + options.tracks = tracks; + this.data = options; + + return this.template( options ); + } + }); + _.extend( wp.mce.media.PlaylistView.prototype, wp.media.mixin ); + + /** + * TinyMCE handler for the playlist shortcode + * + * @mixes wp.mce.media + */ + wp.mce.playlist = _.extend( {}, wp.mce.media, { + shortcode: 'playlist', + state: 'playlist-edit', + View: wp.mce.media.PlaylistView + } ); + wp.mce.views.register( 'playlist', wp.mce.playlist ); + + /** + * TinyMCE handler for the video-playlist shortcode + * + * @mixes wp.mce.media + */ + wp.mce['video-playlist'] = _.extend( {}, wp.mce.media, { + shortcode: 'video-playlist', + state: 'video-playlist-edit', + View: wp.mce.media.PlaylistView + } ); + wp.mce.views.register( 'video-playlist', wp.mce['video-playlist'] ); }(jQuery)); diff --git a/wp-includes/js/mce-view.min.js b/wp-includes/js/mce-view.min.js index 92d42a172b..246c6b8632 100644 --- a/wp-includes/js/mce-view.min.js +++ b/wp-includes/js/mce-view.min.js @@ -1 +1 @@ -window.wp=window.wp||{},function(a){var b={},c={},d=wp.media,e=["encodedText"];wp.mce=wp.mce||{},wp.mce.View=function(a){a||(a={}),_.extend(this,_.pick(a,e)),this.initialize.apply(this,arguments)},_.extend(wp.mce.View.prototype,{initialize:function(){},html:function(){},render:function(){var b=this.getHtml();_.each(tinymce.editors,function(c){var d,e=this;c.plugins.wpview&&(d=c.getDoc(),a(d).find('[data-wpview-text="'+this.encodedText+'"]').each(function(c,d){var f=a(d);f.html(b),a(e).trigger("ready",d)}))},this)}}),wp.mce.View.extend=Backbone.View.extend,wp.mce.views={register:function(a,c){b[a]=c},get:function(a){return b[a]},unregister:function(a){delete b[a]},toViews:function(a){var c,d=[{content:a}];return _.each(b,function(a,b){c=d.slice(),d=[],_.each(c,function(c){var e,f=c.content;if(c.processed)return void d.push(c);for(;f&&(e=a.toView(f));)e.index&&d.push({content:f.substring(0,e.index)}),d.push({content:wp.mce.views.toView(b,e.content,e.options),processed:!0}),f=f.slice(e.index+e.content.length);f&&d.push({content:f})})}),_.pluck(d,"content").join("")},toView:function(a,b,d){var e,f,g=wp.mce.views.get(a),h=window.encodeURIComponent(b);return g?(wp.mce.views.getInstance(h)||(f=d,f.encodedText=h,e=new g.View(f),c[h]=e),wp.html.string({tag:"div",attrs:{"class":"wpview-wrap wpview-type-"+a,"data-wpview-text":h,"data-wpview-type":a,contenteditable:"false"},content:" "})):b},refreshView:function(a,b){var d,e,f,g=window.encodeURIComponent(b);f=wp.mce.views.getInstance(g),f||(e=a.toView(b),d=e.options,d.encodedText=g,f=new a.View(d),c[g]=f),wp.mce.views.render()},getInstance:function(a){return c[a]},render:function(){_.each(c,function(a){a.render()})},edit:function(b){var c=a(b).data("wpview-type"),d=wp.mce.views.get(c);d&&d.edit(b)}},wp.mce.gallery={shortcode:"gallery",toView:function(a){var b=wp.shortcode.next(this.shortcode,a);if(b)return{index:b.index,content:b.content,options:{shortcode:b.shortcode}}},View:wp.mce.View.extend({className:"editor-gallery",template:d.template("editor-gallery"),postID:a("#post_ID").val(),initialize:function(a){this.shortcode=a.shortcode,this.fetch()},fetch:function(){this.attachments=wp.media.gallery.attachments(this.shortcode,this.postID),this.attachments.more().done(_.bind(this.render,this))},getHtml:function(){var a,b,c=this.shortcode.attrs.named;if(this.attachments.length)return b=this.attachments.toJSON(),_.each(b,function(a){a.thumbnail=a.sizes.thumbnail?a.sizes.thumbnail:a.sizes.full}),a={attachments:b,columns:c.columns?parseInt(c.columns,10):3},this.template(a)}}),edit:function(b){var c,d,e=wp.media.gallery,f=this;d=window.decodeURIComponent(a(b).attr("data-wpview-text")),c=e.edit(d),c.state("gallery-edit").on("update",function(d){var g=e.shortcode(d).string();a(b).attr("data-wpview-text",window.encodeURIComponent(g)),wp.mce.views.refreshView(f,g),c.detach()})}},wp.mce.views.register("gallery",wp.mce.gallery)}(jQuery); \ No newline at end of file +window.wp=window.wp||{},function(a){var b={},c={},d=wp.media,e=["encodedText"];wp.mce=wp.mce||{},wp.mce.View=function(a){a||(a={}),_.extend(this,_.pick(a,e)),this.initialize.apply(this,arguments)},_.extend(wp.mce.View.prototype,{initialize:function(){},html:function(){},render:function(){var b=this.getHtml();_.each(tinymce.editors,function(c){var d,e=this;c.plugins.wpview&&(d=c.getDoc(),a(d).find('[data-wpview-text="'+this.encodedText+'"]').each(function(c,d){var f=a(d);f.html(b),a(e).trigger("ready",d)}))},this)}}),wp.mce.View.extend=Backbone.View.extend,wp.mce.views={register:function(a,c){b[a]=c},get:function(a){return b[a]},unregister:function(a){delete b[a]},toViews:function(a){var c,d=[{content:a}];return _.each(b,function(a,b){c=d.slice(),d=[],_.each(c,function(c){var e,f=c.content;if(c.processed)return void d.push(c);for(;f&&(e=a.toView(f));)e.index&&d.push({content:f.substring(0,e.index)}),d.push({content:wp.mce.views.toView(b,e.content,e.options),processed:!0}),f=f.slice(e.index+e.content.length);f&&d.push({content:f})})}),_.pluck(d,"content").join("")},toView:function(a,b,d){var e,f,g=wp.mce.views.get(a),h=window.encodeURIComponent(b);return g?(wp.mce.views.getInstance(h)||(f=d,f.encodedText=h,e=new g.View(f),c[h]=e),wp.html.string({tag:"div",attrs:{"class":"wpview-wrap wpview-type-"+a,"data-wpview-text":h,"data-wpview-type":a,contenteditable:"false"},content:" "})):b},refreshView:function(a,b){var d,e,f,g=window.encodeURIComponent(b);f=wp.mce.views.getInstance(g),f||(e=a.toView(b),d=e.options,d.encodedText=g,f=new a.View(d),c[g]=f),wp.mce.views.render()},getInstance:function(a){return c[a]},render:function(){_.each(c,function(a){a.render()})},edit:function(b){var c=a(b).data("wpview-type"),d=wp.mce.views.get(c);d&&d.edit(b)}},wp.mce.gallery={shortcode:"gallery",toView:function(a){var b=wp.shortcode.next(this.shortcode,a);if(b)return{index:b.index,content:b.content,options:{shortcode:b.shortcode}}},View:wp.mce.View.extend({className:"editor-gallery",template:d.template("editor-gallery"),postID:a("#post_ID").val(),initialize:function(a){this.shortcode=a.shortcode,this.fetch()},fetch:function(){this.attachments=wp.media.gallery.attachments(this.shortcode,this.postID),this.attachments.more().done(_.bind(this.render,this))},getHtml:function(){var a,b,c=this.shortcode.attrs.named;if(this.attachments.length)return b=this.attachments.toJSON(),_.each(b,function(a){a.thumbnail=a.sizes.thumbnail?a.sizes.thumbnail:a.sizes.full}),a={attachments:b,columns:c.columns?parseInt(c.columns,10):3},this.template(a)}}),edit:function(b){var c,d,e=wp.media.gallery,f=this;d=window.decodeURIComponent(a(b).attr("data-wpview-text")),c=e.edit(d),c.state("gallery-edit").on("update",function(d){var g=e.shortcode(d).string();a(b).attr("data-wpview-text",window.encodeURIComponent(g)),wp.mce.views.refreshView(f,g),c.detach()})}},wp.mce.views.register("gallery",wp.mce.gallery),wp.mce.media={toView:function(a){var b=wp.shortcode.next(this.shortcode,a);if(b)return{index:b.index,content:b.content,options:{shortcode:b.shortcode}}},edit:function(b){var c,d,e=wp.media[this.shortcode],f=this;wp.media.mixin.pauseAllPlayers(),d=window.decodeURIComponent(a(b).attr("data-wpview-text")),c=e.edit(d),c.on("close",function(){c.detach()}),c.state(f.state).on("update",function(d){var e=wp.media[f.shortcode].shortcode(d).string();a(b).attr("data-wpview-text",window.encodeURIComponent(e)),wp.mce.views.refreshView(f,e),c.detach()}),c.open()}},wp.mce.media.View=wp.mce.View.extend({initialize:function(b){this.shortcode=b.shortcode,_.bindAll(this,"setPlayer"),a(this).on("ready",this.setPlayer)},setPlayer:function(b,c){if(c){var d,e=this,f=this.ua.is("ff"),g=".wp-"+this.shortcode.tag+"-shortcode";if(this.player&&this.unsetPlayer(),d=a(c).find(g),!this.isCompatible(d))return d.closest(".wpview-wrap").addClass("wont-play"),d.parent().hasClass("wpview-wrap")||d.parent().replaceWith(d),void d.replaceWith("

"+d.find("source").eq(0).prop("src")+"

");d.closest(".wpview-wrap").removeClass("wont-play"),f?d.prop("preload","metadata"):d.prop("preload","none"),d=wp.media.view.MediaDetails.prepareSrc(d.get(0)),f?setTimeout(function(){e.player=new MediaElementPlayer(d,this.mejsSettings)},50):this.player=new MediaElementPlayer(d,this.mejsSettings)}},getHtml:function(){var a=_.defaults(this.shortcode.attrs.named,wp.media[this.shortcode.tag].defaults);return this.template({model:a})}}),_.extend(wp.mce.media.View.prototype,wp.media.mixin),wp.mce.video=_.extend({},wp.mce.media,{shortcode:"video",state:"video-details",View:wp.mce.media.View.extend({className:"editor-video",template:d.template("editor-video")})}),wp.mce.views.register("video",wp.mce.video),wp.mce.audio=_.extend({},wp.mce.media,{shortcode:"audio",state:"audio-details",View:wp.mce.media.View.extend({className:"editor-audio",template:d.template("editor-audio")})}),wp.mce.views.register("audio",wp.mce.audio),wp.mce.media.PlaylistView=wp.mce.View.extend({className:"editor-playlist",template:d.template("editor-playlist"),initialize:function(b){this.data={},this.attachments=[],this.shortcode=b.shortcode,_.bindAll(this,"setPlayer"),a(this).on("ready",this.setNode)},setNode:function(a,b){this.node=b,this.fetch()},fetch:function(){this.attachments=wp.media[this.shortcode.tag].attachments(this.shortcode),this.attachments.more().done(this.setPlayer)},setPlayer:function(){var b,c=this.getHtml(),d=this.encodedText,e=this;this.unsetPlayer(),_.each(tinymce.editors,function(b){var f;b.plugins.wpview&&(f=b.getDoc(),a(f).find('[data-wpview-text="'+d+'"]').each(function(b,d){var f=a(d);f.html(c),e.node=d}))},this),b=new WPPlaylistView({el:a(e.node).find(".wp-playlist").get(0),metadata:this.data}),this.player=b._player},getHtml:function(){var a,b,c=this.shortcode.attrs.named,e=wp.media[this.shortcode.tag],f="playlist"===this.shortcode.tag?"audio":"video",g=[];if(this.attachments.length)return _.each(e.defaults,function(a,b){c[b]=e.coerce(c,b)}),b=this.attachments.toJSON(),a={type:f,style:c.style,tracklist:c.tracklist,tracknumbers:c.tracknumbers,images:c.images,artists:c.artists},_.each(b,function(b){var c={},e={},h={src:b.url,type:b.mime,title:b.title,caption:b.caption,description:b.description,meta:b.meta};"video"===f?(c.width=b.width,c.height=b.height,d.view.settings.contentWidth?(e.width=d.view.settings.contentWidth-22,e.height=Math.ceil(c.height*e.width/c.width),a.width||(a.width=e.width,a.height=e.height)):a.width||(a.width=b.width,a.height=b.height),h.dimensions={original:c,resized:_.isEmpty(e)?c:e}):a.width=400,h.image=b.image,h.thumb=b.thumb,g.push(h)}),a.tracks=g,this.data=a,this.template(a)}}),_.extend(wp.mce.media.PlaylistView.prototype,wp.media.mixin),wp.mce.playlist=_.extend({},wp.mce.media,{shortcode:"playlist",state:"playlist-edit",View:wp.mce.media.PlaylistView}),wp.mce.views.register("playlist",wp.mce.playlist),wp.mce["video-playlist"]=_.extend({},wp.mce.media,{shortcode:"video-playlist",state:"video-playlist-edit",View:wp.mce.media.PlaylistView}),wp.mce.views.register("video-playlist",wp.mce["video-playlist"])}(jQuery); \ No newline at end of file diff --git a/wp-includes/js/media-audiovideo.js b/wp-includes/js/media-audiovideo.js index 0249851099..c07ffd78bf 100644 --- a/wp-includes/js/media-audiovideo.js +++ b/wp-includes/js/media-audiovideo.js @@ -13,7 +13,7 @@ * @mixin */ wp.media.mixin = { - + mejsSettings: baseSettings, /** * Pauses every instance of MediaElementPlayer */ @@ -217,7 +217,8 @@ loop : false, autoplay : false, preload : 'none', - caption : '' + caption : '', + width : 400 }, edit : function( data ) { @@ -1044,364 +1045,6 @@ } } ); - /** - * Tiny MCE Views - * - */ - - /** - * These are base methods that are shared by each shortcode's MCE controller - * - * @mixin - */ - wp.mce.media = { - /** - * @global wp.shortcode - * - * @param {string} content - * @returns {Object} - */ - toView: function( content ) { - var match = wp.shortcode.next( this.shortcode, content ); - - if ( ! match ) { - return; - } - - return { - index: match.index, - content: match.content, - options: { - shortcode: match.shortcode - } - }; - }, - - /** - * Called when a TinyMCE view is clicked for editing. - * - Parses the shortcode out of the element's data attribute - * - Calls the `edit` method on the shortcode model - * - Launches the model window - * - Bind's an `update` callback which updates the element's data attribute - * re-renders the view - * - * @param {HTMLElement} node - */ - edit: function( node ) { - var media = wp.media[ this.shortcode ], - self = this, - frame, data; - - wp.media.mixin.pauseAllPlayers(); - - data = window.decodeURIComponent( $( node ).attr('data-wpview-text') ); - frame = media.edit( data ); - frame.on( 'close', function() { - frame.detach(); - } ); - frame.state( self.state ).on( 'update', function( selection ) { - var shortcode = wp.media[ self.shortcode ].shortcode( selection ).string(); - $( node ).attr( 'data-wpview-text', window.encodeURIComponent( shortcode ) ); - wp.mce.views.refreshView( self, shortcode ); - frame.detach(); - } ); - frame.open(); - } - }; - - /** - * Base View class for audio and video shortcodes - * - * @constructor - * @augments wp.mce.View - * @mixes wp.media.mixin - */ - wp.mce.media.View = wp.mce.View.extend({ - initialize: function( options ) { - this.shortcode = options.shortcode; - _.bindAll( this, 'setPlayer' ); - $(this).on( 'ready', this.setPlayer ); - }, - - /** - * Creates the player instance for the current node - * - * @global MediaElementPlayer - * @global _wpmejsSettings - * - * @param {Event} e - * @param {HTMLElement} node - */ - setPlayer: function(e, node) { - // if the ready event fires on an empty node - if ( ! node ) { - return; - } - - var self = this, - media, - firefox = this.ua.is( 'ff' ), - className = '.wp-' + this.shortcode.tag + '-shortcode'; - - if ( this.player ) { - this.unsetPlayer(); - } - - media = $( node ).find( className ); - - if ( ! this.isCompatible( media ) ) { - media.closest( '.wpview-wrap' ).addClass( 'wont-play' ); - if ( ! media.parent().hasClass( 'wpview-wrap' ) ) { - media.parent().replaceWith( media ); - } - media.replaceWith( '

' + media.find( 'source' ).eq(0).prop( 'src' ) + '

' ); - return; - } else { - media.closest( '.wpview-wrap' ).removeClass( 'wont-play' ); - if ( firefox ) { - media.prop( 'preload', 'metadata' ); - } else { - media.prop( 'preload', 'none' ); - } - } - - media = wp.media.view.MediaDetails.prepareSrc( media.get(0) ); - - // Thanks, Firefox! - if ( firefox ) { - setTimeout( function() { - self.player = new MediaElementPlayer( media, baseSettings ); - }, 50 ); - } else { - this.player = new MediaElementPlayer( media, baseSettings ); - } - }, - - /** - * Pass data to the View's Underscore template and return the compiled output - * - * @returns {string} - */ - getHtml: function() { - var attrs = _.defaults( - this.shortcode.attrs.named, - wp.media[ this.shortcode.tag ].defaults - ); - return this.template({ model: attrs }); - } - }); - _.extend( wp.mce.media.View.prototype, wp.media.mixin ); - - /** - * TinyMCE handler for the video shortcode - * - * @mixes wp.mce.media - */ - wp.mce.video = _.extend( {}, wp.mce.media, { - shortcode: 'video', - state: 'video-details', - View: wp.mce.media.View.extend({ - className: 'editor-video', - template: media.template('editor-video') - }) - } ); - wp.mce.views.register( 'video', wp.mce.video ); - - /** - * TinyMCE handler for the audio shortcode - * - * @mixes wp.mce.media - */ - wp.mce.audio = _.extend( {}, wp.mce.media, { - shortcode: 'audio', - state: 'audio-details', - View: wp.mce.media.View.extend({ - className: 'editor-audio', - template: media.template('editor-audio') - }) - } ); - wp.mce.views.register( 'audio', wp.mce.audio ); - - /** - * Base View class for playlist shortcodes - * - * @constructor - * @augments wp.mce.View - * @mixes wp.media.mixin - */ - wp.mce.media.PlaylistView = wp.mce.View.extend({ - className: 'editor-playlist', - template: media.template('editor-playlist'), - - initialize: function( options ) { - this.data = {}; - this.attachments = []; - this.shortcode = options.shortcode; - _.bindAll( this, 'setPlayer' ); - $(this).on('ready', this.setNode); - }, - - /** - * Set the element context for the view, and then fetch the playlist's - * associated attachments. - * - * @param {Event} e - * @param {HTMLElement} node - */ - setNode: function(e, node) { - this.node = node; - this.fetch(); - }, - - /** - * Asynchronously fetch the shortcode's attachments - */ - fetch: function() { - this.attachments = wp.media[ this.shortcode.tag ].attachments( this.shortcode ); - this.attachments.more().done( this.setPlayer ); - }, - - /** - * Get the HTML for the view (which also set's the data), replace the - * current HTML, and then invoke the WPPlaylistView instance to render - * the playlist in the editor - * - * @global WPPlaylistView - * @global tinymce.editors - */ - setPlayer: function() { - var p, - html = this.getHtml(), - t = this.encodedText, - self = this; - - this.unsetPlayer(); - - _.each( tinymce.editors, function( editor ) { - var doc; - if ( editor.plugins.wpview ) { - doc = editor.getDoc(); - $( doc ).find( '[data-wpview-text="' + t + '"]' ).each(function(i, elem) { - var node = $( elem ); - node.html( html ); - self.node = elem; - }); - } - }, this ); - - p = new WPPlaylistView({ - el: $( self.node ).find( '.wp-playlist' ).get(0), - metadata: this.data - }); - - this.player = p._player; - }, - - /** - * Set the data that will be used to compile the Underscore template, - * compile the template, and then return it. - * - * @returns {string} - */ - getHtml: function() { - var data = this.shortcode.attrs.named, - model = wp.media[ this.shortcode.tag ], - type = 'playlist' === this.shortcode.tag ? 'audio' : 'video', - options, - attachments, - tracks = []; - - if ( ! this.attachments.length ) { - return; - } - - _.each( model.defaults, function( value, key ) { - data[ key ] = model.coerce( data, key ); - }); - - attachments = this.attachments.toJSON(); - - options = { - type: type, - style: data.style, - tracklist: data.tracklist, - tracknumbers: data.tracknumbers, - images: data.images, - artists: data.artists - }; - - _.each( attachments, function( attachment ) { - var size = {}, resize = {}, track = { - src : attachment.url, - type : attachment.mime, - title : attachment.title, - caption : attachment.caption, - description : attachment.description, - meta : attachment.meta - }; - - if ( 'video' === type ) { - size.width = attachment.width; - size.height = attachment.height; - if ( media.view.settings.contentWidth ) { - resize.width = media.view.settings.contentWidth - 22; - resize.height = Math.ceil( ( size.height * resize.width ) / size.width ); - if ( ! options.width ) { - options.width = resize.width; - options.height = resize.height; - } - } else { - if ( ! options.width ) { - options.width = attachment.width; - options.height = attachment.height; - } - } - track.dimensions = { - original : size, - resized : _.isEmpty( resize ) ? size : resize - }; - } else { - options.width = 400; - } - - track.image = attachment.image; - track.thumb = attachment.thumb; - - tracks.push( track ); - } ); - - options.tracks = tracks; - this.data = options; - - return this.template( options ); - } - }); - _.extend( wp.mce.media.PlaylistView.prototype, wp.media.mixin ); - - /** - * TinyMCE handler for the playlist shortcode - * - * @mixes wp.mce.media - */ - wp.mce.playlist = _.extend( {}, wp.mce.media, { - shortcode: 'playlist', - state: 'playlist-edit', - View: wp.mce.media.PlaylistView - } ); - wp.mce.views.register( 'playlist', wp.mce.playlist ); - - /** - * TinyMCE handler for the video-playlist shortcode - * - * @mixes wp.mce.media - */ - wp.mce['video-playlist'] = _.extend( {}, wp.mce.media, { - shortcode: 'video-playlist', - state: 'video-playlist-edit', - View: wp.mce.media.PlaylistView - } ); - wp.mce.views.register( 'video-playlist', wp.mce['video-playlist'] ); - /** * Event binding */ diff --git a/wp-includes/js/media-audiovideo.min.js b/wp-includes/js/media-audiovideo.min.js index 5eeb81509c..ae307735df 100644 --- a/wp-includes/js/media-audiovideo.min.js +++ b/wp-includes/js/media-audiovideo.min.js @@ -1 +1 @@ -!function(a,b,c){function d(){a(document.body).on("click",".wp-switch-editor",wp.media.mixin.pauseAllPlayers).on("click",".add-media-source",function(b){e.frame.lastMime=a(b.currentTarget).data("mime"),e.frame.setState("add-"+e.frame.defaults.id+"-source")})}var e=wp.media,f={},g="undefined"==typeof _wpMediaViewsL10n?{}:_wpMediaViewsL10n;b.isUndefined(window._wpmejsSettings)||(f.pluginPath=_wpmejsSettings.pluginPath),wp.media.mixin={pauseAllPlayers:function(){var a;if(window.mejs&&window.mejs.players)for(a in window.mejs.players)window.mejs.players[a].pause()},ua:{is:function(a){var b=!1,c=window.navigator.userAgent;switch(a){case"oldie":b=null!==c.match(/MSIE [6-8]/gi);break;case"ie":b=null!==c.match(/MSIE/gi);break;case"ff":b=null!==c.match(/firefox/gi);break;case"opera":b=null!==c.match(/OPR/);break;case"safari":b=null!==c.match(/safari/gi)&&null===c.match(/chrome/gi);break;case"chrome":b=null!==c.match(/safari/gi)&&null!==c.match(/chrome/gi)}return b}},compat:{opera:{audio:["ogg","wav"],video:["ogg","webm"]},chrome:{audio:["ogg","mpeg"],video:["ogg","webm","mp4","m4v","mpeg"]},ff:{audio:["ogg","mpeg"],video:["ogg","webm"]},safari:{audio:["mpeg","wav"],video:["mp4","m4v","mpeg","x-ms-wmv","quicktime"]},ie:{audio:["mpeg"],video:["mp4","m4v","mpeg"]}},isCompatible:function(a){if(!a.find("source").length)return!1;var c,d=this.ua,e=!1,f=!1;return d.is("oldIE")?!1:(c=a.find("source"),b.find(this.compat,function(a,g){return d.is(g)&&(f=!0,b.each(c,function(b){var c=new RegExp("audio/("+a.audio.join("|")+")","gi"),d=new RegExp("video/("+a.video.join("|")+")","gi");(null!==b.type.match(d)||null!==b.type.match(c))&&(e=!0)})),e||f}),e)},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.playlist=new wp.media.collection({tag:"playlist",type:"audio",editTitle:g.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:g.editVideoPlaylistTitle,defaults:{id:wp.media.view.settings.post.id,style:"light",tracklist:!1,tracknumbers:!1,images:!0}}),wp.media.audio={coerce:wp.media.coerce,defaults:{id:wp.media.view.settings.post.id,src:"",loop:!1,autoplay:!1,preload:"none",caption:""},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,this.defaults)})},shortcode:function(a){var c,d=this;return b.each(this.defaults,function(b,c){a[c]=d.coerce(a,c),b===a[c]&&delete a[c]}),c=a.content,delete a.content,new wp.shortcode({tag:"audio",attrs:a,content:c})}},wp.media.video={coerce:wp.media.coerce,defaults:{id:wp.media.view.settings.post.id,src:"",poster:"",loop:!1,autoplay:!1,preload:"metadata",content:"",caption:"",width:640,height:360},edit:function(a){var c,d,e=wp.shortcode.next("video",a).shortcode;return d=e.attrs.named,d.content=e.content,c=wp.media({frame:"video",state:"video-details",metadata:b.defaults(d,this.defaults)})},shortcode:function(a){var c,d=this;return b.each(this.defaults,function(b,c){a[c]=d.coerce(a,c),b===a[c]&&delete a[c]}),c=a.content,delete a.content,new wp.shortcode({tag:"video",attrs:a,content:c})}},e.model.PostMedia=c.Model.extend({initialize:function(){this.attachment=!1},setSource:function(a){this.attachment=a,this.extension=a.get("filename").split(".").pop(),this.get("src")&&this.extension===this.get("src").split(".").pop()&&this.unset("src"),b.contains(wp.media.view.settings.embedExts,this.extension)?this.set(this.extension,this.attachment.get("url")):this.unset(this.extension)},changeAttachment:function(a){var c=this;this.setSource(a),this.unset("src"),b.each(b.without(wp.media.view.settings.embedExts,this.extension),function(a){c.unset(a)})}}),e.controller.AudioDetails=e.controller.State.extend({defaults:{id:"audio-details",toolbar:"audio-details",title:g.audioDetailsTitle,content:"audio-details",menu:"audio-details",router:!1,priority:60},initialize:function(a){this.media=a.media,e.controller.State.prototype.initialize.apply(this,arguments)}}),e.controller.VideoDetails=e.controller.State.extend({defaults:{id:"video-details",toolbar:"video-details",title:g.videoDetailsTitle,content:"video-details",menu:"video-details",router:!1,priority:60},initialize:function(a){this.media=a.media,e.controller.State.prototype.initialize.apply(this,arguments)}}),e.view.MediaFrame.MediaDetails=e.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 e.model.PostMedia(a.metadata),this.options.selection=new e.model.Selection(this.media.attachment,{multiple:!1}),e.view.MediaFrame.Select.prototype.initialize.apply(this,arguments)},bindHandlers:function(){var a=this.defaults.menu;e.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,d=this;a.set({cancel:{text:this.cancelText,priority:20,click:function(){c?d.setState(c):d.close()}},separateCancel:new e.View({className:"separator",priority:40})})},setPrimaryButton:function(a,b){this.toolbar.set(new e.view.Toolbar({controller:this,items:{button:{style:"primary",text:a,priority:80,click:function(){var a=this.controller;b.call(this,a,a.state()),a.setState(a.options.state),a.reset()}}}}))},renderDetailsToolbar:function(){this.setPrimaryButton(g.update,function(a,b){a.close(),b.trigger("update",a.media.toJSON())})},renderReplaceToolbar:function(){this.setPrimaryButton(g.replace,function(a,b){var c=b.get("selection").single();a.media.changeAttachment(c),b.trigger("replace",a.media.toJSON())})},renderAddSourceToolbar:function(){this.setPrimaryButton(this.addText,function(a,b){var c=b.get("selection").single();a.media.setSource(c),b.trigger("add-source",a.media.toJSON())})}}),e.view.MediaFrame.AudioDetails=e.view.MediaFrame.MediaDetails.extend({defaults:{id:"audio",url:"",menu:"audio-details",content:"audio-details",toolbar:"audio-details",type:"link",title:g.audioDetailsTitle,priority:120},initialize:function(a){a.DetailsView=e.view.AudioDetails,a.cancelText=g.audioDetailsCancel,a.addText=g.audioAddSourceTitle,e.view.MediaFrame.MediaDetails.prototype.initialize.call(this,a)},bindHandlers:function(){e.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 e.controller.AudioDetails({media:this.media}),new e.controller.MediaLibrary({type:"audio",id:"replace-audio",title:g.audioReplaceTitle,toolbar:"replace-audio",media:this.media,menu:"audio-details"}),new e.controller.MediaLibrary({type:"audio",id:"add-audio-source",title:g.audioAddSourceTitle,toolbar:"add-audio-source",media:this.media,menu:!1})])}}),e.view.MediaFrame.VideoDetails=e.view.MediaFrame.MediaDetails.extend({defaults:{id:"video",url:"",menu:"video-details",content:"video-details",toolbar:"video-details",type:"link",title:g.videoDetailsTitle,priority:120},initialize:function(a){a.DetailsView=e.view.VideoDetails,a.cancelText=g.videoDetailsCancel,a.addText=g.videoAddSourceTitle,e.view.MediaFrame.MediaDetails.prototype.initialize.call(this,a)},bindHandlers:function(){e.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),this.on("toolbar:render:add-track",this.renderAddTrackToolbar,this)},createStates:function(){this.states.add([new e.controller.VideoDetails({media:this.media}),new e.controller.MediaLibrary({type:"video",id:"replace-video",title:g.videoReplaceTitle,toolbar:"replace-video",media:this.media,menu:"video-details"}),new e.controller.MediaLibrary({type:"video",id:"add-video-source",title:g.videoAddSourceTitle,toolbar:"add-video-source",media:this.media,menu:!1}),new e.controller.MediaLibrary({type:"image",id:"select-poster-image",title:g.videoSelectPosterImageTitle,toolbar:"select-poster-image",media:this.media,menu:"video-details"}),new e.controller.MediaLibrary({type:"text",id:"add-track",title:g.videoAddTrackTitle,toolbar:"add-track",media:this.media,menu:"video-details"})])},renderSelectPosterImageToolbar:function(){this.setPrimaryButton(g.videoSelectPosterImageTitle,function(a,b){var c=b.get("selection").single();a.media.set("poster",c.get("url")),b.trigger("set-poster-image",a.media.toJSON())})},renderAddTrackToolbar:function(){this.setPrimaryButton(g.videoAddTrackTitle,function(a,b){var c=b.get("selection").single(),d=a.media.get("content");-1===d.indexOf(c.get("url"))&&(d+=[''].join(""),a.media.set("content",d)),b.trigger("add-track",a.media.toJSON())})}}),e.view.MediaDetails=e.view.Settings.AttachmentDisplay.extend({initialize:function(){b.bindAll(this,"success"),this.listenTo(this.controller,"close",e.mixin.unsetPlayer),this.on("ready",this.setPlayer),this.on("media:setting:remove",e.mixin.unsetPlayer,this),this.on("media:setting:remove",this.render),this.on("media:setting:remove",this.setPlayer),this.events=b.extend(this.events,{"click .remove-setting":"removeSetting","change .content-track":"setTracks","click .remove-track":"setTracks"}),e.view.Settings.AttachmentDisplay.prototype.initialize.apply(this,arguments)},prepare:function(){return b.defaults({model:this.model.toJSON()},this.options)},removeSetting:function(b){var c,d=a(b.currentTarget).parent();c=d.find("input").data("setting"),c&&(this.model.unset(c),this.trigger("media:setting:remove",this)),d.remove()},setTracks:function(){var c="";b.each(this.$(".content-track"),function(b){c+=a(b).val()}),this.model.set("content",c),this.trigger("media:setting:remove",this)},setPlayer:function(){!this.player&&this.media&&(this.player=new MediaElementPlayer(this.media,this.settings))},setMedia:function(){return this},success:function(a){var b=a.attributes.autoplay&&"false"!==a.attributes.autoplay;"flash"===a.pluginType&&b&&a.addEventListener("canplay",function(){a.play()},!1),this.mejs=a},render:function(){var a=this;return e.view.Settings.AttachmentDisplay.prototype.render.apply(this,arguments),setTimeout(function(){a.resetFocus()},10),this.settings=b.defaults({success:this.success},f),this.setMedia()},resetFocus:function(){this.$(".embed-media-settings").scrollTop(0)}},{instances:0,prepareSrc:function(c){var d=e.view.MediaDetails.instances++;return b.each(a(c).find("source"),function(a){a.src=[a.src,a.src.indexOf("?")>-1?"&":"?","_=",d].join("")}),c}}),e.view.AudioDetails=e.view.MediaDetails.extend({className:"audio-details",template:e.template("audio-details"),setMedia:function(){var a=this.$(".wp-audio-shortcode");return a.find("source").length?(a.is(":hidden")&&a.show(),this.media=e.view.MediaDetails.prepareSrc(a.get(0))):(a.hide(),this.media=!1),this}}),e.view.VideoDetails=e.view.MediaDetails.extend({className:"video-details",template:e.template("video-details"),setMedia:function(){var a=this.$(".wp-video-shortcode");return a.find("source").length?(a.is(":hidden")&&a.show(),this.media=a.hasClass("youtube-video")?a.get(0):e.view.MediaDetails.prepareSrc(a.get(0))):(a.hide(),this.media=!1),this}}),b.extend(wp.media.playlist,{counts:function(a){var c={};return function(){if(!b.isEmpty(c))return c;var d=0,e=0;return b.each(a.attachmentCounts,function(a,b){var c;if(-1"+d.find("source").eq(0).prop("src")+"

");d.closest(".wpview-wrap").removeClass("wont-play"),g?d.prop("preload","metadata"):d.prop("preload","none"),d=wp.media.view.MediaDetails.prepareSrc(d.get(0)),g?setTimeout(function(){e.player=new MediaElementPlayer(d,f)},50):this.player=new MediaElementPlayer(d,f)}},getHtml:function(){var a=b.defaults(this.shortcode.attrs.named,wp.media[this.shortcode.tag].defaults);return this.template({model:a})}}),b.extend(wp.mce.media.View.prototype,wp.media.mixin),wp.mce.video=b.extend({},wp.mce.media,{shortcode:"video",state:"video-details",View:wp.mce.media.View.extend({className:"editor-video",template:e.template("editor-video")})}),wp.mce.views.register("video",wp.mce.video),wp.mce.audio=b.extend({},wp.mce.media,{shortcode:"audio",state:"audio-details",View:wp.mce.media.View.extend({className:"editor-audio",template:e.template("editor-audio")})}),wp.mce.views.register("audio",wp.mce.audio),wp.mce.media.PlaylistView=wp.mce.View.extend({className:"editor-playlist",template:e.template("editor-playlist"),initialize:function(c){this.data={},this.attachments=[],this.shortcode=c.shortcode,b.bindAll(this,"setPlayer"),a(this).on("ready",this.setNode)},setNode:function(a,b){this.node=b,this.fetch()},fetch:function(){this.attachments=wp.media[this.shortcode.tag].attachments(this.shortcode),this.attachments.more().done(this.setPlayer)},setPlayer:function(){var c,d=this.getHtml(),e=this.encodedText,f=this;this.unsetPlayer(),b.each(tinymce.editors,function(b){var c;b.plugins.wpview&&(c=b.getDoc(),a(c).find('[data-wpview-text="'+e+'"]').each(function(b,c){var e=a(c);e.html(d),f.node=c}))},this),c=new WPPlaylistView({el:a(f.node).find(".wp-playlist").get(0),metadata:this.data}),this.player=c._player},getHtml:function(){var a,c,d=this.shortcode.attrs.named,f=wp.media[this.shortcode.tag],g="playlist"===this.shortcode.tag?"audio":"video",h=[];if(this.attachments.length)return b.each(f.defaults,function(a,b){d[b]=f.coerce(d,b)}),c=this.attachments.toJSON(),a={type:g,style:d.style,tracklist:d.tracklist,tracknumbers:d.tracknumbers,images:d.images,artists:d.artists},b.each(c,function(c){var d={},f={},i={src:c.url,type:c.mime,title:c.title,caption:c.caption,description:c.description,meta:c.meta};"video"===g?(d.width=c.width,d.height=c.height,e.view.settings.contentWidth?(f.width=e.view.settings.contentWidth-22,f.height=Math.ceil(d.height*f.width/d.width),a.width||(a.width=f.width,a.height=f.height)):a.width||(a.width=c.width,a.height=c.height),i.dimensions={original:d,resized:b.isEmpty(f)?d:f}):a.width=400,i.image=c.image,i.thumb=c.thumb,h.push(i)}),a.tracks=h,this.data=a,this.template(a)}}),b.extend(wp.mce.media.PlaylistView.prototype,wp.media.mixin),wp.mce.playlist=b.extend({},wp.mce.media,{shortcode:"playlist",state:"playlist-edit",View:wp.mce.media.PlaylistView}),wp.mce.views.register("playlist",wp.mce.playlist),wp.mce["video-playlist"]=b.extend({},wp.mce.media,{shortcode:"video-playlist",state:"video-playlist-edit",View:wp.mce.media.PlaylistView}),wp.mce.views.register("video-playlist",wp.mce["video-playlist"]),a(d)}(jQuery,_,Backbone); \ No newline at end of file +!function(a,b,c){function d(){a(document.body).on("click",".wp-switch-editor",wp.media.mixin.pauseAllPlayers).on("click",".add-media-source",function(b){e.frame.lastMime=a(b.currentTarget).data("mime"),e.frame.setState("add-"+e.frame.defaults.id+"-source")})}var e=wp.media,f={},g="undefined"==typeof _wpMediaViewsL10n?{}:_wpMediaViewsL10n;b.isUndefined(window._wpmejsSettings)||(f.pluginPath=_wpmejsSettings.pluginPath),wp.media.mixin={mejsSettings:f,pauseAllPlayers:function(){var a;if(window.mejs&&window.mejs.players)for(a in window.mejs.players)window.mejs.players[a].pause()},ua:{is:function(a){var b=!1,c=window.navigator.userAgent;switch(a){case"oldie":b=null!==c.match(/MSIE [6-8]/gi);break;case"ie":b=null!==c.match(/MSIE/gi);break;case"ff":b=null!==c.match(/firefox/gi);break;case"opera":b=null!==c.match(/OPR/);break;case"safari":b=null!==c.match(/safari/gi)&&null===c.match(/chrome/gi);break;case"chrome":b=null!==c.match(/safari/gi)&&null!==c.match(/chrome/gi)}return b}},compat:{opera:{audio:["ogg","wav"],video:["ogg","webm"]},chrome:{audio:["ogg","mpeg"],video:["ogg","webm","mp4","m4v","mpeg"]},ff:{audio:["ogg","mpeg"],video:["ogg","webm"]},safari:{audio:["mpeg","wav"],video:["mp4","m4v","mpeg","x-ms-wmv","quicktime"]},ie:{audio:["mpeg"],video:["mp4","m4v","mpeg"]}},isCompatible:function(a){if(!a.find("source").length)return!1;var c,d=this.ua,e=!1,f=!1;return d.is("oldIE")?!1:(c=a.find("source"),b.find(this.compat,function(a,g){return d.is(g)&&(f=!0,b.each(c,function(b){var c=new RegExp("audio/("+a.audio.join("|")+")","gi"),d=new RegExp("video/("+a.video.join("|")+")","gi");(null!==b.type.match(d)||null!==b.type.match(c))&&(e=!0)})),e||f}),e)},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.playlist=new wp.media.collection({tag:"playlist",type:"audio",editTitle:g.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:g.editVideoPlaylistTitle,defaults:{id:wp.media.view.settings.post.id,style:"light",tracklist:!1,tracknumbers:!1,images:!0}}),wp.media.audio={coerce:wp.media.coerce,defaults:{id:wp.media.view.settings.post.id,src:"",loop:!1,autoplay:!1,preload:"none",caption:"",width:400},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,this.defaults)})},shortcode:function(a){var c,d=this;return b.each(this.defaults,function(b,c){a[c]=d.coerce(a,c),b===a[c]&&delete a[c]}),c=a.content,delete a.content,new wp.shortcode({tag:"audio",attrs:a,content:c})}},wp.media.video={coerce:wp.media.coerce,defaults:{id:wp.media.view.settings.post.id,src:"",poster:"",loop:!1,autoplay:!1,preload:"metadata",content:"",caption:"",width:640,height:360},edit:function(a){var c,d,e=wp.shortcode.next("video",a).shortcode;return d=e.attrs.named,d.content=e.content,c=wp.media({frame:"video",state:"video-details",metadata:b.defaults(d,this.defaults)})},shortcode:function(a){var c,d=this;return b.each(this.defaults,function(b,c){a[c]=d.coerce(a,c),b===a[c]&&delete a[c]}),c=a.content,delete a.content,new wp.shortcode({tag:"video",attrs:a,content:c})}},e.model.PostMedia=c.Model.extend({initialize:function(){this.attachment=!1},setSource:function(a){this.attachment=a,this.extension=a.get("filename").split(".").pop(),this.get("src")&&this.extension===this.get("src").split(".").pop()&&this.unset("src"),b.contains(wp.media.view.settings.embedExts,this.extension)?this.set(this.extension,this.attachment.get("url")):this.unset(this.extension)},changeAttachment:function(a){var c=this;this.setSource(a),this.unset("src"),b.each(b.without(wp.media.view.settings.embedExts,this.extension),function(a){c.unset(a)})}}),e.controller.AudioDetails=e.controller.State.extend({defaults:{id:"audio-details",toolbar:"audio-details",title:g.audioDetailsTitle,content:"audio-details",menu:"audio-details",router:!1,priority:60},initialize:function(a){this.media=a.media,e.controller.State.prototype.initialize.apply(this,arguments)}}),e.controller.VideoDetails=e.controller.State.extend({defaults:{id:"video-details",toolbar:"video-details",title:g.videoDetailsTitle,content:"video-details",menu:"video-details",router:!1,priority:60},initialize:function(a){this.media=a.media,e.controller.State.prototype.initialize.apply(this,arguments)}}),e.view.MediaFrame.MediaDetails=e.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 e.model.PostMedia(a.metadata),this.options.selection=new e.model.Selection(this.media.attachment,{multiple:!1}),e.view.MediaFrame.Select.prototype.initialize.apply(this,arguments)},bindHandlers:function(){var a=this.defaults.menu;e.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,d=this;a.set({cancel:{text:this.cancelText,priority:20,click:function(){c?d.setState(c):d.close()}},separateCancel:new e.View({className:"separator",priority:40})})},setPrimaryButton:function(a,b){this.toolbar.set(new e.view.Toolbar({controller:this,items:{button:{style:"primary",text:a,priority:80,click:function(){var a=this.controller;b.call(this,a,a.state()),a.setState(a.options.state),a.reset()}}}}))},renderDetailsToolbar:function(){this.setPrimaryButton(g.update,function(a,b){a.close(),b.trigger("update",a.media.toJSON())})},renderReplaceToolbar:function(){this.setPrimaryButton(g.replace,function(a,b){var c=b.get("selection").single();a.media.changeAttachment(c),b.trigger("replace",a.media.toJSON())})},renderAddSourceToolbar:function(){this.setPrimaryButton(this.addText,function(a,b){var c=b.get("selection").single();a.media.setSource(c),b.trigger("add-source",a.media.toJSON())})}}),e.view.MediaFrame.AudioDetails=e.view.MediaFrame.MediaDetails.extend({defaults:{id:"audio",url:"",menu:"audio-details",content:"audio-details",toolbar:"audio-details",type:"link",title:g.audioDetailsTitle,priority:120},initialize:function(a){a.DetailsView=e.view.AudioDetails,a.cancelText=g.audioDetailsCancel,a.addText=g.audioAddSourceTitle,e.view.MediaFrame.MediaDetails.prototype.initialize.call(this,a)},bindHandlers:function(){e.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 e.controller.AudioDetails({media:this.media}),new e.controller.MediaLibrary({type:"audio",id:"replace-audio",title:g.audioReplaceTitle,toolbar:"replace-audio",media:this.media,menu:"audio-details"}),new e.controller.MediaLibrary({type:"audio",id:"add-audio-source",title:g.audioAddSourceTitle,toolbar:"add-audio-source",media:this.media,menu:!1})])}}),e.view.MediaFrame.VideoDetails=e.view.MediaFrame.MediaDetails.extend({defaults:{id:"video",url:"",menu:"video-details",content:"video-details",toolbar:"video-details",type:"link",title:g.videoDetailsTitle,priority:120},initialize:function(a){a.DetailsView=e.view.VideoDetails,a.cancelText=g.videoDetailsCancel,a.addText=g.videoAddSourceTitle,e.view.MediaFrame.MediaDetails.prototype.initialize.call(this,a)},bindHandlers:function(){e.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),this.on("toolbar:render:add-track",this.renderAddTrackToolbar,this)},createStates:function(){this.states.add([new e.controller.VideoDetails({media:this.media}),new e.controller.MediaLibrary({type:"video",id:"replace-video",title:g.videoReplaceTitle,toolbar:"replace-video",media:this.media,menu:"video-details"}),new e.controller.MediaLibrary({type:"video",id:"add-video-source",title:g.videoAddSourceTitle,toolbar:"add-video-source",media:this.media,menu:!1}),new e.controller.MediaLibrary({type:"image",id:"select-poster-image",title:g.videoSelectPosterImageTitle,toolbar:"select-poster-image",media:this.media,menu:"video-details"}),new e.controller.MediaLibrary({type:"text",id:"add-track",title:g.videoAddTrackTitle,toolbar:"add-track",media:this.media,menu:"video-details"})])},renderSelectPosterImageToolbar:function(){this.setPrimaryButton(g.videoSelectPosterImageTitle,function(a,b){var c=b.get("selection").single();a.media.set("poster",c.get("url")),b.trigger("set-poster-image",a.media.toJSON())})},renderAddTrackToolbar:function(){this.setPrimaryButton(g.videoAddTrackTitle,function(a,b){var c=b.get("selection").single(),d=a.media.get("content");-1===d.indexOf(c.get("url"))&&(d+=[''].join(""),a.media.set("content",d)),b.trigger("add-track",a.media.toJSON())})}}),e.view.MediaDetails=e.view.Settings.AttachmentDisplay.extend({initialize:function(){b.bindAll(this,"success"),this.listenTo(this.controller,"close",e.mixin.unsetPlayer),this.on("ready",this.setPlayer),this.on("media:setting:remove",e.mixin.unsetPlayer,this),this.on("media:setting:remove",this.render),this.on("media:setting:remove",this.setPlayer),this.events=b.extend(this.events,{"click .remove-setting":"removeSetting","change .content-track":"setTracks","click .remove-track":"setTracks"}),e.view.Settings.AttachmentDisplay.prototype.initialize.apply(this,arguments)},prepare:function(){return b.defaults({model:this.model.toJSON()},this.options)},removeSetting:function(b){var c,d=a(b.currentTarget).parent();c=d.find("input").data("setting"),c&&(this.model.unset(c),this.trigger("media:setting:remove",this)),d.remove()},setTracks:function(){var c="";b.each(this.$(".content-track"),function(b){c+=a(b).val()}),this.model.set("content",c),this.trigger("media:setting:remove",this)},setPlayer:function(){!this.player&&this.media&&(this.player=new MediaElementPlayer(this.media,this.settings))},setMedia:function(){return this},success:function(a){var b=a.attributes.autoplay&&"false"!==a.attributes.autoplay;"flash"===a.pluginType&&b&&a.addEventListener("canplay",function(){a.play()},!1),this.mejs=a},render:function(){var a=this;return e.view.Settings.AttachmentDisplay.prototype.render.apply(this,arguments),setTimeout(function(){a.resetFocus()},10),this.settings=b.defaults({success:this.success},f),this.setMedia()},resetFocus:function(){this.$(".embed-media-settings").scrollTop(0)}},{instances:0,prepareSrc:function(c){var d=e.view.MediaDetails.instances++;return b.each(a(c).find("source"),function(a){a.src=[a.src,a.src.indexOf("?")>-1?"&":"?","_=",d].join("")}),c}}),e.view.AudioDetails=e.view.MediaDetails.extend({className:"audio-details",template:e.template("audio-details"),setMedia:function(){var a=this.$(".wp-audio-shortcode");return a.find("source").length?(a.is(":hidden")&&a.show(),this.media=e.view.MediaDetails.prepareSrc(a.get(0))):(a.hide(),this.media=!1),this}}),e.view.VideoDetails=e.view.MediaDetails.extend({className:"video-details",template:e.template("video-details"),setMedia:function(){var a=this.$(".wp-video-shortcode");return a.find("source").length?(a.is(":hidden")&&a.show(),this.media=a.hasClass("youtube-video")?a.get(0):e.view.MediaDetails.prepareSrc(a.get(0))):(a.hide(),this.media=!1),this}}),b.extend(wp.media.playlist,{counts:function(a){var c={};return function(){if(!b.isEmpty(c))return c;var d=0,e=0;return b.each(a.attachmentCounts,function(a,b){var c;if(-1