From 81977daa2cedfe3d908454d0eef120457b593c18 Mon Sep 17 00:00:00 2001 From: Vladislav Date: Sun, 4 Jun 2023 19:02:17 +0300 Subject: [PATCH] Fix WordCount plugin removal issue causing a TypeError in app.js #140. --- django_ckeditor_5/static/django_ckeditor_5/app.js | 14 ++++++++------ example/blog/blog/settings.py | 1 + 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/django_ckeditor_5/static/django_ckeditor_5/app.js b/django_ckeditor_5/static/django_ckeditor_5/app.js index 74f447b..ca9ae34 100644 --- a/django_ckeditor_5/static/django_ckeditor_5/app.js +++ b/django_ckeditor_5/static/django_ckeditor_5/app.js @@ -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(); @@ -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)); @@ -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); } }); diff --git a/example/blog/blog/settings.py b/example/blog/blog/settings.py index 2f6642d..e5fbc6c 100644 --- a/example/blog/blog/settings.py +++ b/example/blog/blog/settings.py @@ -135,6 +135,7 @@ CKEDITOR_5_CONFIGS = { "default": { + "removePlugins": ["WordCount"], "toolbar": [ "heading", "|",