aumera-on-screen-widget 0.0.17 → 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.
Files changed (2) hide show
  1. package/df-btn.js +68 -4
  2. package/package.json +1 -1
package/df-btn.js CHANGED
@@ -533,6 +533,26 @@
533
533
  config.shakeDuration / 1000
534
534
  }s cubic-bezier(.36,.07,.19,.97) both;
535
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
+ }
536
556
  `;
537
557
 
538
558
  document.head.appendChild(style);
@@ -572,9 +592,7 @@
572
592
  <div class="df-btn-header">
573
593
  <div class="df-btn-text">${config.openText || "Chat"}</div>
574
594
  </div>
575
- <iframe class="df-btn-content" src="${getChatUrl()}/${detectedLang}/?orgId=${
576
- config.orgId
577
- }" allow="microphone *"></iframe>
595
+ <div class="df-btn-content df-iframe-placeholder"></div>
578
596
  </button>
579
597
  `;
580
598
 
@@ -582,6 +600,7 @@
582
600
  document.body.insertAdjacentHTML("beforeend", buttonHTML);
583
601
 
584
602
  let dfToggled = false;
603
+ let iframeLoaded = false;
585
604
  let inactivityTimer = null;
586
605
  let shakeInterval = null;
587
606
 
@@ -673,6 +692,46 @@
673
692
  }
674
693
  };
675
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
+
676
735
  // Add close and maximize/minimize buttons dynamically when chat is open
677
736
  function updateHeaderButtons() {
678
737
  const header = document.querySelector(".df-btn-header");
@@ -811,7 +870,7 @@
811
870
  // Check if mobile for later use
812
871
  const isMobile = window.innerWidth <= 768;
813
872
 
814
- btn.addEventListener("click", () => {
873
+ btn.addEventListener("click", async () => {
815
874
  // Only toggle if chat is closed (popover mode)
816
875
  if (btn.classList.contains("df-closed")) {
817
876
  // Dismiss notification when opening chat
@@ -836,6 +895,11 @@
836
895
  );
837
896
  }
838
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
+
839
903
  const isMobile = window.innerWidth <= 768;
840
904
 
841
905
  if (isMobile) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aumera-on-screen-widget",
3
- "version": "0.0.17",
3
+ "version": "0.0.18",
4
4
  "description": "A lightweight, customizable chat widget for websites",
5
5
  "main": "df-btn.js",
6
6
  "scripts": {