Custom script - how to modify activities after they load?
Is the best way to do this with a mutation observer on $('div.activity-list-container') and check for the presence of children that match $('div.activity-item')? Or is there another, existing event I could bind an additional function to? My hesitation at taking my own suggestion above is just that I already have a lot of mutation observers on any given page, and I am also unsure of what this might do to performance on tickets that do not have activities and therefore do not stop the observer from observing.
Here are two examples of my actual goal, which only works (long) after the page has loaded:
$('div.activity-item-header[data-activity-id^="RA"]').parent().addClass('reviewActivity'); $('div.activity-item-header[data-activity-id^="PA"]').parent().addClass('parallelActivity');JQuery just doesn't find those elements if you run this within boundReady.
Confirmation and better suggestions are both welcome!
Best Answer
-
Jeff_Lang Customer Ninja IT Monkey ✭✭✭✭you could try something like this to have the element updated as soon as it is added
app.custom.formTasks.add('ServiceRequest', null, function (formObj, viewModel) { <br> formObj.boundReady(function () {<br> $('body').on('DOMNodeInserted', $('div.activity-item-header[data-activity-id^="PA"]'), function () {<br> $('div.activity-item-header[data-activity-id^="PA"]').parent().addClass('parallelActivity');<br> });<br> });<br>});<br>
would just need to duplicate the .on for whichever activity type required.2
Answers