This script is used to add an onclick
event to a table row and then redirect the user to a different page that is not the default behaviour.
In this case we are grabbing the event type (max form name) and id from the table row, creating a clickable event to redirect. The caveat being that the table is loaded asynchronously and is subject to change.
First we need to poll the DOM to make sure the table is loaded.
Then once the table is loaded we can attach a listener to the table and attach the onclick event to the table row.
The data-uid on the table row changes with every search/load, so we need to reattach the onclick event to the table row with every change.
- The
site
variable defines the base URL for redirection. - The
listenForClicksOnTRsWithDataUid
function iterates through rows withdata-uid
attributes, constructing URLs and redirecting users when a row is clicked.
To adapt to changing rows, the script employs a "polling" mechanism to check for the table's existence and a MutationObserver to detect structural changes.
- The
pollForTable
function checks for the table's existence at regular intervals. - Once the table is found, event listeners are attached to existing rows, and a MutationObserver is set up to monitor changes.
- The
logDataUidChange
function responds to new rows by attaching click event listeners. - The observer continues to monitor the table for future changes, maintaining consistent functionality.