PoC for innerHtml click interception

This commit is contained in:
Nicolas Constant 2018-10-26 20:20:01 -04:00
parent 81ae99cc7f
commit af4966abca
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
2 changed files with 50 additions and 17 deletions

View File

@ -14,7 +14,7 @@
</a> </a>
<div class="status__created-at" title="{{ displayedStatus.created_at | date: 'full' }}">{{ <div class="status__created-at" title="{{ displayedStatus.created_at | date: 'full' }}">{{
getCompactRelativeTime(status.created_at) }}</div> getCompactRelativeTime(status.created_at) }}</div>
<div class="status__content" innerHTML="{{displayedStatus.content}}"></div> <div #content class="status__content" innerHTML="{{displayedStatus.content}}"></div>
<app-attachements *ngIf="hasAttachments" class="attachments" [attachments]="displayedStatus.media_attachments"></app-attachements> <app-attachements *ngIf="hasAttachments" class="attachments" [attachments]="displayedStatus.media_attachments"></app-attachements>

View File

@ -1,9 +1,10 @@
import { Component, OnInit, Input, Output, Inject, LOCALE_ID, ElementRef, EventEmitter } from "@angular/core"; import { Component, OnInit, Input, Output, Inject, LOCALE_ID, ElementRef, EventEmitter, Pipe, PipeTransform, ViewChild, Renderer2 } from "@angular/core";
import { Status, Account} from "../../../services/models/mastodon.interfaces"; import { Status, Account } from "../../../services/models/mastodon.interfaces";
import { formatDate } from '@angular/common'; import { formatDate } from '@angular/common';
import { stateNameErrorMessage } from "@ngxs/store/src/decorators/state"; import { stateNameErrorMessage } from "@ngxs/store/src/decorators/state";
import { StatusWrapper } from "../stream.component"; import { StatusWrapper } from "../stream.component";
import { DomSanitizer } from '@angular/platform-browser'
@Component({ @Component({
selector: "app-status", selector: "app-status",
@ -20,6 +21,8 @@ export class StatusComponent implements OnInit {
@Output() browseHashtag = new EventEmitter<string>(); @Output() browseHashtag = new EventEmitter<string>();
@Output() browseThread = new EventEmitter<string>(); @Output() browseThread = new EventEmitter<string>();
@ViewChild('content') contentElement: ElementRef;
private _statusWrapper: StatusWrapper; private _statusWrapper: StatusWrapper;
status: Status; status: Status;
@Input('statusWrapper') @Input('statusWrapper')
@ -27,35 +30,60 @@ export class StatusComponent implements OnInit {
this._statusWrapper = value; this._statusWrapper = value;
this.status = value.status; this.status = value.status;
if(this.status.reblog){ //TEST
this.status.content += '<br/><br/><a href class="test">TEST</a>';
if (this.status.reblog) {
this.reblog = true; this.reblog = true;
this.displayedStatus = this.status.reblog; this.displayedStatus = this.status.reblog;
} else { } else {
this.displayedStatus = this.status; this.displayedStatus = this.status;
} }
if(!this.displayedStatus.account.display_name){ if (!this.displayedStatus.account.display_name) {
this.displayedStatus.account.display_name = this.displayedStatus.account.username; this.displayedStatus.account.display_name = this.displayedStatus.account.username;
} }
if(this.displayedStatus.media_attachments && this.displayedStatus.media_attachments.length > 0){ if (this.displayedStatus.media_attachments && this.displayedStatus.media_attachments.length > 0) {
this.hasAttachments = true; this.hasAttachments = true;
} }
} }
get statusWrapper(): StatusWrapper{ get statusWrapper(): StatusWrapper {
return this._statusWrapper; return this._statusWrapper;
} }
constructor( constructor(
private renderer: Renderer2,
@Inject(LOCALE_ID) private locale: string) { } @Inject(LOCALE_ID) private locale: string) { }
ngOnInit() { ngOnInit() {
} }
openAccount(account: Account): boolean{ ngAfterViewInit() {
//this.contentElement.nativeElement.querySelector('my-element').addEventListener('click',this.test.bind(this));
let el = this.contentElement.nativeElement.querySelector('.test');
console.log(this.contentElement.nativeElement);
console.log(el);
if(el)
this.renderer.listen(el, 'click', (el2) => {
console.log(el2);
console.warn('YOOOOO');
return false;
});
// setTimeout(() => {
// this.contentElement.nativeElement.querySelector('a.test')[0].onclick(this.test());
// }, 100);
}
openAccount(account: Account): boolean {
this.browseAccount.next(account); this.browseAccount.next(account);
return false; return false;
} }
@ -70,7 +98,7 @@ export class StatusComponent implements OnInit {
} else if (timeDelta < 60 * 60) { } else if (timeDelta < 60 * 60) {
return `${timeDelta / 60 | 0}m`; return `${timeDelta / 60 | 0}m`;
} else if (timeDelta < 60 * 60 * 24) { } else if (timeDelta < 60 * 60 * 24) {
return `${timeDelta / (60 * 60)| 0}h`; return `${timeDelta / (60 * 60) | 0}h`;
} else if (timeDelta < 60 * 60 * 24 * 31) { } else if (timeDelta < 60 * 60 * 24 * 31) {
return `${timeDelta / (60 * 60 * 24) | 0}d`; return `${timeDelta / (60 * 60 * 24) | 0}d`;
} }
@ -78,7 +106,7 @@ export class StatusComponent implements OnInit {
return formatDate(date, 'MM/dd', this.locale); return formatDate(date, 'MM/dd', this.locale);
} }
openReply(): boolean{ openReply(): boolean {
this.replyingToStatus = !this.replyingToStatus; this.replyingToStatus = !this.replyingToStatus;
return false; return false;
@ -88,4 +116,9 @@ export class StatusComponent implements OnInit {
this.replyingToStatus = false; this.replyingToStatus = false;
return false; return false;
} }
test(): boolean {
console.warn('heeeeyaaa!');
return false;
}
} }