diff options
author | Chocobozzz <me@florianbigard.com> | 2020-06-23 14:10:17 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-06-23 16:00:49 +0200 |
commit | 67ed6552b831df66713bac9e672738796128d33f (patch) | |
tree | 59c97d41e0b49d75a90aa3de987968ab9b1ff447 /client/src/app/shared/forms/markdown-textarea.component.ts | |
parent | 0c4bacbff53bc732f5a2677d62a6ead7752e2405 (diff) | |
download | PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.gz PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.zst PeerTube-67ed6552b831df66713bac9e672738796128d33f.zip |
Reorganize client shared modules
Diffstat (limited to 'client/src/app/shared/forms/markdown-textarea.component.ts')
-rw-r--r-- | client/src/app/shared/forms/markdown-textarea.component.ts | 114 |
1 files changed, 0 insertions, 114 deletions
diff --git a/client/src/app/shared/forms/markdown-textarea.component.ts b/client/src/app/shared/forms/markdown-textarea.component.ts deleted file mode 100644 index dde7b4d98..000000000 --- a/client/src/app/shared/forms/markdown-textarea.component.ts +++ /dev/null | |||
@@ -1,114 +0,0 @@ | |||
1 | import { debounceTime, distinctUntilChanged } from 'rxjs/operators' | ||
2 | import { Component, forwardRef, Input, OnInit, ViewChild, ElementRef } from '@angular/core' | ||
3 | import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms' | ||
4 | import { Subject } from 'rxjs' | ||
5 | import truncate from 'lodash-es/truncate' | ||
6 | import { ScreenService } from '@app/shared/misc/screen.service' | ||
7 | import { MarkdownService } from '@app/shared/renderer' | ||
8 | |||
9 | @Component({ | ||
10 | selector: 'my-markdown-textarea', | ||
11 | templateUrl: './markdown-textarea.component.html', | ||
12 | styleUrls: [ './markdown-textarea.component.scss' ], | ||
13 | providers: [ | ||
14 | { | ||
15 | provide: NG_VALUE_ACCESSOR, | ||
16 | useExisting: forwardRef(() => MarkdownTextareaComponent), | ||
17 | multi: true | ||
18 | } | ||
19 | ] | ||
20 | }) | ||
21 | |||
22 | export class MarkdownTextareaComponent implements ControlValueAccessor, OnInit { | ||
23 | @Input() content = '' | ||
24 | @Input() classes: string[] | { [klass: string]: any[] | any } = [] | ||
25 | @Input() textareaMaxWidth = '100%' | ||
26 | @Input() textareaHeight = '150px' | ||
27 | @Input() truncate: number | ||
28 | @Input() markdownType: 'text' | 'enhanced' = 'text' | ||
29 | @Input() markdownVideo = false | ||
30 | @Input() name = 'description' | ||
31 | |||
32 | @ViewChild('textarea') textareaElement: ElementRef | ||
33 | |||
34 | truncatedPreviewHTML = '' | ||
35 | previewHTML = '' | ||
36 | isMaximized = false | ||
37 | |||
38 | private contentChanged = new Subject<string>() | ||
39 | |||
40 | constructor ( | ||
41 | private screenService: ScreenService, | ||
42 | private markdownService: MarkdownService | ||
43 | ) {} | ||
44 | |||
45 | ngOnInit () { | ||
46 | this.contentChanged | ||
47 | .pipe( | ||
48 | debounceTime(150), | ||
49 | distinctUntilChanged() | ||
50 | ) | ||
51 | .subscribe(() => this.updatePreviews()) | ||
52 | |||
53 | this.contentChanged.next(this.content) | ||
54 | } | ||
55 | |||
56 | propagateChange = (_: any) => { /* empty */ } | ||
57 | |||
58 | writeValue (description: string) { | ||
59 | this.content = description | ||
60 | |||
61 | this.contentChanged.next(this.content) | ||
62 | } | ||
63 | |||
64 | registerOnChange (fn: (_: any) => void) { | ||
65 | this.propagateChange = fn | ||
66 | } | ||
67 | |||
68 | registerOnTouched () { | ||
69 | // Unused | ||
70 | } | ||
71 | |||
72 | onModelChange () { | ||
73 | this.propagateChange(this.content) | ||
74 | |||
75 | this.contentChanged.next(this.content) | ||
76 | } | ||
77 | |||
78 | onMaximizeClick () { | ||
79 | this.isMaximized = !this.isMaximized | ||
80 | |||
81 | // Make sure textarea have the focus | ||
82 | this.textareaElement.nativeElement.focus() | ||
83 | |||
84 | // Make sure the window has no scrollbars | ||
85 | if (!this.isMaximized) { | ||
86 | this.unlockBodyScroll() | ||
87 | } else { | ||
88 | this.lockBodyScroll() | ||
89 | } | ||
90 | } | ||
91 | |||
92 | private lockBodyScroll () { | ||
93 | document.getElementById('content').classList.add('lock-scroll') | ||
94 | } | ||
95 | |||
96 | private unlockBodyScroll () { | ||
97 | document.getElementById('content').classList.remove('lock-scroll') | ||
98 | } | ||
99 | |||
100 | private async updatePreviews () { | ||
101 | if (this.content === null || this.content === undefined) return | ||
102 | |||
103 | this.truncatedPreviewHTML = await this.markdownRender(truncate(this.content, { length: this.truncate })) | ||
104 | this.previewHTML = await this.markdownRender(this.content) | ||
105 | } | ||
106 | |||
107 | private async markdownRender (text: string) { | ||
108 | const html = this.markdownType === 'text' ? | ||
109 | await this.markdownService.textMarkdownToHTML(text) : | ||
110 | await this.markdownService.enhancedMarkdownToHTML(text) | ||
111 | |||
112 | return this.markdownVideo ? this.markdownService.processVideoTimestamps(html) : html | ||
113 | } | ||
114 | } | ||