Media: Improve acceptance of YouTube /embed/ URLs when inserting in media modal.
Props timmydcrawford. Fixes #41201. git-svn-id: https://develop.svn.wordpress.org/trunk@41179 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
e2cd1a0f46
commit
43fc92e4a9
@ -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,
|
||||
|
@ -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
|
||||
|
@ -35,9 +35,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;
|
||||
}
|
||||
|
||||
@ -45,10 +46,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
|
||||
|
Loading…
Reference in New Issue
Block a user