bitwarden-estensione-browser/src/app/services/modal.service.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

61 lines
1.8 KiB
TypeScript
Raw Normal View History

import { ApplicationRef, ComponentFactoryResolver, Injectable, Injector } from "@angular/core";
import * as jq from "jquery";
import { first } from "rxjs/operators";
import { MessagingService } from "jslib-common/abstractions/messaging.service";
import { ModalRef } from "jslib-angular/components/modal/modal.ref";
import { ModalService as BaseModalService } from "jslib-angular/services/modal.service";
import { Utils } from "jslib-common/misc/utils";
@Injectable()
export class ModalService extends BaseModalService {
el: any = null;
modalOpen: boolean = false;
2021-12-17 15:57:11 +01:00
constructor(
componentFactoryResolver: ComponentFactoryResolver,
applicationRef: ApplicationRef,
injector: Injector,
private messagingService: MessagingService
) {
super(componentFactoryResolver, applicationRef, injector);
}
2021-12-17 15:57:11 +01:00
protected setupHandlers(modalRef: ModalRef) {
modalRef.onCreated.pipe(first()).subscribe(() => {
const modals = Array.from(document.querySelectorAll(".modal"));
if (modals.length > 0) {
this.el = jq(modals[0]);
this.el.modal("show");
2021-12-17 15:57:11 +01:00
this.el.on("show.bs.modal", () => {
modalRef.show();
this.messagingService.send("modalShow");
});
this.el.on("shown.bs.modal", () => {
modalRef.shown();
this.messagingService.send("modalShown");
if (!Utils.isMobileBrowser) {
this.el.find("*[appAutoFocus]").focus();
2021-12-17 15:57:11 +01:00
}
});
this.el.on("hide.bs.modal", () => {
this.messagingService.send("modalClose");
2021-12-17 15:57:11 +01:00
});
this.el.on("hidden.bs.modal", () => {
modalRef.closed();
this.messagingService.send("modalClosed");
});
}
2021-12-17 15:57:11 +01:00
});
modalRef.onClose.pipe(first()).subscribe(() => {
if (this.el != null) {
this.el.modal("hide");
2021-12-17 15:57:11 +01:00
}
});
}
}