Widgets: Introduce isHostedVideo method on VideoWidgetControl to allow plugins to extend for recognizing services beyond YouTube and Vimeo.

Also update jshint configuration in Gruntfile to include the widget scripts among the JS files linted.

Props timmydcrawford.
See #39994.
Fixes #40808.


git-svn-id: https://develop.svn.wordpress.org/trunk@40810 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Weston Ruter
2017-05-20 04:17:33 +00:00
parent 2a5f7a8901
commit 016dc58620
3 changed files with 20 additions and 4 deletions

View File

@@ -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 ) {