diff --git a/wp-includes/js/mce-view.js b/wp-includes/js/mce-view.js index 87d96efce4..96fc01974e 100644 --- a/wp-includes/js/mce-view.js +++ b/wp-includes/js/mce-view.js @@ -104,6 +104,65 @@ window.wp = window.wp || {}; } }, this ); }, + + /* jshint scripturl: true */ + createIframe: function ( content ) { + var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver, + iframe, iframeDoc, i, resize, + dom = tinymce.DOM; + + if ( content.indexOf( '' + + '' + + '' + + '' + + '' + + '' + + content + + '' + + '' + ); + iframeDoc.close(); + + resize = function() { + $( iframe ).height( $( iframeDoc.body ).height() ); + }; + + if ( MutationObserver ) { + new MutationObserver( _.debounce( function() { + resize(); + }, 100 ) ) + .observe( iframeDoc.body, { + attributes: true, + childList: true, + subtree: true + } ); + } else { + for ( i = 1; i < 6; i++ ) { + setTimeout( resize, i * 700 ); + } + } + } else { + this.setContent( content ); + } + }, + setError: function( message, dashicon ) { this.setContent( '
' + @@ -421,54 +480,60 @@ window.wp = window.wp || {}; wp.mce.av = { loaded: false, - View: _.extend( {}, wp.media.mixin, { + View: { overlay: true, + action: 'parse-media-shortcode', + initialize: function( options ) { - this.players = []; this.shortcode = options.shortcode; - _.bindAll( this, 'setPlayer', 'pausePlayers' ); - $( this ).on( 'ready', this.setPlayer ); - $( this ).on( 'ready', function( event, editor ) { - editor.on( 'hide', this.pausePlayers ); - } ); - $( document ).on( 'media:edit', this.pausePlayers ); + this.fetching = false; + + _.bindAll( this, 'createIframe', 'setNode', 'fetch' ); + $( this ).on( 'ready', this.setNode ); }, - /** - * Creates the player instance for the current node - * - * @global MediaElementPlayer - * - * @param {Event} event - * @param {Object} editor - * @param {HTMLElement} node - */ - setPlayer: function( event, editor, node ) { - var self = this, - media; - - media = $( node ).find( '.wp-' + this.shortcode.tag + '-shortcode' ); - - if ( ! this.isCompatible( media ) ) { - media.closest( '.wpview-wrap' ).addClass( 'wont-play' ); - media.replaceWith( '

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

' ); - return; - } else { - media.closest( '.wpview-wrap' ).removeClass( 'wont-play' ); - if ( this.ua.is( 'ff' ) ) { - media.prop( 'preload', 'metadata' ); - } else { - media.prop( 'preload', 'none' ); - } + setNode: function () { + if ( this.parsed ) { + this.createIframe( this.parsed ); + } else if ( ! this.fetching ) { + this.fetch(); } + }, - media = wp.media.view.MediaDetails.prepareSrc( media.get(0) ); + fetch: function () { + var self = this; + this.fetching = true; - setTimeout( function() { - wp.mce.av.loaded = true; - self.players.push( new MediaElementPlayer( media, self.mejsSettings ) ); - }, wp.mce.av.loaded ? 10 : 500 ); + wp.ajax.send( this.action, { + data: { + post_ID: $( '#post_ID' ).val() || 0, + type: this.shortcode.tag, + shortcode: this.shortcode.string() + } + } ) + .always( function() { + self.fetching = false; + } ) + .done( function( response ) { + if ( response ) { + self.parsed = response; + self.createIframe( response ); + } + } ) + .fail( function( response ) { + if ( response && response.message ) { + if ( ( response.type === 'not-embeddable' && self.type === 'embed' ) || + response.type === 'not-ssl' ) { + + self.setError( response.message, 'admin-media' ); + } else { + self.setContent( '

' + self.original + '

', null, 'replace' ); + } + } else if ( response && response.statusText ) { + self.setError( response.statusText, 'admin-media' ); + } + } ); }, /** @@ -477,19 +542,12 @@ window.wp = window.wp || {}; * @returns {string} */ getHtml: function() { - var attrs = this.shortcode.attrs.named; - attrs.content = this.shortcode.content; - - return this.template({ model: _.defaults( - attrs, - wp.media[ this.shortcode.tag ].defaults ) - }); - }, - - unbind: function() { - this.unsetPlayers(); + if ( ! this.parsed ) { + return ''; + } + return this.parsed; } - } ), + }, /** * Called when a TinyMCE view is clicked for editing. @@ -537,10 +595,7 @@ window.wp = window.wp || {}; * @mixes wp.mce.av */ wp.mce.views.register( 'video', _.extend( {}, wp.mce.av, { - state: 'video-details', - View: _.extend( {}, wp.mce.av.View, { - template: media.template( 'editor-video' ) - } ) + state: 'video-details' } ) ); /** @@ -549,10 +604,7 @@ window.wp = window.wp || {}; * @mixes wp.mce.av */ wp.mce.views.register( 'audio', _.extend( {}, wp.mce.av, { - state: 'audio-details', - View: _.extend( {}, wp.mce.av.View, { - template: media.template( 'editor-audio' ) - } ) + state: 'audio-details' } ) ); /** @@ -561,274 +613,34 @@ window.wp = window.wp || {}; * @mixes wp.mce.av */ wp.mce.views.register( 'playlist', _.extend( {}, wp.mce.av, { - state: ['playlist-edit', 'video-playlist-edit'], - View: _.extend( {}, wp.media.mixin, { - template: media.template( 'editor-playlist' ), - overlay: true, - - initialize: function( options ) { - this.players = []; - this.data = {}; - this.attachments = []; - this.shortcode = options.shortcode; - - $( this ).on( 'ready', function( event, editor ) { - editor.on( 'hide', this.pausePlayers ); - } ); - $( document ).on( 'media:edit', this.pausePlayers ); - - this.fetch(); - - $( this ).on( 'ready', this.setPlaylist ); - }, - - /** - * Asynchronously fetch the shortcode's attachments - */ - fetch: function() { - this.attachments = wp.media.playlist.attachments( this.shortcode ); - this.dfd = this.attachments.more().done( _.bind( this.render, this ) ); - }, - - setPlaylist: function( event, editor, element ) { - if ( ! this.data.tracks ) { - return; - } - - this.players.push( new WPPlaylistView( { - el: $( element ).find( '.wp-playlist' ).get( 0 ), - metadata: this.data - } ).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.playlist, - options, - attachments, - tracks = []; - - // Don't render errors while still fetching attachments - if ( this.dfd && 'pending' === this.dfd.state() && ! this.attachments.length ) { - return ''; - } - - _.each( model.defaults, function( value, key ) { - data[ key ] = model.coerce( data, key ); - }); - - options = { - type: data.type, - style: data.style, - tracklist: data.tracklist, - tracknumbers: data.tracknumbers, - images: data.images, - artists: data.artists - }; - - if ( ! this.attachments.length ) { - return this.template( options ); - } - - attachments = this.attachments.toJSON(); - - _.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' === data.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 ); - }, - - unbind: function() { - this.unsetPlayers(); - } - } ) + state: [ 'playlist-edit', 'video-playlist-edit' ] } ) ); /** * TinyMCE handler for the embed shortcode */ - wp.mce.embedView = _.extend( {}, wp.media.mixin, { - overlay: true, - initialize: function( options ) { - this.players = []; - this.content = options.content; - this.fetching = false; - this.parsed = false; - this.original = options.url || options.shortcode.string(); + wp.mce.embedMixin = { + View: _.extend( {}, wp.mce.av.View, { + overlay: true, + action: 'parse-embed', + initialize: function( options ) { + this.content = options.content; + this.fetching = false; + this.parsed = false; + this.original = options.url || options.shortcode.string(); - if ( options.url ) { - this.shortcode = '[embed]' + options.url + '[/embed]'; - } else { - this.shortcode = options.shortcode.string(); - } - - _.bindAll( this, 'setHtml', 'setNode', 'fetch' ); - $( this ).on( 'ready', this.setNode ); - }, - unbind: function() { - var self = this; - _.each( this.players, function ( player ) { - player.pause(); - self.removePlayer( player ); - } ); - this.players = []; - }, - setNode: function () { - if ( this.parsed ) { - this.setHtml( this.parsed ); - this.parseMediaShortcodes(); - } else if ( ! this.fetching ) { - this.fetch(); - } - }, - fetch: function () { - var self = this; - - this.fetching = true; - - wp.ajax.send( 'parse-embed', { - data: { - post_ID: $( '#post_ID' ).val() || 0, - shortcode: this.shortcode - } - } ) - .always( function() { - self.fetching = false; - } ) - .done( function( response ) { - if ( response ) { - self.parsed = response; - self.setHtml( response ); - } - } ) - .fail( function( response ) { - if ( response && response.message ) { - if ( ( response.type === 'not-embeddable' && self.type === 'embed' ) || - response.type === 'not-ssl' ) { - - self.setError( response.message, 'admin-media' ); - } else { - self.setContent( '

' + self.original + '

', null, 'replace' ); - } - } else if ( response && response.statusText ) { - self.setError( response.statusText, 'admin-media' ); - } - } ); - }, - /* jshint scripturl: true */ - setHtml: function ( content ) { - var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver, - iframe, iframeDoc, i, resize, - dom = tinymce.DOM; - - if ( content.indexOf( '' + - '' + - '' + - '' + - '' + - '' + - content + - '' + - '' - ); - iframeDoc.close(); - - resize = function() { - $( iframe ).height( $( iframeDoc ).height() ); - }; - - if ( MutationObserver ) { - new MutationObserver( _.debounce( function() { - resize(); - }, 100 ) ) - .observe( iframeDoc.body, { - attributes: true, - childList: true, - subtree: true + if ( options.url ) { + this.shortcode = media.embed.shortcode( { + url: options.url } ); } else { - for ( i = 1; i < 6; i++ ) { - setTimeout( resize, i * 700 ); - } + this.shortcode = options.shortcode; } - } else { - this.setContent( content ); + + _.bindAll( this, 'createIframe', 'setNode', 'fetch' ); + $( this ).on( 'ready', this.setNode ); } - - this.parseMediaShortcodes(); - }, - parseMediaShortcodes: function () { - var self = this; - $( '.wp-audio-shortcode, .wp-video-shortcode', this.node ).each( function ( i, element ) { - self.players.push( new MediaElementPlayer( element, self.mejsSettings ) ); - } ); - } - } ); - - wp.mce.embedMixin = { - View: wp.mce.embedView, + } ), edit: function( node ) { var embed = media.embed, self = this, diff --git a/wp-includes/js/mce-view.min.js b/wp-includes/js/mce-view.min.js index 5c325237b4..9e18a44d20 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){"use strict";var b={},c={},d=wp.media,e=["encodedText"];wp.mce=wp.mce||{},wp.mce.View=function(a){a=a||{},this.type=a.type,_.extend(this,_.pick(a,e)),this.initialize.apply(this,arguments)},_.extend(wp.mce.View.prototype,{initialize:function(){},getHtml:function(){return""},loadingPlaceholder:function(){return'
'},render:function(){var c=this.getHtml()||this.loadingPlaceholder();this.setContent('

 

'+(_.isFunction(b[this.type].edit)?'
':"")+'
'+c+"
"+(this.overlay?'
':"")+'

 

',function(b,c,d){a(b).trigger("ready",[c,d])},"wrap")},unbind:function(){},setContent:function(b,c,d){_.each(tinymce.editors,function(e){var f=this;e.plugins.wpview&&a(e.getBody()).find('[data-wpview-text="'+this.encodedText+'"]').each(function(g,h){var i=a(h).find(".wpview-content"),j=h;i.length&&"wrap"!==d&&(h=i=i[0]),_.isString(b)?"replace"===d?h=e.dom.replace(e.dom.createFragment(b),j):e.dom.setHTML(h,b):"replace"===d?h=e.dom.replace(b,j):a(h).empty().append(b),_.isFunction(c)&&c(f,e,a(h).find(".wpview-content")[0])})},this)},setError:function(a,b){this.setContent('

'+a+"

")}}),wp.mce.View.extend=Backbone.View.extend,wp.mce.views={register:function(a,c){var d={type:a,View:{},toView:function(a){var b=wp.shortcode.next(this.type,a);if(b)return{index:b.index,content:b.content,options:{shortcode:b.shortcode}}}};c=_.defaults(c,d),c.View=wp.mce.View.extend(c.View),b[a]=c},get:function(a){return b[a]},unregister:function(a){delete b[a]},unbind:function(){_.each(c,function(a){a.unbind()})},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.type=a,f.encodedText=h,e=new g.View(f),c[h]=e),wp.html.string({tag:"div",attrs:{"class":"wpview-wrap","data-wpview-text":h,"data-wpview-type":a},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.type=a.type,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.views.register("gallery",{View:{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.dfd=this.attachments.more().done(_.bind(this.render,this))},getHtml:function(){var a,b=this.shortcode.attrs.named,c=!1;return this.dfd&&"pending"===this.dfd.state()&&!this.attachments.length?"":(this.attachments.length&&(c=this.attachments.toJSON(),_.each(c,function(a){a.sizes&&(a.sizes.thumbnail?a.thumbnail=a.sizes.thumbnail:a.sizes.full&&(a.thumbnail=a.sizes.full))})),a={attachments:c,columns:b.columns?parseInt(b.columns,10):wp.media.galleryDefaults.columns},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.av={loaded:!1,View:_.extend({},wp.media.mixin,{overlay:!0,initialize:function(b){this.players=[],this.shortcode=b.shortcode,_.bindAll(this,"setPlayer","pausePlayers"),a(this).on("ready",this.setPlayer),a(this).on("ready",function(a,b){b.on("hide",this.pausePlayers)}),a(document).on("media:edit",this.pausePlayers)},setPlayer:function(b,c,d){var e,f=this;return e=a(d).find(".wp-"+this.shortcode.tag+"-shortcode"),this.isCompatible(e)?(e.closest(".wpview-wrap").removeClass("wont-play"),this.ua.is("ff")?e.prop("preload","metadata"):e.prop("preload","none"),e=wp.media.view.MediaDetails.prepareSrc(e.get(0)),void setTimeout(function(){wp.mce.av.loaded=!0,f.players.push(new MediaElementPlayer(e,f.mejsSettings))},wp.mce.av.loaded?10:500)):(e.closest(".wpview-wrap").addClass("wont-play"),void e.replaceWith("

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

"))},getHtml:function(){var a=this.shortcode.attrs.named;return a.content=this.shortcode.content,this.template({model:_.defaults(a,wp.media[this.shortcode.tag].defaults)})},unbind:function(){this.unsetPlayers()}}),edit:function(b){var c,d,e,f=wp.media[this.type],g=this;a(document).trigger("media:edit"),d=window.decodeURIComponent(a(b).attr("data-wpview-text")),c=f.edit(d),c.on("close",function(){c.detach()}),e=function(d){var e=wp.media[g.type].shortcode(d).string();a(b).attr("data-wpview-text",window.encodeURIComponent(e)),wp.mce.views.refreshView(g,e),c.detach()},_.isArray(g.state)?_.each(g.state,function(a){c.state(a).on("update",e)}):c.state(g.state).on("update",e),c.open()}},wp.mce.views.register("video",_.extend({},wp.mce.av,{state:"video-details",View:_.extend({},wp.mce.av.View,{template:d.template("editor-video")})})),wp.mce.views.register("audio",_.extend({},wp.mce.av,{state:"audio-details",View:_.extend({},wp.mce.av.View,{template:d.template("editor-audio")})})),wp.mce.views.register("playlist",_.extend({},wp.mce.av,{state:["playlist-edit","video-playlist-edit"],View:_.extend({},wp.media.mixin,{template:d.template("editor-playlist"),overlay:!0,initialize:function(b){this.players=[],this.data={},this.attachments=[],this.shortcode=b.shortcode,a(this).on("ready",function(a,b){b.on("hide",this.pausePlayers)}),a(document).on("media:edit",this.pausePlayers),this.fetch(),a(this).on("ready",this.setPlaylist)},fetch:function(){this.attachments=wp.media.playlist.attachments(this.shortcode),this.dfd=this.attachments.more().done(_.bind(this.render,this))},setPlaylist:function(b,c,d){this.data.tracks&&this.players.push(new WPPlaylistView({el:a(d).find(".wp-playlist").get(0),metadata:this.data}).player)},getHtml:function(){var a,b,c=this.shortcode.attrs.named,e=wp.media.playlist,f=[];return this.dfd&&"pending"===this.dfd.state()&&!this.attachments.length?"":(_.each(e.defaults,function(a,b){c[b]=e.coerce(c,b)}),a={type:c.type,style:c.style,tracklist:c.tracklist,tracknumbers:c.tracknumbers,images:c.images,artists:c.artists},this.attachments.length?(b=this.attachments.toJSON(),_.each(b,function(b){var e={},g={},h={src:b.url,type:b.mime,title:b.title,caption:b.caption,description:b.description,meta:b.meta};"video"===c.type?(e.width=b.width,e.height=b.height,d.view.settings.contentWidth?(g.width=d.view.settings.contentWidth-22,g.height=Math.ceil(e.height*g.width/e.width),a.width||(a.width=g.width,a.height=g.height)):a.width||(a.width=b.width,a.height=b.height),h.dimensions={original:e,resized:_.isEmpty(g)?e:g}):a.width=400,h.image=b.image,h.thumb=b.thumb,f.push(h)}),a.tracks=f,this.data=a,this.template(a)):this.template(a))},unbind:function(){this.unsetPlayers()}})})),wp.mce.embedView=_.extend({},wp.media.mixin,{overlay:!0,initialize:function(b){this.players=[],this.content=b.content,this.fetching=!1,this.parsed=!1,this.original=b.url||b.shortcode.string(),this.shortcode=b.url?"[embed]"+b.url+"[/embed]":b.shortcode.string(),_.bindAll(this,"setHtml","setNode","fetch"),a(this).on("ready",this.setNode)},unbind:function(){var a=this;_.each(this.players,function(b){b.pause(),a.removePlayer(b)}),this.players=[]},setNode:function(){this.parsed?(this.setHtml(this.parsed),this.parseMediaShortcodes()):this.fetching||this.fetch()},fetch:function(){var b=this;this.fetching=!0,wp.ajax.send("parse-embed",{data:{post_ID:a("#post_ID").val()||0,shortcode:this.shortcode}}).always(function(){b.fetching=!1}).done(function(a){a&&(b.parsed=a,b.setHtml(a))}).fail(function(a){a&&a.message?"not-embeddable"===a.type&&"embed"===b.type||"not-ssl"===a.type?b.setError(a.message,"admin-media"):b.setContent("

"+b.original+"

",null,"replace"):a&&a.statusText&&b.setError(a.statusText,"admin-media")})},setHtml:function(b){var c,d,e,f,g=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver,h=tinymce.DOM;if(-1!==b.indexOf("'+b+""),d.close(),f=function(){a(c).height(a(d).height())},g)new g(_.debounce(function(){f()},100)).observe(d.body,{attributes:!0,childList:!0,subtree:!0});else for(e=1;6>e;e++)setTimeout(f,700*e);else this.setContent(b);this.parseMediaShortcodes()},parseMediaShortcodes:function(){var b=this;a(".wp-audio-shortcode, .wp-video-shortcode",this.node).each(function(a,c){b.players.push(new MediaElementPlayer(c,b.mejsSettings))})}}),wp.mce.embedMixin={View:wp.mce.embedView,edit:function(b){var c,e,f=d.embed,g=this,h="embedURL"===this.type;a(document).trigger("media:edit"),e=window.decodeURIComponent(a(b).attr("data-wpview-text")),c=f.edit(e,h),c.on("close",function(){c.detach()}),c.state("embed").props.on("change:url",function(a,b){b&&(c.state("embed").metadata=a.toJSON())}),c.state("embed").on("select",function(){var d;d=h?c.state("embed").metadata.url:f.shortcode(c.state("embed").metadata).string(),a(b).attr("data-wpview-text",window.encodeURIComponent(d)),wp.mce.views.refreshView(g,d),c.detach()}),c.open()}},wp.mce.views.register("embed",_.extend({},wp.mce.embedMixin)),wp.mce.views.register("embedURL",_.extend({},wp.mce.embedMixin,{toView:function(a){var b=/(?:^|

)(https?:\/\/[^\s"]+?)(?:<\/p>\s*|$)/gi,c=b.exec(tinymce.trim(a));if(c)return{index:c.index,content:c[0],options:{url:c[1]}}}}))}(jQuery); \ No newline at end of file +window.wp=window.wp||{},function(a){"use strict";var b={},c={},d=wp.media,e=["encodedText"];wp.mce=wp.mce||{},wp.mce.View=function(a){a=a||{},this.type=a.type,_.extend(this,_.pick(a,e)),this.initialize.apply(this,arguments)},_.extend(wp.mce.View.prototype,{initialize:function(){},getHtml:function(){return""},loadingPlaceholder:function(){return'

'},render:function(){var c=this.getHtml()||this.loadingPlaceholder();this.setContent('

 

'+(_.isFunction(b[this.type].edit)?'
':"")+'
'+c+"
"+(this.overlay?'
':"")+'

 

',function(b,c,d){a(b).trigger("ready",[c,d])},"wrap")},unbind:function(){},setContent:function(b,c,d){_.each(tinymce.editors,function(e){var f=this;e.plugins.wpview&&a(e.getBody()).find('[data-wpview-text="'+this.encodedText+'"]').each(function(g,h){var i=a(h).find(".wpview-content"),j=h;i.length&&"wrap"!==d&&(h=i=i[0]),_.isString(b)?"replace"===d?h=e.dom.replace(e.dom.createFragment(b),j):e.dom.setHTML(h,b):"replace"===d?h=e.dom.replace(b,j):a(h).empty().append(b),_.isFunction(c)&&c(f,e,a(h).find(".wpview-content")[0])})},this)},createIframe:function(b){var c,d,e,f,g=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver,h=tinymce.DOM;if(-1!==b.indexOf("'+b+""),d.close(),f=function(){a(c).height(a(d.body).height())},g)new g(_.debounce(function(){f()},100)).observe(d.body,{attributes:!0,childList:!0,subtree:!0});else for(e=1;6>e;e++)setTimeout(f,700*e);else this.setContent(b)},setError:function(a,b){this.setContent('

'+a+"

")}}),wp.mce.View.extend=Backbone.View.extend,wp.mce.views={register:function(a,c){var d={type:a,View:{},toView:function(a){var b=wp.shortcode.next(this.type,a);if(b)return{index:b.index,content:b.content,options:{shortcode:b.shortcode}}}};c=_.defaults(c,d),c.View=wp.mce.View.extend(c.View),b[a]=c},get:function(a){return b[a]},unregister:function(a){delete b[a]},unbind:function(){_.each(c,function(a){a.unbind()})},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.type=a,f.encodedText=h,e=new g.View(f),c[h]=e),wp.html.string({tag:"div",attrs:{"class":"wpview-wrap","data-wpview-text":h,"data-wpview-type":a},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.type=a.type,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.views.register("gallery",{View:{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.dfd=this.attachments.more().done(_.bind(this.render,this))},getHtml:function(){var a,b=this.shortcode.attrs.named,c=!1;return this.dfd&&"pending"===this.dfd.state()&&!this.attachments.length?"":(this.attachments.length&&(c=this.attachments.toJSON(),_.each(c,function(a){a.sizes&&(a.sizes.thumbnail?a.thumbnail=a.sizes.thumbnail:a.sizes.full&&(a.thumbnail=a.sizes.full))})),a={attachments:c,columns:b.columns?parseInt(b.columns,10):wp.media.galleryDefaults.columns},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.av={loaded:!1,View:{overlay:!0,action:"parse-media-shortcode",initialize:function(b){this.shortcode=b.shortcode,this.fetching=!1,_.bindAll(this,"createIframe","setNode","fetch"),a(this).on("ready",this.setNode)},setNode:function(){this.parsed?this.createIframe(this.parsed):this.fetching||this.fetch()},fetch:function(){var b=this;this.fetching=!0,wp.ajax.send(this.action,{data:{post_ID:a("#post_ID").val()||0,type:this.shortcode.tag,shortcode:this.shortcode.string()}}).always(function(){b.fetching=!1}).done(function(a){a&&(b.parsed=a,b.createIframe(a))}).fail(function(a){a&&a.message?"not-embeddable"===a.type&&"embed"===b.type||"not-ssl"===a.type?b.setError(a.message,"admin-media"):b.setContent("

"+b.original+"

",null,"replace"):a&&a.statusText&&b.setError(a.statusText,"admin-media")})},getHtml:function(){return this.parsed?this.parsed:""}},edit:function(b){var c,d,e,f=wp.media[this.type],g=this;a(document).trigger("media:edit"),d=window.decodeURIComponent(a(b).attr("data-wpview-text")),c=f.edit(d),c.on("close",function(){c.detach()}),e=function(d){var e=wp.media[g.type].shortcode(d).string();a(b).attr("data-wpview-text",window.encodeURIComponent(e)),wp.mce.views.refreshView(g,e),c.detach()},_.isArray(g.state)?_.each(g.state,function(a){c.state(a).on("update",e)}):c.state(g.state).on("update",e),c.open()}},wp.mce.views.register("video",_.extend({},wp.mce.av,{state:"video-details"})),wp.mce.views.register("audio",_.extend({},wp.mce.av,{state:"audio-details"})),wp.mce.views.register("playlist",_.extend({},wp.mce.av,{state:["playlist-edit","video-playlist-edit"]})),wp.mce.embedMixin={View:_.extend({},wp.mce.av.View,{overlay:!0,action:"parse-embed",initialize:function(b){this.content=b.content,this.fetching=!1,this.parsed=!1,this.original=b.url||b.shortcode.string(),this.shortcode=b.url?d.embed.shortcode({url:b.url}):b.shortcode,_.bindAll(this,"createIframe","setNode","fetch"),a(this).on("ready",this.setNode)}}),edit:function(b){var c,e,f=d.embed,g=this,h="embedURL"===this.type;a(document).trigger("media:edit"),e=window.decodeURIComponent(a(b).attr("data-wpview-text")),c=f.edit(e,h),c.on("close",function(){c.detach()}),c.state("embed").props.on("change:url",function(a,b){b&&(c.state("embed").metadata=a.toJSON())}),c.state("embed").on("select",function(){var d;d=h?c.state("embed").metadata.url:f.shortcode(c.state("embed").metadata).string(),a(b).attr("data-wpview-text",window.encodeURIComponent(d)),wp.mce.views.refreshView(g,d),c.detach()}),c.open()}},wp.mce.views.register("embed",_.extend({},wp.mce.embedMixin)),wp.mce.views.register("embedURL",_.extend({},wp.mce.embedMixin,{toView:function(a){var b=/(?:^|

)(https?:\/\/[^\s"]+?)(?:<\/p>\s*|$)/gi,c=b.exec(tinymce.trim(a));if(c)return{index:c.index,content:c[0],options:{url:c[1]}}}}))}(jQuery); \ No newline at end of file diff --git a/wp-includes/js/media-audiovideo.js b/wp-includes/js/media-audiovideo.js index 0c6f31e5b3..4bf622f764 100644 --- a/wp-includes/js/media-audiovideo.js +++ b/wp-includes/js/media-audiovideo.js @@ -46,103 +46,6 @@ } ); }, - /** - * Utility to identify the user's browser - */ - ua: { - is : function( browser ) { - var passes = false, ua = window.navigator.userAgent; - - switch ( browser ) { - case 'oldie': - passes = ua.match(/MSIE [6-8]/gi) !== null; - break; - case 'ie': - passes = /MSIE /.test( ua ) || ( /Trident\//.test( ua ) && /rv:\d/.test( ua ) ); // IE11 - break; - case 'ff': - passes = ua.match(/firefox/gi) !== null; - break; - case 'opera': - passes = ua.match(/OPR/) !== null; - break; - case 'safari': - passes = ua.match(/safari/gi) !== null && ua.match(/chrome/gi) === null; - break; - case 'chrome': - passes = ua.match(/safari/gi) !== null && ua.match(/chrome/gi) !== null; - break; - } - - return passes; - } - }, - - /** - * Specify compatibility for native playback by browser - */ - 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'] - } - }, - - /** - * Determine if the passed media contains a that provides - * native playback in the user's browser - * - * @param {jQuery} media - * @returns {Boolean} - */ - isCompatible: function( media ) { - if ( ! media.find( 'source' ).length ) { - return false; - } - - var ua = this.ua, test = false, found = false, sources; - - if ( ua.is( 'oldIE' ) ) { - return false; - } - - sources = media.find( 'source' ); - - _.find( this.compat, function( supports, browser ) { - if ( ua.is( browser ) ) { - found = true; - _.each( sources, function( elem ) { - var audio = new RegExp( 'audio\/(' + supports.audio.join('|') + ')', 'gi' ), - video = new RegExp( 'video\/(' + supports.video.join('|') + ')', 'gi' ); - - if ( elem.type.match( video ) !== null || elem.type.match( audio ) !== null ) { - test = true; - } - } ); - } - - return test || found; - } ); - - return test; - }, - /** * 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-audiovideo.min.js b/wp-includes/js/media-audiovideo.min.js index f99246392b..1e90af74d1 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",".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=_wpmejsSettings),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()},removeAllPlayers:function(){var a;if(window.mejs&&window.mejs.players)for(a in window.mejs.players)window.mejs.players[a].pause(),this.removePlayer(window.mejs.players[a])},pausePlayers:function(){b.each(this.players,function(a){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=/MSIE /.test(c)||/Trident\//.test(c)&&/rv:\d/.test(c);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(a){var b,c;if(a.options){for(b in a.options.features)if(c=a.options.features[b],a["clean"+c])try{a["clean"+c](a)}catch(d){}a.isDynamic||a.$node.remove(),"native"!==a.media.pluginType&&a.media.remove(),delete window.mejs.players[a.id],a.container.remove(),a.globalUnbind(),delete a.node.player}},unsetPlayers:function(){this.players&&this.players.length&&(b.each(this.players,function(a){a.pause(),wp.media.mixin.removePlayer(a)}),this.players=[])}},wp.media.playlist=new wp.media.collection({tag:"playlist",editTitle:g.editPlaylistTitle,defaults:{id:wp.media.view.settings.post.id,style:"light",tracklist:!0,tracknumbers:!0,images:!0,artists:!0,type:"audio"}}),wp.media.audio={coerce:wp.media.coerce,defaults:{id:wp.media.view.settings.post.id,src:"",loop:!1,autoplay:!1,preload:"none",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:"",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,c){var d=[],e=c.get("selection").single();a.media.set("poster",e.get("url")),c.trigger("set-poster-image",a.media.toJSON()),b.each(wp.media.view.settings.embedExts,function(b){a.media.get(b)&&d.push(a.media.get(b))}),wp.ajax.send("set-attachment-thumbnail",{data:{urls:d,thumbnail_id:e.get("id")}})})},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.players=[],this.listenTo(this.controller,"close",e.mixin.unsetPlayers),this.on("ready",this.setPlayer),this.on("media:setting:remove",e.mixin.unsetPlayers,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.players.length&&this.media&&this.players.push(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}}),a(d)}(jQuery,_,Backbone); \ No newline at end of file +!function(a,b,c){function d(){a(document.body).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=_wpmejsSettings),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()},removeAllPlayers:function(){var a;if(window.mejs&&window.mejs.players)for(a in window.mejs.players)window.mejs.players[a].pause(),this.removePlayer(window.mejs.players[a])},pausePlayers:function(){b.each(this.players,function(a){a.pause()})},removePlayer:function(a){var b,c;if(a.options){for(b in a.options.features)if(c=a.options.features[b],a["clean"+c])try{a["clean"+c](a)}catch(d){}a.isDynamic||a.$node.remove(),"native"!==a.media.pluginType&&a.media.remove(),delete window.mejs.players[a.id],a.container.remove(),a.globalUnbind(),delete a.node.player}},unsetPlayers:function(){this.players&&this.players.length&&(b.each(this.players,function(a){a.pause(),wp.media.mixin.removePlayer(a)}),this.players=[])}},wp.media.playlist=new wp.media.collection({tag:"playlist",editTitle:g.editPlaylistTitle,defaults:{id:wp.media.view.settings.post.id,style:"light",tracklist:!0,tracknumbers:!0,images:!0,artists:!0,type:"audio"}}),wp.media.audio={coerce:wp.media.coerce,defaults:{id:wp.media.view.settings.post.id,src:"",loop:!1,autoplay:!1,preload:"none",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:"",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,c){var d=[],e=c.get("selection").single();a.media.set("poster",e.get("url")),c.trigger("set-poster-image",a.media.toJSON()),b.each(wp.media.view.settings.embedExts,function(b){a.media.get(b)&&d.push(a.media.get(b))}),wp.ajax.send("set-attachment-thumbnail",{data:{urls:d,thumbnail_id:e.get("id")}})})},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.players=[],this.listenTo(this.controller,"close",e.mixin.unsetPlayers),this.on("ready",this.setPlayer),this.on("media:setting:remove",e.mixin.unsetPlayers,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.players.length&&this.media&&this.players.push(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}}),a(d)}(jQuery,_,Backbone); \ No newline at end of file diff --git a/wp-includes/js/mediaelement/wp-mediaelement.css b/wp-includes/js/mediaelement/wp-mediaelement.css index 371faa6398..c95b88b1dd 100644 --- a/wp-includes/js/mediaelement/wp-mediaelement.css +++ b/wp-includes/js/mediaelement/wp-mediaelement.css @@ -111,6 +111,10 @@ video.wp-video-shortcode, line-height: 1.5; } +.wp-admin .wp-playlist { + margin: 0 0 18px; +} + .wp-playlist video { display: inline-block; max-width: 100%; diff --git a/wp-includes/js/mediaelement/wp-playlist.js b/wp-includes/js/mediaelement/wp-playlist.js index f42457398d..9c0fb2c589 100644 --- a/wp-includes/js/mediaelement/wp-playlist.js +++ b/wp-includes/js/mediaelement/wp-playlist.js @@ -7,7 +7,6 @@ initialize : function (options) { this.index = 0; this.settings = {}; - this.compatMode = $( 'body' ).hasClass( 'wp-admin' ) && $( '#content_ifr' ).length; this.data = options.metadata || $.parseJSON( this.$('script').html() ); this.playerNode = this.$( this.data.type ); @@ -27,9 +26,7 @@ this.renderTracks(); } - if ( this.isCompatibleSrc() ) { - this.playerNode.attr( 'src', this.current.get( 'src' ) ); - } + this.playerNode.attr( 'src', this.current.get( 'src' ) ); _.bindAll( this, 'bindPlayer', 'bindResetPlayer', 'setPlayer', 'ended', 'clickTrack' ); @@ -47,25 +44,7 @@ bindResetPlayer : function (mejs) { this.bindPlayer( mejs ); - if ( this.isCompatibleSrc() ) { - this.playCurrentSrc(); - } - }, - - isCompatibleSrc: function () { - var testNode; - - if ( this.compatMode ) { - testNode = $( '' ); - - if ( ! wp.media.mixin.isCompatible( testNode ) ) { - this.playerNode.removeAttr( 'src' ); - this.playerNode.removeAttr( 'poster' ); - return; - } - } - - return true; + this.playCurrentSrc(); }, setPlayer: function (force) { @@ -76,9 +55,7 @@ } if (force) { - if ( this.isCompatibleSrc() ) { - this.playerNode.attr( 'src', this.current.get( 'src' ) ); - } + this.playerNode.attr( 'src', this.current.get( 'src' ) ); this.settings.success = this.bindResetPlayer; } @@ -188,11 +165,9 @@ }); $(document).ready(function () { - if ( ! $( 'body' ).hasClass( 'wp-admin' ) || $( 'body' ).hasClass( 'about-php' ) ) { - $('.wp-playlist').each(function () { - return new WPPlaylistView({ el: this }); - }); - } + $('.wp-playlist').each( function() { + return new WPPlaylistView({ el: this }); + } ); }); window.WPPlaylistView = WPPlaylistView; diff --git a/wp-includes/media-template.php b/wp-includes/media-template.php index 87642197cb..40a20a4712 100644 --- a/wp-includes/media-template.php +++ b/wp-includes/media-template.php @@ -1216,35 +1216,6 @@ function wp_print_media_templates() { <# } #> - - - - - - - -