mirror of
https://github.com/bigskysoftware/htmx.git
synced 2025-09-27 13:01:03 +00:00
include extensions in dist
This commit is contained in:
parent
e0a8b2e9a9
commit
2110d49ee1
11
dist/ext/debug.js
vendored
Normal file
11
dist/ext/debug.js
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
htmx.defineExtension('debug', {
|
||||
onEvent: function (name, evt) {
|
||||
if (console.debug) {
|
||||
console.debug(name, evt);
|
||||
} else if (console) {
|
||||
console.log("DEBUG:", name, evt);
|
||||
} else {
|
||||
throw "NO CONSOLE SUPPORTED"
|
||||
}
|
||||
}
|
||||
});
|
7
dist/ext/json-enc.js
vendored
Normal file
7
dist/ext/json-enc.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
htmx.defineExtension('json-enc', {
|
||||
encodeParameters : function(xhr, parameters, elt) {
|
||||
xhr.requestHeaders['Content-Type'] = 'application/json';
|
||||
xhr.overrideMimeType('text/json');
|
||||
return (JSON.stringify(parameters));
|
||||
}
|
||||
});
|
8
dist/ext/morphdom-swap.js
vendored
Normal file
8
dist/ext/morphdom-swap.js
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
htmx.defineExtension('morphdom-swap', {
|
||||
handleSwap: function (swapStyle, target, fragment) {
|
||||
if (swapStyle === 'morphdom') {
|
||||
morphdom(target, fragment.outerHTML);
|
||||
return []; // no settle phase when using morphdom!
|
||||
}
|
||||
}
|
||||
});
|
10
dist/ext/rails-method.js
vendored
Normal file
10
dist/ext/rails-method.js
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
htmx.defineExtension('rails-method', {
|
||||
onEvent: function (name, evt) {
|
||||
if (name === "configRequest.htmx") {
|
||||
var methodOverride = evt.detail.headers['X-HTTP-Method-Override'];
|
||||
if (methodOverride) {
|
||||
evt.detail.parameters['_method'] = methodOverride;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
BIN
dist/htmx.min.js.gz
vendored
BIN
dist/htmx.min.js.gz
vendored
Binary file not shown.
@ -15,13 +15,14 @@
|
||||
"LICENSE",
|
||||
"README.md",
|
||||
"dist/*.js",
|
||||
"dist/ext/*.js",
|
||||
"dist/*.js.gz"
|
||||
],
|
||||
"main": "dist/htmx.min.js",
|
||||
"unpkg": "dist/htmx.min.js",
|
||||
"scripts": {
|
||||
"test": "mocha-chrome test/index.html",
|
||||
"dist": "cp src/htmx.js dist/ && npm run-script uglify && gzip -k -f dist/htmx.min.js > dist/htmx.min.js.gz && exit",
|
||||
"dist": "cp -r src/* dist/ && npm run-script uglify && gzip -k -f dist/htmx.min.js > dist/htmx.min.js.gz && exit",
|
||||
"www": "node scripts/www.js",
|
||||
"uglify": "uglifyjs -m eval -o dist/htmx.min.js dist/htmx.js"
|
||||
},
|
||||
|
11
src/ext/debug.js
Normal file
11
src/ext/debug.js
Normal file
@ -0,0 +1,11 @@
|
||||
htmx.defineExtension('debug', {
|
||||
onEvent: function (name, evt) {
|
||||
if (console.debug) {
|
||||
console.debug(name, evt);
|
||||
} else if (console) {
|
||||
console.log("DEBUG:", name, evt);
|
||||
} else {
|
||||
throw "NO CONSOLE SUPPORTED"
|
||||
}
|
||||
}
|
||||
});
|
7
src/ext/json-enc.js
Normal file
7
src/ext/json-enc.js
Normal file
@ -0,0 +1,7 @@
|
||||
htmx.defineExtension('json-enc', {
|
||||
encodeParameters : function(xhr, parameters, elt) {
|
||||
xhr.requestHeaders['Content-Type'] = 'application/json';
|
||||
xhr.overrideMimeType('text/json');
|
||||
return (JSON.stringify(parameters));
|
||||
}
|
||||
});
|
8
src/ext/morphdom-swap.js
Normal file
8
src/ext/morphdom-swap.js
Normal file
@ -0,0 +1,8 @@
|
||||
htmx.defineExtension('morphdom-swap', {
|
||||
handleSwap: function (swapStyle, target, fragment) {
|
||||
if (swapStyle === 'morphdom') {
|
||||
morphdom(target, fragment.outerHTML);
|
||||
return []; // no settle phase when using morphdom!
|
||||
}
|
||||
}
|
||||
});
|
10
src/ext/rails-method.js
Normal file
10
src/ext/rails-method.js
Normal file
@ -0,0 +1,10 @@
|
||||
htmx.defineExtension('rails-method', {
|
||||
onEvent: function (name, evt) {
|
||||
if (name === "configRequest.htmx") {
|
||||
var methodOverride = evt.detail.headers['X-HTTP-Method-Override'];
|
||||
if (methodOverride) {
|
||||
evt.detail.parameters['_method'] = methodOverride;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
@ -2,22 +2,10 @@ describe("debug extension", function() {
|
||||
beforeEach(function () {
|
||||
this.server = makeServer();
|
||||
clearWorkArea();
|
||||
htmx.defineExtension('debug', {
|
||||
onEvent : function(name, evt) {
|
||||
if(console.debug){
|
||||
console.debug(name, evt);
|
||||
} else if(console) {
|
||||
console.log("DEBUG:", name, evt);
|
||||
} else {
|
||||
throw "NO CONSOLE SUPPORTED"
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
this.server.restore();
|
||||
clearWorkArea();
|
||||
htmx.removeExtension('debug');
|
||||
});
|
||||
|
||||
it('works on basic request', function () {
|
@ -3,13 +3,6 @@ describe("json-enc extension", function() {
|
||||
beforeEach(function () {
|
||||
this.server = makeServer();
|
||||
clearWorkArea();
|
||||
htmx.defineExtension('json-enc', {
|
||||
encodeParameters : function(xhr, parameters, elt) {
|
||||
xhr.requestHeaders['Content-Type'] = 'application/json';
|
||||
xhr.overrideMimeType('text/json');
|
||||
return (JSON.stringify(parameters));
|
||||
}
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
this.server.restore();
|
@ -2,19 +2,10 @@ describe("morphdom-swap extension", function() {
|
||||
beforeEach(function () {
|
||||
this.server = makeServer();
|
||||
clearWorkArea();
|
||||
htmx.defineExtension('morphdom-swap', {
|
||||
handleSwap : function(swapStyle, target, fragment) {
|
||||
if (swapStyle === 'morphdom') {
|
||||
morphdom(target, fragment.outerHTML);
|
||||
return []; // no settle phase when using morphdom!
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
this.server.restore();
|
||||
clearWorkArea();
|
||||
htmx.removeExtension('morphdom-swap');
|
||||
});
|
||||
|
||||
it('works on basic request', function () {
|
@ -2,21 +2,10 @@ describe("rails-method extension", function() {
|
||||
beforeEach(function () {
|
||||
this.server = makeServer();
|
||||
clearWorkArea();
|
||||
htmx.defineExtension('rails-method', {
|
||||
onEvent : function(name, evt) {
|
||||
if(name === "configRequest.htmx"){
|
||||
var methodOverride = evt.detail.headers['X-HTTP-Method-Override'];
|
||||
if(methodOverride){
|
||||
evt.detail.parameters['_method'] = methodOverride;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
this.server.restore();
|
||||
clearWorkArea();
|
||||
htmx.removeExtension('rails-method');
|
||||
});
|
||||
|
||||
it('Does not affect a GET request', function () {
|
@ -84,10 +84,17 @@
|
||||
<script src="attributes/hx-trigger.js"></script>
|
||||
|
||||
<!-- extension tests -->
|
||||
<script src="extensions/rails-method.js"></script>
|
||||
<script src="extensions/debug.js"></script>
|
||||
<script src="extensions/morphdom-swap.js"></script>
|
||||
<script src="extensions/json-enc.js"></script>
|
||||
<script src="../src/ext/rails-method.js"></script>
|
||||
<script src="ext/rails-method.js"></script>
|
||||
|
||||
<script src="../src/ext/debug.js"></script>
|
||||
<script src="ext/debug.js"></script>
|
||||
|
||||
<script src="../src/ext/morphdom-swap.js"></script>
|
||||
<script src="ext/morphdom-swap.js"></script>
|
||||
|
||||
<script src="../src/ext/json-enc.js"></script>
|
||||
<script src="ext/json-enc.js"></script>
|
||||
|
||||
<!-- events last so they don't screw up other tests -->
|
||||
<script src="core/events.js"></script>
|
||||
|
11
www/test/0.0.4/src/ext/debug.js
Normal file
11
www/test/0.0.4/src/ext/debug.js
Normal file
@ -0,0 +1,11 @@
|
||||
htmx.defineExtension('debug', {
|
||||
onEvent: function (name, evt) {
|
||||
if (console.debug) {
|
||||
console.debug(name, evt);
|
||||
} else if (console) {
|
||||
console.log("DEBUG:", name, evt);
|
||||
} else {
|
||||
throw "NO CONSOLE SUPPORTED"
|
||||
}
|
||||
}
|
||||
});
|
7
www/test/0.0.4/src/ext/json-enc.js
Normal file
7
www/test/0.0.4/src/ext/json-enc.js
Normal file
@ -0,0 +1,7 @@
|
||||
htmx.defineExtension('json-enc', {
|
||||
encodeParameters : function(xhr, parameters, elt) {
|
||||
xhr.requestHeaders['Content-Type'] = 'application/json';
|
||||
xhr.overrideMimeType('text/json');
|
||||
return (JSON.stringify(parameters));
|
||||
}
|
||||
});
|
8
www/test/0.0.4/src/ext/morphdom-swap.js
Normal file
8
www/test/0.0.4/src/ext/morphdom-swap.js
Normal file
@ -0,0 +1,8 @@
|
||||
htmx.defineExtension('morphdom-swap', {
|
||||
handleSwap: function (swapStyle, target, fragment) {
|
||||
if (swapStyle === 'morphdom') {
|
||||
morphdom(target, fragment.outerHTML);
|
||||
return []; // no settle phase when using morphdom!
|
||||
}
|
||||
}
|
||||
});
|
10
www/test/0.0.4/src/ext/rails-method.js
Normal file
10
www/test/0.0.4/src/ext/rails-method.js
Normal file
@ -0,0 +1,10 @@
|
||||
htmx.defineExtension('rails-method', {
|
||||
onEvent: function (name, evt) {
|
||||
if (name === "configRequest.htmx") {
|
||||
var methodOverride = evt.detail.headers['X-HTTP-Method-Override'];
|
||||
if (methodOverride) {
|
||||
evt.detail.parameters['_method'] = methodOverride;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
19
www/test/0.0.4/test/ext/debug.js
Normal file
19
www/test/0.0.4/test/ext/debug.js
Normal file
@ -0,0 +1,19 @@
|
||||
describe("debug extension", function() {
|
||||
beforeEach(function () {
|
||||
this.server = makeServer();
|
||||
clearWorkArea();
|
||||
});
|
||||
afterEach(function () {
|
||||
this.server.restore();
|
||||
clearWorkArea();
|
||||
});
|
||||
|
||||
it('works on basic request', function () {
|
||||
this.server.respondWith("GET", "/test", "Clicked!");
|
||||
var btn = make('<button hx-get="/test" hx-ext="debug">Click Me!</button>')
|
||||
btn.click();
|
||||
this.server.respond();
|
||||
btn.innerHTML.should.equal("Clicked!");
|
||||
});
|
||||
|
||||
});
|
136
www/test/0.0.4/test/ext/json-enc.js
Normal file
136
www/test/0.0.4/test/ext/json-enc.js
Normal file
@ -0,0 +1,136 @@
|
||||
//
|
||||
describe("json-enc extension", function() {
|
||||
beforeEach(function () {
|
||||
this.server = makeServer();
|
||||
clearWorkArea();
|
||||
});
|
||||
afterEach(function () {
|
||||
this.server.restore();
|
||||
clearWorkArea();
|
||||
});
|
||||
|
||||
it('handles basic post properly', function () {
|
||||
var jsonResponseBody = JSON.stringify({});
|
||||
this.server.respondWith("POST", "/test", jsonResponseBody);
|
||||
var div = make("<div hx-post='/test' hx-ext='json-enc'>click me</div>");
|
||||
div.click();
|
||||
this.server.respond();
|
||||
this.server.lastRequest.response.should.equal("{}");
|
||||
})
|
||||
|
||||
it('handles basic put properly', function () {
|
||||
var jsonResponseBody = JSON.stringify({});
|
||||
this.server.respondWith("PUT", "/test", jsonResponseBody);
|
||||
var div = make('<div hx-put="/test" hx-ext="json-enc">click me</div>');
|
||||
div.click();
|
||||
this.server.respond();
|
||||
this.server.lastRequest.response.should.equal("{}");
|
||||
})
|
||||
|
||||
it('handles basic patch properly', function () {
|
||||
var jsonResponseBody = JSON.stringify({});
|
||||
this.server.respondWith("PATCH", "/test", jsonResponseBody);
|
||||
var div = make('<div hx-patch="/test" hx-ext="json-enc">click me</div>');
|
||||
div.click();
|
||||
this.server.respond();
|
||||
this.server.lastRequest.response.should.equal("{}");
|
||||
})
|
||||
|
||||
it('handles basic delete properly', function () {
|
||||
var jsonResponseBody = JSON.stringify({});
|
||||
this.server.respondWith("DELETE", "/test", jsonResponseBody);
|
||||
var div = make('<div hx-delete="/test" hx-ext="json-enc">click me</div>');
|
||||
div.click();
|
||||
this.server.respond();
|
||||
this.server.lastRequest.response.should.equal("{}");
|
||||
})
|
||||
|
||||
it('handles post with form parameters', function () {
|
||||
|
||||
this.server.respondWith("POST", "/test", function (xhr) {
|
||||
var values = JSON.parse(xhr.requestBody);
|
||||
values.should.have.keys("username","password");
|
||||
values["username"].should.be.equal("joe");
|
||||
values["password"].should.be.equal("123456");
|
||||
var ans = { "passwordok": values["password"] == "123456"};
|
||||
xhr.respond(200, {}, JSON.stringify(ans));
|
||||
});
|
||||
|
||||
var html = make('<form hx-post="/test" hx-ext="json-enc" > ' +
|
||||
'<input type="text" name="username" value="joe"> ' +
|
||||
'<input type="password" name="password" value="123456"> ' +
|
||||
'<button id="btnSubmit">Submit</button> ');
|
||||
|
||||
byId("btnSubmit").click();
|
||||
this.server.respond();
|
||||
this.server.lastRequest.response.should.equal('{"passwordok":true}');
|
||||
})
|
||||
|
||||
it('handles put with form parameters', function () {
|
||||
|
||||
this.server.respondWith("PUT", "/test", function (xhr) {
|
||||
var values = JSON.parse(xhr.requestBody);
|
||||
values.should.have.keys("username","password");
|
||||
values["username"].should.be.equal("joe");
|
||||
values["password"].should.be.equal("123456");
|
||||
var ans = { "passwordok": values["password"] == "123456"};
|
||||
xhr.respond(200, {}, JSON.stringify(ans));
|
||||
});
|
||||
|
||||
var html = make('<form hx-put="/test" hx-ext="json-enc" > ' +
|
||||
'<input type="text" name="username" value="joe"> ' +
|
||||
'<input type="password" name="password" value="123456"> ' +
|
||||
'<button id="btnSubmit">Submit</button> ');
|
||||
|
||||
byId("btnSubmit").click();
|
||||
this.server.respond();
|
||||
this.server.lastRequest.response.should.equal('{"passwordok":true}');
|
||||
})
|
||||
|
||||
|
||||
it('handles patch with form parameters', function () {
|
||||
|
||||
this.server.respondWith("PATCH", "/test", function (xhr) {
|
||||
var values = JSON.parse(xhr.requestBody);
|
||||
values.should.have.keys("username","password");
|
||||
values["username"].should.be.equal("joe");
|
||||
values["password"].should.be.equal("123456");
|
||||
var ans = { "passwordok": values["password"] == "123456"};
|
||||
xhr.respond(200, {}, JSON.stringify(ans));
|
||||
});
|
||||
|
||||
var html = make('<form hx-patch="/test" hx-ext="json-enc" > ' +
|
||||
'<input type="text" name="username" value="joe"> ' +
|
||||
'<input type="password" name="password" value="123456"> ' +
|
||||
'<button id="btnSubmit">Submit</button> ');
|
||||
|
||||
byId("btnSubmit").click();
|
||||
this.server.respond();
|
||||
this.server.lastRequest.response.should.equal('{"passwordok":true}');
|
||||
})
|
||||
|
||||
it('handles delete with form parameters', function () {
|
||||
|
||||
this.server.respondWith("DELETE", "/test", function (xhr) {
|
||||
var values = JSON.parse(xhr.requestBody);
|
||||
values.should.have.keys("username","password");
|
||||
values["username"].should.be.equal("joe");
|
||||
values["password"].should.be.equal("123456");
|
||||
var ans = { "passwordok": values["password"] == "123456"};
|
||||
xhr.respond(200, {}, JSON.stringify(ans));
|
||||
});
|
||||
|
||||
var html = make('<form hx-delete="/test" hx-ext="json-enc" > ' +
|
||||
'<input type="text" name="username" value="joe"> ' +
|
||||
'<input type="password" name="password" value="123456"> ' +
|
||||
'<button id="btnSubmit">Submit</button> ');
|
||||
|
||||
byId("btnSubmit").click();
|
||||
this.server.respond();
|
||||
this.server.lastRequest.response.should.equal('{"passwordok":true}');
|
||||
})
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
21
www/test/0.0.4/test/ext/morphdom-swap.js
Normal file
21
www/test/0.0.4/test/ext/morphdom-swap.js
Normal file
@ -0,0 +1,21 @@
|
||||
describe("morphdom-swap extension", function() {
|
||||
beforeEach(function () {
|
||||
this.server = makeServer();
|
||||
clearWorkArea();
|
||||
});
|
||||
afterEach(function () {
|
||||
this.server.restore();
|
||||
clearWorkArea();
|
||||
});
|
||||
|
||||
it('works on basic request', function () {
|
||||
this.server.respondWith("GET", "/test", "<button>Clicked!</button>!");
|
||||
var btn = make('<button hx-get="/test" hx-ext="morphdom-swap" hx-swap="morphdom" >Click Me!</button>')
|
||||
btn.click();
|
||||
should.equal(btn.getAttribute("hx-get"), "/test");
|
||||
this.server.respond();
|
||||
should.equal(btn.getAttribute("hx-get"), null);
|
||||
btn.innerHTML.should.equal("Clicked!");
|
||||
});
|
||||
|
||||
});
|
61
www/test/0.0.4/test/ext/rails-method.js
Normal file
61
www/test/0.0.4/test/ext/rails-method.js
Normal file
@ -0,0 +1,61 @@
|
||||
describe("rails-method extension", function() {
|
||||
beforeEach(function () {
|
||||
this.server = makeServer();
|
||||
clearWorkArea();
|
||||
});
|
||||
afterEach(function () {
|
||||
this.server.restore();
|
||||
clearWorkArea();
|
||||
});
|
||||
|
||||
it('Does not affect a GET request', function () {
|
||||
this.server.respondWith("GET", "/test", function (xhr) {
|
||||
xhr.respond(200, {}, xhr.url)
|
||||
});
|
||||
var btn = make('<button hx-get="/test" hx-ext="rails-method">Click Me!</button>')
|
||||
btn.click();
|
||||
this.server.respond();
|
||||
btn.innerHTML.should.equal("/test");
|
||||
});
|
||||
|
||||
it('Does not affect a POST request', function () {
|
||||
this.server.respondWith("POST", "/test", function (xhr) {
|
||||
xhr.respond(200, {}, getParameters(xhr)['_method']);
|
||||
});
|
||||
var btn = make('<button hx-post="/test" hx-ext="rails-method">Click Me!</button>')
|
||||
btn.click();
|
||||
this.server.respond();
|
||||
btn.innerHTML.should.equal("");
|
||||
});
|
||||
|
||||
it('Adds proper _method param to PUT request', function () {
|
||||
this.server.respondWith("PUT", "/test", function (xhr) {
|
||||
xhr.respond(200, {}, getParameters(xhr)['_method']);
|
||||
});
|
||||
var btn = make('<button hx-put="/test" hx-ext="rails-method">Click Me!</button>')
|
||||
btn.click();
|
||||
this.server.respond();
|
||||
btn.innerHTML.should.equal("PUT");
|
||||
});
|
||||
|
||||
it('Adds proper _method param to PATCH request', function () {
|
||||
this.server.respondWith("PATCH", "/test", function (xhr) {
|
||||
xhr.respond(200, {}, getParameters(xhr)['_method']);
|
||||
});
|
||||
var btn = make('<button hx-patch="/test" hx-ext="rails-method">Click Me!</button>')
|
||||
btn.click();
|
||||
this.server.respond();
|
||||
btn.innerHTML.should.equal("PATCH");
|
||||
});
|
||||
|
||||
it('Adds proper _method param to DELETE request', function () {
|
||||
this.server.respondWith("DELETE", "/test", function (xhr) {
|
||||
xhr.respond(200, {}, getParameters(xhr)['_method']);
|
||||
});
|
||||
var btn = make('<button hx-delete="/test" hx-ext="rails-method">Click Me!</button>')
|
||||
btn.click();
|
||||
this.server.respond();
|
||||
btn.innerHTML.should.equal("DELETE");
|
||||
});
|
||||
|
||||
});
|
@ -84,10 +84,17 @@
|
||||
<script src="attributes/hx-trigger.js"></script>
|
||||
|
||||
<!-- extension tests -->
|
||||
<script src="extensions/rails-method.js"></script>
|
||||
<script src="extensions/debug.js"></script>
|
||||
<script src="extensions/morphdom-swap.js"></script>
|
||||
<script src="extensions/json-enc.js"></script>
|
||||
<script src="../src/ext/rails-method.js"></script>
|
||||
<script src="ext/rails-method.js"></script>
|
||||
|
||||
<script src="../src/ext/debug.js"></script>
|
||||
<script src="ext/debug.js"></script>
|
||||
|
||||
<script src="../src/ext/morphdom-swap.js"></script>
|
||||
<script src="ext/morphdom-swap.js"></script>
|
||||
|
||||
<script src="../src/ext/json-enc.js"></script>
|
||||
<script src="ext/json-enc.js"></script>
|
||||
|
||||
<!-- events last so they don't screw up other tests -->
|
||||
<script src="core/events.js"></script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user