Dynamically remove duplicates from the 'display name' profile.php option. fixes #10030

git-svn-id: http://svn.automattic.com/wordpress/trunk@13539 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2010-03-01 22:34:43 +00:00
parent b657e01fad
commit 30b82141f9
3 changed files with 21 additions and 12 deletions

View File

@ -31,21 +31,29 @@
$('.color-palette').click(function(){$(this).siblings('input[name=admin_color]').attr('checked', 'checked')});
$('#nickname').blur(function(){
var str = $(this).val() || $('#user_login').val();
$('#display_name #display_nickname').val(str).html(str);
var select = $('#display_name');
var sel = select.children('option:selected').attr('id');
select.children('#display_nickname').remove();
if ( ! select.children('option[value=' + str + ']').length )
select.append('<option id="display_nickname" value="' + str + '">' + str + '</option>');
$('#'+sel).attr('selected', 'selected');
});
$('#first_name, #last_name').blur(function(){
var select = $('#display_name');
var first = $('#first_name').val(), last = $('#last_name').val();
var sel = select.children('option:selected').attr('id');
$('#display_firstname, #display_lastname, #display_firstlast, #display_lastfirst').remove();
if ( first && ! select.children('option[value=' + first + ']').length )
select.append('<option id="display_firstname" value="' + first + '">' + first + '</option>');
if ( last && ! select.children('option[value=' + last + ']').length )
select.append('<option id="display_lastname" value="' + last + '">' + last + '</option>');
if ( first && last ) {
$('#display_name').append('<option id="display_firstname" value="' + first + '">' + first + '</option>' +
'<option id="display_lastname" value="' + last + '">' + last + '</option>' +
'<option id="display_firstlast" value="' + first + ' ' + last + '">' + first + ' ' + last + '</option>' +
'<option id="display_lastfirst" value="' + last + ' ' + first + '">' + last + ' ' + first + '</option>');
} else if ( first && !last ) {
$('#display_name').append('<option id="display_firstname" value="' + first + '">' + first + '</option>');
} else if ( !first && last ) {
$('#display_name').append('<option id="display_lastname" value="' + last + '">' + last + '</option>');
if ( ! select.children('option[value=' + first + ' ' + last + ']').length )
select.append('<option id="display_firstlast" value="' + first + ' ' + last + '">' + first + ' ' + last + '</option>');
if ( ! select.children('option[value=' + last + ' ' + first + ']').length )
select.append('<option id="display_lastfirst" value="' + last + ' ' + first + '">' + last + ' ' + first + '</option>');
}
$('#'+sel).attr('selected', 'selected');
});
});

View File

@ -1 +1 @@
(function(a){function b(){var d=a("#pass1").val(),c=a("#user_login").val(),e;a("#pass-strength-result").removeClass("short bad good strong");if(!d){a("#pass-strength-result").html(pwsL10n.empty);return}e=passwordStrength(d,c);switch(e){case 2:a("#pass-strength-result").addClass("bad").html(pwsL10n.bad);break;case 3:a("#pass-strength-result").addClass("good").html(pwsL10n.good);break;case 4:a("#pass-strength-result").addClass("strong").html(pwsL10n.strong);break;default:a("#pass-strength-result").addClass("short").html(pwsL10n["short"])}}a(document).ready(function(){a("#pass1").val("").keyup(b);a(".color-palette").click(function(){a(this).siblings("input[name=admin_color]").attr("checked","checked")});a("#nickname").blur(function(){var c=a(this).val()||a("#user_login").val();a("#display_name #display_nickname").val(c).html(c)});a("#first_name, #last_name").blur(function(){var d=a("#first_name").val(),c=a("#last_name").val();a("#display_firstname, #display_lastname, #display_firstlast, #display_lastfirst").remove();if(d&&c){a("#display_name").append('<option id="display_firstname" value="'+d+'">'+d+'</option><option id="display_lastname" value="'+c+'">'+c+'</option><option id="display_firstlast" value="'+d+" "+c+'">'+d+" "+c+'</option><option id="display_lastfirst" value="'+c+" "+d+'">'+c+" "+d+"</option>")}else{if(d&&!c){a("#display_name").append('<option id="display_firstname" value="'+d+'">'+d+"</option>")}else{if(!d&&c){a("#display_name").append('<option id="display_lastname" value="'+c+'">'+c+"</option>")}}}})})})(jQuery);
(function(a){function b(){var d=a("#pass1").val(),c=a("#user_login").val(),e;a("#pass-strength-result").removeClass("short bad good strong");if(!d){a("#pass-strength-result").html(pwsL10n.empty);return}e=passwordStrength(d,c);switch(e){case 2:a("#pass-strength-result").addClass("bad").html(pwsL10n.bad);break;case 3:a("#pass-strength-result").addClass("good").html(pwsL10n.good);break;case 4:a("#pass-strength-result").addClass("strong").html(pwsL10n.strong);break;default:a("#pass-strength-result").addClass("short").html(pwsL10n["short"])}}a(document).ready(function(){a("#pass1").val("").keyup(b);a(".color-palette").click(function(){a(this).siblings("input[name=admin_color]").attr("checked","checked")});a("#nickname").blur(function(){var e=a(this).val()||a("#user_login").val();var c=a("#display_name");var d=c.children("option:selected").attr("id");c.children("#display_nickname").remove();if(!c.children("option[value="+e+"]").length){c.append('<option id="display_nickname" value="'+e+'">'+e+"</option>")}a("#"+d).attr("selected","selected")});a("#first_name, #last_name").blur(function(){var c=a("#display_name");var f=a("#first_name").val(),d=a("#last_name").val();var e=c.children("option:selected").attr("id");a("#display_firstname, #display_lastname, #display_firstlast, #display_lastfirst").remove();if(f&&!c.children("option[value="+f+"]").length){c.append('<option id="display_firstname" value="'+f+'">'+f+"</option>")}if(d&&!c.children("option[value="+d+"]").length){c.append('<option id="display_lastname" value="'+d+'">'+d+"</option>")}if(f&&d){if(!c.children("option[value="+f+" "+d+"]").length){c.append('<option id="display_firstlast" value="'+f+" "+d+'">'+f+" "+d+"</option>")}if(!c.children("option[value="+d+" "+f+"]").length){c.append('<option id="display_lastfirst" value="'+d+" "+f+'">'+d+" "+f+"</option>")}}a("#"+e).attr("selected","selected")})})})(jQuery);

View File

@ -256,8 +256,8 @@ else
<select name="display_name" id="display_name">
<?php
$public_display = array();
$public_display['display_nickname'] = $profileuser->nickname;
$public_display['display_username'] = $profileuser->user_login;
$public_display['display_nickname'] = $profileuser->nickname;
if ( !empty($profileuser->first_name) )
$public_display['display_firstname'] = $profileuser->first_name;
if ( !empty($profileuser->last_name) )
@ -266,9 +266,10 @@ else
$public_display['display_firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name;
$public_display['display_lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name;
}
if ( !in_array( $profileuser->display_name, $public_display ) )// Only add this if it isn't duplicated elsewhere
if ( !in_array( $profileuser->display_name, $public_display ) ) // Only add this if it isn't duplicated elsewhere
$public_display = array( 'display_displayname' => $profileuser->display_name ) + $public_display;
$public_display = array_map( 'trim', $public_display );
$public_display = array_unique( $public_display );
foreach ( $public_display as $id => $item ) {
?>
<option id="<?php echo $id; ?>" value="<?php echo esc_attr($item); ?>"<?php selected( $profileuser->display_name, $item ); ?>><?php echo $item; ?></option>