Skip to content

Commit

Permalink
fix(interactives) Fixed setting of data-intid to not be part of the i…
Browse files Browse the repository at this point in the history
…nner dom update delay process
  • Loading branch information
nyeholt committed Aug 22, 2021
1 parent 8cd7877 commit 51bd50e
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions client/javascript/interactives.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
(function () {
var loaded = false;

/**
* Indicates how long we delay the finalisation of
* interactive insertion to account for other libraries swapping
* items in/out of contained content such as react
*/
var DOM_LOAD_DELAY = 300;

var config = {
remember: false, // remember the user through requests
trackviews: false,
Expand Down Expand Up @@ -492,8 +499,16 @@
effect = item.Transition;
}

/**
* Updates an element's contents to bind click handling information
*/
function updateElem(elem) {
// 300 ms delay to allow for react rendering to occur before we query the ele's DOM
elem.setAttribute('data-intid', item.ID)
if (item.TrackViews) {
elem.classList.add('int-track-view');
}
// 150 ms delay to allow for other libs to make changes to the internal
// dom structure before binding any tracking logic
setTimeout(function () {
var linkEles = Array.from(elem.querySelectorAll('a,button'));
linkEles.forEach(function (innerElem) {
Expand Down Expand Up @@ -526,12 +541,7 @@
innerElem.classList.add('hide-on-interact');
}
});

elem.setAttribute('data-intid', item.ID)
if (item.TrackViews) {
elem.classList.add('int-track-view');
}
}, 300);
}, DOM_LOAD_DELAY);
};

var timeout = item.Delay ? item.Delay : 0;
Expand Down

0 comments on commit 51bd50e

Please sign in to comment.