mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-18 16:18:47 +02:00
N°3685 - Use WebResourcesHelper for D3/C3.js usages
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
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...
|
||||
|
||||
23
js/ckeditor.on-init.js
Normal file
23
js/ckeditor.on-init.js
Normal file
@@ -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');
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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(
|
||||
<<<EOF
|
||||
$('#{$this->oField->GetGlobalId()}').addClass('htmlEditor');
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user