diff --git a/src/ext/response-targets.js b/src/ext/response-targets.js index 3914ba88a..dd6fd4182 100644 --- a/src/ext/response-targets.js +++ b/src/ext/response-targets.js @@ -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'); } diff --git a/test/attributes/hx-on.js b/test/attributes/hx-on.js index 51b4a13b0..209366b68 100644 --- a/test/attributes/hx-on.js +++ b/test/attributes/hx-on.js @@ -139,7 +139,8 @@ describe("hx-on attribute", function() { it("can handle event types with dots", function () { var btn = make(""); - 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; }); diff --git a/test/core/extensions.js b/test/core/extensions.js index 2bcfe208e..f2d3ed2a9 100644 --- a/test/core/extensions.js +++ b/test/core/extensions.js @@ -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 + } } } }); diff --git a/test/index.html b/test/index.html index b0841d254..eb6f15b18 100644 --- a/test/index.html +++ b/test/index.html @@ -168,7 +168,7 @@

Mocha Test Suite