Skip to content

Commit

Permalink
🐛 Fix: fix fixit-encryptor shortcode duplicate binding events
Browse files Browse the repository at this point in the history
  • Loading branch information
Lruihao committed Aug 26, 2024
1 parent 466bb7b commit 91f3c7c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions assets/js/fixit-decryptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down
4 changes: 2 additions & 2 deletions assets/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/init/index.html
Original file line number Diff line number Diff line change
@@ -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" . -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/posts/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ <h1 class="single-title animate__animated animate__flipInX">
{{- end -}}
<div class="content" id="content"
{{- with $params.endFlag }} data-end-flag="{{ . }}"{{ end }}
{{- with $params.password }} data-password="{{ hash.XxHash . }}"{{ end }}
{{- with $params.password }} data-password="{{ xxhash . }}"{{ end }}
{{- with $params.password }} data-content="{{ $content }}"{{ end -}}
>
{{- if not $params.password -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/shortcodes/fixit-encryptor.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
{{- dict "Class" "fa-solid fa-unlock" | partial "plugin/icon.html" }} {{ T "single.enterBtn" -}}
</button>
</div>
<div data-password="{{ md5 $password }}" data-content="{{ $content }}"></div>
<div data-password="{{ xxhash $password }}" data-content="{{ $content }}"></div>
</fixit-encryptor>
{{- .Page.Scratch.SetInMap "this" "encryptPartial" true -}}
{{- else -}}
Expand Down

0 comments on commit 91f3c7c

Please sign in to comment.