diff --git a/js/pages/backoffice/toolbox.js b/js/pages/backoffice/toolbox.js index 0e7b1ee7c..7294849e9 100644 --- a/js/pages/backoffice/toolbox.js +++ b/js/pages/backoffice/toolbox.js @@ -82,13 +82,37 @@ const CombodoBackofficeToolbox = { * @param {object} oElem The jQuery object of the element * @constructor */ - ToggleFullscreenForElement: function(oElem) { - if(oElem.hasClass('ibo-is-fullscreen')) { + ToggleFullscreenForElement: function (oElem) { + if (oElem.hasClass('ibo-is-fullscreen')) { this.ExitFullscreenForElement(oElem); - } - else { + } else { this.EnterFullscreenForElement(oElem); } + }, + + /** + * Initialize the code highlighting on elements + * + * @param {Object} oContainerElem code highlighting will only be init. on elements within the container + * @param {boolean} bForce Whether the highlighting should be forced or not (if already done) + * @return {void} + * @constructor + */ + InitCodeHighlighting: function (oContainerElem = null, bForce = false) { + if (oContainerElem === null) { + oContainerElem = $('body'); + } + + const sComplementarySelector = bForce ? '' : ':not(.hljs)'; + + // AttributeHTML and HTML AttributeText + oContainerElem.find('[data-attribute-type="AttributeHTML"], [data-attribute-type="AttributeText"]').find('.HTML pre'+sComplementarySelector).each(function (iIdx, oElem) { + hljs.highlightBlock(oElem); + }); + // CaseLogs + oContainerElem.find('[data-role="ibo-activity-entry--main-information-content"] pre'+sComplementarySelector).each(function (iIdx, oElem) { + hljs.highlightBlock(oElem); + }); } }; @@ -106,7 +130,7 @@ CKEDITOR.plugins.add( 'disabler', }); -// Processing +// Processing on each pages of the backoffice $(document).ready(function(){ // Enable tooltips based on existing HTML markup, won't work on markup added dynamically after DOM ready (AJAX, ...) $('[data-tooltip-content]:not([data-tooltip-instantiated="true"])').each(function () { @@ -161,4 +185,7 @@ $(document).ready(function(){ $(document).on('init.dt draw.dt', function (oEvent) { CombodoTooltip.InitAllNonInstantiatedTooltips($(oEvent.target), true); }); + + // Code highlighting + CombodoBackofficeToolbox.InitCodeHighlighting(); }); \ No newline at end of file diff --git a/sources/application/WebPage/iTopWebPage.php b/sources/application/WebPage/iTopWebPage.php index 2941148fa..59073cec6 100644 --- a/sources/application/WebPage/iTopWebPage.php +++ b/sources/application/WebPage/iTopWebPage.php @@ -303,21 +303,6 @@ JS JS ); - // TODO 3.0.0: Change CSS class and extract this in backoffice/toolbox.js - // Highlight code content created with CKEditor - $this->add_ready_script( - <<add_ready_script( <<< JS @@ -409,10 +394,11 @@ JS } }); $(document).ajaxSuccess(function(){ - // Init tooltips from async. markup, small timeout to allow markup to be built if necessary + // Async. markup, small timeout to allow markup to be built if necessary setTimeout(function(){ CombodoTooltip.InitAllNonInstantiatedTooltips(); - }, 1000); + CombodoBackofficeToolbox.InitCodeHighlighting(); + }, 500); }); JS );