1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00

move various angular bits into shared jslib

This commit is contained in:
Kyle Spearrin
2018-04-04 08:22:55 -04:00
parent 00bb0fdbdf
commit 579f970323
11 changed files with 366 additions and 16 deletions

View File

@@ -0,0 +1,32 @@
import {
Directive,
ElementRef,
Input,
OnChanges,
} from '@angular/core';
import { ValidationService } from '../services/validation.service';
@Directive({
selector: '[appApiAction]',
})
export class ApiActionDirective implements OnChanges {
@Input() appApiAction: Promise<any>;
constructor(private el: ElementRef, private validationService: ValidationService) { }
ngOnChanges(changes: any) {
if (this.appApiAction == null || this.appApiAction.then == null) {
return;
}
this.el.nativeElement.loading = true;
this.appApiAction.then((response: any) => {
this.el.nativeElement.loading = false;
}, (e: any) => {
this.el.nativeElement.loading = false;
this.validationService.showError(e);
});
}
}

View File

@@ -0,0 +1,24 @@
import {
Directive,
ElementRef,
Input,
} from '@angular/core';
@Directive({
selector: '[appAutofocus]',
})
export class AutofocusDirective {
@Input() set appAutofocus(condition: boolean | string) {
this.autofocus = condition === '' || condition === true;
}
private autofocus: boolean;
constructor(private el: ElementRef) { }
ngOnInit() {
if (this.autofocus) {
this.el.nativeElement.focus();
}
}
}

View File

@@ -0,0 +1,17 @@
import {
Directive,
ElementRef,
HostListener,
} from '@angular/core';
@Directive({
selector: '[appBlurClick]',
})
export class BlurClickDirective {
constructor(private el: ElementRef) {
}
@HostListener('click') onClick() {
this.el.nativeElement.blur();
}
}

View File

@@ -0,0 +1,20 @@
import {
Directive,
ElementRef,
HostListener,
Input,
} from '@angular/core';
@Directive({
selector: '[appFallbackSrc]',
})
export class FallbackSrcDirective {
@Input('appFallbackSrc') appFallbackSrc: string;
constructor(private el: ElementRef) {
}
@HostListener('error') onError() {
this.el.nativeElement.src = this.appFallbackSrc;
}
}

View File

@@ -0,0 +1,13 @@
import {
Directive,
HostListener,
} from '@angular/core';
@Directive({
selector: '[appStopClick]',
})
export class StopClickDirective {
@HostListener('click', ['$event']) onClick($event: MouseEvent) {
$event.preventDefault();
}
}

View File

@@ -0,0 +1,13 @@
import {
Directive,
HostListener,
} from '@angular/core';
@Directive({
selector: '[appStopProp]',
})
export class StopPropDirective {
@HostListener('click', ['$event']) onClick($event: MouseEvent) {
$event.stopPropagation();
}
}