Skip to content

Commit 14ee9e2

Browse files
committed
Observe changes to the table of types and restyle everytime
1 parent 30b3978 commit 14ee9e2

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

main.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,24 @@
151151
}
152152
}
153153

154-
// Style old table
154+
const styleTable = (mutationList, observer) => {
155+
if ($("#val_table tr td").first().attr("colspan") == "4") return // Already styled
156+
$("#val_table tr td").first().attr("colspan", "4")
157+
$("#val_table tr:not(:first)").append(`
158+
<td class="data2" style="text-align:center;font-size:13px">
159+
<a class="validationRemove hidden">
160+
<i class="fa-solid fa-trash-can"></i>
161+
</a>
162+
</td>
163+
`)
164+
module.settings.emTypes.forEach((el) => $(`#${el} a`).removeClass('hidden'))
165+
};
166+
167+
// Style old table, watches for changes when enable/disable is clicked (Add delete buttons)
155168
$("head").append(`<style>${css}</style>`)
156-
$("#val_table tr td").first().attr("colspan", "4")
157-
$("#val_table tr:not(:first)").append(`
158-
<td class="data2" style="text-align:center;font-size:13px">
159-
<a class="validationRemove hidden">
160-
<i class="fa-solid fa-trash-can"></i>
161-
</a>
162-
</td>
163-
`)
164-
module.settings.emTypes.forEach((el) => $(`#${el} a`).removeClass('hidden'))
169+
const observer = new MutationObserver(styleTable)
170+
observer.observe($("#val_table").get(0), { childList: true, subtree: true })
171+
styleTable()
165172

166173
// Insert the new form and setup
167174
$("#val_table").before(html).show()
@@ -194,7 +201,7 @@
194201
})
195202
})
196203

197-
// Setup old table Interactivity (delete)
204+
// Setup old table Interactivity (Delete functionality)
198205
$("#val_table").on("click", ".validationRemove", (el) => {
199206
const $el = $(el.currentTarget)
200207
const $row = $el.closest('tr')

0 commit comments

Comments
 (0)