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