Skip to content

Commit

Permalink
Merge pull request #25 from Countly/resize-event
Browse files Browse the repository at this point in the history
Resize event
  • Loading branch information
turtledreams authored Jan 9, 2025
2 parents dc4fdfb + 34ef38f commit baf790c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion modules/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ var healthCheckCounterEnum = Object.freeze({
errorMessage: "cly_hc_error_message",
});

var SDK_VERSION = "24.11.0";
var SDK_VERSION = "24.11.2";
var SDK_NAME = "javascript_native_web";

// Using this on document.referrer would return an array with 17 elements in it. The 12th element (array[11]) would be the path we are looking for. Others would be things like password and such (use https://regex101.com/ to check more)
Expand Down
31 changes: 30 additions & 1 deletion modules/CountlyClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -3743,6 +3743,21 @@ constructor(ob) {
window.addEventListener('message', (event) => {
this.#interpretContentMessage(event);
});
let resizeTimeout;
window.addEventListener('resize', () => {
clearTimeout(resizeTimeout);
resizeTimeout = setTimeout(() => {
const width = window.innerWidth;
const height = window.innerHeight;
const iframe = document.getElementById(this.#contentIframeID);
iframe.contentWindow.postMessage(
{ type: 'resize', width: width, height: height },
'*'
);
}, 200);
});


}, true);
};

Expand Down Expand Up @@ -3778,7 +3793,7 @@ constructor(ob) {
this.#log(logLevelEnums.ERROR, "sendContentRequest, Received message from invalid origin");
return;
}
const {close, link, event} = messageEvent.data;
const {close, link, event, resize_me} = messageEvent.data;

if (event) {
this.#log(logLevelEnums.DEBUG, "sendContentRequest, Received event: [" + event + "]");
Expand Down Expand Up @@ -3809,6 +3824,20 @@ constructor(ob) {
this.#log(logLevelEnums.DEBUG, `sendContentRequest, Opened link in new tab: [${link}]`);
}

if (resize_me) {
this.#log(logLevelEnums.DEBUG, "sendContentRequest, Resizing iframe");
const resInfo = this.#getResolution(true);
var dimensionToUse = resize_me.p;
if (resInfo.width >= resInfo.height) {
dimensionToUse = resize_me.l;
};
const iframe = document.getElementById(this.#contentIframeID);
iframe.style.left = dimensionToUse.x + "px";
iframe.style.top = dimensionToUse.y + "px";
iframe.style.width = dimensionToUse.w + "px";
iframe.style.height = dimensionToUse.h + "px";
}

if (close === 1) {
this.#closeContentFrame();
}
Expand Down

0 comments on commit baf790c

Please sign in to comment.