diff --git a/public/js/components/Cis/Cms/Content_types/General.js b/public/js/components/Cis/Cms/Content_types/General.js index 985e9c556..31c214368 100644 --- a/public/js/components/Cis/Cms/Content_types/General.js +++ b/public/js/components/Cis/Cms/Content_types/General.js @@ -6,19 +6,63 @@ export default { required:true, }, }, + methods: { + sanitizeLegacyTables(table) { + + // find nested tables and replace with p element + const tt = table.querySelectorAll('table') + tt.forEach(t => { + const textContent = t.textContent.trim(); + const pElement = document.createElement('p'); + pElement.textContent = textContent; + t.parentNode.replaceChild(pElement, t); + }) + + // find unordered lists, traverse li childs and replace with p element -> more readable than 1 p tag for ul + const ul = table.querySelectorAll('ul') + ul.forEach(u => { + Array.from(u.children).forEach(li => { + const p = document.createElement('p'); + p.textContent = li.textContent + u.parentNode.appendChild(p) + }) + u.parentNode.removeChild(u) + + }) + + // find bare text nodes and put into p element + const td = Array.from(table.querySelectorAll('td')).filter(el => el.scrollWidth > 200) + td.forEach(element => { + if (element.firstChild?.nodeType === Node.TEXT_NODE && element.firstChild.length > 10) { + const div = document.createElement('p'); + div.appendChild(element.firstChild) + element.appendChild(div); + } + }); + + // let p elements wrap on overflow + const p = table.querySelectorAll('p') + p.forEach(p => { + p.style.setProperty('word-wrap', 'break-word'); + p.style.setProperty('white-space', 'normal'); + }) + } + }, mounted(){ // replaces the tablesorter with the tabulator let tables = document.getElementsByClassName("tablesorter"); - + for (let table of tables) { + this.sanitizeLegacyTables(table) new Tabulator(table, { - layout: "fitDataStretch", + layout: "fitDataFill", columnDefaults: { formatter: "html", - resizable: false, + resizable: true, minWidth: "100px", + maxWidth: "400px" } }) } diff --git a/public/js/components/Cis/Menu.js b/public/js/components/Cis/Menu.js index 35fe847a3..8bb49a9bd 100644 --- a/public/js/components/Cis/Menu.js +++ b/public/js/components/Cis/Menu.js @@ -124,7 +124,7 @@ export default { -