1 import { Component, ElementRef, HostListener, Input, OnInit, ViewChild } from '@angular/core'
2 import { MarkdownService } from '@app/videos/shared'
3 import { TooltipDirective } from 'ngx-bootstrap/tooltip'
7 styleUrls: [ './help.component.scss' ],
8 templateUrl: './help.component.html'
11 export class HelpComponent implements OnInit {
12 @ViewChild('tooltipDirective') tooltipDirective: TooltipDirective
14 @Input() postHtml = ''
15 @Input() customHtml = ''
16 @Input() helpType: 'custom' | 'markdownText' | 'markdownEnhanced' = 'custom'
20 constructor (private elementRef: ElementRef) { }
23 if (this.helpType === 'custom') {
24 this.mainHtml = this.customHtml
28 if (this.helpType === 'markdownText') {
29 this.mainHtml = this.formatMarkdownSupport(MarkdownService.TEXT_RULES)
33 if (this.helpType === 'markdownEnhanced') {
34 this.mainHtml = this.formatMarkdownSupport(MarkdownService.ENHANCED_RULES)
39 @HostListener('document:click', ['$event.target'])
40 public onClick (targetElement) {
41 const clickedInside = this.elementRef.nativeElement.contains(targetElement)
43 if (this.tooltipDirective.isOpen && !clickedInside) {
44 this.tooltipDirective.hide()
48 private formatMarkdownSupport (rules: string[]) {
49 return '<a href="https://en.wikipedia.org/wiki/Markdown#Example" target="_blank">Markdown</a> compatible that supports:' +
50 this.createMarkdownList(rules)
53 private createMarkdownList (rules: string[]) {
55 'emphasis': 'Emphasis',
57 'newline': 'New lines',
62 const bullets = rules.map(r => rulesToText[r])
64 .map(text => '<li>' + text + '</li>')
67 return '<ul>' + bullets + '</ul>'