diff --git a/index.html b/index.html index b482e24..a4858de 100644 --- a/index.html +++ b/index.html @@ -75,5 +75,11 @@ + + + + + + diff --git a/src/components/event.ts b/src/components/event.ts new file mode 100644 index 0000000..81245d3 --- /dev/null +++ b/src/components/event.ts @@ -0,0 +1,27 @@ +import { traverseChildren } from '../main'; +import { BaseHtmlangElement } from './htmlangElement'; + +export class EventDash extends BaseHtmlangElement { + static getTagName = () => 'event' as const; + + execute = (): void => { + const on = this.getAttribute('on'); + if (!on) { + return; + } + + const target = this.getAttribute('target'); + if (!target) { + return; + } + + const targetElements = document.querySelectorAll(target); + if (!targetElements) { + return; + } + + targetElements.forEach((element) => { + element.addEventListener(on, () => traverseChildren(this)); + }); + }; +} diff --git a/src/components/htmllangElement.test.ts b/src/components/htmlangElement.test.ts similarity index 100% rename from src/components/htmllangElement.test.ts rename to src/components/htmlangElement.test.ts diff --git a/src/main.ts b/src/main.ts index fc037a6..c8a7079 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,6 +4,7 @@ import { ConsoleDash } from './components/console'; import { ConstDash } from './components/const'; import { ElseDash } from './components/else'; import { ElseIfDash } from './components/elseIf'; +import { EventDash } from './components/event'; import { ForDash } from './components/for'; import { BaseHtmlangElement, HtmlangElement } from './components/htmlangElement'; import { IfDash } from './components/if'; @@ -22,6 +23,7 @@ export function defineElements(): void { ConstDash, ElseDash, ElseIfDash, + EventDash, ForDash, IfDash, LetDash,