Ticket #26017: 26016.diff
File 26016.diff, 5.7 KB (added by , 11 years ago) |
---|
-
src/wp-admin/js/user-profile.js
1 (function($){ 1 /* global ajaxurl:false */ 2 /* global pwsL10n:false */ 3 /* global svgPainter:false */ 2 4 5 (function( $ ) { 6 3 7 function check_pass_strength() { 4 var pass1 = $( '#pass1').val(), user = $('#user_login').val(), pass2 = $('#pass2').val(), strength;8 var pass1 = $( '#pass1' ).val(), pass2 = $( '#pass2' ).val(), strength; 5 9 6 $( '#pass-strength-result').removeClass('short bad good strong');10 $( '#pass-strength-result' ).removeClass( 'short bad good strong' ); 7 11 if ( ! pass1 ) { 8 $( '#pass-strength-result').html( pwsL10n.empty );12 $( '#pass-strength-result' ).html( pwsL10n.empty ); 9 13 return; 10 14 } 11 15 … … 13 17 14 18 switch ( strength ) { 15 19 case 2: 16 $( '#pass-strength-result').addClass('bad').html( pwsL10n['bad']);17 20 $( '#pass-strength-result' ).addClass( 'bad' ).html( pwsL10n.bad ); 21 break; 18 22 case 3: 19 $( '#pass-strength-result').addClass('good').html( pwsL10n['good']);20 23 $( '#pass-strength-result' ).addClass( 'good' ).html( pwsL10n.good ); 24 break; 21 25 case 4: 22 $( '#pass-strength-result').addClass('strong').html( pwsL10n['strong']);23 26 $( '#pass-strength-result' ).addClass( 'strong' ).html( pwsL10n.strong ); 27 break; 24 28 case 5: 25 $( '#pass-strength-result').addClass('short').html( pwsL10n['mismatch']);26 29 $( '#pass-strength-result' ).addClass( 'short' ).html( pwsL10n.mismatch ); 30 break; 27 31 default: 28 $( '#pass-strength-result').addClass('short').html( pwsL10n['short'] );32 $( '#pass-strength-result' ).addClass( 'short' ).html( pwsL10n['short'] ); 29 33 } 30 34 } 31 35 32 $( document).ready( function() {33 var select = $( '#display_name');36 $( document ).ready( function() { 37 var select = $( '#display_name'), $colorpicker, $stylesheet, user_id, current_user_id; 34 38 35 $( '#pass1').val('').keyup( check_pass_strength );36 $( '#pass2').val('').keyup( check_pass_strength );37 $( '#pass-strength-result').show();38 $( '.color-palette').click( function() {39 $( this).siblings('input[name="admin_color"]').prop('checked', true);39 $( '#pass1' ).val( '' ).keyup( check_pass_strength ); 40 $( '#pass2' ).val( '' ).keyup( check_pass_strength ); 41 $( '#pass-strength-result' ).show(); 42 $( '.color-palette' ).click( function() { 43 $( this ).siblings('input[name="admin_color"]' ).prop('checked', true); 40 44 }); 41 45 42 46 if ( select.length ) { 43 $( '#first_name, #last_name, #nickname').bind( 'blur.user_profile', function() {47 $( '#first_name, #last_name, #nickname' ).bind( 'blur.user_profile', function() { 44 48 var dub = [], 45 49 inputs = { 46 display_nickname : $('#nickname').val() || '',47 display_username : $('#user_login').val() || '',48 display_firstname : $( '#first_name').val() || '',49 display_lastname : $('#last_name').val() || ''50 display_nickname : $( '#nickname' ).val() || '', 51 display_username : $( '#user_login' ).val() || '', 52 display_firstname : $( '#first_name' ).val() || '', 53 display_lastname : $( '#last_name' ).val() || '' 50 54 }; 51 55 52 56 if ( inputs.display_firstname && inputs.display_lastname ) { 53 inputs ['display_firstlast']= inputs.display_firstname + ' ' + inputs.display_lastname;54 inputs ['display_lastfirst']= inputs.display_lastname + ' ' + inputs.display_firstname;57 inputs.display_firstlast = inputs.display_firstname + ' ' + inputs.display_lastname; 58 inputs.display_lastfirst = inputs.display_lastname + ' ' + inputs.display_firstname; 55 59 } 56 60 57 $.each( $( 'option', select), function( i, el ){61 $.each( $( 'option', select ), function( i, el ) { 58 62 dub.push( el.value ); 59 63 }); 60 64 61 $.each( inputs, function( id, value ) {62 if ( ! value ) 65 $.each( inputs, function( id, value ) { 66 if ( ! value ) { 63 67 return; 68 } 64 69 65 var val = value.replace( /<\/?[a-z][^>]*>/gi, '');70 var val = value.replace( /<\/?[a-z][^>]*>/gi, '' ); 66 71 67 if ( inputs[ id].length && $.inArray( val, dub )== -1 ) {68 dub.push( val);69 $( '<option />', {70 'text': val72 if ( inputs[ id ].length && $.inArray( val, dub ) === -1 ) { 73 dub.push( val ); 74 $( '<option />', { 75 text: val 71 76 }).appendTo( select ); 72 77 } 73 78 }); 74 79 }); 75 80 } 76 81 77 var $colorpicker = $( '#color-picker' ),78 $stylesheet = $( '#colors-css' ),79 user_id = $( 'input#user_id' ).val(),80 82 $colorpicker = $( '#color-picker' ); 83 $stylesheet = $( '#colors-css' ); 84 user_id = $( 'input#user_id' ).val(); 85 current_user_id = $( 'input[name="checkuser_id"]' ).val(); 81 86 82 87 // dropdown toggle 83 88 $colorpicker.on( 'click', '.dropdown-current', function() { … … 89 94 var color_scheme = $( this ).children( 'input[name="admin_color"]' ).val(); 90 95 91 96 // update selected 92 $( this ).siblings( '.selected' ).removeClass( 'selected' ) 97 $( this ).siblings( '.selected' ).removeClass( 'selected' ); 93 98 $( this ).addClass( 'selected' ); 94 99 $( this ).find( 'input' ).prop( 'checked', true ); 95 100 … … 99 104 $colorpicker.toggleClass( 'picker-expanded' ); 100 105 101 106 // preview/save color scheme 102 if ( user_id == current_user_id ) {107 if ( user_id === current_user_id ) { 103 108 104 109 // repaint icons 105 110 $stylesheet.attr( 'href', $( this ).children( '.css_url' ).val() ); … … 108 113 109 114 // update user option 110 115 $.post( ajaxurl, { 111 action: 'save-user-color-scheme',116 action: 'save-user-color-scheme', 112 117 color_scheme: color_scheme, 113 user_id: user_id118 user_id: user_id 114 119 }); 115 120 116 121 }