39 lines
849 B
TypeScript
39 lines
849 B
TypeScript
import { ElementType } from "./ElementType";
|
|
import { MouseEventCallback, OnClick } from "./EventListeners";
|
|
|
|
|
|
export class DomElementConstructorType
|
|
{
|
|
type:ElementType<any>;
|
|
}
|
|
|
|
export class DOMElement<T extends Element>
|
|
{
|
|
_element:T;
|
|
get element(){ return this._element; }
|
|
|
|
constructor( e:T )
|
|
{
|
|
this._element = e;
|
|
}
|
|
|
|
get( constructorType:DomElementConstructorType )
|
|
{
|
|
let element = constructorType.type.query( this._element );
|
|
|
|
return new ( constructorType as any )( element );
|
|
}
|
|
|
|
getAll( constructorType:DomElementConstructorType )
|
|
{
|
|
let elements = constructorType.type.queryAll( this._element );
|
|
|
|
return elements.map( e => new ( constructorType as any )( e ) );
|
|
}
|
|
|
|
|
|
onClick( action:MouseEventCallback, options?: any )
|
|
{
|
|
OnClick.add( this.element as any as HTMLElement, action, options );
|
|
}
|
|
} |