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'); |
| 39 | var first = $('#first_name').val(), last = $('#last_name').val(), nickname = $('#nickname').val(); |
| 40 | var inputs = [first, last, nickname]; |
| 41 | if ( first && last ) |
| 42 | inputs.push(first + ' ' + last, last + ' ' + first); |
| 43 | var inputs = jQuery.unique(inputs).reverse(); |
| 44 | $(select).children('option[id!="display_username"]').remove(); |
| 45 | $.each(inputs, function( index, value ) { |
| 46 | if ( inputs[index].length ) |
| 47 | select.append('<option value="' + value + '">' + value + '</option>'); |
| 48 | }); |
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>'); |
60 | | } |
61 | | $('#'+sel).attr('selected', 'selected'); |
62 | | }); |