diff --git a/wp-admin/js/widgets/media-video-widget.js b/wp-admin/js/widgets/media-video-widget.js index 547c4efc48..79ff84d86b 100644 --- a/wp-admin/js/widgets/media-video-widget.js +++ b/wp-admin/js/widgets/media-video-widget.js @@ -134,6 +134,18 @@ }); }, + /** + * Whether a url is a supported external host. + * + * @param {String} url - Video url. + * @returns {boolean} Whether url is a supported video host. + */ + isHostedVideo: function isHostedVideo( url ) { + var parsedUrl = document.createElement( 'a' ); + parsedUrl.href = url; + return /vimeo|youtu\.?be/.test( parsedUrl.host ); + }, + /** * Render preview. * @@ -150,9 +162,7 @@ } if ( ! attachmentId && attachmentUrl ) { - parsedUrl = document.createElement( 'a' ); - parsedUrl.href = attachmentUrl; - isHostedEmbed = /vimeo|youtu\.?be/.test( parsedUrl.host ); + isHostedEmbed = control.isHostedVideo( attachmentUrl ); } if ( isHostedEmbed ) { diff --git a/wp-admin/js/widgets/media-video-widget.min.js b/wp-admin/js/widgets/media-video-widget.min.js index eb6862d9e8..9c513e7c1a 100644 --- a/wp-admin/js/widgets/media-video-widget.min.js +++ b/wp-admin/js/widgets/media-video-widget.min.js @@ -1 +1 @@ -!function(a){"use strict";var b,c,d;d=wp.media.view.MediaFrame.VideoDetails.extend({createStates:function(){this.states.add([new wp.media.controller.VideoDetails({media:this.media}),new wp.media.controller.MediaLibrary({type:"video",id:"add-video-source",title:wp.media.view.l10n.videoAddSourceTitle,toolbar:"add-video-source",media:this.media,menu:!1}),new wp.media.controller.MediaLibrary({type:"text",id:"add-track",title:wp.media.view.l10n.videoAddTrackTitle,toolbar:"add-track",media:this.media,menu:"video-details"})])}}),b=a.MediaWidgetModel.extend({}),c=a.MediaWidgetControl.extend({showDisplaySettings:!1,oembedResponses:{},mapModelToMediaFrameProps:function(b){var c,d=this;return c=a.MediaWidgetControl.prototype.mapModelToMediaFrameProps.call(d,b),c.link="embed",c},fetchEmbed:function(){var a,b=this;a=b.model.get("url"),b.oembedResponses[a]||(b.fetchEmbedDfd&&"pending"===b.fetchEmbedDfd.state()&&b.fetchEmbedDfd.abort(),b.fetchEmbedDfd=jQuery.ajax({url:wp.media.view.settings.oEmbedProxyUrl,data:{url:b.model.get("url"),maxwidth:b.model.get("width"),maxheight:b.model.get("height"),_wpnonce:wp.media.view.settings.nonce.wpRestApi,discover:!1},type:"GET",dataType:"json",context:b}),b.fetchEmbedDfd.done(function(c){b.oembedResponses[a]=c,b.renderPreview()}),b.fetchEmbedDfd.fail(function(){b.oembedResponses[a]=null}))},renderPreview:function(){var a,b,c,d,e,f,g,h,i=this,j=!1;c=i.model.get("attachment_id"),d=i.model.get("url"),h=i.model.get("error"),(c||d)&&(!c&&d&&(f=document.createElement("a"),f.href=d,j=/vimeo|youtu\.?be/.test(f.host)),j&&(i.fetchEmbed(),e=i.oembedResponses[d]?i.oembedResponses[d].thumbnail_url:null),g=i.selectedAttachment.get("mime"),g&&c&&(_.contains(_.values(wp.media.view.settings.embedMimes),g)||(h="unsupported_file_type")),a=i.$el.find(".media-widget-preview"),b=wp.template("wp-media-widget-video-preview"),a.html(b({model:{attachment_id:i.model.get("attachment_id"),src:d,poster:e},is_hosted_embed:j,error:h})),wp.mediaelement.initialize())},editMedia:function(){var a,b,c,e=this;b=e.mapModelToMediaFrameProps(e.model.toJSON()),a=new d({frame:"video",state:"video-details",metadata:b}),wp.media.frame=a,a.$el.addClass("media-widget"),c=function(a){e.selectedAttachment.set(a),e.model.set(_.extend(_.omit(e.model.defaults(),"title"),e.mapMediaToModelProps(a),{error:!1}))},a.state("video-details").on("update",c),a.state("replace-video").on("replace",c),a.on("close",function(){a.detach()}),a.open()}}),a.controlConstructors.media_video=c,a.modelConstructors.media_video=b}(wp.mediaWidgets); \ No newline at end of file +!function(a){"use strict";var b,c,d;d=wp.media.view.MediaFrame.VideoDetails.extend({createStates:function(){this.states.add([new wp.media.controller.VideoDetails({media:this.media}),new wp.media.controller.MediaLibrary({type:"video",id:"add-video-source",title:wp.media.view.l10n.videoAddSourceTitle,toolbar:"add-video-source",media:this.media,menu:!1}),new wp.media.controller.MediaLibrary({type:"text",id:"add-track",title:wp.media.view.l10n.videoAddTrackTitle,toolbar:"add-track",media:this.media,menu:"video-details"})])}}),b=a.MediaWidgetModel.extend({}),c=a.MediaWidgetControl.extend({showDisplaySettings:!1,oembedResponses:{},mapModelToMediaFrameProps:function(b){var c,d=this;return c=a.MediaWidgetControl.prototype.mapModelToMediaFrameProps.call(d,b),c.link="embed",c},fetchEmbed:function(){var a,b=this;a=b.model.get("url"),b.oembedResponses[a]||(b.fetchEmbedDfd&&"pending"===b.fetchEmbedDfd.state()&&b.fetchEmbedDfd.abort(),b.fetchEmbedDfd=jQuery.ajax({url:wp.media.view.settings.oEmbedProxyUrl,data:{url:b.model.get("url"),maxwidth:b.model.get("width"),maxheight:b.model.get("height"),_wpnonce:wp.media.view.settings.nonce.wpRestApi,discover:!1},type:"GET",dataType:"json",context:b}),b.fetchEmbedDfd.done(function(c){b.oembedResponses[a]=c,b.renderPreview()}),b.fetchEmbedDfd.fail(function(){b.oembedResponses[a]=null}))},isHostedVideo:function(a){var b=document.createElement("a");return b.href=a,/vimeo|youtu\.?be/.test(b.host)},renderPreview:function(){var a,b,c,d,e,f,g,h=this,i=!1;c=h.model.get("attachment_id"),d=h.model.get("url"),g=h.model.get("error"),(c||d)&&(!c&&d&&(i=h.isHostedVideo(d)),i&&(h.fetchEmbed(),e=h.oembedResponses[d]?h.oembedResponses[d].thumbnail_url:null),f=h.selectedAttachment.get("mime"),f&&c&&(_.contains(_.values(wp.media.view.settings.embedMimes),f)||(g="unsupported_file_type")),a=h.$el.find(".media-widget-preview"),b=wp.template("wp-media-widget-video-preview"),a.html(b({model:{attachment_id:h.model.get("attachment_id"),src:d,poster:e},is_hosted_embed:i,error:g})),wp.mediaelement.initialize())},editMedia:function(){var a,b,c,e=this;b=e.mapModelToMediaFrameProps(e.model.toJSON()),a=new d({frame:"video",state:"video-details",metadata:b}),wp.media.frame=a,a.$el.addClass("media-widget"),c=function(a){e.selectedAttachment.set(a),e.model.set(_.extend(_.omit(e.model.defaults(),"title"),e.mapMediaToModelProps(a),{error:!1}))},a.state("video-details").on("update",c),a.state("replace-video").on("replace",c),a.on("close",function(){a.detach()}),a.open()}}),a.controlConstructors.media_video=c,a.modelConstructors.media_video=b}(wp.mediaWidgets); \ No newline at end of file diff --git a/wp-includes/version.php b/wp-includes/version.php index 47a257893a..c0970425cf 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.8-beta1-40809'; +$wp_version = '4.8-beta1-40810'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.