Skip to content

Commit b500bda

Browse files
feat: add resize to rating widget
1 parent 78286c1 commit b500bda

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

plugins/star-rating/frontend/public/templates/feedback-popup.html

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,55 @@
435435
duration: 250,
436436
animation: 'scale'
437437
});
438+
handleWidgetResize('feedback');
438439
},
439440
type: "GET",
440441
url: url + "/o/feedback/widget"
441442
});
442443

444+
function handleWidgetResize(screen) {
445+
console.log("Resizing widget...");
446+
if (window.parent && typeof window.parent.postMessage === "function") {
447+
const bodyElement = $('body');
448+
let modalContentElement = null;
449+
450+
if (screen === 'feedback') {
451+
modalContentElement = $('.modal-content')[0];
452+
}
453+
else if (screen === 'success') {
454+
modalContentElement = $('.success-modal-content')[0];
455+
}
456+
457+
const bottomMargin = parseFloat(bodyElement.css('margin-bottom')) || 0;
458+
const leftMargin = parseFloat(bodyElement.css('margin-left')) || 0;
459+
const rightMargin = parseFloat(bodyElement.css('margin-right')) || 0;
460+
const topMargin = parseFloat(bodyElement.css('margin-top')) || 0;
461+
462+
console.log("Widget body element: ", modalContentElement);
463+
464+
const width = modalContentElement.offsetWidth + (leftMargin + rightMargin);
465+
const height = modalContentElement.offsetHeight + (topMargin + bottomMargin);
466+
467+
console.log("Widget size: ", { width: width, height: height });
468+
469+
var d = {
470+
key: "resize-me",
471+
data: {
472+
width: width,
473+
height: height
474+
}
475+
};
476+
477+
var parent = "*";
478+
479+
if (parentOrigin) {
480+
parent = parentOrigin;
481+
}
482+
483+
window.parent.postMessage(d, parent);
484+
}
485+
}
486+
443487
var eventObject = {
444488
key: "[CLY]_star_rating",
445489
count: 1,
@@ -561,6 +605,8 @@
561605
showCommentCheckbox.setAttribute('data-state', 0);
562606
document.getElementById('countly-feedback-comment-textarea').style.display = "none";
563607
}
608+
609+
handleWidgetResize('feedback');
564610
}
565611

566612
function showHideEmailArea() {
@@ -572,6 +618,8 @@
572618
showEmailCheckbox.setAttribute('data-state', 0);
573619
document.getElementById('countly-feedback-contact-me-email').style.display = "none";
574620
}
621+
622+
handleWidgetResize('feedback');
575623
}
576624

577625
function consent() {
@@ -620,6 +668,7 @@
620668
// set popup to default state
621669
document.getElementsByClassName("success-modal-content")[0].style.display = "none";
622670
document.getElementsByClassName("modal-content")[0].style.display = "flex";
671+
handleWidgetResize('success');
623672
document.getElementById('countly-feedback-comment-textarea').value = "";
624673
document.getElementById('countly-feedback-contact-me-email').value = "";
625674
for (var i = 0; i < 5; i++) {

0 commit comments

Comments
 (0)