diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php
index 2b5d9e3d9..03e93be02 100644
--- a/application/cmdbabstract.class.inc.php
+++ b/application/cmdbabstract.class.inc.php
@@ -5,6 +5,7 @@
*/
use Combodo\iTop\Application\Helper\Session;
+use Combodo\iTop\Application\Helper\WebResourcesHelper;
use Combodo\iTop\Application\Search\SearchForm;
use Combodo\iTop\Application\UI\Base\Component\Alert\AlertUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Button\Button;
@@ -2242,6 +2243,7 @@ EOF
// - Final config
$sConfigJS = json_encode($aConfig);
+ WebResourcesHelper::EnableCKEditorToWebPage($oPage);
$oPage->add_ready_script("$('#$iId').ckeditor(function() { /* callback code */ }, $sConfigJS);"); // Transform $iId into a CKEdit
$oPage->add_ready_script(
diff --git a/application/ui.htmleditorwidget.class.inc.php b/application/ui.htmleditorwidget.class.inc.php
index db4a5baab..8904c5dff 100644
--- a/application/ui.htmleditorwidget.class.inc.php
+++ b/application/ui.htmleditorwidget.class.inc.php
@@ -15,6 +15,7 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with iTop. If not, see
+use Combodo\iTop\Application\Helper\WebResourcesHelper;
/**
* Class UIHTMLEditorWidget
@@ -83,6 +84,7 @@ class UIHTMLEditorWidget
}
$sConfigJS = json_encode($aConfig);
+ WebResourcesHelper::EnableCKEditorToWebPage($oPage);
$oPage->add_ready_script("$('#$iId').ckeditor(function() { /* callback code */ }, $sConfigJS);"); // Transform $iId into a CKEdit
// Please read...
diff --git a/js/ckeditor.on-init.js b/js/ckeditor.on-init.js
new file mode 100644
index 000000000..d48509993
--- /dev/null
+++ b/js/ckeditor.on-init.js
@@ -0,0 +1,23 @@
+/*
+ * @copyright Copyright (C) 2010-2021 Combodo SARL
+ * @license http://opensource.org/licenses/AGPL-3.0
+ */
+
+// WARNING: This code cannot be placed directly within the page as CKEditor could not be loaded yet.
+// As it can be loaded from an XHR call (several times), we need to ensure it will be called when necessary (see PHP WebResourcesHelper)
+
+// For disabling the CKEditor at init time when the corresponding textarea is disabled !
+if ((CKEDITOR !== undefined) && (CKEDITOR.plugins.registered['disabler'] === undefined)) {
+ CKEDITOR.plugins.add( 'disabler',
+ {
+ init : function( editor )
+ {
+ editor.on( 'instanceReady', function(e)
+ {
+ e.removeListener();
+ $('#'+ editor.name).trigger('update');
+ });
+ }
+
+ });
+}
diff --git a/js/pages/backoffice/toolbox.js b/js/pages/backoffice/toolbox.js
index ce1123d29..948c45ffc 100644
--- a/js/pages/backoffice/toolbox.js
+++ b/js/pages/backoffice/toolbox.js
@@ -116,20 +116,6 @@ const CombodoBackofficeToolbox = {
}
};
-// For disabling the CKEditor at init time when the corresponding textarea is disabled !
-CKEDITOR.plugins.add( 'disabler',
- {
- init : function( editor )
- {
- editor.on( 'instanceReady', function(e)
- {
- e.removeListener();
- $('#'+ editor.name).trigger('update');
- });
- }
-
- });
-
// Processing on each pages of the backoffice
$(document).ready(function(){
// Initialize global keyboard shortcuts
diff --git a/sources/Renderer/Console/FieldRenderer/ConsoleSimpleFieldRenderer.php b/sources/Renderer/Console/FieldRenderer/ConsoleSimpleFieldRenderer.php
index 97ac0619c..033532834 100644
--- a/sources/Renderer/Console/FieldRenderer/ConsoleSimpleFieldRenderer.php
+++ b/sources/Renderer/Console/FieldRenderer/ConsoleSimpleFieldRenderer.php
@@ -22,6 +22,7 @@ namespace Combodo\iTop\Renderer\Console\FieldRenderer;
use AttributeDate;
use AttributeDateTime;
use AttributeDuration;
+use Combodo\iTop\Application\Helper\WebResourcesHelper;
use Combodo\iTop\Application\UI\Base\Component\Field\FieldUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Html\Html;
use Combodo\iTop\Application\UI\Base\Component\Input\InputUIBlockFactory;
@@ -124,7 +125,11 @@ class ConsoleSimpleFieldRenderer extends FieldRenderer
$aConfig = utils::GetCkeditorPref();
$aConfig['extraPlugins'] = 'codesnippet';
$sJsConfig = json_encode($aConfig);
-
+
+ foreach (WebResourcesHelper::GetJSFilesRelPathsForCKEditor() as $sJSFile) {
+ $oOutput->AddJsFile($sJSFile);
+ }
+
$oOutput->AddJs(
<<oField->GetGlobalId()}').addClass('htmlEditor');
diff --git a/sources/application/Helper/WebResourcesHelper.php b/sources/application/Helper/WebResourcesHelper.php
index 3f644cb31..7f9db93da 100644
--- a/sources/application/Helper/WebResourcesHelper.php
+++ b/sources/application/Helper/WebResourcesHelper.php
@@ -20,6 +20,41 @@ use utils;
*/
class WebResourcesHelper
{
+ //---------------------------------
+ // CKEditor
+ //---------------------------------
+
+ /**
+ * Add necessary files (JS) to be able to use CKEditor in the page
+ *
+ * @param \WebPage $oPage
+ *
+ * @throws \Exception
+ */
+ public static function EnableCKEditorToWebPage(WebPage &$oPage): void
+ {
+ foreach (static::GetJSFilesRelPathsForCKEditor() as $sFile) {
+ $oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot().$sFile);
+ }
+ }
+
+ /**
+ * @return string[] Relative URLs to the JS files necessary for CKEditor
+ */
+ public static function GetJSFilesRelPathsForCKEditor(): array
+ {
+ return [
+ 'js/ckeditor/ckeditor.js',
+ 'js/ckeditor/adapters/jquery.js',
+ 'js/ckeditor/plugins/codesnippet/lib/highlight/highlight.pack.js',
+ 'js/ckeditor.on-init.js',
+ ];
+ }
+
+ //---------------------------------
+ // D3/C3.js
+ //---------------------------------
+
/**
* Add necessary files (JS/CSS) to be able to use d3/c3.js in the page
*
@@ -59,6 +94,10 @@ class WebResourcesHelper
];
}
+ //---------------------------------
+ // SimpleGraph
+ //---------------------------------
+
/**
* Add necessary files (JS/CSS) to be able to use simple_graph in the page
*
diff --git a/sources/application/UI/Base/Component/Input/RichText/RichText.php b/sources/application/UI/Base/Component/Input/RichText/RichText.php
index e8edcbdbc..841a87667 100644
--- a/sources/application/UI/Base/Component/Input/RichText/RichText.php
+++ b/sources/application/UI/Base/Component/Input/RichText/RichText.php
@@ -22,6 +22,7 @@ class RichText extends UIBlock
'js/ckeditor/ckeditor.js',
'js/ckeditor/adapters/jquery.js',
'js/ckeditor/plugins/codesnippet/lib/highlight/highlight.pack.js',
+ 'js/ckeditor.on-init.js',
];
public const DEFAULT_CSS_FILES_REL_PATH = [
'js/ckeditor/plugins/codesnippet/lib/highlight/styles/obsidian.css',
diff --git a/sources/application/WebPage/iTopWebPage.php b/sources/application/WebPage/iTopWebPage.php
index 9b88f600f..2c1e14935 100644
--- a/sources/application/WebPage/iTopWebPage.php
+++ b/sources/application/WebPage/iTopWebPage.php
@@ -156,11 +156,6 @@ class iTopWebPage extends NiceWebPage implements iTabbedPage
$this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery-ui-timepicker-addon.js');
$this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery-ui-timepicker-addon-i18n.min.js');
- // Note: CKEditor files can't be moved easily as we need to find a way to init the "disabler" plugin, {@see js/toolbox.js}
- $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/ckeditor/ckeditor.js');
- $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/ckeditor/adapters/jquery.js');
- $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/ckeditor/plugins/codesnippet/lib/highlight/highlight.pack.js');
-
// Tooltips
$this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'node_modules/@popperjs/core/dist/umd/popper.min.js');
$this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'node_modules/tippy.js/dist/tippy-bundle.umd.min.js');