Skip to content

Commit

Permalink
Fix WordCount plugin removal issue causing a TypeError in app.js #140.
Browse files Browse the repository at this point in the history
  • Loading branch information
hvlads committed Jun 4, 2023
1 parent 6b10195 commit 81977da
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
14 changes: 8 additions & 6 deletions django_ckeditor_5/static/django_ckeditor_5/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function createEditors() {
const allEditors = document.querySelectorAll('.django_ckeditor_5');
for (let i = 0; i < allEditors.length; ++i) {
const script_id = `${allEditors[i].id}_script`;
if (editorsIds.indexOf(script_id) !== -1){
if (editorsIds.indexOf(script_id) !== -1) {
continue;
}
allEditors[i].nextSibling.remove();
Expand Down Expand Up @@ -53,10 +53,12 @@ function createEditors() {
allEditors[i],
config
).then(editor => {
const wordCountPlugin = editor.plugins.get('WordCount');
const wordCountWrapper = document.getElementById(`word-count-${script_id}`);
wordCountWrapper.innerHTML = '';
wordCountWrapper.appendChild(wordCountPlugin.wordCountContainer);
if (editor.plugins.has('WordCount')) {
const wordCountPlugin = editor.plugins.get('WordCount');
const wordCountWrapper = document.getElementById(`word-count-${script_id}`);
wordCountWrapper.innerHTML = '';
wordCountWrapper.appendChild(wordCountPlugin.wordCountContainer);
}
editors.push(editor);
}).catch(error => {
console.error((error));
Expand All @@ -70,7 +72,7 @@ function createEditors() {
document.addEventListener("DOMContentLoaded", () => {
createEditors();
if (typeof django === "object" && django.jQuery) {
django.jQuery(document).on("formset:added", createEditors);
django.jQuery(document).on("formset:added", createEditors);
}
});

1 change: 1 addition & 0 deletions example/blog/blog/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@

CKEDITOR_5_CONFIGS = {
"default": {
"removePlugins": ["WordCount"],
"toolbar": [
"heading",
"|",
Expand Down

0 comments on commit 81977da

Please sign in to comment.