-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6d5633
commit 1bd7ef3
Showing
8 changed files
with
171 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,51 @@ <h1>Buttons</h1> | |
</button> | ||
</label> | ||
</p> | ||
<script defer> | ||
<p> | ||
<!-- FORM POST --> | ||
<form hx-post="/submitmail" hx-ext="serverless"> | ||
<label> Email | ||
<input type="text" name="email_address"> | ||
</label> | ||
<label> Button 2 | ||
<button type="submit">Go!</button> | ||
</label> | ||
</form> | ||
|
||
<!-- FORM GET --> | ||
<form hx-get="/submitmail" hx-ext="serverless"> | ||
<label> Email | ||
<input type="text" name="email_address"> | ||
</label> | ||
<label> Button 2 | ||
<button type="submit">Go!</button> | ||
</label> | ||
</form> | ||
</p> | ||
|
||
<span class="counter"></span> | ||
<button hx-get="/example" hx-target="previous .counter" hx-trigger="load, click" hx-vals='js:{myVal: i++}' hx-ext="serverless">Click to Increment</button> | ||
|
||
|
||
<script> | ||
htmxServerless.handlers.set('/clicked', '<button hx-post="/clicked2" hx-swap="outerHTML" hx-ext="serverless">Click again!</button>') | ||
htmxServerless.handlers.set('/clicked2', '<button hx-post="/clicked" hx-swap="outerHTML" hx-ext="serverless">Click!</button>') | ||
htmxServerless.handlers.set('/clicked2', '<button hx-post="/clicked" hx-swap="outerHTML" hx-ext="serverless">Click!</button>'); | ||
|
||
// Form | ||
htmxServerless.handlers.set('/submitmail', function(text, params, xhr){ | ||
if ( params?.email_address != '[email protected]' ) { | ||
return this.outerHTML; | ||
} else { | ||
return "Thanks!" | ||
} | ||
}); | ||
|
||
// DIV | ||
let i = 0; | ||
htmxServerless.handlers.set('/example', function(text, params, xhr){ | ||
let status = params?.myVal < 10 ? "smaller" : "bigger"; | ||
return `Value of "i" is: ${i}, it is ${status} than 10. Click to increment!`; | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
import htmx from "htmx.org"; | ||
type path = string; | ||
type HTML = string; | ||
import { path, ServerlessHandler, XHRServerless, HtmxElement } from "./types"; | ||
export default class Serverless { | ||
handlers: Map<path, HTML>; | ||
handlers: Map<path, ServerlessHandler>; | ||
constructor(); | ||
init(h?: typeof htmx): void; | ||
onEvent(name: string, evt: any): void; | ||
transformResponse(text: string, xhr: XMLHttpRequest, elt: Element & { | ||
'htmx-internal-data'?: any; | ||
}): string | undefined; | ||
transformResponse(text: string, xhr: XHRServerless, elt: HtmxElement): string; | ||
shouldIntercept(path: string | undefined): boolean; | ||
} | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters