Skip to content

Commit

Permalink
Merge pull request #63 from keithamus/use-invokers
Browse files Browse the repository at this point in the history
use invokers
  • Loading branch information
Kristján Oddsson authored Nov 11, 2023
2 parents 2ca4ad5 + a9ff757 commit 7e88387
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

<meta name="viewport" content="width=device-width">

<script async type="module" src="./src/js/index.ts"></script>
<link rel="stylesheet" href="./dist/index.css" />
</head>
<body>
Expand All @@ -19,6 +18,7 @@
<textarea id="input" placeholder="Write some text here!"></textarea>
</div>

<button>Fullscreen!</button>
<button invoketarget="input" invokeaction="toggleFullScreen">Fullscreen!</button>
<script async type="module" src="./src/js/index.ts"></script>
</body>
</html>
21 changes: 6 additions & 15 deletions src/js/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
function ready(): Promise<void> {
return new Promise(resolve => {
if (document.readyState === 'complete' || document.readyState === 'interactive') {
resolve()
} else {
document.addEventListener('DOMContentLoaded', () => resolve())
}
})
}

await ready()
const fullScreenButton = document.querySelector('button')
const input = document.querySelector('textarea')
fullScreenButton?.addEventListener('click', async () => {
await input?.requestFullscreen()
input?.focus()
})
if (!fullScreenButton.invokeTargetElement) {
fullScreenButton?.addEventListener('click', async () => {
await input?.requestFullscreen()
input?.focus()
})
}

export {}

0 comments on commit 7e88387

Please sign in to comment.