1
0
mirror of https://github.com/NicolasConstant/sengi synced 2025-01-31 10:44:55 +01:00

better links, fix #309

This commit is contained in:
Nicolas Constant 2020-08-28 20:54:09 -04:00
parent 95454e29a0
commit 8710b0267e
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
2 changed files with 27 additions and 25 deletions

View File

@ -1,5 +1,5 @@
<div class="card-data" *ngIf="card.type === 'link' || card.type === 'video'"> <div class="card-data" *ngIf="card.type === 'link' || card.type === 'video'">
<a *ngIf="card.type === 'link'" class="card-data__link" href="{{ card.url }}" target="_blank" title="{{ card.title }} &#10;{{ host }}"> <a *ngIf="card.type === 'link'" class="card-data__link" href="{{ card.url }}" target="_blank" rel="noopener noreferrer" title="{{ card.title }} &#10;{{ host }}">
<img *ngIf="card.image" class="card-data__link--image" src="{{ card.image | ensureHttps }}" alt="" /> <img *ngIf="card.image" class="card-data__link--image" src="{{ card.image | ensureHttps }}" alt="" />
<div *ngIf="!card.image" class="card-data__link--image"> <div *ngIf="!card.image" class="card-data__link--image">
<fa-icon class="card-data__link--image--logo" [icon]="faFileAlt"></fa-icon> <fa-icon class="card-data__link--image--logo" [icon]="faFileAlt"></fa-icon>

View File

@ -12,7 +12,7 @@ export class DatabindedTextComponent implements OnInit {
private accounts: string[] = []; private accounts: string[] = [];
private hashtags: string[] = []; private hashtags: string[] = [];
private links: string[] = []; // private links: string[] = [];
processedText: string; processedText: string;
isCollapsed: boolean = false; isCollapsed: boolean = false;
@ -164,10 +164,12 @@ export class DatabindedTextComponent implements OnInit {
} }
} }
this.links.push(extractedUrl); // this.links.push(extractedUrl);
let classname = this.getClassNameForLink(extractedUrl); let classname = this.getClassNameForLink(extractedUrl);
this.processedText += `<a href class="${classname}" title="open link">${extractedName}</a>`; let sanitizedLink = this.sanitizeLink(extractedUrl);
this.processedText += `<a href="${sanitizedLink}" class="${classname}" title="open link" target="_blank" rel="noopener noreferrer">${extractedName}</a>`;
if (extractedLinkAndNext.length > 1) this.processedText += extractedLinkAndNext[1]; if (extractedLinkAndNext.length > 1) this.processedText += extractedLinkAndNext[1];
} }
@ -209,32 +211,32 @@ export class DatabindedTextComponent implements OnInit {
} }
} }
for (const link of this.links) { // for (const link of this.links) {
let classname = this.getClassNameForLink(link); // let classname = this.getClassNameForLink(link);
let els = this.contentElement.nativeElement.querySelectorAll(`.${classname}`); // let els = this.contentElement.nativeElement.querySelectorAll(`.${classname}`);
let sanitizedLink = this.sanitizeLink(link); // let sanitizedLink = this.sanitizeLink(link);
for (const el of els) { // for (const el of els) {
this.renderer.listen(el, 'click', (event) => { // this.renderer.listen(el, 'click', (event) => {
event.preventDefault(); // event.preventDefault();
event.stopImmediatePropagation(); // event.stopImmediatePropagation();
window.open(sanitizedLink, '_blank'); // window.open(sanitizedLink, '_blank');
return false; // return false;
}); // });
this.renderer.listen(el, 'mouseup', (event) => { // this.renderer.listen(el, 'mouseup', (event) => {
if (event.which === 2) { // if (event.which === 2) {
event.preventDefault(); // event.preventDefault();
event.stopImmediatePropagation(); // event.stopImmediatePropagation();
window.open(sanitizedLink, '_blank'); // window.open(sanitizedLink, '_blank');
return false; // return false;
} // }
}); // });
} // }
} // }
} }
private sanitizeLink(link: string): string { private sanitizeLink(link: string): string {