Fix background and fix PageElement system
This commit is contained in:
parent
6fc16f4de0
commit
91d92f7f48
24 changed files with 528 additions and 809 deletions
|
|
@ -1,46 +1,21 @@
|
|||
import { EventHandler } from '../events/event-handler';
|
||||
import { EventBroadcaster } from '../events/event-broadcaster';
|
||||
import { OnEventBroadcasterChangedEvent } from '../events/concrete-events/on-event-broadcaster-changed-event';
|
||||
import { OptionalEvent } from '../events/optional-event';
|
||||
import { Event } from '../events/event';
|
||||
import { OnLoadEvent } from '../events/concrete-events/on-load-event';
|
||||
|
||||
export abstract class PageElement extends EventHandler implements EventBroadcaster {
|
||||
protected eventBroadcaster: EventBroadcaster;
|
||||
|
||||
export abstract class PageElement {
|
||||
public constructor(
|
||||
public readonly htmlRoot?: HTMLElement,
|
||||
public readonly htmlRoot: HTMLElement,
|
||||
protected children: Array<PageElement> = []
|
||||
) {
|
||||
super();
|
||||
) {}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
protected setParent(parent?: PageElement): void {
|
||||
this.children.forEach(c => c.setParent(this));
|
||||
}
|
||||
|
||||
public broadcastEvent(event: Event) {
|
||||
event = this.handle(event);
|
||||
if (event) {
|
||||
this.children.forEach(c => c.broadcastEvent(event));
|
||||
}
|
||||
}
|
||||
|
||||
public handleOnEventBroadcasterChangedEvent(
|
||||
event: OnEventBroadcasterChangedEvent
|
||||
): OptionalEvent {
|
||||
this.eventBroadcaster = event.broadcaster;
|
||||
return super.handleOnEventBroadcasterChangedEvent(event);
|
||||
}
|
||||
|
||||
public handleOnLoadEvent(_: OnLoadEvent): OptionalEvent {
|
||||
return super.handleOnLoadEvent(new OnLoadEvent(this));
|
||||
}
|
||||
|
||||
protected query(query: string): HTMLElement | null {
|
||||
return this.htmlRoot?.querySelector(query);
|
||||
protected query(query: string): HTMLElement {
|
||||
return this.htmlRoot.querySelector(query) as HTMLElement;
|
||||
}
|
||||
|
||||
protected attachElementByReplacing(query: string, element: PageElement) {
|
||||
const old = this.query(query);
|
||||
old.parentElement.replaceChild(element.htmlRoot, old);
|
||||
|
||||
old.parentElement!.replaceChild(element.htmlRoot, old);
|
||||
this.children.push(element);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue