From 933ca20e6588277356db4e8c63fb198489c35315 Mon Sep 17 00:00:00 2001 From: Johann Hoffmann Date: Thu, 21 Nov 2024 13:27:39 +0100 Subject: [PATCH] tabulator in cms content -> sanitize table header contructs breaking tabulator; --- public/js/apps/Cis/Cms.js | 5 ++- .../Cis/Cms/Content_types/General.js | 34 +++++++++++++------ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/public/js/apps/Cis/Cms.js b/public/js/apps/Cis/Cms.js index b0a5ccd3c..d654395fd 100644 --- a/public/js/apps/Cis/Cms.js +++ b/public/js/apps/Cis/Cms.js @@ -1,8 +1,8 @@ import BsConfirm from "../../components/Bootstrap/Confirm.js"; -//import Pagination from "../../components/Pagination/Pagination.js"; import CmsNews from "../../components/Cis/Cms/News.js"; import CmsContent from "../../components/Cis/Cms/Content.js"; import Phrasen from "../../plugin/Phrasen.js"; +import {setScrollbarWidth} from "../../helpers/CssVarCalcHelpers"; const app = Vue.createApp({ @@ -35,6 +35,9 @@ const app = Vue.createApp({ }); }, }); + +setScrollbarWidth(); + app.use(primevue.config.default, { zIndex: { overlay: 9999 } }); app.use(Phrasen, {reload: true}); app.mount("#cms"); diff --git a/public/js/components/Cis/Cms/Content_types/General.js b/public/js/components/Cis/Cms/Content_types/General.js index 8c1ab5cf3..0c938943a 100644 --- a/public/js/components/Cis/Cms/Content_types/General.js +++ b/public/js/components/Cis/Cms/Content_types/General.js @@ -29,17 +29,26 @@ export default { 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) + const td = Array.from(table.querySelectorAll('td')).filter(el => el.scrollWidth > 100) 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); + const p = document.createElement('p'); + p.appendChild(element.firstChild) + element.appendChild(p); } }); + // flatten nested th elements + const ths = Array.from(table.querySelectorAll('th')) + ths.forEach(th => { + + if(th.children.length > 1) { + th.innerHTML = Array.from(th.childNodes).find(cn => cn.textContent).textContent + } + }) + // let p elements wrap on overflow const p = table.querySelectorAll('p') p.forEach(p => { @@ -50,13 +59,14 @@ export default { } }, mounted(){ - // replaces the tablesorter with the tabulator - let tables = document.getElementsByClassName("tablesorter"); - - for (let table of tables) { + let tables = Array.from(document.getElementsByClassName("tablesorter")); + + tables.forEach((table, index) => { this.sanitizeLegacyTables(table) + new Tabulator(table, { + index: index, layout: "fitDataFill", columnDefaults: { @@ -65,7 +75,7 @@ export default { minWidth: "100px" } }) - } + }) document.querySelectorAll("#cms [data-confirm]").forEach((el) => { el.addEventListener("click", (evt) => { @@ -91,7 +101,9 @@ export default { }, template: /*html*/ ` -
+
+
+

Content was not found

`, };