Skip to content

Commit 29c4cae

Browse files
FrancescoMolinaroSimone-Ramundi
authored andcommitted
[CST-14843] prevent script loading if page is still growing
1 parent a7c774e commit 29c4cae

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/app/social/social.service.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,21 @@ export class SocialService {
6363
script.type = 'text/javascript';
6464
script.src = environment.addToAnyPlugin.scriptUrl;
6565
script.async = true;
66-
this._document.body.appendChild(script);
66+
67+
// Wait for document to finish grow vertically so that script listener handles properly body height changes
68+
let lastBodyHeight = 0;
69+
const documentBody = this._document.body;
70+
71+
const bodyHeightInterval = setInterval(() => {
72+
const currentBodyHeight = documentBody.getBoundingClientRect().height;
73+
74+
if (currentBodyHeight > lastBodyHeight) {
75+
lastBodyHeight = currentBodyHeight;
76+
} else {
77+
this._document.head.appendChild(script);
78+
clearInterval(bodyHeightInterval);
79+
}
80+
}, 200);
6781
}
6882

6983
/**

0 commit comments

Comments
 (0)