Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resize event #25

Open
wants to merge 2 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -3724,6 +3724,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 @@ -3759,7 +3774,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 @@ -3790,6 +3805,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
Loading