|
83 | 83 | showOrHideWeakPasswordCheckbox(); |
84 | 84 | } ); |
85 | 85 |
|
86 | | - /** |
87 | | - * Monitors the Caps Lock status while the user is typing in the password input field. |
88 | | - * |
89 | | - * Shows a warning if Caps Lock is detected. Also uses wp.a11y.speak() |
90 | | - * for screen readers. Hides the warning on blur or when Caps Lock is not on. |
91 | | - */ |
92 | | - var $capsWarning = $( '#caps-warning' ); |
93 | | - |
94 | | - $pass1.on( 'keydown', function( e ) { |
95 | | - if ( isCapsLockOn( e.originalEvent || e ) ) { |
96 | | - $capsWarning.show(); |
97 | | - wp.a11y.speak( __( 'Caps lock is on.' ) ); |
98 | | - } else { |
99 | | - $capsWarning.hide(); |
100 | | - } |
101 | | - }); |
102 | | - |
103 | | - /** |
104 | | - * Hides the Caps Lock warning when the password input loses focus. |
105 | | - */ |
106 | | - $pass1.on( 'blur', function() { |
107 | | - $capsWarning.hide(); |
108 | | - }); |
| 86 | + bindCapsLockWarning( $pass1 ); |
109 | 87 | } |
110 | 88 |
|
111 | 89 | function resetToggle( show ) { |
|
230 | 208 | // Password field for the login form. |
231 | 209 | $pass1 = $( '#user_pass' ); |
232 | 210 |
|
233 | | - /** |
234 | | - * Monitors the Caps Lock status while the user is typing in the password input field. |
235 | | - * |
236 | | - * Shows a warning if Caps Lock is detected. Also uses wp.a11y.speak() |
237 | | - * for screen readers. Hides the warning on blur or when Caps Lock is not on. |
238 | | - */ |
239 | | - var $capsWarning = $( '#caps-warning' ); |
240 | | - |
241 | | - $pass1.on( 'keydown', function( e ) { |
242 | | - if ( isCapsLockOn( e.originalEvent || e ) ) { |
243 | | - $capsWarning.show(); |
244 | | - wp.a11y.speak( __( 'Caps lock is on.' ) ); |
245 | | - } else { |
246 | | - $capsWarning.hide(); |
247 | | - } |
248 | | - }); |
249 | | - |
250 | | - /** |
251 | | - * Hides the Caps Lock warning when the password input loses focus. |
252 | | - */ |
253 | | - $pass1.on( 'blur', function() { |
254 | | - $capsWarning.hide(); |
255 | | - }); |
| 211 | + bindCapsLockWarning( $pass1 ); |
256 | 212 | } |
257 | 213 |
|
258 | 214 | /* |
|
372 | 328 | } |
373 | 329 | } |
374 | 330 |
|
| 331 | + /** |
| 332 | + * Binds Caps Lock detection to a given password input field. |
| 333 | + * |
| 334 | + * @param {jQuery} $input The password input field. |
| 335 | + */ |
| 336 | + function bindCapsLockWarning( $input ) { |
| 337 | + var $capsWarning = $( '#caps-warning' ); |
| 338 | + |
| 339 | + $input.on( 'keydown', function( e ) { |
| 340 | + if ( isCapsLockOn( e.originalEvent || e ) ) { |
| 341 | + $capsWarning.show(); |
| 342 | + wp.a11y.speak( __( 'Caps lock is on.' ) ); |
| 343 | + } else { |
| 344 | + $capsWarning.hide(); |
| 345 | + } |
| 346 | + } ); |
| 347 | + |
| 348 | + $input.on( 'blur', function() { |
| 349 | + $capsWarning.hide(); |
| 350 | + } ); |
| 351 | + } |
| 352 | + |
375 | 353 | /** |
376 | 354 | * Determines if Caps Lock is currently enabled. |
377 | 355 | * |
|
0 commit comments