diff --git a/src/app/app.module.ts b/src/app/app.module.ts index b026bd5aef..19a2c081c2 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -9,9 +9,12 @@ import { ServicesModule } from './services/services.module'; import { AppComponent } from './app.component'; import { CiphersComponent } from './vault/ciphers.component'; +import { FallbackSrcDirective } from './directives/fallback-src.directive'; import { GroupingsComponent } from './vault/groupings.component'; import { IconComponent } from './vault/icon.component'; import { LoginComponent } from './accounts/login.component'; +import { StopClickDirective } from './directives/stop-click.directive'; +import { StopPropDirective } from './directives/stop-prop.directive'; import { VaultComponent } from './vault/vault.component'; import { ViewComponent } from './vault/view.component'; @@ -25,9 +28,11 @@ import { ViewComponent } from './vault/view.component'; declarations: [ AppComponent, CiphersComponent, + FallbackSrcDirective, GroupingsComponent, IconComponent, LoginComponent, + StopClickDirective, VaultComponent, ViewComponent, ], diff --git a/src/app/directives/fallback-src.directive.ts b/src/app/directives/fallback-src.directive.ts new file mode 100644 index 0000000000..db716f53c5 --- /dev/null +++ b/src/app/directives/fallback-src.directive.ts @@ -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; + } +} diff --git a/src/app/directives/stop-click.directive.ts b/src/app/directives/stop-click.directive.ts new file mode 100644 index 0000000000..f0c24f5c49 --- /dev/null +++ b/src/app/directives/stop-click.directive.ts @@ -0,0 +1,13 @@ +import { + Directive, + HostListener, +} from '@angular/core'; + +@Directive({ + selector: '[appStopClick]' +}) +export class StopClickDirective { + @HostListener('click', ['$event']) onClick($event: MouseEvent) { + $event.preventDefault(); + } +} diff --git a/src/app/directives/stop-prop.directive.ts b/src/app/directives/stop-prop.directive.ts new file mode 100644 index 0000000000..fba8737259 --- /dev/null +++ b/src/app/directives/stop-prop.directive.ts @@ -0,0 +1,13 @@ +import { + Directive, + HostListener, +} from '@angular/core'; + +@Directive({ + selector: '[appStopProp]' +}) +export class StopPropDirective { + @HostListener('click', ['$event']) onClick($event: MouseEvent) { + $event.stopPropagation(); + } +} diff --git a/src/app/vault/ciphers.component.html b/src/app/vault/ciphers.component.html index 4c3deeef85..eec16e883d 100644 --- a/src/app/vault/ciphers.component.html +++ b/src/app/vault/ciphers.component.html @@ -10,7 +10,7 @@