Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | 29x 29x | import { DOM } from '../utils/exported';
/**
* will be event handler, just need to rethink and redo it all
* main pointis to delegate the events, so we have 1 event listener for many elements and let event bubble
*
*/
export class DomEventHandler {
private eventHandlerBinded: any;
private count = 0;
private id: any[] = [];
private events: any[] = [];
private target: any[] = [];
private call: any[] = [];
constructor() {
this.eventHandlerBinded = this.eventHandler.bind(this);
}
public listenFor(event: string, target: any, call: Function): number {
this.count++;
if (this.events.indexOf(event) === -1) {
this.addEventListener(event);
}
this.id.push(this.count);
this.events.push(event);
this.target.push(target);
this.call.push(call);
return this.count;
}
public removeListener(id: number): void {
this.id.splice(id, 1);
const event = this.events.splice(id, 1);
this.target.splice(id, 1);
this.call.splice(id, 1);
if (this.events.indexOf(event) === -1) {
this.removeEventListener(event);
}
}
private addEventListener(event: any): void {
(DOM.document.body as any).addEventListener(event, (this.eventHandlerBinded as EventListenerOrEventListenerObject), false);
}
private removeEventListener(event: any): void {
(DOM.document.body as any).removeEventListener(event, (this.eventHandlerBinded as EventListenerOrEventListenerObject), false);
}
private eventHandler(event: any): void {
const targetID = this.target.indexOf(event.target);
const targetEvent = this.events[targetID];
const eventID = this.events.indexOf(event.type);
if (eventID !== -1 && targetID !== -1) {
if (targetID !== -1 && targetEvent === event.type) {
this.call[targetID](event);
} else {
// todo
}
}
}
}
|