diff options
| author | Xe Iaso <me@xeiaso.net> | 2024-08-21 12:42:32 -0400 |
|---|---|---|
| committer | Xe Iaso <me@xeiaso.net> | 2024-08-21 12:42:40 -0400 |
| commit | 83902a1af00e76e9aaa40651cf33e4c399ff7380 (patch) | |
| tree | 5e1e1f3d00975fd8d9191c4a40312a1cd17cdb96 /htmx/path-params.js | |
| parent | 7a4ad5e24d0c3c3e702544315062485281a868a7 (diff) | |
| download | x-83902a1af00e76e9aaa40651cf33e4c399ff7380.tar.xz x-83902a1af00e76e9aaa40651cf33e4c399ff7380.zip | |
get started on htmx fun
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'htmx/path-params.js')
| -rw-r--r-- | htmx/path-params.js | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/htmx/path-params.js b/htmx/path-params.js new file mode 100644 index 0000000..0c65d84 --- /dev/null +++ b/htmx/path-params.js @@ -0,0 +1,11 @@ +htmx.defineExtension('path-params', { + onEvent: function(name, evt) { + if (name === 'htmx:configRequest') { + evt.detail.path = evt.detail.path.replace(/{([^}]+)}/g, function(_, param) { + var val = evt.detail.parameters[param] + delete evt.detail.parameters[param] + return val === undefined ? '{' + param + '}' : encodeURIComponent(val) + }) + } + } +}) |
