diff options
author | Chocobozzz <me@florianbigard.com> | 2018-02-23 10:05:17 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-02-23 10:05:17 +0100 |
commit | 621d99f53f47a11919ec243e05273ecf5907b444 (patch) | |
tree | dcd0d0ccc21bad4065bf49e2df3e641ffa18fee1 /client/src/app/shared | |
parent | 8a8e02a43e346b9b777c8192a7c5cbdccb928b11 (diff) | |
download | PeerTube-621d99f53f47a11919ec243e05273ecf5907b444.tar.gz PeerTube-621d99f53f47a11919ec243e05273ecf5907b444.tar.zst PeerTube-621d99f53f47a11919ec243e05273ecf5907b444.zip |
Better help on markdown fields
Diffstat (limited to 'client/src/app/shared')
-rw-r--r-- | client/src/app/shared/misc/help.component.html | 5 | ||||
-rw-r--r-- | client/src/app/shared/misc/help.component.scss | 1 | ||||
-rw-r--r-- | client/src/app/shared/misc/help.component.ts | 55 |
3 files changed, 44 insertions, 17 deletions
diff --git a/client/src/app/shared/misc/help.component.html b/client/src/app/shared/misc/help.component.html index 956095996..bacbe9cdb 100644 --- a/client/src/app/shared/misc/help.component.html +++ b/client/src/app/shared/misc/help.component.html | |||
@@ -12,4 +12,7 @@ | |||
12 | </ng-template> | 12 | </ng-template> |
13 | </ng-template> | 13 | </ng-template> |
14 | 14 | ||
15 | <button class="help-tooltip-button" containerClass="help-tooltip" [tooltipHtml]="tooltipTemplate" triggers="focus"></button> | 15 | <button |
16 | class="help-tooltip-button" containerClass="help-tooltip" title="Click to get help" | ||
17 | #tooltipDirective="bs-tooltip" [tooltip]="tooltipTemplate" triggers="click" | ||
18 | ></button> | ||
diff --git a/client/src/app/shared/misc/help.component.scss b/client/src/app/shared/misc/help.component.scss index 5fe6b7366..b8bf3a7a5 100644 --- a/client/src/app/shared/misc/help.component.scss +++ b/client/src/app/shared/misc/help.component.scss | |||
@@ -18,6 +18,7 @@ | |||
18 | .tooltip-inner { | 18 | .tooltip-inner { |
19 | text-align: left; | 19 | text-align: left; |
20 | padding: 10px; | 20 | padding: 10px; |
21 | max-width: 300px; | ||
21 | 22 | ||
22 | font-size: 13px; | 23 | font-size: 13px; |
23 | font-family: $main-fonts; | 24 | font-family: $main-fonts; |
diff --git a/client/src/app/shared/misc/help.component.ts b/client/src/app/shared/misc/help.component.ts index b8530e1d4..a4a223cd6 100644 --- a/client/src/app/shared/misc/help.component.ts +++ b/client/src/app/shared/misc/help.component.ts | |||
@@ -1,4 +1,6 @@ | |||
1 | import { Component, Input, OnInit } from '@angular/core' | 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' | ||
2 | 4 | ||
3 | @Component({ | 5 | @Component({ |
4 | selector: 'my-help', | 6 | selector: 'my-help', |
@@ -7,6 +9,7 @@ import { Component, Input, OnInit } from '@angular/core' | |||
7 | }) | 9 | }) |
8 | 10 | ||
9 | export class HelpComponent implements OnInit { | 11 | export class HelpComponent implements OnInit { |
12 | @ViewChild('tooltipDirective') tooltipDirective: TooltipDirective | ||
10 | @Input() preHtml = '' | 13 | @Input() preHtml = '' |
11 | @Input() postHtml = '' | 14 | @Input() postHtml = '' |
12 | @Input() customHtml = '' | 15 | @Input() customHtml = '' |
@@ -14,6 +17,8 @@ export class HelpComponent implements OnInit { | |||
14 | 17 | ||
15 | mainHtml = '' | 18 | mainHtml = '' |
16 | 19 | ||
20 | constructor (private elementRef: ElementRef) { } | ||
21 | |||
17 | ngOnInit () { | 22 | ngOnInit () { |
18 | if (this.helpType === 'custom') { | 23 | if (this.helpType === 'custom') { |
19 | this.mainHtml = this.customHtml | 24 | this.mainHtml = this.customHtml |
@@ -21,26 +26,44 @@ export class HelpComponent implements OnInit { | |||
21 | } | 26 | } |
22 | 27 | ||
23 | if (this.helpType === 'markdownText') { | 28 | if (this.helpType === 'markdownText') { |
24 | this.mainHtml = 'Markdown compatible.<br /><br />' + | 29 | this.mainHtml = this.formatMarkdownSupport(MarkdownService.TEXT_RULES) |
25 | 'Supports:' + | ||
26 | '<ul>' + | ||
27 | '<li>Links</li>' + | ||
28 | '<li>Lists</li>' + | ||
29 | '<li>Emphasis</li>' + | ||
30 | '</ul>' | ||
31 | return | 30 | return |
32 | } | 31 | } |
33 | 32 | ||
34 | if (this.helpType === 'markdownEnhanced') { | 33 | if (this.helpType === 'markdownEnhanced') { |
35 | this.mainHtml = 'Markdown compatible.<br /><br />' + | 34 | this.mainHtml = this.formatMarkdownSupport(MarkdownService.ENHANCED_RULES) |
36 | 'Supports:' + | ||
37 | '<ul>' + | ||
38 | '<li>Links</li>' + | ||
39 | '<li>Lists</li>' + | ||
40 | '<li>Emphasis</li>' + | ||
41 | '<li>Images</li>' + | ||
42 | '</ul>' | ||
43 | return | 35 | return |
44 | } | 36 | } |
45 | } | 37 | } |
38 | |||
39 | @HostListener('document:click', ['$event.target']) | ||
40 | public onClick (targetElement) { | ||
41 | const clickedInside = this.elementRef.nativeElement.contains(targetElement) | ||
42 | |||
43 | if (this.tooltipDirective.isOpen && !clickedInside) { | ||
44 | this.tooltipDirective.hide() | ||
45 | } | ||
46 | } | ||
47 | |||
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) | ||
51 | } | ||
52 | |||
53 | private createMarkdownList (rules: string[]) { | ||
54 | const rulesToText = { | ||
55 | 'emphasis': 'Emphasis', | ||
56 | 'link': 'Links', | ||
57 | 'newline': 'New lines', | ||
58 | 'list': 'Lists', | ||
59 | 'image': 'Images' | ||
60 | } | ||
61 | |||
62 | const bullets = rules.map(r => rulesToText[r]) | ||
63 | .filter(text => text) | ||
64 | .map(text => '<li>' + text + '</li>') | ||
65 | .join('') | ||
66 | |||
67 | return '<ul>' + bullets + '</ul>' | ||
68 | } | ||
46 | } | 69 | } |