mirror of
https://github.com/bitwarden/browser
synced 2025-12-22 19:23:52 +00:00
Add CoreModule (#3149)
This commit is contained in:
58
apps/web/src/app/core/modal.service.ts
Normal file
58
apps/web/src/app/core/modal.service.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { ApplicationRef, ComponentFactoryResolver, Injectable, Injector } from "@angular/core";
|
||||
import * as jq from "jquery";
|
||||
import { first } from "rxjs/operators";
|
||||
|
||||
import { ModalRef } from "@bitwarden/angular/components/modal/modal.ref";
|
||||
import { ModalService as BaseModalService } from "@bitwarden/angular/services/modal.service";
|
||||
import { MessagingService } from "@bitwarden/common/abstractions/messaging.service";
|
||||
import { Utils } from "@bitwarden/common/misc/utils";
|
||||
|
||||
@Injectable()
|
||||
export class ModalService extends BaseModalService {
|
||||
el: any = null;
|
||||
modalOpen = false;
|
||||
|
||||
constructor(
|
||||
componentFactoryResolver: ComponentFactoryResolver,
|
||||
applicationRef: ApplicationRef,
|
||||
injector: Injector,
|
||||
private messagingService: MessagingService
|
||||
) {
|
||||
super(componentFactoryResolver, applicationRef, injector);
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
||||
this.el.on("hide.bs.modal", () => {
|
||||
this.messagingService.send("modalClose");
|
||||
});
|
||||
this.el.on("hidden.bs.modal", () => {
|
||||
modalRef.closed();
|
||||
this.messagingService.send("modalClosed");
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
modalRef.onClose.pipe(first()).subscribe(() => {
|
||||
if (this.el != null) {
|
||||
this.el.modal("hide");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user