author | ymh <ymh.work@gmail.com> |
Mon, 08 Sep 2025 19:44:41 +0200 | |
changeset 23 | 417f20492bf7 |
parent 22 | 8c2e4d02f4ef |
permissions | -rw-r--r-- |
9 | 1 |
/** |
2 |
* @output wp-admin/js/user-profile.js |
|
3 |
*/ |
|
4 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5 |
/* global ajaxurl, pwsL10n, userProfileL10n, ClipboardJS */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6 |
(function($) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7 |
var updateLock = false, |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8 |
isSubmitting = false, |
16 | 9 |
__ = wp.i18n.__, |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
10 |
clipboard = new ClipboardJS( '.application-password-display .copy-button' ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
11 |
$pass1Row, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
12 |
$pass1, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
13 |
$pass2, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
$weakRow, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
15 |
$weakCheckbox, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
16 |
$toggleButton, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
$submitButtons, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
18 |
$submitButton, |
18 | 19 |
currentPass, |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
20 |
$form, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
21 |
originalFormContent, |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
22 |
$passwordWrapper, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
23 |
successTimeout; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
24 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
function generatePassword() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
26 |
if ( typeof zxcvbn !== 'function' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
27 |
setTimeout( generatePassword, 50 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
28 |
return; |
18 | 29 |
} else if ( ! $pass1.val() || $passwordWrapper.hasClass( 'is-open' ) ) { |
30 |
// zxcvbn loaded before user entered password, or generating new password. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
31 |
$pass1.val( $pass1.data( 'pw' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
32 |
$pass1.trigger( 'pwupdate' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
33 |
showOrHideWeakPasswordCheckbox(); |
18 | 34 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
// zxcvbn loaded after the user entered password, check strength. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
36 |
check_pass_strength(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
showOrHideWeakPasswordCheckbox(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
38 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
|
19 | 40 |
/* |
41 |
* This works around a race condition when zxcvbn loads quickly and |
|
42 |
* causes `generatePassword()` to run prior to the toggle button being |
|
43 |
* bound. |
|
44 |
*/ |
|
45 |
bindToggleButton(); |
|
46 |
||
18 | 47 |
// Install screen. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
if ( 1 !== parseInt( $toggleButton.data( 'start-masked' ), 10 ) ) { |
18 | 49 |
// Show the password not masked if admin_password hasn't been posted yet. |
16 | 50 |
$pass1.attr( 'type', 'text' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
} else { |
18 | 52 |
// Otherwise, mask the password. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
53 |
$toggleButton.trigger( 'click' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
55 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
// Once zxcvbn loads, passwords strength is known. |
16 | 57 |
$( '#pw-weak-text-label' ).text( __( 'Confirm use of weak password' ) ); |
19 | 58 |
|
59 |
// Focus the password field. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
60 |
if ( 'mailserver_pass' !== $pass1.prop('id' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
61 |
$( $pass1 ).trigger( 'focus' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
62 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
function bindPass1() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
66 |
currentPass = $pass1.val(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
67 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
68 |
if ( 1 === parseInt( $pass1.data( 'reveal' ), 10 ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
69 |
generatePassword(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
70 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
71 |
|
9 | 72 |
$pass1.on( 'input' + ' pwupdate', function () { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
73 |
if ( $pass1.val() === currentPass ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
74 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
75 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
76 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
77 |
currentPass = $pass1.val(); |
16 | 78 |
|
18 | 79 |
// Refresh password strength area. |
16 | 80 |
$pass1.removeClass( 'short bad good strong' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
81 |
showOrHideWeakPasswordCheckbox(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
84 |
|
16 | 85 |
function resetToggle( show ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
86 |
$toggleButton |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
87 |
.attr({ |
16 | 88 |
'aria-label': show ? __( 'Show password' ) : __( 'Hide password' ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
89 |
}) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
90 |
.find( '.text' ) |
16 | 91 |
.text( show ? __( 'Show' ) : __( 'Hide' ) ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
92 |
.end() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
93 |
.find( '.dashicons' ) |
16 | 94 |
.removeClass( show ? 'dashicons-hidden' : 'dashicons-visibility' ) |
95 |
.addClass( show ? 'dashicons-visibility' : 'dashicons-hidden' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
96 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
97 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
98 |
function bindToggleButton() { |
19 | 99 |
if ( !! $toggleButton ) { |
100 |
// Do not rebind. |
|
101 |
return; |
|
102 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
103 |
$toggleButton = $pass1Row.find('.wp-hide-pw'); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
104 |
$toggleButton.show().on( 'click', function () { |
16 | 105 |
if ( 'password' === $pass1.attr( 'type' ) ) { |
106 |
$pass1.attr( 'type', 'text' ); |
|
107 |
resetToggle( false ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
108 |
} else { |
16 | 109 |
$pass1.attr( 'type', 'password' ); |
110 |
resetToggle( true ); |
|
111 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
112 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
113 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
114 |
|
18 | 115 |
/** |
116 |
* Handle the password reset button. Sets up an ajax callback to trigger sending |
|
117 |
* a password reset email. |
|
118 |
*/ |
|
19 | 119 |
function bindPasswordResetLink() { |
18 | 120 |
$( '#generate-reset-link' ).on( 'click', function() { |
121 |
var $this = $(this), |
|
122 |
data = { |
|
123 |
'user_id': userProfileL10n.user_id, // The user to send a reset to. |
|
124 |
'nonce': userProfileL10n.nonce // Nonce to validate the action. |
|
125 |
}; |
|
126 |
||
127 |
// Remove any previous error messages. |
|
128 |
$this.parent().find( '.notice-error' ).remove(); |
|
129 |
||
130 |
// Send the reset request. |
|
131 |
var resetAction = wp.ajax.post( 'send-password-reset', data ); |
|
132 |
||
133 |
// Handle reset success. |
|
134 |
resetAction.done( function( response ) { |
|
135 |
addInlineNotice( $this, true, response ); |
|
136 |
} ); |
|
137 |
||
138 |
// Handle reset failure. |
|
139 |
resetAction.fail( function( response ) { |
|
140 |
addInlineNotice( $this, false, response ); |
|
141 |
} ); |
|
142 |
||
143 |
}); |
|
144 |
||
145 |
} |
|
146 |
||
147 |
/** |
|
148 |
* Helper function to insert an inline notice of success or failure. |
|
149 |
* |
|
150 |
* @param {jQuery Object} $this The button element: the message will be inserted |
|
151 |
* above this button |
|
152 |
* @param {bool} success Whether the message is a success message. |
|
153 |
* @param {string} message The message to insert. |
|
154 |
*/ |
|
155 |
function addInlineNotice( $this, success, message ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
156 |
var resultDiv = $( '<div />', { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
157 |
role: 'alert' |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
158 |
} ); |
18 | 159 |
|
160 |
// Set up the notice div. |
|
161 |
resultDiv.addClass( 'notice inline' ); |
|
162 |
||
163 |
// Add a class indicating success or failure. |
|
164 |
resultDiv.addClass( 'notice-' + ( success ? 'success' : 'error' ) ); |
|
165 |
||
166 |
// Add the message, wrapping in a p tag, with a fadein to highlight each message. |
|
167 |
resultDiv.text( $( $.parseHTML( message ) ).text() ).wrapInner( '<p />'); |
|
168 |
||
169 |
// Disable the button when the callback has succeeded. |
|
170 |
$this.prop( 'disabled', success ); |
|
171 |
||
172 |
// Remove any previous notices. |
|
173 |
$this.siblings( '.notice' ).remove(); |
|
174 |
||
175 |
// Insert the notice. |
|
176 |
$this.before( resultDiv ); |
|
177 |
} |
|
178 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
179 |
function bindPasswordForm() { |
18 | 180 |
var $generateButton, |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
181 |
$cancelButton; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
182 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
183 |
$pass1Row = $( '.user-pass1-wrap, .user-pass-wrap, .mailserver-pass-wrap, .reset-pass-submit' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
184 |
|
16 | 185 |
// Hide the confirm password field when JavaScript support is enabled. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
186 |
$('.user-pass2-wrap').hide(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
187 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
188 |
$submitButton = $( '#submit, #wp-submit' ).on( 'click', function () { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
189 |
updateLock = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
190 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
191 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
192 |
$submitButtons = $submitButton.add( ' #createusersub' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
193 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
194 |
$weakRow = $( '.pw-weak' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
195 |
$weakCheckbox = $weakRow.find( '.pw-checkbox' ); |
18 | 196 |
$weakCheckbox.on( 'change', function() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
197 |
$submitButtons.prop( 'disabled', ! $weakCheckbox.prop( 'checked' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
198 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
199 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
200 |
$pass1 = $('#pass1, #mailserver_pass'); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
201 |
if ( $pass1.length ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
202 |
bindPass1(); |
16 | 203 |
} else { |
204 |
// Password field for the login form. |
|
205 |
$pass1 = $( '#user_pass' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
206 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
207 |
|
18 | 208 |
/* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
209 |
* Fix a LastPass mismatch issue, LastPass only changes pass2. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
210 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
211 |
* This fixes the issue by copying any changes from the hidden |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
212 |
* pass2 field to the pass1 field, then running check_pass_strength. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
213 |
*/ |
9 | 214 |
$pass2 = $( '#pass2' ).on( 'input', function () { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
215 |
if ( $pass2.val().length > 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
216 |
$pass1.val( $pass2.val() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
217 |
$pass2.val(''); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
218 |
currentPass = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
219 |
$pass1.trigger( 'pwupdate' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
220 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
221 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
222 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
223 |
// Disable hidden inputs to prevent autofill and submission. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
224 |
if ( $pass1.is( ':hidden' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
225 |
$pass1.prop( 'disabled', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
226 |
$pass2.prop( 'disabled', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
227 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
228 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
229 |
$passwordWrapper = $pass1Row.find( '.wp-pwd' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
230 |
$generateButton = $pass1Row.find( 'button.wp-generate-pw' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
231 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
232 |
bindToggleButton(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
233 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
234 |
$generateButton.show(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
235 |
$generateButton.on( 'click', function () { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
236 |
updateLock = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
237 |
|
18 | 238 |
// Make sure the password fields are shown. |
19 | 239 |
$generateButton.not( '.skip-aria-expanded' ).attr( 'aria-expanded', 'true' ); |
18 | 240 |
$passwordWrapper |
241 |
.show() |
|
242 |
.addClass( 'is-open' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
243 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
244 |
// Enable the inputs when showing. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
245 |
$pass1.attr( 'disabled', false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
246 |
$pass2.attr( 'disabled', false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
247 |
|
18 | 248 |
// Set the password to the generated value. |
249 |
generatePassword(); |
|
250 |
||
251 |
// Show generated password in plaintext by default. |
|
252 |
resetToggle ( false ); |
|
253 |
||
254 |
// Generate the next password and cache. |
|
255 |
wp.ajax.post( 'generate-password' ) |
|
256 |
.done( function( data ) { |
|
257 |
$pass1.data( 'pw', data ); |
|
258 |
} ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
259 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
260 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
261 |
$cancelButton = $pass1Row.find( 'button.wp-cancel-pw' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
262 |
$cancelButton.on( 'click', function () { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
263 |
updateLock = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
264 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
265 |
// Disable the inputs when hiding to prevent autofill and submission. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
266 |
$pass1.prop( 'disabled', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
267 |
$pass2.prop( 'disabled', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
268 |
|
18 | 269 |
// Clear password field and update the UI. |
270 |
$pass1.val( '' ).trigger( 'pwupdate' ); |
|
16 | 271 |
resetToggle( false ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
272 |
|
18 | 273 |
// Hide password controls. |
274 |
$passwordWrapper |
|
275 |
.hide() |
|
276 |
.removeClass( 'is-open' ); |
|
277 |
||
278 |
// Stop an empty password from being submitted as a change. |
|
279 |
$submitButtons.prop( 'disabled', false ); |
|
19 | 280 |
|
281 |
$generateButton.attr( 'aria-expanded', 'false' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
282 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
283 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
284 |
$pass1Row.closest( 'form' ).on( 'submit', function () { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
285 |
updateLock = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
286 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
287 |
$pass1.prop( 'disabled', false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
288 |
$pass2.prop( 'disabled', false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
289 |
$pass2.val( $pass1.val() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
290 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
291 |
} |
0 | 292 |
|
293 |
function check_pass_strength() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
294 |
var pass1 = $('#pass1').val(), strength; |
0 | 295 |
|
16 | 296 |
$('#pass-strength-result').removeClass('short bad good strong empty'); |
18 | 297 |
if ( ! pass1 || '' === pass1.trim() ) { |
16 | 298 |
$( '#pass-strength-result' ).addClass( 'empty' ).html( ' ' ); |
0 | 299 |
return; |
300 |
} |
|
301 |
||
16 | 302 |
strength = wp.passwordStrength.meter( pass1, wp.passwordStrength.userInputDisallowedList(), pass1 ); |
0 | 303 |
|
304 |
switch ( strength ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
305 |
case -1: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
306 |
$( '#pass-strength-result' ).addClass( 'bad' ).html( pwsL10n.unknown ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
307 |
break; |
0 | 308 |
case 2: |
5 | 309 |
$('#pass-strength-result').addClass('bad').html( pwsL10n.bad ); |
0 | 310 |
break; |
311 |
case 3: |
|
5 | 312 |
$('#pass-strength-result').addClass('good').html( pwsL10n.good ); |
0 | 313 |
break; |
314 |
case 4: |
|
5 | 315 |
$('#pass-strength-result').addClass('strong').html( pwsL10n.strong ); |
0 | 316 |
break; |
317 |
case 5: |
|
5 | 318 |
$('#pass-strength-result').addClass('short').html( pwsL10n.mismatch ); |
0 | 319 |
break; |
320 |
default: |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
321 |
$('#pass-strength-result').addClass('short').html( pwsL10n.short ); |
0 | 322 |
} |
323 |
} |
|
324 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
325 |
function showOrHideWeakPasswordCheckbox() { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
326 |
var passStrengthResult = $('#pass-strength-result'); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
327 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
328 |
if ( passStrengthResult.length ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
329 |
var passStrength = passStrengthResult[0]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
330 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
331 |
if ( passStrength.className ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
332 |
$pass1.addClass( passStrength.className ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
333 |
if ( $( passStrength ).is( '.short, .bad' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
334 |
if ( ! $weakCheckbox.prop( 'checked' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
335 |
$submitButtons.prop( 'disabled', true ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
336 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
337 |
$weakRow.show(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
338 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
339 |
if ( $( passStrength ).is( '.empty' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
340 |
$submitButtons.prop( 'disabled', true ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
341 |
$weakCheckbox.prop( 'checked', false ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
342 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
343 |
$submitButtons.prop( 'disabled', false ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
344 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
345 |
$weakRow.hide(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
346 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
347 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
348 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
349 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
350 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
351 |
// Debug information copy section. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
352 |
clipboard.on( 'success', function( e ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
353 |
var triggerElement = $( e.trigger ), |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
354 |
successElement = $( '.success', triggerElement.closest( '.application-password-display' ) ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
355 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
356 |
// Clear the selection and move focus back to the trigger. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
357 |
e.clearSelection(); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
358 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
359 |
// Show success visual feedback. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
360 |
clearTimeout( successTimeout ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
361 |
successElement.removeClass( 'hidden' ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
362 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
363 |
// Hide success visual feedback after 3 seconds since last success. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
364 |
successTimeout = setTimeout( function() { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
365 |
successElement.addClass( 'hidden' ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
366 |
}, 3000 ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
367 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
368 |
// Handle success audible feedback. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
369 |
wp.a11y.speak( __( 'Application password has been copied to your clipboard.' ) ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
370 |
} ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
371 |
|
18 | 372 |
$( function() { |
5 | 373 |
var $colorpicker, $stylesheet, user_id, current_user_id, |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
374 |
select = $( '#display_name' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
375 |
current_name = select.val(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
376 |
greeting = $( '#wp-admin-bar-my-account' ).find( '.display-name' ); |
0 | 377 |
|
9 | 378 |
$( '#pass1' ).val( '' ).on( 'input' + ' pwupdate', check_pass_strength ); |
0 | 379 |
$('#pass-strength-result').show(); |
18 | 380 |
$('.color-palette').on( 'click', function() { |
0 | 381 |
$(this).siblings('input[name="admin_color"]').prop('checked', true); |
382 |
}); |
|
383 |
||
384 |
if ( select.length ) { |
|
18 | 385 |
$('#first_name, #last_name, #nickname').on( 'blur.user_profile', function() { |
0 | 386 |
var dub = [], |
387 |
inputs = { |
|
388 |
display_nickname : $('#nickname').val() || '', |
|
389 |
display_username : $('#user_login').val() || '', |
|
390 |
display_firstname : $('#first_name').val() || '', |
|
391 |
display_lastname : $('#last_name').val() || '' |
|
392 |
}; |
|
393 |
||
394 |
if ( inputs.display_firstname && inputs.display_lastname ) { |
|
5 | 395 |
inputs.display_firstlast = inputs.display_firstname + ' ' + inputs.display_lastname; |
396 |
inputs.display_lastfirst = inputs.display_lastname + ' ' + inputs.display_firstname; |
|
0 | 397 |
} |
398 |
||
399 |
$.each( $('option', select), function( i, el ){ |
|
400 |
dub.push( el.value ); |
|
401 |
}); |
|
402 |
||
403 |
$.each(inputs, function( id, value ) { |
|
5 | 404 |
if ( ! value ) { |
0 | 405 |
return; |
5 | 406 |
} |
0 | 407 |
|
408 |
var val = value.replace(/<\/?[a-z][^>]*>/gi, ''); |
|
409 |
||
5 | 410 |
if ( inputs[id].length && $.inArray( val, dub ) === -1 ) { |
0 | 411 |
dub.push(val); |
412 |
$('<option />', { |
|
413 |
'text': val |
|
414 |
}).appendTo( select ); |
|
415 |
} |
|
416 |
}); |
|
417 |
}); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
418 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
419 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
420 |
* Replaces "Howdy, *" in the admin toolbar whenever the display name dropdown is updated for one's own profile. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
421 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
422 |
select.on( 'change', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
423 |
if ( user_id !== current_user_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
424 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
425 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
|
18 | 427 |
var display_name = this.value.trim() || current_name; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
428 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
429 |
greeting.text( display_name ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
430 |
} ); |
0 | 431 |
} |
5 | 432 |
|
433 |
$colorpicker = $( '#color-picker' ); |
|
434 |
$stylesheet = $( '#colors-css' ); |
|
435 |
user_id = $( 'input#user_id' ).val(); |
|
436 |
current_user_id = $( 'input[name="checkuser_id"]' ).val(); |
|
437 |
||
438 |
$colorpicker.on( 'click.colorpicker', '.color-option', function() { |
|
439 |
var colors, |
|
440 |
$this = $(this); |
|
441 |
||
442 |
if ( $this.hasClass( 'selected' ) ) { |
|
443 |
return; |
|
444 |
} |
|
445 |
||
446 |
$this.siblings( '.selected' ).removeClass( 'selected' ); |
|
447 |
$this.addClass( 'selected' ).find( 'input[type="radio"]' ).prop( 'checked', true ); |
|
448 |
||
16 | 449 |
// Set color scheme. |
5 | 450 |
if ( user_id === current_user_id ) { |
451 |
// Load the colors stylesheet. |
|
452 |
// The default color scheme won't have one, so we'll need to create an element. |
|
453 |
if ( 0 === $stylesheet.length ) { |
|
454 |
$stylesheet = $( '<link rel="stylesheet" />' ).appendTo( 'head' ); |
|
455 |
} |
|
456 |
$stylesheet.attr( 'href', $this.children( '.css_url' ).val() ); |
|
457 |
||
16 | 458 |
// Repaint icons. |
5 | 459 |
if ( typeof wp !== 'undefined' && wp.svgPainter ) { |
460 |
try { |
|
18 | 461 |
colors = JSON.parse( $this.children( '.icon_colors' ).val() ); |
5 | 462 |
} catch ( error ) {} |
463 |
||
464 |
if ( colors ) { |
|
465 |
wp.svgPainter.setColors( colors ); |
|
466 |
wp.svgPainter.paint(); |
|
467 |
} |
|
468 |
} |
|
469 |
||
16 | 470 |
// Update user option. |
5 | 471 |
$.post( ajaxurl, { |
472 |
action: 'save-user-color-scheme', |
|
473 |
color_scheme: $this.children( 'input[name="admin_color"]' ).val(), |
|
474 |
nonce: $('#color-nonce').val() |
|
475 |
}).done( function( response ) { |
|
476 |
if ( response.success ) { |
|
477 |
$( 'body' ).removeClass( response.data.previousScheme ).addClass( response.data.currentScheme ); |
|
478 |
} |
|
479 |
}); |
|
480 |
} |
|
481 |
}); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
482 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
483 |
bindPasswordForm(); |
19 | 484 |
bindPasswordResetLink(); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
485 |
$submitButtons.on( 'click', function() { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
486 |
isSubmitting = true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
487 |
}); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
488 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
489 |
$form = $( '#your-profile, #createuser' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
490 |
originalFormContent = $form.serialize(); |
5 | 491 |
}); |
492 |
||
493 |
$( '#destroy-sessions' ).on( 'click', function( e ) { |
|
494 |
var $this = $(this); |
|
495 |
||
496 |
wp.ajax.post( 'destroy-sessions', { |
|
497 |
nonce: $( '#_wpnonce' ).val(), |
|
498 |
user_id: $( '#user_id' ).val() |
|
499 |
}).done( function( response ) { |
|
500 |
$this.prop( 'disabled', true ); |
|
501 |
$this.siblings( '.notice' ).remove(); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
502 |
$this.before( '<div class="notice notice-success inline" role="alert"><p>' + response.message + '</p></div>' ); |
5 | 503 |
}).fail( function( response ) { |
504 |
$this.siblings( '.notice' ).remove(); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
505 |
$this.before( '<div class="notice notice-error inline" role="alert"><p>' + response.message + '</p></div>' ); |
5 | 506 |
}); |
507 |
||
508 |
e.preventDefault(); |
|
0 | 509 |
}); |
510 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
511 |
window.generatePassword = generatePassword; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
512 |
|
18 | 513 |
// Warn the user if password was generated but not saved. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
514 |
$( window ).on( 'beforeunload', function () { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
515 |
if ( true === updateLock ) { |
16 | 516 |
return __( 'Your new password has not been saved.' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
517 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
518 |
if ( originalFormContent !== $form.serialize() && ! isSubmitting ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
519 |
return __( 'The changes you made will be lost if you navigate away from this page.' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
520 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
521 |
}); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
522 |
|
18 | 523 |
/* |
524 |
* We need to generate a password as soon as the Reset Password page is loaded, |
|
525 |
* to avoid double clicking the button to retrieve the first generated password. |
|
526 |
* See ticket #39638. |
|
527 |
*/ |
|
528 |
$( function() { |
|
529 |
if ( $( '.reset-pass-submit' ).length ) { |
|
530 |
$( '.reset-pass-submit button.wp-generate-pw' ).trigger( 'click' ); |
|
531 |
} |
|
532 |
}); |
|
533 |
||
0 | 534 |
})(jQuery); |