Media: Improve acceptance of YouTube /embed/ URLs when inserting in media modal.

Props timmydcrawford.
Fixes #41201.

Built from https://develop.svn.wordpress.org/trunk@41179


git-svn-id: http://core.svn.wordpress.org/trunk@41019 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter 2017-07-28 02:36:46 +00:00
parent df808fc42d
commit 18fd50d2b6
5 changed files with 27 additions and 9 deletions

View File

@ -145,7 +145,7 @@ wp.mediaWidgets = ( function( $ ) {
* @returns {void}
*/
fetch: function() {
var embedLinkView = this, fetchSuccess, matches, fileExt, urlParser; // eslint-disable-line consistent-this
var embedLinkView = this, fetchSuccess, matches, fileExt, urlParser, url, re, youTubeEmbedMatch; // eslint-disable-line consistent-this
if ( embedLinkView.dfd && 'pending' === embedLinkView.dfd.state() ) {
embedLinkView.dfd.abort();
@ -190,10 +190,20 @@ wp.mediaWidgets = ( function( $ ) {
return;
}
// Support YouTube embed links.
url = embedLinkView.model.get( 'url' );
re = /https?:\/\/www\.youtube\.com\/embed\/([^/]+)/;
youTubeEmbedMatch = re.exec( url );
if ( youTubeEmbedMatch ) {
url = 'https://www.youtube.com/watch?v=' + youTubeEmbedMatch[ 1 ];
// silently change url to proper oembed-able version.
embedLinkView.model.attributes.url = url;
}
embedLinkView.dfd = $.ajax({
url: wp.media.view.settings.oEmbedProxyUrl,
data: {
url: embedLinkView.model.get( 'url' ),
url: url,
maxwidth: embedLinkView.model.get( 'width' ),
maxheight: embedLinkView.model.get( 'height' ),
_wpnonce: wp.media.view.settings.nonce.wpRestApi,

File diff suppressed because one or more lines are too long

View File

@ -4624,9 +4624,10 @@ EmbedLink = wp.media.view.Settings.extend({
}, wp.media.controller.Embed.sensitivity ),
fetch: function() {
var url = this.model.get( 'url' ), re, youTubeEmbedMatch;
// check if they haven't typed in 500 ms
if ( $('#embed-url-field').val() !== this.model.get('url') ) {
if ( $('#embed-url-field').val() !== url ) {
return;
}
@ -4634,10 +4635,17 @@ EmbedLink = wp.media.view.Settings.extend({
this.dfd.abort();
}
// Support YouTube embed urls, since they work once in the editor.
re = /https?:\/\/www\.youtube\.com\/embed\/([^/]+)/;
youTubeEmbedMatch = re.exec( url );
if ( youTubeEmbedMatch ) {
url = 'https://www.youtube.com/watch?v=' + youTubeEmbedMatch[ 1 ];
}
this.dfd = $.ajax({
url: wp.media.view.settings.oEmbedProxyUrl,
data: {
url: this.model.get( 'url' ),
url: url,
maxwidth: this.model.get( 'width' ),
maxheight: this.model.get( 'height' ),
_wpnonce: wp.media.view.settings.nonce.wpRestApi

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.9-alpha-41178';
$wp_version = '4.9-alpha-41179';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.