Changes for page Helpers

Last modified by Benjamin Fischer on 2025/06/17 11:57

From version 1.1
edited by Benjamin Fischer
on 2025/05/15 13:30
Change comment: There is no comment for this version
To version 1.6
edited by Benjamin Fischer
on 2025/05/15 16:14
Change comment: There is no comment for this version

Summary

Details

XWiki.JavaScriptExtension[0]
Caching policy
... ... @@ -1,0 +1,1 @@
1 +default
Code
... ... @@ -1,0 +1,83 @@
1 +const livetableRowHook = {};
2 +
3 +((() => {
4 + const tagCols = {};
5 +
6 + document.observe('xwiki:livetable:loading', () => {
7 + for (const tab of document.querySelectorAll(".xwiki-livetable")) {
8 + const tableId = tab.id;
9 + if (!tableId) continue;
10 +
11 + // coulmn data sources
12 + const conf = JSON.parse(tab.dataset.settings);
13 +
14 + tagCols[tableId] = (conf.columnDescriptors.tags ?? { aux: [] }).aux ?? [["Tags", true]];
15 + tagCols[tableId].forEach(([name], i) => {
16 + const cn = `tags-${i}`;
17 + conf.columns.splice(conf.columns.indexOf("tags"), 1, cn);
18 + conf.columnDescriptors[cn] = {
19 + displayName: name,
20 + headerClass: "tagsCol",
21 + html: true,
22 + sortable: false,
23 + };
24 + });
25 + tab.dataset.settings = JSON.stringify(conf);
26 +
27 + // column headers
28 + tab.querySelectorAll(".xwiki-livetable-display-header .tagsCol").forEach(
29 + (v, i) => v.textContent = tagCols[tableId][i][0]
30 + );
31 +
32 + // column tooltips
33 + tab.querySelectorAll(".xwiki-livetable-display-header-text").forEach(
34 + el => {
35 + const t = el.textContent.trim();
36 + const c = conf.columnDescriptors[t]?.tooltip;
37 + if (c) {
38 + el.title = t;
39 + el.dataset.content = c;
40 + el.dataset.toggle = "popover";
41 + el.dataset.placement = "top";
42 + }
43 + }
44 + )
45 +
46 + // handle clicks for tags
47 + tab.getElementsByClassName("xwiki-livetable-display-body")[0].addEventListener("click", ev => {
48 + if (ev.button) return; // only left click
49 + if (ev.target.nodeName !== "SPAN") return;
50 + if (!ev.target.classList.contains("ltTag")) return;
51 + const tag = ev.target.textContent;
52 + ev.preventDefault();
53 + const lt = tab.__liveTable;
54 + const st = lt.tagCloud.selectedTags;
55 + if (tag in st) delete st[tag];
56 + else st[tag] = {};
57 + lt.tags = Object.keys(st);
58 + lt.clearCache();
59 + lt.showRows(1, lt.limit);
60 + });
61 +
62 + }
63 + });
64 +
65 + document.observe("xwiki:livetable:receivedEntries", ({ memo: { data }, tableId }) => {
66 + const rf = livetableRowHook[tableId];
67 + for (const row of data.rows) {
68 + if (rf) rf(row);
69 +
70 + // tags
71 + const tags = new Set(row.tags_value.slice(1, -1).split(", "));
72 + tagCols[tableId].forEach(([name, ...want], i) =>
73 + row[`tags-${i}`] = (
74 + want[0] === true
75 + ? Array.from(tags)
76 + : want.filter(tag => tags.delete(tag))
77 + ).sort().map(tag => `<span class="ltTag" style="cursor:pointer;">${tag}</span>`).join(", ")
78 + );
79 + }
80 + });
81 +
82 +})());
83 +
Name
... ... @@ -1,0 +1,1 @@
1 +Global Helpers
Parse content
... ... @@ -1,0 +1,1 @@
1 +No
Use this extension
... ... @@ -1,0 +1,1 @@
1 +always