From 91f3c7c3cf5f4bfd147c56cc305a6b6c235f5484 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Mon, 26 Aug 2024 10:58:34 +0800 Subject: [PATCH] :bug: Fix: fix fixit-encryptor shortcode duplicate binding events --- assets/js/fixit-decryptor.js | 5 +++-- assets/js/theme.js | 4 ++-- layouts/partials/init/index.html | 2 +- layouts/posts/single.html | 2 +- layouts/shortcodes/fixit-encryptor.html | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/assets/js/fixit-decryptor.js b/assets/js/fixit-decryptor.js index 4294aa8f..ee6c1af2 100644 --- a/assets/js/fixit-decryptor.js +++ b/assets/js/fixit-decryptor.js @@ -139,10 +139,11 @@ FixItDecryptor = function (options = {}) { /** * initialize fixit-encryptor shortcodes + * @param {Element} [$container=document] container element */ - _proto.initShortcodes = () => { + _proto.initShortcodes = ($container = document) => { customElements.get('fixit-encryptor') || customElements.define('fixit-encryptor', class extends HTMLElement {}); - const $shortcodes = document.querySelectorAll('fixit-encryptor:not(:has(.decrypted))'); + const $shortcodes = $container.querySelectorAll('fixit-encryptor:not(:has(.decrypted))'); $shortcodes.forEach($shortcode => { const decryptorHandler = () => { diff --git a/assets/js/theme.js b/assets/js/theme.js index b462350b..b9b88d6c 100644 --- a/assets/js/theme.js +++ b/assets/js/theme.js @@ -1047,8 +1047,8 @@ class FixIt { this.decryptor.addEventListener('decrypted', () => { this.decryptor.initShortcodes(); }) - this.decryptor.addEventListener('partial-decrypted', () => { - this.decryptor.initShortcodes(); + this.decryptor.addEventListener('partial-decrypted', ($content) => { + this.decryptor.initShortcodes($content); }) this.decryptor.initShortcodes(); } diff --git a/layouts/partials/init/index.html b/layouts/partials/init/index.html index 9ad815de..f21a1e73 100644 --- a/layouts/partials/init/index.html +++ b/layouts/partials/init/index.html @@ -1,4 +1,4 @@ -{{- .Scratch.Set "version" "v0.3.10-53484f8c" -}} +{{- .Scratch.Set "version" "v0.3.10-466bb7b7" -}} {{- .Scratch.Set "this" dict -}} {{- partial "init/detection-env.html" . -}} diff --git a/layouts/posts/single.html b/layouts/posts/single.html index 753dd308..b5b012ac 100644 --- a/layouts/posts/single.html +++ b/layouts/posts/single.html @@ -172,7 +172,7 @@ {{- end -}}