Constrain large videos from rendering bigger than $content_width on both frontend and backend.

props wonderboymusic. fixes #23955.

git-svn-id: http://core.svn.wordpress.org/trunk@23989 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Mark Jaquith 2013-04-14 16:43:26 +00:00
parent f715505934
commit de45c749df
3 changed files with 32 additions and 7 deletions

View File

@ -111,15 +111,24 @@ window.wp = window.wp || {};
});
mediaPreview = function (attachment) {
var dimensions = '', url = attachment.url,
var w, h, dimensions = '', url = attachment.url,
mime = attachment.mime,
format = attachment.type;
if ( 'video' === format ) {
if ( attachment.width )
dimensions += ' width="' + attachment.width + '"';
if ( attachment.height )
dimensions += ' height="' + attachment.height + '"';
if ( attachment.width ) {
w = attachment.width;
if ( w > 600 )
w = 600;
dimensions += ' width="' + w + '"';
}
if ( attachment.height ) {
h = attachment.height;
if ( attachment.width && w < attachment.width )
h = Math.round( ( h * w ) / attachment.width );
dimensions += ' height="' + h + '"';
}
}
$('#' + format + '-preview').remove();

View File

@ -547,8 +547,11 @@ add_action( 'template_redirect', 'twentythirteen_content_width' );
* @return array Filtered attribute list.
*/
function twentythirteen_video_width( $atts ) {
if ( has_post_format( 'video' ) )
$atts['width'] = 724;
if ( ! is_admin() && has_post_format( 'video' ) ) {
$new_width = 724;
$atts['height'] = round( ( $atts['height'] * $new_width ) / $atts['width'] );
$atts['width'] = $new_width;
}
return $atts;
}

View File

@ -956,12 +956,25 @@ function wp_video_shortcode( $attr ) {
'height' => 360,
'width' => empty( $content_width ) ? 640 : $content_width,
);
foreach ( $default_types as $type )
$defaults_atts[$type] = '';
$atts = shortcode_atts( $defaults_atts, $attr, 'video' );
extract( $atts );
$w = $width;
$h = $height;
if ( is_admin() && $width > 600 )
$w = 600;
elseif ( ! is_admin() && $w > $defaults_atts['width'] )
$w = $defaults_atts['width'];
if ( $w < $width )
$height = round( ( $h * $w ) / $width );
$width = $w;
$primary = false;
if ( ! empty( $src ) ) {
$type = wp_check_filetype( $src );