aumera-on-screen-widget 0.0.16 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/df-btn.js +78 -6
- package/package.json +1 -1
package/df-btn.js
CHANGED
|
@@ -26,6 +26,14 @@
|
|
|
26
26
|
return supportedLangs.includes(lang) ? lang : "de";
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
// Helper function to resize Cloudinary images for optimized file size
|
|
30
|
+
function cloudinaryResize(url, width = 32, height = 32) {
|
|
31
|
+
const transform = `w_${width},h_${height},c_fill,f_auto,q_auto`;
|
|
32
|
+
|
|
33
|
+
// Insert transformation right after `/upload/`
|
|
34
|
+
return url.replace('/upload/', `/upload/${transform}/`);
|
|
35
|
+
}
|
|
36
|
+
|
|
29
37
|
// Async function to fetch chatbot settings from GraphQL
|
|
30
38
|
async function fetchChatbotSettings(orgId, env, language) {
|
|
31
39
|
try {
|
|
@@ -219,8 +227,8 @@
|
|
|
219
227
|
|
|
220
228
|
// Use chatbotMask as logo if available
|
|
221
229
|
if (settings.chatbotMask) {
|
|
222
|
-
config.logo = settings.chatbotMask;
|
|
223
|
-
config.logoDark = settings.chatbotMask;
|
|
230
|
+
config.logo = cloudinaryResize(settings.chatbotMask, 64, 64);
|
|
231
|
+
config.logoDark = cloudinaryResize(settings.chatbotMask, 64, 64);
|
|
224
232
|
console.log(
|
|
225
233
|
"[OSW Widget] Using chatbotMask as logo:",
|
|
226
234
|
settings.chatbotMask
|
|
@@ -525,6 +533,26 @@
|
|
|
525
533
|
config.shakeDuration / 1000
|
|
526
534
|
}s cubic-bezier(.36,.07,.19,.97) both;
|
|
527
535
|
}
|
|
536
|
+
|
|
537
|
+
.df-iframe-placeholder {
|
|
538
|
+
display: none;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
.df-btn-loading .df-btn-text:after {
|
|
542
|
+
content: '';
|
|
543
|
+
display: inline-block;
|
|
544
|
+
width: 16px;
|
|
545
|
+
height: 16px;
|
|
546
|
+
margin-left: 8px;
|
|
547
|
+
border: 2px solid transparent;
|
|
548
|
+
border-top-color: currentColor;
|
|
549
|
+
border-radius: 50%;
|
|
550
|
+
animation: df-spin 0.8s linear infinite;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
@keyframes df-spin {
|
|
554
|
+
to { transform: rotate(360deg); }
|
|
555
|
+
}
|
|
528
556
|
`;
|
|
529
557
|
|
|
530
558
|
document.head.appendChild(style);
|
|
@@ -564,9 +592,7 @@
|
|
|
564
592
|
<div class="df-btn-header">
|
|
565
593
|
<div class="df-btn-text">${config.openText || "Chat"}</div>
|
|
566
594
|
</div>
|
|
567
|
-
<
|
|
568
|
-
config.orgId
|
|
569
|
-
}" allow="microphone *"></iframe>
|
|
595
|
+
<div class="df-btn-content df-iframe-placeholder"></div>
|
|
570
596
|
</button>
|
|
571
597
|
`;
|
|
572
598
|
|
|
@@ -574,6 +600,7 @@
|
|
|
574
600
|
document.body.insertAdjacentHTML("beforeend", buttonHTML);
|
|
575
601
|
|
|
576
602
|
let dfToggled = false;
|
|
603
|
+
let iframeLoaded = false;
|
|
577
604
|
let inactivityTimer = null;
|
|
578
605
|
let shakeInterval = null;
|
|
579
606
|
|
|
@@ -665,6 +692,46 @@
|
|
|
665
692
|
}
|
|
666
693
|
};
|
|
667
694
|
|
|
695
|
+
// Create and inject the iframe on first open
|
|
696
|
+
function ensureIframeLoaded() {
|
|
697
|
+
return new Promise((resolve) => {
|
|
698
|
+
if (iframeLoaded) {
|
|
699
|
+
resolve();
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
const btn = document.querySelector(".df-btn");
|
|
704
|
+
const placeholder = btn?.querySelector(".df-iframe-placeholder");
|
|
705
|
+
|
|
706
|
+
if (!placeholder) {
|
|
707
|
+
console.error("[OSW Widget] Placeholder not found");
|
|
708
|
+
resolve();
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
const iframe = document.createElement("iframe");
|
|
713
|
+
iframe.className = "df-btn-content";
|
|
714
|
+
iframe.src = `${getChatUrl()}/${detectedLang}/?orgId=${config.orgId}`;
|
|
715
|
+
iframe.allow = "microphone *";
|
|
716
|
+
iframe.style.opacity = "0";
|
|
717
|
+
|
|
718
|
+
iframe.addEventListener("load", () => {
|
|
719
|
+
iframe.style.opacity = "";
|
|
720
|
+
iframeLoaded = true;
|
|
721
|
+
resolve();
|
|
722
|
+
});
|
|
723
|
+
|
|
724
|
+
setTimeout(() => {
|
|
725
|
+
iframe.style.opacity = "";
|
|
726
|
+
iframeLoaded = true;
|
|
727
|
+
resolve();
|
|
728
|
+
}, 5000);
|
|
729
|
+
|
|
730
|
+
placeholder.replaceWith(iframe);
|
|
731
|
+
console.log("[OSW Widget] Iframe created on first open");
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
|
|
668
735
|
// Add close and maximize/minimize buttons dynamically when chat is open
|
|
669
736
|
function updateHeaderButtons() {
|
|
670
737
|
const header = document.querySelector(".df-btn-header");
|
|
@@ -803,7 +870,7 @@
|
|
|
803
870
|
// Check if mobile for later use
|
|
804
871
|
const isMobile = window.innerWidth <= 768;
|
|
805
872
|
|
|
806
|
-
btn.addEventListener("click", () => {
|
|
873
|
+
btn.addEventListener("click", async () => {
|
|
807
874
|
// Only toggle if chat is closed (popover mode)
|
|
808
875
|
if (btn.classList.contains("df-closed")) {
|
|
809
876
|
// Dismiss notification when opening chat
|
|
@@ -828,6 +895,11 @@
|
|
|
828
895
|
);
|
|
829
896
|
}
|
|
830
897
|
|
|
898
|
+
// Load iframe on first open
|
|
899
|
+
btn.classList.add("df-btn-loading");
|
|
900
|
+
await ensureIframeLoaded();
|
|
901
|
+
btn.classList.remove("df-btn-loading");
|
|
902
|
+
|
|
831
903
|
const isMobile = window.innerWidth <= 768;
|
|
832
904
|
|
|
833
905
|
if (isMobile) {
|