Change ads directory name & add iframe-tracker directive

This commit is contained in:
Yûki VACHOT 2021-10-28 20:40:58 +02:00
parent bec9ff6c0d
commit 45f9057490
9 changed files with 80 additions and 14 deletions

View file

@ -1,6 +1,6 @@
<div class="conteneur">
<span>debut</span>
<img src="assets/logo_plateforms/Youtube.png" width="40px" height="40px">
<img src="assets/ads/Youtube.png" width="40px" height="40px">
<img src="assets/logo_plateforms/Youtube.png" width="40px" height="40px" alt="image Youtube logo">
<img src="assets/pub/Youtube.png" width="40px" height="40px" alt="image Youtube">
<span>fin</span>
</div>

View file

@ -0,0 +1,8 @@
import { IframeTrackerDirective } from './iframe-tracker.directive';
describe('IframeTrackerDirective', () => {
it('should create an instance', () => {
const directive = new IframeTrackerDirective();
expect(directive).toBeTruthy();
});
});

View file

@ -0,0 +1,62 @@
import {
Directive,
ElementRef,
OnInit,
Renderer2,
Input,
Output,
EventEmitter,
HostListener
} from '@angular/core';
@Directive({
selector: '[appIframeTracker]'
})
export class IframeTrackerDirective implements OnInit {
private iframeMouseOver: boolean;
@Input() debug: boolean;
@Output() iframeClick = new EventEmitter<ElementRef>();
constructor(private el: ElementRef, private renderer: Renderer2) {}
ngOnInit(): void {
this.renderer.listen(window, 'blur', () => this.onWindowBlur());
}
@HostListener('mouseover')
private onIframeMouseOver() {
this.log('Iframe mouse over');
this.iframeMouseOver = true;
this.resetFocusOnWindow();
}
@HostListener('mouseout')
private onIframeMouseOut() {
this.log('Iframe mouse out');
this.iframeMouseOver = false;
this.resetFocusOnWindow();
}
private onWindowBlur() {
if (this.iframeMouseOver) {
this.log('WOW! Iframe click!!!');
this.resetFocusOnWindow();
this.iframeClick.emit(this.el);
}
}
private resetFocusOnWindow() {
setTimeout(() => {
this.log('reset focus to window');
window.focus();
}, 100);
}
private log(message: string) {
if (this.debug) {
console.log(message);
}
}
}