equal
deleted
inserted
replaced
|
1 /** |
|
2 * @output wp-admin/js/user-profile.js |
|
3 */ |
|
4 |
1 /* global ajaxurl, pwsL10n, userProfileL10n */ |
5 /* global ajaxurl, pwsL10n, userProfileL10n */ |
2 (function($) { |
6 (function($) { |
3 var updateLock = false, |
7 var updateLock = false, |
4 |
8 |
5 $pass1Row, |
9 $pass1Row, |
11 $weakRow, |
15 $weakRow, |
12 $weakCheckbox, |
16 $weakCheckbox, |
13 $toggleButton, |
17 $toggleButton, |
14 $submitButtons, |
18 $submitButtons, |
15 $submitButton, |
19 $submitButton, |
16 currentPass, |
20 currentPass; |
17 inputEvent; |
|
18 |
|
19 /* |
|
20 * Use feature detection to determine whether password inputs should use |
|
21 * the `keyup` or `input` event. Input is preferred but lacks support |
|
22 * in legacy browsers. |
|
23 */ |
|
24 if ( 'oninput' in document.createElement( 'input' ) ) { |
|
25 inputEvent = 'input'; |
|
26 } else { |
|
27 inputEvent = 'keyup'; |
|
28 } |
|
29 |
21 |
30 function generatePassword() { |
22 function generatePassword() { |
31 if ( typeof zxcvbn !== 'function' ) { |
23 if ( typeof zxcvbn !== 'function' ) { |
32 setTimeout( generatePassword, 50 ); |
24 setTimeout( generatePassword, 50 ); |
33 return; |
25 return; |
65 'autocomplete': 'off' |
57 'autocomplete': 'off' |
66 } ) |
58 } ) |
67 .addClass( $pass1[0].className ) |
59 .addClass( $pass1[0].className ) |
68 .data( 'pw', $pass1.data( 'pw' ) ) |
60 .data( 'pw', $pass1.data( 'pw' ) ) |
69 .val( $pass1.val() ) |
61 .val( $pass1.val() ) |
70 .on( inputEvent, function () { |
62 .on( 'input', function () { |
71 if ( $pass1Text.val() === currentPass ) { |
63 if ( $pass1Text.val() === currentPass ) { |
72 return; |
64 return; |
73 } |
65 } |
74 $pass2.val( $pass1Text.val() ); |
66 $pass2.val( $pass1Text.val() ); |
75 $pass1.val( $pass1Text.val() ).trigger( 'pwupdate' ); |
67 $pass1.val( $pass1Text.val() ).trigger( 'pwupdate' ); |
80 |
72 |
81 if ( 1 === parseInt( $pass1.data( 'reveal' ), 10 ) ) { |
73 if ( 1 === parseInt( $pass1.data( 'reveal' ), 10 ) ) { |
82 generatePassword(); |
74 generatePassword(); |
83 } |
75 } |
84 |
76 |
85 $pass1.on( inputEvent + ' pwupdate', function () { |
77 $pass1.on( 'input' + ' pwupdate', function () { |
86 if ( $pass1.val() === currentPass ) { |
78 if ( $pass1.val() === currentPass ) { |
87 return; |
79 return; |
88 } |
80 } |
89 |
81 |
90 currentPass = $pass1.val(); |
82 currentPass = $pass1.val(); |
182 * Fix a LastPass mismatch issue, LastPass only changes pass2. |
174 * Fix a LastPass mismatch issue, LastPass only changes pass2. |
183 * |
175 * |
184 * This fixes the issue by copying any changes from the hidden |
176 * This fixes the issue by copying any changes from the hidden |
185 * pass2 field to the pass1 field, then running check_pass_strength. |
177 * pass2 field to the pass1 field, then running check_pass_strength. |
186 */ |
178 */ |
187 $pass2 = $('#pass2').on( inputEvent, function () { |
179 $pass2 = $( '#pass2' ).on( 'input', function () { |
188 if ( $pass2.val().length > 0 ) { |
180 if ( $pass2.val().length > 0 ) { |
189 $pass1.val( $pass2.val() ); |
181 $pass1.val( $pass2.val() ); |
190 $pass2.val(''); |
182 $pass2.val(''); |
191 currentPass = ''; |
183 currentPass = ''; |
192 $pass1.trigger( 'pwupdate' ); |
184 $pass1.trigger( 'pwupdate' ); |
244 wp.ajax.post( 'generate-password' ) |
236 wp.ajax.post( 'generate-password' ) |
245 .done( function( data ) { |
237 .done( function( data ) { |
246 $pass1.data( 'pw', data ); |
238 $pass1.data( 'pw', data ); |
247 } ); |
239 } ); |
248 |
240 |
249 $generateButton.show(); |
241 $generateButton.show().focus(); |
250 $passwordWrapper.hide(); |
242 $passwordWrapper.hide(); |
251 |
243 |
252 $weakRow.hide( 0, function () { |
244 $weakRow.hide( 0, function () { |
253 $weakCheckbox.removeProp( 'checked' ); |
245 $weakCheckbox.removeProp( 'checked' ); |
254 } ); |
246 } ); |
330 var $colorpicker, $stylesheet, user_id, current_user_id, |
322 var $colorpicker, $stylesheet, user_id, current_user_id, |
331 select = $( '#display_name' ), |
323 select = $( '#display_name' ), |
332 current_name = select.val(), |
324 current_name = select.val(), |
333 greeting = $( '#wp-admin-bar-my-account' ).find( '.display-name' ); |
325 greeting = $( '#wp-admin-bar-my-account' ).find( '.display-name' ); |
334 |
326 |
335 $('#pass1').val('').on( inputEvent + ' pwupdate', check_pass_strength ); |
327 $( '#pass1' ).val( '' ).on( 'input' + ' pwupdate', check_pass_strength ); |
336 $('#pass-strength-result').show(); |
328 $('#pass-strength-result').show(); |
337 $('.color-palette').click( function() { |
329 $('.color-palette').click( function() { |
338 $(this).siblings('input[name="admin_color"]').prop('checked', true); |
330 $(this).siblings('input[name="admin_color"]').prop('checked', true); |
339 }); |
331 }); |
340 |
332 |