mirror of https://github.com/abpframework/abp.git
committed by
GitHub
4 changed files with 49 additions and 1 deletions
@ -0,0 +1,30 @@ |
|||
import { Directive, EventEmitter, HostListener, Output } from '@angular/core'; |
|||
|
|||
@Directive({ |
|||
standalone: true, |
|||
selector: '[abpCapsLock]', |
|||
}) |
|||
export class TrackCapsLockDirective { |
|||
@Output('abpCapsLock') capsLock = new EventEmitter<Boolean>(); |
|||
|
|||
@HostListener('window:keydown', ['$event']) |
|||
onKeyDown(event: KeyboardEvent): void { |
|||
this.capsLock.emit(this.isCapsLockOpen(event)); |
|||
} |
|||
@HostListener('window:keyup', ['$event']) |
|||
onKeyUp(event: KeyboardEvent): void { |
|||
this.capsLock.emit(this.isCapsLockOpen(event)); |
|||
} |
|||
|
|||
isCapsLockOpen(e): boolean { |
|||
var s = String.fromCharCode(e.which); |
|||
if ( |
|||
(s.toUpperCase() === s && s.toLowerCase() !== s && e.shiftKey) || |
|||
(s.toUpperCase() !== s && s.toLowerCase() === s && e.shiftKey) || |
|||
e.getModifierState('CapsLock') |
|||
) { |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
import { Directive, ElementRef, Input, inject } from '@angular/core'; |
|||
|
|||
@Directive({ |
|||
standalone: true, |
|||
selector: '[abpShowPassword]', |
|||
}) |
|||
export class ShowPasswordDirective { |
|||
protected readonly elementRef = inject(ElementRef); |
|||
|
|||
@Input() set abpShowPassword(visible: boolean) { |
|||
const element = this.elementRef.nativeElement as HTMLInputElement; |
|||
if (!element) return; |
|||
|
|||
element.type = visible ? 'text' : 'password'; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue