Skip to content
Snippets Groups Projects
Commit c7538c4c authored by Ruben Bimberg's avatar Ruben Bimberg :computer:
Browse files

Fix handling of videos inside quill

[Ticket: #623]
parent 7211b92b
No related merge requests found
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
<strong>{{'deepl.option-normal' | translate}}</strong> <strong>{{'deepl.option-normal' | translate}}</strong>
</mat-radio-button> </mat-radio-button>
<app-view-comment-data #normal <app-view-comment-data #normal
class="deepl-view-comment"
[maxTextCharacters]="data.maxTextCharacters" [maxTextCharacters]="data.maxTextCharacters"
[maxDataCharacters]="data.maxDataCharacters" [maxDataCharacters]="data.maxDataCharacters"
[isModerator]="data.isModerator" [isModerator]="data.isModerator"
...@@ -19,6 +20,7 @@ ...@@ -19,6 +20,7 @@
<strong>{{'deepl.option-improved' | translate}}</strong> <strong>{{'deepl.option-improved' | translate}}</strong>
</mat-radio-button> </mat-radio-button>
<app-view-comment-data #improved <app-view-comment-data #improved
class="deepl-view-comment"
[maxTextCharacters]="data.maxTextCharacters" [maxTextCharacters]="data.maxTextCharacters"
[maxDataCharacters]="data.maxDataCharacters" [maxDataCharacters]="data.maxDataCharacters"
[isModerator]="data.isModerator" [isModerator]="data.isModerator"
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
width: 100%; width: 100%;
} }
app-view-comment-data > div { app-view-comment-data.deepl-view-comment > div {
background: var(--surface); background: var(--surface);
border-radius: 10px; border-radius: 10px;
padding: 7px; padding: 7px;
......
...@@ -60,7 +60,7 @@ export class ViewCommentDataComponent implements OnInit, AfterViewInit { ...@@ -60,7 +60,7 @@ export class ViewCommentDataComponent implements OnInit, AfterViewInit {
container: participantToolbar, container: participantToolbar,
handlers: { handlers: {
image: () => this.handle('image'), image: () => this.handle('image'),
video: () => this.handle('video'), video: () => this.handleVideo(),
link: () => this.handleLink(), link: () => this.handleLink(),
formula: () => this.handle('formula') formula: () => this.handle('formula')
} }
...@@ -268,6 +268,44 @@ export class ViewCommentDataComponent implements OnInit, AfterViewInit { ...@@ -268,6 +268,44 @@ export class ViewCommentDataComponent implements OnInit, AfterViewInit {
.subscribe(translation => tooltip.textbox.placeholder = translation); .subscribe(translation => tooltip.textbox.placeholder = translation);
} }
private handleVideo(): void {
const quill = this.editor.quillEditor;
const tooltip = quill.theme.tooltip;
const originalSave = tooltip.save;
const originalHide = tooltip.hide;
tooltip.save = () => {
const range = quill.getSelection(true);
const value = this.getVideoUrl(tooltip.textbox.value);
if (value) {
quill.insertEmbed(range.index, 'video', value, 'user');
}
};
// Called on hide and save.
tooltip.hide = () => {
tooltip.save = originalSave;
tooltip.hide = originalHide;
tooltip.hide();
};
tooltip.edit('video');
this.translateService.get('quill.tooltip-placeholder-video')
.subscribe(translation => tooltip.textbox.placeholder = translation);
}
private getVideoUrl(url) {
let match = url.match(/^(?:(https?):\/\/)?(?:(?:www|m)\.)?youtube\.com\/watch.*v=([a-zA-Z0-9_-]+)/) ||
url.match(/^(?:(https?):\/\/)?(?:(?:www|m)\.)?youtu\.be\/([a-zA-Z0-9_-]+)/) ||
url.match(/^.*(youtu.be\/|v\/|e\/|u\/\w+\/|embed\/|v=)([^#&?]*).*/);
if (match && match[2].length === 11) {
return 'https://www.youtube-nocookie.com/embed/' + match[2] + '?showinfo=0';
}
match = url.match(/^(?:(https?):\/\/)?(?:www\.)?vimeo\.com\/(\d+)/);
if (match) {
return (match[1] || 'https') + '://player.vimeo.com/video/' + match[2] + '/';
}
return null;
}
private handle(type: string): void { private handle(type: string): void {
const quill = this.editor.quillEditor; const quill = this.editor.quillEditor;
const tooltip = quill.theme.tooltip; const tooltip = quill.theme.tooltip;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment