Skip to content

Commit 325b0ef

Browse files
committed
Incorporate suggestions from @westonruter
I have some additional changes I want to make to this and haven't seen any activity from @nikunj8866 recently.
1 parent 42d5822 commit 325b0ef

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/js/_enqueues/admin/user-profile.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,17 @@
349349
var $capsWarning = $( '#caps-warning' ),
350350
capsLockOn = false;
351351

352-
$input.on( 'keydown', function( e ) {
353-
var ev = e.originalEvent || e;
352+
// Skip warning on macOS Safari + Firefox (they show native indicators).
353+
if ( isMac && ( isSafari || isFirefox ) ) {
354+
return;
355+
}
356+
357+
$input.on( 'keydown', function( jqEvent ) {
358+
var event = jqEvent.originalEvent;
354359

355360
// Skip CapsLock key itself.
356361
if ( ev.key === 'CapsLock' ) {
357-
if (capsLockOn) {
362+
if ( capsLockOn ) {
358363
capsLockOn = false;
359364
$capsWarning.hide();
360365
}
@@ -363,11 +368,11 @@
363368

364369
// Skip if key is not a printable character.
365370
// Key length > 1 usually means non-printable (e.g., "Enter", "Tab").
366-
if ( ev.ctrlKey || ev.metaKey || ev.altKey || ! ev.key || ev.key.length !== 1 ) {
371+
if ( event.ctrlKey || event.metaKey || event.altKey || ! event.key || event.key.length !== 1 ) {
367372
return;
368373
}
369374

370-
var state = isCapsLockOn( ev );
375+
var state = isCapsLockOn( event );
371376

372377
// Only react when the state changes.
373378
if ( state !== capsLockOn ) {
@@ -398,15 +403,8 @@
398403
*
399404
* @return {boolean} True if Caps Lock is on, false otherwise.
400405
*/
401-
function isCapsLockOn( e ) {
402-
// Skip warning on macOS Safari + Firefox (they show native indicators).
403-
if ( isMac && ( isSafari || isFirefox ) ) {
404-
return false;
405-
}
406-
407-
if ( typeof e.getModifierState === 'function' ) {
408-
return e.getModifierState( 'CapsLock' );
409-
}
406+
function isCapsLockOn( event ) {
407+
return event.getModifierState( 'CapsLock' );
410408
}
411409

412410
function showOrHideWeakPasswordCheckbox() {

0 commit comments

Comments
 (0)