1/* Version 1.1 */ 2/* 3 * Clears the auto-suggested password to avoid confusing users. 4 * 5 * Provides a button for requesting a suggested password. 6 * 7 * Turns the user_login hidden field into a read-only text field and 8 * hides it with CSS instead. (This helps the browser to recognise the 9 * submitted username and password so it can offer to save them.) 10 */ 11jQuery( document ).ready( function( $ ) { 12 13 /* Clear the initial password suggestion from WordPress */ 14 $( '#resetpassform input[name=\'pass1\']' ).attr( 'data-pw', '' ) 15 16 if ( 'off' !== flizcpr.savefix ) { 17 /* Hide the username with CSS, instead of as a hidden form field. */ 18 // Dumb-browser-friendly solution is to wrap field in hidden div 19 $( '#resetpassform input[id=\'user_login\']' ).wrap( 20 '<div style="display:none">') 21 // Browsers are more likely to recognise the user ID if it's a text field 22 $( '#resetpassform input[id=\'user_login\']' ).attr( 'type', 'text' ) 23 // Just in case, make sure the textfield isn't editable by the user 24 $( '#resetpassform input[id=\'user_login\']' ).attr( 'readonly', true ) 25 } 26 27 /* Generate a random password if the user asks for one */ 28 $( '#flizcpr-button' ).click( function() { 29 // First clear the box 30 $( '#resetpassform input[name=\'pass1-text\']' ).val( '' ) 31 // Now ask WordPress for a new password 32 $.ajax( { 33 url: flizcpr.ajaxurl, 34 dataType: 'text', 35 data: { 36 action: 'get_password_suggestion', 37 security: flizcpr_pw_nonce.security 38 }, 39 success:function( data ) { 40 if ( ( '-1' === data ) || ( '0' === data ) ) { 41 // Something went wrong at the server 42 $( '#resetpassform input[name=\'pass1-text\']' ).val( 'ERROR 1' ) 43 } 44 else { 45 // Put suggested password in box 46 $( '#resetpassform input[name=\'pass1-text\']' ).val( data ) 47 48 // WP 4.3 uses 'keyup' to trigger strength check/fields sync 49 $( '#resetpassform input[name=\'pass1-text\']' ).trigger( 'keyup' ) 50 51 // WP 4.3.1 uses 'input' to trigger strength check/fields sync 52 $( '#resetpassform input[name=\'pass1-text\']' ).trigger( 'input' ) 53 } 54 // Release the pressed button 55 $( '#flizcpr-button' ).blur() 56 }, 57 error: function( errorThrown ) { 58 // Something went wrong making the call 59 $( '#resetpassform input[name=\'pass1-text\']' ).val( 'ERROR 2' ) 60 61 // Release the pressed button 62 $( '#flizcpr-button' ).blur() 63 } 64 }); 65 }); 66});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.