Ticket #40808: 40808.1.diff
File 40808.1.diff, 2.3 KB (added by , 8 years ago) |
---|
-
src/wp-admin/js/widgets/media-video-widget.js
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 ) { -
tests/qunit/wp-admin/js/widgets/test-media-video-widget.js
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 ) {