diff --git Gruntfile.js Gruntfile.js
index 37848c1449..c7e7f73b2b 100644
|
|
module.exports = function(grunt) { |
329 | 329 | expand: true, |
330 | 330 | cwd: SOURCE_DIR, |
331 | 331 | src: [ |
332 | | 'wp-admin/js/*.js', |
| 332 | 'wp-admin/js/**/*.js', |
333 | 333 | 'wp-includes/js/*.js', |
334 | 334 | // Built scripts. |
335 | 335 | '!wp-includes/js/media-*', |
diff --git src/wp-admin/js/widgets/media-video-widget.js src/wp-admin/js/widgets/media-video-widget.js
index 547c4efc48..79ff84d86b 100644
|
|
|
135 | 135 | }, |
136 | 136 | |
137 | 137 | /** |
| 138 | * Whether a url is a supported external host. |
| 139 | * |
| 140 | * @param {String} url - Video url. |
| 141 | * @returns {boolean} Whether url is a supported video host. |
| 142 | */ |
| 143 | isHostedVideo: function isHostedVideo( url ) { |
| 144 | var parsedUrl = document.createElement( 'a' ); |
| 145 | parsedUrl.href = url; |
| 146 | return /vimeo|youtu\.?be/.test( parsedUrl.host ); |
| 147 | }, |
| 148 | |
| 149 | /** |
138 | 150 | * Render preview. |
139 | 151 | * |
140 | 152 | * @returns {void} |
… |
… |
|
150 | 162 | } |
151 | 163 | |
152 | 164 | if ( ! attachmentId && attachmentUrl ) { |
153 | | parsedUrl = document.createElement( 'a' ); |
154 | | parsedUrl.href = attachmentUrl; |
155 | | isHostedEmbed = /vimeo|youtu\.?be/.test( parsedUrl.host ); |
| 165 | isHostedEmbed = control.isHostedVideo( attachmentUrl ); |
156 | 166 | } |
157 | 167 | |
158 | 168 | if ( isHostedEmbed ) { |
diff --git tests/qunit/wp-admin/js/widgets/test-media-video-widget.js tests/qunit/wp-admin/js/widgets/test-media-video-widget.js
index f3b111ecc5..f74c29833d 100644
|
|
|
32 | 32 | equal( mappedProps.title, undefined, 'mapMediaToModelProps should ignore title inputs' ); |
33 | 33 | equal( mappedProps.loop, false, 'mapMediaToModelProps should set loop' ); |
34 | 34 | equal( mappedProps.preload, 'meta', 'mapMediaToModelProps should set preload' ); |
| 35 | |
| 36 | // Test isHostedVideo(). |
| 37 | equal( videoWidgetControlInstance.isHostedVideo( 'https://www.youtube.com/watch?v=OQSNhk5ICTI'), true, 'isHostedVideo should return true for full YouTube url.' ); |
| 38 | equal( videoWidgetControlInstance.isHostedVideo( 'https://youtu.be/OQSNhk5ICTI' ), true, 'isHostedVideo should return true for shortened youtube url' ); |
| 39 | equal( videoWidgetControlInstance.isHostedVideo( 'https://vimeo.com/190372437' ), true, 'isHostedVideo should return true for vimeo url.' ); |
| 40 | equal( videoWidgetControlInstance.isHostedVideo( 'https://wordpress.org/' ), false, 'isHostedVideo should return false for non-supported video url.' ); |
35 | 41 | }); |
36 | 42 | |
37 | 43 | test( 'video widget control renderPreview', function( assert ) { |