Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IE11 compatibility fixes #1948

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/ext/response-targets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -38,7 +43,7 @@
'***',
'xxx',
];
if (respCode.startsWith('4') || respCode.startsWith('5')) {
if (startsWith(respCode, '4') || startsWith(respCode, '5')) {
attrPossibilities.push('error');
}

Expand Down
3 changes: 2 additions & 1 deletion test/attributes/hx-on.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
5 changes: 5 additions & 0 deletions test/core/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ <h2>Mocha Test Suite</h2>

<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>
Expand Down