37 | | $('#nickname').blur(function(){ |
38 | | var str = $(this).val() || $('#user_login').val(); |
39 | | var select = $('#display_name'); |
40 | | var sel = select.children('option:selected').attr('id'); |
41 | | select.children('#display_nickname').remove(); |
42 | | if ( ! select.children('option[value=' + str + ']').length ) |
43 | | select.append('<option id="display_nickname" value="' + str + '">' + str + '</option>'); |
44 | | $('#'+sel).attr('selected', 'selected'); |
45 | | }); |
46 | | $('#first_name, #last_name').blur(function(){ |
47 | | var select = $('#display_name'); |
48 | | var first = $('#first_name').val(), last = $('#last_name').val(); |
49 | | var sel = select.children('option:selected').attr('id'); |
50 | | $('#display_firstname, #display_lastname, #display_firstlast, #display_lastfirst').remove(); |
51 | | if ( first && ! select.children('option[value=' + first + ']').length ) |
52 | | select.append('<option id="display_firstname" value="' + first + '">' + first + '</option>'); |
53 | | if ( last && ! select.children('option[value=' + last + ']').length ) |
54 | | select.append('<option id="display_lastname" value="' + last + '">' + last + '</option>'); |
55 | | if ( first && last ) { |
56 | | if ( ! select.children('option[value=' + first + ' ' + last + ']').length ) |
57 | | select.append('<option id="display_firstlast" value="' + first + ' ' + last + '">' + first + ' ' + last + '</option>'); |
58 | | if ( ! select.children('option[value=' + last + ' ' + first + ']').length ) |
59 | | select.append('<option id="display_lastfirst" value="' + last + ' ' + first + '">' + last + ' ' + first + '</option>'); |
| 37 | $('#first_name, #last_name, #nickname').blur(function(){ |
| 38 | var select = $('#display_name'), current = select.find('option:selected').attr('id'), dub = [], |
| 39 | inputs = { |
| 40 | display_username : $('#user_login').val(), |
| 41 | display_firstname : $('#first_name').val(), |
| 42 | display_lastname : $('#last_name').val(), |
| 43 | display_nickname : $('#nickname').val() |
| 44 | }; |
| 45 | |
| 46 | if ( inputs.display_firstname && inputs.display_lastname ) { |
| 47 | inputs['display_firstlast'] = inputs.display_firstname + ' ' + inputs.display_lastname; |
| 48 | inputs['display_lastfirst'] = inputs.display_lastname + ' ' + inputs.display_firstname; |
61 | | $('#'+sel).attr('selected', 'selected'); |
| 50 | |
| 51 | $('option', select).remove(); |
| 52 | $.each(inputs, function( id, value ) { |
| 53 | var selected; |
| 54 | |
| 55 | if ( inputs[id].length && $.inArray( value, dub ) == -1 ) { |
| 56 | dub.push(value); |
| 57 | selected = id == current ? 'selected="selected"' : ''; |
| 58 | select.append('<option id="' + id + '" ' + selected + ' value="' + value + '">' + value + '</option>'); |
| 59 | } |
| 60 | }); |