]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/misc/help.component.ts
adding CSP, no-referrer policies and allow dns prefetching
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / misc / help.component.ts
index a4a223cd6108d87b047ddfe9c039b8806f8f9989..e7af61b4a8e36103d98d1f357aae8d5576e95473 100644 (file)
@@ -1,6 +1,6 @@
-import { Component, ElementRef, HostListener, Input, OnInit, ViewChild } from '@angular/core'
+import { Component, Input, OnChanges, OnInit } from '@angular/core'
 import { MarkdownService } from '@app/videos/shared'
-import { TooltipDirective } from 'ngx-bootstrap/tooltip'
+import { I18n } from '@ngx-translate/i18n-polyfill'
 
 @Component({
   selector: 'my-help',
@@ -8,18 +8,26 @@ import { TooltipDirective } from 'ngx-bootstrap/tooltip'
   templateUrl: './help.component.html'
 })
 
-export class HelpComponent implements OnInit {
-  @ViewChild('tooltipDirective') tooltipDirective: TooltipDirective
+export class HelpComponent implements OnInit, OnChanges {
   @Input() preHtml = ''
   @Input() postHtml = ''
   @Input() customHtml = ''
   @Input() helpType: 'custom' | 'markdownText' | 'markdownEnhanced' = 'custom'
+  @Input() tooltipPlacement = 'right'
 
   mainHtml = ''
 
-  constructor (private elementRef: ElementRef) { }
+  constructor (private i18n: I18n) { }
 
   ngOnInit () {
+    this.init()
+  }
+
+  ngOnChanges () {
+    this.init()
+  }
+
+  private init () {
     if (this.helpType === 'custom') {
       this.mainHtml = this.customHtml
       return
@@ -36,27 +44,19 @@ export class HelpComponent implements OnInit {
     }
   }
 
-  @HostListener('document:click', ['$event.target'])
-  public onClick (targetElement) {
-    const clickedInside = this.elementRef.nativeElement.contains(targetElement)
-
-    if (this.tooltipDirective.isOpen && !clickedInside) {
-      this.tooltipDirective.hide()
-    }
-  }
-
   private formatMarkdownSupport (rules: string[]) {
-    return '<a href="https://en.wikipedia.org/wiki/Markdown#Example" target="_blank">Markdown</a> compatible that supports:' +
+    // tslint:disable:max-line-length
+    return this.i18n('<a href="https://en.wikipedia.org/wiki/Markdown#Example" target="_blank" rel="noopener noreferrer">Markdown</a> compatible that supports:') +
       this.createMarkdownList(rules)
   }
 
   private createMarkdownList (rules: string[]) {
     const rulesToText = {
-      'emphasis': 'Emphasis',
-      'link': 'Links',
-      'newline': 'New lines',
-      'list': 'Lists',
-      'image': 'Images'
+      'emphasis': this.i18n('Emphasis'),
+      'link': this.i18n('Links'),
+      'newline': this.i18n('New lines'),
+      'list': this.i18n('Lists'),
+      'image': this.i18n('Images')
     }
 
     const bullets = rules.map(r => rulesToText[r])