Fix code highlighting instantiation for async (XHR) markup

This commit is contained in:
Molkobain
2021-03-17 10:07:06 +01:00
parent b97e2839c5
commit 599c838fd9
2 changed files with 35 additions and 22 deletions

View File

@@ -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();
});

View File

@@ -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(
<<<JS
// Highlight code content for AttributeHTML and HTML AttributeText
$('[data-attribute-type="AttributeHTML"], [data-attribute-type="AttributeText"]').find('.HTML pre').each(function(i, block) {
hljs.highlightBlock(block);
});
// Highlight code content for CaseLogs
$('[data-role="ibo-activity-entry--main-information-content"] pre').each(function(i, block) {
hljs.highlightBlock(block);
});
JS
);
// TODO 3.0.0: What is this for?
$this->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
);