From c1eb928893dc5801bfb3e9942c9ddc8cd3a5ceb8 Mon Sep 17 00:00:00 2001 From: Molkobain Date: Thu, 9 Dec 2021 18:05:27 +0100 Subject: [PATCH] =?UTF-8?q?CombodoBackofficeToolbox.InitCodeHighlighting:?= =?UTF-8?q?=20Better=20protection=20as=20it=20was=20adding=20a=20log=20on?= =?UTF-8?q?=20every=20page=20with=20no=20attribute=20=F0=9F=92=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/pages/backoffice/toolbox.js | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/js/pages/backoffice/toolbox.js b/js/pages/backoffice/toolbox.js index f0c2f6a56..72c22771a 100644 --- a/js/pages/backoffice/toolbox.js +++ b/js/pages/backoffice/toolbox.js @@ -134,12 +134,6 @@ const CombodoBackofficeToolbox = { * @constructor */ InitCodeHighlighting: function (oContainerElem = null, bForce = false) { - // Check if the lib is loaded - if (typeof hljs === 'undefined') { - CombodoJSConsole.Error('Cannot format code snippets as the highlight.js lib is not loaded'); - return; - } - if (oContainerElem === null) { oContainerElem = $('body'); } @@ -147,13 +141,28 @@ const CombodoBackofficeToolbox = { const sComplementarySelector = bForce ? '' : ':not(.hljs)'; // AttributeHTML and HTML AttributeText - oContainerElem.find('[data-attribute-type="AttributeHTML"], [data-attribute-type="AttributeText"], [data-attribute-type="AttributeTemplateHTML"]').find('.HTML pre'+sComplementarySelector+' > code').parent().each(function (iIdx, oElem) { - hljs.highlightBlock(oElem); - }); + let oCodeElements = oContainerElem.find('[data-attribute-type="AttributeHTML"], [data-attribute-type="AttributeText"], [data-attribute-type="AttributeTemplateHTML"]').find('.HTML pre'+sComplementarySelector+' > code'); + if (oCodeElements.length > 0) { + if (typeof hljs === 'undefined') { + CombodoJSConsole.Error('Cannot format code snippets in HTML fields as the highlight.js lib is not loaded'); + } else { + oCodeElements.parent().each(function (iIdx, oElem) { + hljs.highlightBlock(oElem); + }); + } + } + // CaseLogs - oContainerElem.find('[data-role="ibo-activity-entry--main-information-content"] pre'+sComplementarySelector+' > code').parent().each(function (iIdx, oElem) { - hljs.highlightBlock(oElem); - }); + oCodeElements = oContainerElem.find('[data-role="ibo-activity-entry--main-information-content"] pre'+sComplementarySelector+' > code'); + if (oCodeElements.length > 0) { + if (typeof hljs === 'undefined') { + CombodoJSConsole.Error('Cannot format code snippets in log entries as the highlight.js lib is not loaded'); + } else { + oCodeElements.parent().each(function (iIdx, oElem) { + hljs.highlightBlock(oElem); + }); + } + } } };