From 0786b12d896def00531cb1d8e5d4bc8265d06b2f Mon Sep 17 00:00:00 2001 From: Jackie Tea Date: Wed, 27 Nov 2024 08:47:47 +0100 Subject: [PATCH 1/3] Fix touch not working --- js/bootstrap5-toggle.jquery.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/js/bootstrap5-toggle.jquery.js b/js/bootstrap5-toggle.jquery.js index beee7cd..736ad91 100644 --- a/js/bootstrap5-toggle.jquery.js +++ b/js/bootstrap5-toggle.jquery.js @@ -272,10 +272,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) => { From cce588b0b1d34021aadbffbfe506810a3d31aa9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Alcaraz=20Mart=C3=ADnez?= Date: Sun, 8 Dec 2024 17:15:34 +0100 Subject: [PATCH 2/3] fix: replace event handler click and touch to pointerdown --- js/bootstrap5-toggle.ecmas.js | 36 +++++++++++++++++----------------- js/bootstrap5-toggle.jquery.js | 3 +-- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/js/bootstrap5-toggle.ecmas.js b/js/bootstrap5-toggle.ecmas.js index b84a093..30fbc22 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,34 @@ 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) => { + this.toggle(); + ecmasToggle.focus(); + }, + { passive: true } + ); }); } diff --git a/js/bootstrap5-toggle.jquery.js b/js/bootstrap5-toggle.jquery.js index 736ad91..e6005e9 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 @@ -283,7 +282,7 @@ function sanitize(text) { if (this.$element.prop("id")) { $('label[for="' + this.$element.prop("id") + '"]').on( - "touchstart click", + "pointerdown", (_e) => { this.toggle(); this.$toggle.focus(); From dae116c85c3281aa4e6cb14a5936bbe1a6ec9ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Alcaraz=20Mart=C3=ADnez?= Date: Sun, 8 Dec 2024 17:29:11 +0100 Subject: [PATCH 3/3] fix: label click --- js/bootstrap5-toggle.ecmas.js | 3 ++- js/bootstrap5-toggle.jquery.js | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/js/bootstrap5-toggle.ecmas.js b/js/bootstrap5-toggle.ecmas.js index 30fbc22..729a54b 100644 --- a/js/bootstrap5-toggle.ecmas.js +++ b/js/bootstrap5-toggle.ecmas.js @@ -332,7 +332,8 @@ function sanitize(text) { .forEach((label) => { label.addEventListener( "pointerdown", - (_e) => { + (e) => { + e.preventDefault(); this.toggle(); ecmasToggle.focus(); }, diff --git a/js/bootstrap5-toggle.jquery.js b/js/bootstrap5-toggle.jquery.js index e6005e9..13f3b78 100644 --- a/js/bootstrap5-toggle.jquery.js +++ b/js/bootstrap5-toggle.jquery.js @@ -282,8 +282,9 @@ function sanitize(text) { if (this.$element.prop("id")) { $('label[for="' + this.$element.prop("id") + '"]').on( - "pointerdown", - (_e) => { + "click touchstart", + (e) => { + e.preventDefault(); this.toggle(); this.$toggle.focus(); }