Skip to content

Commit 20c9eba

Browse files
authored
Fix removing content from trix editor (#114)
| Q | A | --------------- | ----- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | partially #104 | License | MIT
2 parents 54eaf0d + 9d0da4a commit 20c9eba

File tree

1 file changed

+11
-25
lines changed

1 file changed

+11
-25
lines changed

assets/admin/js/trix/trix-editor.js

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,6 @@ const bodyObserver = new MutationObserver((mutationsList) => {
3939

4040
bodyObserver.observe(document.body, { childList: true, subtree: true });
4141

42-
document.querySelectorAll('select').forEach(select => {
43-
select.addEventListener('change', (event) => {
44-
document.querySelectorAll('trix-editor').forEach((editor) => {
45-
const innerInput = document.getElementById(editor.attributes.input.value);
46-
47-
editor.innerHTML = innerInput.value;
48-
});
49-
50-
updateToolbars();
51-
});
52-
});
53-
54-
document.querySelectorAll('button[data-live-action-param]').forEach(button => {
55-
button.addEventListener('click', (event) => {
56-
document.querySelectorAll('trix-editor').forEach((editor) => {
57-
const innerInput = document.getElementById(editor.attributes.input.value);
58-
59-
editor.innerHTML = innerInput.value;
60-
});
61-
62-
updateToolbars();
63-
});
64-
});
65-
6642
document.addEventListener('trix-blur', (event) => {
6743
const innerInput = document.getElementById(event.target.attributes.input.value);
6844

@@ -72,10 +48,20 @@ document.addEventListener('trix-blur', (event) => {
7248
}
7349
});
7450

75-
document.addEventListener("trix-file-accept", (event) => {
51+
document.addEventListener('trix-file-accept', (event) => {
7652
event.preventDefault();
7753
});
7854

55+
document.addEventListener('DOMContentLoaded', () => {
56+
document.querySelectorAll('trix-editor').forEach((editor) => {
57+
const innerInput = document.getElementById(editor.attributes.input.value);
58+
59+
if (innerInput) {
60+
editor.innerHTML = innerInput.value;
61+
}
62+
});
63+
});
64+
7965
function updateToolbars() {
8066
const toolbars = document.querySelectorAll('trix-toolbar');
8167
const html = removeToolbarFileTools(Trix.config.toolbar.getDefaultHTML());

0 commit comments

Comments
 (0)