corrections des erreurs remarquées par Wilfried
This commit is contained in:
parent
d1ac1b77f0
commit
939e5f4df1
33 changed files with 66 additions and 112 deletions
|
|
@ -1,8 +0,0 @@
|
|||
import { DragAndDropDirective } from './drag-and-drop.directive';
|
||||
|
||||
describe('DragAndDropDirective', () => {
|
||||
it('should create an instance', () => {
|
||||
const directive = new DragAndDropDirective();
|
||||
expect(directive).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
import {Directive, EventEmitter, HostBinding, HostListener, Output} from '@angular/core';
|
||||
|
||||
@Directive({
|
||||
selector: '[appDragAndDrop]'
|
||||
})
|
||||
export class DragAndDropDirective
|
||||
{
|
||||
@HostBinding('class.fileover') fileOver: boolean;
|
||||
@Output() fileDropped = new EventEmitter<any>();
|
||||
|
||||
// Dragover listener
|
||||
@HostListener('dragover', ['$event']) onDragOver(evt) {
|
||||
evt.preventDefault();
|
||||
evt.stopPropagation();
|
||||
this.fileOver = true;
|
||||
}
|
||||
|
||||
// Dragleave listener
|
||||
@HostListener('dragleave', ['$event']) public onDragLeave(evt) {
|
||||
evt.preventDefault();
|
||||
evt.stopPropagation();
|
||||
this.fileOver = false;
|
||||
}
|
||||
|
||||
// Drop listener
|
||||
@HostListener('drop', ['$event']) public ondrop(evt) {
|
||||
evt.preventDefault();
|
||||
evt.stopPropagation();
|
||||
this.fileOver = false;
|
||||
let files = evt.dataTransfer.files;
|
||||
if (files.length > 0) {
|
||||
this.fileDropped.emit(files);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
import { IframeTrackerDirective } from './iframe-tracker.directive';
|
||||
|
||||
describe('IframeTrackerDirective', () => {
|
||||
it('should create an instance', () => {
|
||||
const directive = new IframeTrackerDirective();
|
||||
expect(directive).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in a new issue