mirror of
https://github.com/bigskysoftware/htmx.git
synced 2025-09-27 13:01:03 +00:00
IE11 compatibility fixes (#1948)
This commit is contained in:
parent
3912e3c2c2
commit
8ddd079b90
@ -5,6 +5,11 @@
|
||||
|
||||
var attrPrefix = 'hx-target-';
|
||||
|
||||
// IE11 doesn't support string.startsWith
|
||||
function startsWith(str, prefix) {
|
||||
return str.substring(0, prefix.length) === prefix
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLElement} elt
|
||||
* @param {number} respCode
|
||||
@ -38,7 +43,7 @@
|
||||
'***',
|
||||
'xxx',
|
||||
];
|
||||
if (respCode.startsWith('4') || respCode.startsWith('5')) {
|
||||
if (startsWith(respCode, '4') || startsWith(respCode, '5')) {
|
||||
attrPossibilities.push('error');
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,8 @@ describe("hx-on attribute", function() {
|
||||
|
||||
it("can handle event types with dots", function () {
|
||||
var btn = make("<button hx-on='my.custom.event: window.foo = true'>Foo</button>");
|
||||
btn.dispatchEvent(new CustomEvent('my.custom.event'));
|
||||
// IE11 doesn't support `new CustomEvent()` so call htmx' internal utility function
|
||||
btn.dispatchEvent(htmx._("makeEvent")('my.custom.event'));
|
||||
window.foo.should.equal(true);
|
||||
delete window.foo;
|
||||
});
|
||||
|
@ -29,6 +29,11 @@ describe('Core htmx extension tests', function() {
|
||||
onEvent: function(name, evt) {
|
||||
if (name === 'htmx:beforeRequest') {
|
||||
evt.preventDefault();
|
||||
if (IsIE11()) {
|
||||
// IE11 doesn't set defaultPrevented to true on custom events it seems, so use a
|
||||
// return false instead to cancel the event
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -168,7 +168,7 @@
|
||||
|
||||
<script class="mocha-exec">
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
mocha.setup({globals: ['$0', '$1', '$2', '$3', '$4', 'performance', 'requestAnimationFrame', 'cancelAnimationFrame']}); <!-- IE11 -->
|
||||
mocha.setup({globals: ['$0', '$1', '$2', '$3', '$4', 'performance', 'requestAnimationFrame', 'cancelAnimationFrame', 'confirm']}); <!-- IE11 -->
|
||||
mocha.run();
|
||||
})
|
||||
</script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user