diff --git a/js/bootstrap5-toggle.ecmas.js b/js/bootstrap5-toggle.ecmas.js index b84a093..729a54b 100644 --- a/js/bootstrap5-toggle.ecmas.js +++ b/js/bootstrap5-toggle.ecmas.js @@ -10,7 +10,6 @@ * @see https://github.com/palcarazm/bootstrap5-toggle/blob/master/LICENSE */ - "use strict"; function sanitize(text) { if (!text) return text; // handle null or undefined @@ -311,33 +310,35 @@ function sanitize(text) { // 9: Add listeners ecmasToggle.addEventListener( - "touchstart", + "pointerdown", (e) => { this.#toggleActionPerformed(e); }, { passive: true } ); - ecmasToggle.addEventListener("click", (e) => { - this.#toggleActionPerformed(e); - }); - ecmasToggle.addEventListener("keypress", (e) => { - if (e.key == " ") { - this.#toggleActionPerformed(e); - } - }); + ecmasToggle.addEventListener( + "keypress", + (e) => { + if (e.key == " ") { + this.#toggleActionPerformed(e); + } + }, + { passive: true } + ); if (this.element.id) { document .querySelectorAll('label[for="' + this.element.id + '"]') .forEach((label) => { - label.addEventListener("touchstart", (_e) => { - this.toggle(); - ecmasToggle.focus(); - }); - label.addEventListener("click", (_e) => { - this.toggle(); - ecmasToggle.focus(); - }); + label.addEventListener( + "pointerdown", + (e) => { + e.preventDefault(); + this.toggle(); + ecmasToggle.focus(); + }, + { passive: true } + ); }); } diff --git a/js/bootstrap5-toggle.jquery.js b/js/bootstrap5-toggle.jquery.js index beee7cd..13f3b78 100644 --- a/js/bootstrap5-toggle.jquery.js +++ b/js/bootstrap5-toggle.jquery.js @@ -10,7 +10,6 @@ * @see https://github.com/palcarazm/bootstrap5-toggle/blob/master/LICENSE */ - "use strict"; function sanitize(text) { if (!text) return text; // handle null or undefined @@ -272,10 +271,7 @@ function sanitize(text) { } // 9: Add listeners - this.$toggle.on("touchstart", (e) => { - toggleActionPerformed(e, this); - }); - this.$toggle.on("click", (e) => { + this.$toggle.on("pointerdown", (e) => { toggleActionPerformed(e, this); }); this.$toggle.on("keypress", (e) => { @@ -286,8 +282,9 @@ function sanitize(text) { if (this.$element.prop("id")) { $('label[for="' + this.$element.prop("id") + '"]').on( - "touchstart click", - (_e) => { + "click touchstart", + (e) => { + e.preventDefault(); this.toggle(); this.$toggle.focus(); }