defaultkavy
4c078c26b6
- remove: class $EventMethod, $Event. - change: $EventManager rewrite logic. - change: most $Node base node element generic type have new EM(EventMap) parameter. - new: $EventTarget. - change: $Node extends $EventTarget. - change: mix dom events and $EventManager events into $EventTarget.on().off().once(). - fix: $Container.insert() process synchronous when passing an not async function - new: $Window element. - fix: $(document.documentElement) throw error. - new: $KeyboardManager, $FocusManager, $PointerManager. - new: $ global methods: - $.events() return new $EventManager. - $.pointers() return new $PointerManager. - $.keys() return new $KeyboardManager. - $.focus() return new $FocusManager. - $.call() - change: $Media extends $HTMLElement - change: $Anchor.href() support $State parameter. - new: $State.convert()
27 lines
1.2 KiB
TypeScript
27 lines
1.2 KiB
TypeScript
import { $StateArgument } from "../$State";
|
|
import { $Container, $ContainerOptions } from "./$Container";
|
|
|
|
export interface AnchorOptions extends $ContainerOptions {}
|
|
|
|
export class $Anchor extends $Container<HTMLAnchorElement> {
|
|
constructor(options?: AnchorOptions) {
|
|
super('a', options);
|
|
// Link Handler event
|
|
this.dom.addEventListener('click', e => {
|
|
if ($.anchorHandler && !!this.href()) {
|
|
e.preventDefault();
|
|
$.anchorHandler(this, e);
|
|
}
|
|
})
|
|
}
|
|
/**Set URL of anchor element. */
|
|
href(): string;
|
|
href(url: $StateArgument<string>): this;
|
|
href(url?: $StateArgument<string>) { return $.fluent(this, arguments, () => this.dom.href, () => $.set(this.dom, 'href', url)) }
|
|
/**Link open with this window, new tab or other */
|
|
target(): $AnchorTarget | undefined;
|
|
target(target: $AnchorTarget | undefined): this;
|
|
target(target?: $AnchorTarget | undefined) { return $.fluent(this, arguments, () => (this.dom.target ?? undefined) as $AnchorTarget | undefined, () => {if (target) this.dom.target = target}) }
|
|
}
|
|
|
|
export type $AnchorTarget = '_blank' | '_self' | '_parent' | '_top'; |