Fix improper selection of radio buttons, improve JS for storing image settings, fixes #11021
git-svn-id: https://develop.svn.wordpress.org/trunk@12188 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
dd36b37254
commit
ac9c33e0e9
@ -780,16 +780,19 @@ function media_upload_library() {
|
||||
*/
|
||||
function image_align_input_fields( $post, $checked = '' ) {
|
||||
|
||||
if ( empty($checked) )
|
||||
$checked = get_user_setting('align', 'none');
|
||||
|
||||
$alignments = array('none' => __('None'), 'left' => __('Left'), 'center' => __('Center'), 'right' => __('Right'));
|
||||
if ( !array_key_exists( (string) $checked, $alignments ) )
|
||||
$checked = 'none';
|
||||
|
||||
$out = array();
|
||||
foreach ($alignments as $name => $label) {
|
||||
foreach ( $alignments as $name => $label ) {
|
||||
$name = esc_attr($name);
|
||||
$out[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='$name'".
|
||||
( $checked == $name ? " checked='checked'" : "" ) .
|
||||
" /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>" . $label . "</label>";
|
||||
" /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>$label</label>";
|
||||
}
|
||||
return join("\n", $out);
|
||||
}
|
||||
@ -803,27 +806,36 @@ function image_align_input_fields( $post, $checked = '' ) {
|
||||
* @param unknown_type $checked
|
||||
* @return unknown
|
||||
*/
|
||||
function image_size_input_fields( $post, $checked = '' ) {
|
||||
function image_size_input_fields( $post, $check = '' ) {
|
||||
|
||||
// get a list of the actual pixel dimensions of each possible intermediate version of this image
|
||||
$size_names = array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full size'));
|
||||
|
||||
foreach ( $size_names as $size => $name ) {
|
||||
if ( empty($check) )
|
||||
$check = get_user_setting('imgsize', 'medium');
|
||||
|
||||
foreach ( $size_names as $size => $label ) {
|
||||
$downsize = image_downsize($post->ID, $size);
|
||||
$checked = '';
|
||||
|
||||
// is this size selectable?
|
||||
$enabled = ( $downsize[3] || 'full' == $size );
|
||||
$css_id = "image-size-{$size}-{$post->ID}";
|
||||
// if this size is the default but that's not available, don't select it
|
||||
if ( $checked && !$enabled )
|
||||
$checked = '';
|
||||
// if $checked was not specified, default to the first available size that's bigger than a thumbnail
|
||||
if ( !$checked && $enabled && 'thumbnail' != $size )
|
||||
$checked = $size;
|
||||
if ( $size == $check ) {
|
||||
if ( $enabled )
|
||||
$checked = " checked='checked'";
|
||||
else
|
||||
$check = '';
|
||||
} elseif ( !$check && $enabled && 'thumbnail' != $size ) {
|
||||
// if $check is not enabled, default to the first available size that's bigger than a thumbnail
|
||||
$check = $size;
|
||||
$checked = " checked='checked'";
|
||||
}
|
||||
|
||||
$html = "<div class='image-size-item'><input type='radio' ".( $enabled ? '' : "disabled='disabled'")."name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'".( $checked == $size ? " checked='checked'" : '') ." />";
|
||||
$html = "<div class='image-size-item'><input type='radio' " . ( $enabled ? '' : "disabled='disabled' " ) . "name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'$checked />";
|
||||
|
||||
$html .= "<label for='{$css_id}'>" . __($name). "</label>";
|
||||
$html .= "<label for='{$css_id}'>$label</label>";
|
||||
// only show the dimensions if that choice is available
|
||||
if ( $enabled )
|
||||
$html .= " <label for='{$css_id}' class='help'>" . sprintf( __("(%d × %d)"), $downsize[1], $downsize[2] ). "</label>";
|
||||
@ -849,21 +861,25 @@ function image_size_input_fields( $post, $checked = '' ) {
|
||||
* @param unknown_type $url_type
|
||||
* @return unknown
|
||||
*/
|
||||
function image_link_input_fields($post, $url_type='') {
|
||||
function image_link_input_fields($post, $url_type = '') {
|
||||
|
||||
$file = wp_get_attachment_url($post->ID);
|
||||
$link = get_attachment_link($post->ID);
|
||||
|
||||
if ( empty($url_type) )
|
||||
$url_type = get_user_setting('urlbutton', 'post');
|
||||
|
||||
$url = '';
|
||||
if ( $url_type == 'file' )
|
||||
$url = $file;
|
||||
elseif ( $url_type == 'post' )
|
||||
$url = $link;
|
||||
|
||||
return "<input type='text' class='urlfield' name='attachments[$post->ID][url]' value='" . esc_attr($url) . "' /><br />
|
||||
<button type='button' class='button urlnone' title=''>" . __('None') . "</button>
|
||||
<button type='button' class='button urlfile' title='" . esc_attr($file) . "'>" . __('File URL') . "</button>
|
||||
<button type='button' class='button urlpost' title='" . esc_attr($link) . "'>" . __('Post URL') . "</button>
|
||||
return "
|
||||
<input type='text' class='urlfield' name='attachments[$post->ID][url]' value='" . esc_attr($url) . "' /><br />
|
||||
<button type='button' class='button urlnone' title=''>" . __('None') . "</button>
|
||||
<button type='button' class='button urlfile' title='" . esc_attr($file) . "'>" . __('File URL') . "</button>
|
||||
<button type='button' class='button urlpost' title='" . esc_attr($link) . "'>" . __('Post URL') . "</button>
|
||||
";
|
||||
}
|
||||
|
||||
@ -896,7 +912,7 @@ function image_attachment_fields_to_edit($form_fields, $post) {
|
||||
'html' => image_align_input_fields($post, get_option('image_default_align')),
|
||||
);
|
||||
|
||||
$form_fields['image-size'] = image_size_input_fields( $post, get_option('image_default_size') );
|
||||
$form_fields['image-size'] = image_size_input_fields( $post, get_option('image_default_size', 'medium') );
|
||||
|
||||
} else {
|
||||
unset( $form_fields['image_alt'] );
|
||||
|
@ -169,7 +169,7 @@ function deleteError(X, textStatus, errorThrown) {
|
||||
|
||||
function updateMediaForm() {
|
||||
var one = jQuery('form.type-form #media-items').children(), items = jQuery('#media-items').children();
|
||||
storeState();
|
||||
|
||||
// Just one file, no need for collapsible part
|
||||
if ( one.length == 1 ) {
|
||||
jQuery('.slidetoggle', one).slideDown(500).siblings().addClass('hidden').filter('.toggle').toggle();
|
||||
@ -316,38 +316,22 @@ function cancelUpload() {
|
||||
}
|
||||
|
||||
// remember the last used image size, alignment and url
|
||||
var storeState;
|
||||
(function($){
|
||||
jQuery(document).ready(function($){
|
||||
$('input[type="radio"]', '#media-items').live('click', function(){
|
||||
var tr = $(this).closest('tr');
|
||||
|
||||
storeState = function(){
|
||||
var align = getUserSetting('align') || '', imgsize = getUserSetting('imgsize') || '';
|
||||
if ( $(tr).hasClass('align') )
|
||||
setUserSetting('align', $(this).val());
|
||||
else if ( $(tr).hasClass('image-size') )
|
||||
setUserSetting('imgsize', $(this).val());
|
||||
});
|
||||
|
||||
$('tr.align input[type="radio"]').click(function(){
|
||||
setUserSetting('align', $(this).val());
|
||||
}).filter(function(){
|
||||
if ( $(this).val() == align )
|
||||
return true;
|
||||
return false;
|
||||
}).attr('checked','checked');
|
||||
|
||||
$('tr.image-size input[type="radio"]').click(function(){
|
||||
setUserSetting('imgsize', $(this).val());
|
||||
}).filter(function(){
|
||||
if ( $(this).attr('disabled') || $(this).val() != imgsize )
|
||||
return false;
|
||||
return true;
|
||||
}).attr('checked','checked');
|
||||
|
||||
$('tr.url button').click(function(){
|
||||
$('button.button', '#media-items').live('click', function(){
|
||||
var c = this.className || '';
|
||||
c = c.replace(/.*?(url[^ '"]+).*/, '$1');
|
||||
if (c) setUserSetting('urlbutton', c);
|
||||
$(this).siblings('.urlfield').val( $(this).attr('title') );
|
||||
c = c.replace(/.*?url([^ '"]+).*/, '$1');
|
||||
if ( c ) {
|
||||
setUserSetting('urlbutton', c);
|
||||
$(this).siblings('.urlfield').val( $(this).attr('title') );
|
||||
}
|
||||
});
|
||||
|
||||
$('tr.url .urlfield').each(function(){
|
||||
var b = getUserSetting('urlbutton');
|
||||
$(this).val( $(this).siblings('button.'+b).attr('title') );
|
||||
});
|
||||
}
|
||||
})(jQuery);
|
||||
});
|
||||
|
File diff suppressed because one or more lines are too long
@ -183,7 +183,7 @@ function wp_default_scripts( &$scripts ) {
|
||||
$scripts->add( 'swfupload-all', '/wp-includes/js/swfupload/swfupload-all.js', array(), '2201');
|
||||
}
|
||||
|
||||
$scripts->add( 'swfupload-handlers', "/wp-includes/js/swfupload/handlers$suffix.js", array('swfupload-all', 'jquery'), '2201-20091029');
|
||||
$scripts->add( 'swfupload-handlers', "/wp-includes/js/swfupload/handlers$suffix.js", array('swfupload-all', 'jquery'), '2201-20091115');
|
||||
$max_upload_size = ( (int) ( $max_up = @ini_get('upload_max_filesize') ) < (int) ( $max_post = @ini_get('post_max_size') ) ) ? $max_up : $max_post;
|
||||
if ( empty($max_upload_size) )
|
||||
$max_upload_size = __('not configured');
|
||||
|
Loading…
Reference in New Issue
Block a user