forked from bigskysoftware/htmx
-
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
Showing
5 changed files
with
93 additions
and
62 deletions.
There are no files selected for viewing
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,3 +1,4 @@ | ||
/locality-of-behaviour /essays/locality-of-behaviour | ||
/posts/2020-6-19-htmx-0.0.5-is-released/ /posts/2020-6-20-htmx-0.0.6-is-released/ | ||
/discord https://discord.gg/Z6gPqAd | ||
/locality-of-behaviour /essays/locality-of-behaviour | ||
/posts/2020-6-19-htmx-0.0.5-is-released/ /posts/2020-6-20-htmx-0.0.6-is-released/ | ||
/discord https://discord.gg/Z6gPqAd | ||
https://demo.htmx.org/* /js/demo/it.js 200! |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -4,24 +4,28 @@ function addScript(url) { | |
document.head.appendChild(myScript); | ||
} | ||
|
||
function interpolate(str) { | ||
function interpolate(str, params) { | ||
var returnStr = ""; | ||
var charArray = Array.from(str); | ||
while (charArray.length > 0) { | ||
var current = charArray.shift(); | ||
if (current === "$" && charArray[0] === "{") { | ||
var evalStr = "(function() { return " | ||
charArray.shift(); | ||
while (charArray.length > 0 && charArray[0] !== "}") { | ||
evalStr += charArray.shift() | ||
try { | ||
var charArray = Array.from(str); | ||
while (charArray.length > 0) { | ||
var current = charArray.shift(); | ||
if (current === "$" && charArray[0] === "{") { | ||
var evalStr = "(function(env) { with(env) { return " | ||
charArray.shift(); | ||
while (charArray.length > 0 && charArray[0] !== "}") { | ||
evalStr += charArray.shift() | ||
} | ||
charArray.shift(); | ||
evalStr += " } })"; | ||
// console.log("Evaling", evalStr); | ||
returnStr += eval(evalStr)(params); | ||
} else { | ||
returnStr += current; | ||
} | ||
charArray.shift(); | ||
evalStr += " })()"; | ||
// console.log("Evaling", evalStr); | ||
returnStr += eval(evalStr); | ||
} else { | ||
returnStr += current; | ||
} | ||
} catch (e) { | ||
returnStr = e.message; | ||
} | ||
return returnStr; | ||
} | ||
|
@@ -38,16 +42,17 @@ function initMockRequests() { | |
if(elt.getAttribute("url")){ | ||
MockRequests.setDynamicMockUrlResponse(elt.getAttribute("url"), | ||
{dynamicResponseModFn: | ||
function(request, response) { | ||
return interpolate(elt.innerHTML); | ||
function(request, response, parameters) { | ||
console.log(request, response, parameters) | ||
return interpolate(elt.innerHTML, parameters); | ||
}, | ||
usePathnameForAllQueries: true}); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
addScript("https://unpkg.com/htmx.org@1.6.1/dist/htmx.js"); | ||
addScript("https://unpkg.com/hyperscript.org@0.9.4/dist/_hyperscript_w9y.min.js"); | ||
addScript("https://unpkg.com/htmx.org"); | ||
addScript("https://unpkg.com/hyperscript.org"); | ||
addScript("https://unpkg.com/[email protected]/index.js"); | ||
initMockRequests(); |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<html> | ||
<head> | ||
<script src="it.js"></script> | ||
</head> | ||
<body> | ||
<!-- post to /foo --> | ||
<button hx-get="/foo?bar=10" hx-target="#result">Count Up</button> <output id="result"></output> | ||
<!-- respond to /foo --> | ||
<script> | ||
globalInt = 0; | ||
</script> | ||
<template url="/foo"> | ||
${bar + 5} | ||
</template> | ||
|
||
</body> | ||
</html> |