import {Component, ElementRef, EventEmitter, Input, OnDestroy, OnInit, Output, ViewChild} from '@angular/core'; import {FormGroup} from "@angular/forms"; import {Subscriber} from "rxjs"; declare var UIkit; @Component({ selector: 'quick-contact', templateUrl: 'quick-contact.component.html', styleUrls: ['quick-contact.component.css'] }) export class QuickContactComponent implements OnInit, OnDestroy { public showForm: boolean = false; @Input() public contactForm: FormGroup; @Input() public sending = false; @Input() public organizationTypes: string[] = []; @Output() sendEmitter: EventEmitter = new EventEmitter(); private subscriptions: any[] = []; @ViewChild('drop') drop: ElementRef; ngOnInit() { if (document !== undefined) { this.subscriptions.push(UIkit.util.on(document, 'beforehide', '#quick-contact', (event) => { if(this.sending) { event.preventDefault(); } })); } } ngOnDestroy() { this.subscriptions.forEach(value => { if (value instanceof Subscriber) { value.unsubscribe(); } else if (value instanceof Function) { value(); } }); } public close() { UIkit.drop(this.drop.nativeElement).hide(); } public send(event) { this.sendEmitter.emit(event); } public toggleModal() { this.showForm = !this.showForm; } }