mirror of
https://github.com/Terncode/pixel.horse.git
synced 2026-09-24 21:55:52 +02:00
* Revert "7f7efbb94bab8574e42d942ad82d414e007b2970" Code style changes should probably be part of a PR
18 lines
416 B
TypeScript
18 lines
416 B
TypeScript
import { Directive, OnInit, ElementRef } from '@angular/core';
|
|
|
|
@Directive({
|
|
selector: 'a[href]'
|
|
})
|
|
export class Anchor implements OnInit {
|
|
constructor(private element: ElementRef) {
|
|
}
|
|
ngOnInit() {
|
|
const a = this.element.nativeElement as HTMLAnchorElement;
|
|
|
|
if (/^(https?|mailto):/.test(a.href) && !a.target) {
|
|
a.setAttribute('target', '_blank');
|
|
a.setAttribute('rel', 'noopener noreferrer');
|
|
}
|
|
}
|
|
}
|