Changeset 41759
- Timestamp:
- 10/05/2017 12:21:27 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/js/widgets/media-video-widget.js
r41206 r41759 137 137 * Whether a url is a supported external host. 138 138 * 139 * @deprecated since 4.9. 140 * 139 141 * @param {String} url - Video url. 140 142 * @returns {boolean} Whether url is a supported video host. 141 143 */ 142 144 isHostedVideo: function isHostedVideo( url ) { 143 var parsedUrl = document.createElement( 'a' ); 144 parsedUrl.href = url; 145 return /vimeo|youtu\.?be/.test( parsedUrl.host ); 145 return false; 146 146 }, 147 147 … … 152 152 */ 153 153 renderPreview: function renderPreview() { 154 var control = this, previewContainer, previewTemplate, attachmentId, attachmentUrl, poster, isHostedEmbed = false, mime, error;154 var control = this, previewContainer, previewTemplate, attachmentId, attachmentUrl, poster, html = '', isOEmbed = false, mime, error, urlParser, matches; 155 155 attachmentId = control.model.get( 'attachment_id' ); 156 156 attachmentUrl = control.model.get( 'url' ); … … 159 159 if ( ! attachmentId && ! attachmentUrl ) { 160 160 return; 161 }162 163 if ( ! attachmentId && attachmentUrl ) {164 isHostedEmbed = control.isHostedVideo( attachmentUrl );165 }166 167 if ( isHostedEmbed ) {168 control.fetchEmbed();169 poster = control.oembedResponses[ attachmentUrl ] ? control.oembedResponses[ attachmentUrl ].thumbnail_url : null;170 161 } 171 162 … … 176 167 error = 'unsupported_file_type'; 177 168 } 169 } else if ( ! attachmentId ) { 170 urlParser = document.createElement( 'a' ); 171 urlParser.href = attachmentUrl; 172 matches = urlParser.pathname.toLowerCase().match( /\.(\w+)$/ ); 173 if ( matches ) { 174 if ( ! _.contains( _.keys( wp.media.view.settings.embedMimes ), matches[1] ) ) { 175 error = 'unsupported_file_type'; 176 } 177 } else { 178 isOEmbed = true; 179 } 180 } 181 182 if ( isOEmbed ) { 183 control.fetchEmbed(); 184 if ( control.oembedResponses[ attachmentUrl ] ) { 185 poster = control.oembedResponses[ attachmentUrl ].thumbnail_url; 186 html = control.oembedResponses[ attachmentUrl ].html.replace( /\swidth="\d+"/, ' width="100%"' ).replace( /\sheight="\d+"/, '' ); 187 } 178 188 } 179 189 … … 183 193 previewContainer.html( previewTemplate({ 184 194 model: { 185 attachment_id: control.model.get( 'attachment_id' ), 195 attachment_id: attachmentId, 196 html: html, 186 197 src: attachmentUrl, 187 198 poster: poster 188 199 }, 189 is_ hosted_embed: isHostedEmbed,200 is_oembed: isOEmbed, 190 201 error: error 191 202 })); -
trunk/src/wp-admin/js/widgets/media-widgets.js
r41590 r41759 182 182 fetchSuccess( '<!--success-->' ); 183 183 } 184 return;185 }186 187 // If video, test for Vimeo and YouTube, otherwise, renderFail(). This should be removed once #34115 is resolved.188 if ( 'video' === this.controller.options.mimeType && ! /vimeo|youtu\.?be/.test( urlParser.host ) ) {189 embedLinkView.renderFail();190 184 return; 191 185 } -
trunk/src/wp-includes/widgets/class-wp-widget-media-video.php
r41640 r41759 122 122 } 123 123 124 add_filter( 'wp_video_shortcode', array( $this, 'inject_video_max_width_style' ) ); 125 126 echo wp_video_shortcode( 127 array_merge( 128 $instance, 129 compact( 'src' ) 130 ), 131 $instance['content'] 132 ); 133 134 remove_filter( 'wp_video_shortcode', array( $this, 'inject_video_max_width_style' ) ); 124 if ( $attachment ) { 125 add_filter( 'wp_video_shortcode', array( $this, 'inject_video_max_width_style' ) ); 126 127 echo wp_video_shortcode( 128 array_merge( 129 $instance, 130 compact( 'src' ) 131 ), 132 $instance['content'] 133 ); 134 135 remove_filter( 'wp_video_shortcode', array( $this, 'inject_video_max_width_style' ) ); 136 } else { 137 echo $this->inject_video_max_width_style( wp_oembed_get( $src ) ); 138 } 135 139 } 136 140 … … 228 232 <p><?php _e( 'Unable to preview media due to an unknown error.' ); ?></p> 229 233 </div> 230 <# } else if ( data.is_ hosted_embed && data.model.poster ) { #>234 <# } else if ( data.is_oembed && data.model.poster ) { #> 231 235 <a href="{{ data.model.src }}" target="_blank" class="media-widget-video-link"> 232 236 <img src="{{ data.model.poster }}" /> 233 237 </a> 234 <# } else if ( data.is_ hosted_embed ) { #>238 <# } else if ( data.is_oembed ) { #> 235 239 <a href="{{ data.model.src }}" target="_blank" class="media-widget-video-link no-poster"> 236 240 <span class="dashicons dashicons-format-video"></span> -
trunk/tests/qunit/wp-admin/js/widgets/test-media-video-widget.js
r40941 r41759 35 35 equal( mappedProps.loop, false, 'mapMediaToModelProps should set loop' ); 36 36 equal( mappedProps.preload, 'meta', 'mapMediaToModelProps should set preload' ); 37 38 // Test isHostedVideo().39 equal( videoWidgetControlInstance.isHostedVideo( 'https://www.youtube.com/watch?v=OQSNhk5ICTI' ), true, 'isHostedVideo should return true for full YouTube url.' );40 equal( videoWidgetControlInstance.isHostedVideo( 'https://youtu.be/OQSNhk5ICTI' ), true, 'isHostedVideo should return true for shortened youtube url' );41 equal( videoWidgetControlInstance.isHostedVideo( 'https://vimeo.com/190372437' ), true, 'isHostedVideo should return true for vimeo url.' );42 equal( videoWidgetControlInstance.isHostedVideo( 'https://wordpress.org/' ), false, 'isHostedVideo should return false for non-supported video url.' );43 37 }); 44 38
Note: See TracChangeset
for help on using the changeset viewer.