diff --git a/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts b/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts index 0fa95c1b5..abf91aad8 100644 --- a/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts +++ b/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts @@ -1,5 +1,5 @@ import { ActivatedRoute, Router } from '@angular/router'; -import { Component, OnInit, ViewChild, ElementRef } from '@angular/core'; +import { Component, OnInit, ViewChild, ElementRef, HostListener } from '@angular/core'; import { DomSanitizer, SafeHtml, Title } from '@angular/platform-browser'; import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms'; import { MatDialog, MatExpansionPanel, MatSnackBar, MatCheckboxChange, ErrorStateMatcher } from '@angular/material'; @@ -1172,6 +1172,19 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit { this.personalNoteService.setPersonalNoteStar(this.motion.motion, !this.motion.star); } + /** + * Function to prevent automatically closing the window/tab, + * if the user is editing a motion. + * + * @param $event The event object from 'onUnbeforeUnload'. + */ + @HostListener('window:beforeunload', ['$event']) + public stopClosing($event: Event): void { + if (this.editMotion) { + $event.returnValue = null; + } + } + /** * Translate the state's css class into a color *