From 180e28fca37f875d0dfe932bda1377a77b8075fe Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 30 Jan 2018 14:33:06 -0500 Subject: [PATCH] box row directive --- src/app/app.module.ts | 2 + src/app/directives/box-row.directive.ts | 49 +++++++++++++ src/app/vault/add-edit.component.html | 73 ++++++++++--------- .../vault/password-generator.component.html | 16 ++-- 4 files changed, 96 insertions(+), 44 deletions(-) create mode 100644 src/app/directives/box-row.directive.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 007f067644..061908bfa3 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -14,6 +14,7 @@ import { AddEditComponent } from './vault/add-edit.component'; import { AppComponent } from './app.component'; import { AttachmentsComponent } from './vault/attachments.component'; import { BlurClickDirective } from './directives/blur-click.directive'; +import { BoxRowDirective } from './directives/box-row.directive'; import { CiphersComponent } from './vault/ciphers.component'; import { FallbackSrcDirective } from './directives/fallback-src.directive'; import { GroupingsComponent } from './vault/groupings.component'; @@ -46,6 +47,7 @@ import { ViewComponent } from './vault/view.component'; AppComponent, AttachmentsComponent, BlurClickDirective, + BoxRowDirective, CiphersComponent, FallbackSrcDirective, GroupingsComponent, diff --git a/src/app/directives/box-row.directive.ts b/src/app/directives/box-row.directive.ts new file mode 100644 index 0000000000..8a74a90483 --- /dev/null +++ b/src/app/directives/box-row.directive.ts @@ -0,0 +1,49 @@ +import { + Directive, + ElementRef, + HostListener, + OnInit, +} from '@angular/core'; + +@Directive({ + selector: '[appBoxRow]', +}) +export class BoxRowDirective implements OnInit { + el: HTMLElement = null; + formEls: NodeListOf; + + constructor(private elRef: ElementRef) { + this.el = elRef.nativeElement; + } + + ngOnInit(): void { + this.formEls = this.el.querySelectorAll('input:not([type="hidden"]), select, textarea'); + this.formEls.forEach((formEl) => { + formEl.addEventListener('focus', (event: Event) => { + this.el.classList.add('active'); + }, false); + + formEl.addEventListener('blur', (event: Event) => { + this.el.classList.remove('active'); + }, false); + }); + } + + @HostListener('click', ['$event']) onClick(event: Event) { + if (event.target !== this.el) { + return; + } + + if (this.formEls.length > 0) { + const formEl = (this.formEls[0] as HTMLElement); + if (formEl.tagName.toLowerCase() === 'input') { + const inputEl = (formEl as HTMLInputElement); + if (inputEl.type != null && inputEl.type.toLowerCase() === 'checkbox') { + inputEl.checked = !inputEl.checked; + return; + } + } + formEl.focus(); + } + } +} diff --git a/src/app/vault/add-edit.component.html b/src/app/vault/add-edit.component.html index f11d84d582..4be66b855c 100644 --- a/src/app/vault/add-edit.component.html +++ b/src/app/vault/add-edit.component.html @@ -5,28 +5,28 @@ {{'itemInformation' | i18n}}
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -171,18 +171,18 @@
-
+
-
+
-
+
@@ -198,8 +198,8 @@
-
- +
+
@@ -209,7 +209,8 @@
-
+
{{'newCustomField' | i18n}} diff --git a/src/app/vault/password-generator.component.html b/src/app/vault/password-generator.component.html index d02bc40701..27764763b1 100644 --- a/src/app/vault/password-generator.component.html +++ b/src/app/vault/password-generator.component.html @@ -20,27 +20,27 @@ Options
-
+
{{options.length}}
-
+
-
+
-
+
-
+
@@ -49,17 +49,17 @@
-
+
-
+
-
+