/** * ModalService * A service to display the modals from OVO bootstrap. For now, this service uses the JQuery modal implementation * that is provided in bootstrap.js. * * It is certainly possible to use a pure angular implementation, however both * angular-strap and angular-ui-bootstrap had limitations that were incompatible with our current codebase, and * a fresh rewrite seemed not a good use of time. */ export class ModalService { constructor(private $document: ng.IDocumentService, private $compile: ng.ICompileService, private $rootScope: ng.IRootScopeService) { } open(options: ModalOptions) { const body = this.$document.find('body'); const linkFunction = this.$compile(this.modalHTML(options)); const scope = this.$rootScope.$new(); for (const k in options.scope) scope[k] = options.scope[k]; const element = linkFunction(scope); element.appendTo(body).modal(); // Remove the DOM element for this modal after the close animation has finished element.on('hidden.bs.modal', () => scope.$destroy() && element.remove()); } private modalHTML(options: ModalOptions) { return ``; } } export interface ModalOptions { /** An angular template string for the header of the modal. */ title?: string; /** An angular template string for the body of the modal. */ content: string; /** Extra CSS classes to apply to the modal body. */ class?: string; /** Bound values to use for resolving angular expressions in the title and content template strings. */ scope?: T; }