From ba134476c4715620a8dc545aa804ab9360890f6b Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Sat, 30 Nov 2024 15:25:05 +0100 Subject: [PATCH] Use a different method of avoiding reinitialization of the editor --- django_prose_editor/static/django_prose_editor/init.js | 2 +- src/init.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/django_prose_editor/static/django_prose_editor/init.js b/django_prose_editor/static/django_prose_editor/init.js index a932297..97f67e1 100644 --- a/django_prose_editor/static/django_prose_editor/init.js +++ b/django_prose_editor/static/django_prose_editor/init.js @@ -1 +1 @@ -(()=>{window.__proseEditor=JSON.parse(document.currentScript.dataset.config);var i="data-django-prose-editor";function H(t){let o=JSON.parse(t.getAttribute(i));t.removeAttribute(i);let{Document:n,Dropcursor:l,Gapcursor:s,Paragraph:a,HardBreak:c,Text:d,Blockquote:u,Bold:p,BulletList:g,Heading:b,HorizontalRule:k,Italic:h,ListItem:E,OrderedList:f,Strike:S,Subscript:_,Superscript:m,Underline:T,Link:B,Menu:D,NoSpellCheck:I,Typographic:L,createTextareaEditor:O}=DjangoProseEditor,e=(r=>z=>r!=null&&r.length?r.includes(z):!0)(o.types),j=[n,l,s,a,c,d,D.configure({config:o}),I,o.typographic&&L,e("blockquote")&&u,e("strong")&&p,e("bullet_list")&&g,e("heading")&&b,e("horizontal_rule")&&k,e("em")&&h,e("link")&&B.configure({openOnClick:!1}),(e("bullet_list")||e("ordered_list"))&&E,e("ordered_list")&&f,e("strikethrough")&&S,e("sub")&&_,e("sup")&&m,e("underline")&&T].filter(Boolean);return O(t,j)}DjangoProseEditor.initializeEditors(H,`[${i}]`);})(); +(()=>{window.__proseEditor=JSON.parse(document.currentScript.dataset.config);var i="data-django-prose-editor";function H(t){if(t.closest(".prose-editor"))return;let o=JSON.parse(t.getAttribute(i)),{Document:n,Dropcursor:s,Gapcursor:l,Paragraph:c,HardBreak:a,Text:d,Blockquote:u,Bold:p,BulletList:g,Heading:k,HorizontalRule:b,Italic:h,ListItem:E,OrderedList:f,Strike:S,Subscript:_,Superscript:T,Underline:m,Link:B,Menu:D,NoSpellCheck:I,Typographic:L,createTextareaEditor:O}=DjangoProseEditor,e=(r=>z=>r!=null&&r.length?r.includes(z):!0)(o.types),j=[n,s,l,c,a,d,D.configure({config:o}),I,o.typographic&&L,e("blockquote")&&u,e("strong")&&p,e("bullet_list")&&g,e("heading")&&k,e("horizontal_rule")&&b,e("em")&&h,e("link")&&B.configure({openOnClick:!1}),(e("bullet_list")||e("ordered_list"))&&E,e("ordered_list")&&f,e("strikethrough")&&S,e("sub")&&_,e("sup")&&T,e("underline")&&m].filter(Boolean);return O(t,j)}DjangoProseEditor.initializeEditors(H,`[${i}]`);})(); diff --git a/src/init.js b/src/init.js index e221e1f..d950eca 100644 --- a/src/init.js +++ b/src/init.js @@ -3,8 +3,9 @@ window.__proseEditor = JSON.parse(document.currentScript.dataset.config) const marker = "data-django-prose-editor" function createEditor(textarea) { + if (textarea.closest(".prose-editor")) return + const config = JSON.parse(textarea.getAttribute(marker)) - textarea.removeAttribute(marker) const { Document,