diff --git src/wp-admin/js/user-profile.js src/wp-admin/js/user-profile.js
index e95a42844e..aff38ff5c8 100644
|
|
|
161 | 161 | // hide this |
162 | 162 | $('.user-pass2-wrap').hide(); |
163 | 163 | |
164 | | $submitButton = $( '#submit, #wp-submit' ).on( 'click', function () { |
| 164 | $submitButton = $( '#submit' ).on( 'click', function () { |
165 | 165 | updateLock = false; |
166 | 166 | }); |
167 | 167 | |
… |
… |
|
205 | 205 | |
206 | 206 | bindToggleButton(); |
207 | 207 | |
208 | | if ( $generateButton.length ) { |
209 | | $passwordWrapper.hide(); |
210 | | } |
| 208 | $generateButton.on( 'click', function() { |
| 209 | if($generateButton.hasClass( 'open' ) ) { |
| 210 | $generateButton.removeClass( 'open' ); |
| 211 | // Clear any entered password. |
| 212 | $pass1Text.val( '' ); |
211 | 213 | |
212 | | $generateButton.show(); |
213 | | $generateButton.on( 'click', function () { |
214 | | updateLock = true; |
| 214 | // Generate a new password. |
| 215 | wp.ajax.post( 'generate-password' ) |
| 216 | .done( function( data ) { |
| 217 | $pass1.data( 'pw', data ); |
| 218 | } ); |
215 | 219 | |
216 | | $generateButton.hide(); |
217 | | $passwordWrapper.show(); |
| 220 | $passwordWrapper.hide(); |
| 221 | $generateButton.attr( 'aria-expanded', false ); |
218 | 222 | |
219 | | // Enable the inputs when showing. |
220 | | $pass1.attr( 'disabled', false ); |
221 | | $pass2.attr( 'disabled', false ); |
222 | | $pass1Text.attr( 'disabled', false ); |
| 223 | $weakRow.hide( 0, function () { |
| 224 | $weakCheckbox.removeProp( 'checked' ); |
| 225 | } ); |
223 | 226 | |
224 | | if ( $pass1Text.val().length === 0 ) { |
225 | | generatePassword(); |
226 | | } |
| 227 | // Disable the inputs when hiding to prevent autofill and submission. |
| 228 | $pass1.prop( 'disabled', true ); |
| 229 | $pass2.prop( 'disabled', true ); |
| 230 | $pass1Text.prop( 'disabled', true ); |
227 | 231 | |
228 | | _.defer( function() { |
| 232 | resetToggle(); |
| 233 | |
| 234 | if ( $pass1Row.closest( 'form' ).is( '#your-profile' ) ) { |
| 235 | // Clear password field to prevent update |
| 236 | $pass1.val( '' ).trigger( 'pwupdate' ); |
| 237 | $submitButtons.prop( 'disabled', false ); |
| 238 | } |
| 239 | } else { |
| 240 | $generateButton.addClass( 'open' ); |
| 241 | $generateButton.attr( 'aria-expanded', true ); |
| 242 | $passwordWrapper.show(); |
| 243 | |
| 244 | // Enable the inputs when showing. |
| 245 | $pass1.attr( 'disabled', false ); |
| 246 | $pass2.attr( 'disabled', false ); |
| 247 | $pass1Text.attr( 'disabled', false ); |
| 248 | |
| 249 | if ( $pass1Text.val().length === 0 ) { |
| 250 | generatePassword(); |
| 251 | } |
229 | 252 | $pass1Text.focus(); |
| 253 | } |
| 254 | _.defer( function() { |
230 | 255 | if ( ! _.isUndefined( $pass1Text[0].setSelectionRange ) ) { |
231 | 256 | $pass1Text[0].setSelectionRange( 0, 100 ); |
232 | 257 | } |
… |
… |
|
237 | 262 | $cancelButton.on( 'click', function () { |
238 | 263 | updateLock = false; |
239 | 264 | |
| 265 | $generateButton.removeClass( 'open' ); |
| 266 | |
240 | 267 | // Clear any entered password. |
241 | 268 | $pass1Text.val( '' ); |
242 | 269 | |
… |
… |
|
246 | 273 | $pass1.data( 'pw', data ); |
247 | 274 | } ); |
248 | 275 | |
249 | | $generateButton.show(); |
| 276 | $generateButton.attr( 'aria-expanded', false ).focus(); |
250 | 277 | $passwordWrapper.hide(); |
251 | 278 | |
252 | 279 | $weakRow.hide( 0, function () { |
… |
… |
|
314 | 341 | |
315 | 342 | if ( passStrength.className ) { |
316 | 343 | $pass1.add( $pass1Text ).addClass( passStrength.className ); |
317 | | if ( $( passStrength ).is( '.short, .bad' ) ) { |
| 344 | if ( 'short' === passStrength.className || 'bad' === passStrength.className ) { |
318 | 345 | if ( ! $weakCheckbox.prop( 'checked' ) ) { |
319 | 346 | $submitButtons.prop( 'disabled', true ); |
320 | 347 | } |