diff --git a/app/assets/javascripts/my_modules/protocols.js b/app/assets/javascripts/my_modules/protocols.js index 7d74d1e41..70dbc5593 100644 --- a/app/assets/javascripts/my_modules/protocols.js +++ b/app/assets/javascripts/my_modules/protocols.js @@ -29,7 +29,8 @@ function initEditMyModuleDescription() { }); setTimeout(function() { - TinyMCE.wrapTables(viewObject); + const notesContainerEl = document.getElementById('notes-container'); + window.wrapTables(notesContainerEl); }, 100); } @@ -327,16 +328,6 @@ function initAccessModal() { }); } -function initWrapTables() { - const viewMode = new URLSearchParams(window.location.search).get('view_mode'); - if (['archived', 'locked'].includes(viewMode)) { - setTimeout(() => { - const notesContainerEl = document.getElementById('notes-container'); - window.wrapTables(notesContainerEl); - }, 100); - } -} - /** * Initializes page */ @@ -348,7 +339,6 @@ function init() { initProtocolSectionOpenEvent(); initDetailsDropdown(); initAccessModal(); - initWrapTables(); } init(); diff --git a/app/assets/javascripts/shareable_links/handson_table_wraping.js b/app/assets/javascripts/shareable_links/handson_table_wraping.js index 084c6d1ae..68c91b104 100644 --- a/app/assets/javascripts/shareable_links/handson_table_wraping.js +++ b/app/assets/javascripts/shareable_links/handson_table_wraping.js @@ -1,17 +1,12 @@ /* global */ (function () { - const rtf = $('.rtf-view').toArray(); - for (let i = 0; i < rtf.length; i += 1) { - const container = $(rtf[i]).find('table').toArray(); - - for (let j = 0; j < container.length; j += 1) { - const table = $(container[j]); - if ($(table).parent().hasClass('table-wrapper')) return; - - $(table).wrap(` -
- `); - } - } + $('.rtf-view').toArray().forEach((rtf) => { + $(rtf).find('table').toArray().forEach((table) => { + if ($(table).parents('table').length === 0) { + $(table).css('float', 'none') + .wrapAll('
'); + } + }); + }); }()); diff --git a/app/assets/javascripts/sitewide/utils.js b/app/assets/javascripts/sitewide/utils.js index d4ae79462..bfd02c99f 100644 --- a/app/assets/javascripts/sitewide/utils.js +++ b/app/assets/javascripts/sitewide/utils.js @@ -142,23 +142,14 @@ $.fn.initSubmitModal = function(modalID, modelName) { * @returns {string} - HTML with tables wrapped. */ function wrapTables(htmlStringOrDomEl) { - if (typeof htmlStringOrDomEl === 'string') { - const container = $(`${htmlStringOrDomEl}`); - container.find('table').toArray().forEach((table) => { - if ($(table).parent().hasClass('table-wrapper')) return; - $(table).css('float', 'none').wrapAll(` -
- `); - }); - return container.prop('outerHTML'); - } - // Check if the value is a DOM element - if (htmlStringOrDomEl instanceof Element) { - const tableElement = $(htmlStringOrDomEl).find('table'); - if (tableElement.length > 0) { - tableElement.wrap('
'); - const updatedHtml = $(htmlStringOrDomEl).html(); - $(htmlStringOrDomEl).replaceWith(updatedHtml); + const htmlContent = `${htmlStringOrDomEl}`; + const container = typeof htmlStringOrDomEl === 'string' ? $(htmlContent) : $(htmlStringOrDomEl); + + container.find('table').toArray().forEach((table) => { + if ($(table).parents('table').length === 0) { + $(table).css('float', 'none') + .wrapAll('
'); } - } + }); + return container.prop('outerHTML'); } diff --git a/app/javascript/packs/tiny_mce.js b/app/javascript/packs/tiny_mce.js index 723d3ab0a..cc041eb4c 100644 --- a/app/javascript/packs/tiny_mce.js +++ b/app/javascript/packs/tiny_mce.js @@ -489,11 +489,10 @@ window.TinyMCE = (() => { }, wrapTables: (container) => { container.find('table').toArray().forEach((table) => { - if ($(table).parent().hasClass('table-wrapper')) return; - - $(table).css('float', 'none').wrapAll(` -
- `); + if ($(table).parents('table').length === 0) { + $(table).css('float', 'none') + .wrapAll('
'); + } }); } };