From e64238dba3113c2eabe26b1e9e9ba7fe29ba3010 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 21 Mar 2024 23:06:44 +0100 Subject: [PATCH] Fix IE11 incompatibilities (#2408) --- src/htmx.js | 17 ++++++++++------- test/core/ajax.js | 10 ++++++++++ test/core/regressions.js | 10 ++++++++++ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/htmx.js b/src/htmx.js index 0e31707b5..5620b45b6 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -138,12 +138,12 @@ return (function () { /** * @param {string} tag - * @param {boolean} global + * @param {boolean} [global] * @returns {RegExp} */ - function makeTagRegEx(tag, global = false) { - return new RegExp(`<${tag}(\\s[^>]*>|>)([\\s\\S]*?)<\\/${tag}>`, - global ? 'gim' : 'im'); + function makeTagRegEx(tag, global) { + return new RegExp('<' + tag + '(\\s[^>]*>|>)([\\s\\S]*?)<\\/' + tag + '>', + !!global ? 'gim' : 'im') } function parseInterval(str) { @@ -1945,6 +1945,9 @@ return (function () { function shouldProcessHxOn(elt) { var attributes = elt.attributes + if (!attributes) { + return false + } for (var j = 0; j < attributes.length; j++) { var attrName = attributes[j].name if (startsWith(attrName, "hx-on:") || startsWith(attrName, "data-hx-on:") || @@ -1967,11 +1970,11 @@ return (function () { var iter = document.evaluate('.//*[@*[ starts-with(name(), "hx-on:") or starts-with(name(), "data-hx-on:") or' + ' starts-with(name(), "hx-on-") or starts-with(name(), "data-hx-on-") ]]', elt) while (node = iter.iterateNext()) elements.push(node) - } else { + } else if (typeof elt.getElementsByTagName === "function") { var allElements = elt.getElementsByTagName("*") for (var i = 0; i < allElements.length; i++) { - if (shouldProcessHxOn(allElements[i])) { - elements.push(allElements[i]) + if (shouldProcessHxOn(allElements[i])) { + elements.push(allElements[i]) } } } diff --git a/test/core/ajax.js b/test/core/ajax.js index 00e677df6..58603e851 100644 --- a/test/core/ajax.js +++ b/test/core/ajax.js @@ -1237,6 +1237,11 @@ describe("Core htmx AJAX Tests", function(){ }) it('properly handles inputs external to form', function () { + if (!supportsFormAttribute()) { + this._runnable.title += " - Skipped as IE11 doesn't support form attribute" + this.skip() + return + } var values; this.server.respondWith("Post", "/test", function (xhr) { values = getParameters(xhr); @@ -1287,6 +1292,11 @@ describe("Core htmx AJAX Tests", function(){ }) it("can associate submit buttons from outside a form with the current version of the form after swap", function(){ + if (!supportsFormAttribute()) { + this._runnable.title += " - Skipped as IE11 doesn't support form attribute" + this.skip() + return + } const template = '