Skip to content

Commit

Permalink
feat: add onload js setup
Browse files Browse the repository at this point in the history
  • Loading branch information
hperl committed Jan 10, 2024
1 parent d45c7f1 commit 6f92697
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions views/login.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{{{card}}}

{{> webauthn_setup nodes=nodes webAuthnHandler=webAuthnHandler webauthnTriggerName="webauthn_login_trigger"}}
{{> js_setup nodes=nodes}}
{{#if extraPartial }}
{{> (extraPartial) }}
{{/if}}
Expand Down
18 changes: 18 additions & 0 deletions views/partials/js_setup.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{! This partial sets up the onclick and onload event handlers for each passkey node.}}
<script type="text/javascript">
// register onclick and onload event handlers for each passkey node.
window.addEventListener("load", () => {
{{#each (onlyNodes nodes "passkey" "")}}
{{#if attributes.onclick}}
// onclick for {{attributes.name}}
document.getElementsByName("{{attributes.name}}").forEach((el) => {
el.addEventListener("click", () => { {{{attributes.onclick}}} })
})
{{/if}}
{{#if attributes.onload}}
// onload for {{attributes.name}}
{{{attributes.onload}}}
{{/if}}
{{/each}}
})
</script>
1 change: 1 addition & 0 deletions views/registration.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{{{card}}}

{{> webauthn_setup nodes=nodes webAuthnHandler=webAuthnHandler webauthnTriggerName="webauthn_register_trigger"}}
{{> js_setup nodes=nodes}}
{{#if extraPartial }}
{{> (extraPartial) }}
{{/if}}
Expand Down
2 changes: 1 addition & 1 deletion views/settings.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
</div>

{{> webauthn_setup nodes=nodes webAuthnHandler=webAuthnHandler webauthnTriggerName="webauthn_register_trigger"}}

{{> js_setup nodes=nodes}}
</div>

0 comments on commit 6f92697

Please sign in to comment.