aumera-on-screen-widget 0.0.17 → 0.0.19

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 +77 -4
  2. package/package.json +1 -1
package/df-btn.js CHANGED
@@ -139,6 +139,9 @@
139
139
  showNotification: false,
140
140
  };
141
141
 
142
+ // Track if dark mode was explicitly requested via HTML attribute
143
+ const hasExplicitDarkBackground = !!wrapper.getAttribute("backgroundDark");
144
+
142
145
  // Initial config from HTML attributes with fallback to defaults
143
146
  const config = {
144
147
  src: wrapper.getAttribute("src"),
@@ -151,6 +154,7 @@
151
154
  background: wrapper.getAttribute("background") || defaultConfig.background,
152
155
  backgroundDark:
153
156
  wrapper.getAttribute("backgroundDark") || defaultConfig.backgroundDark,
157
+ hasDarkMode: hasExplicitDarkBackground,
154
158
  fontColor: wrapper.getAttribute("fontColor") || defaultConfig.fontColor,
155
159
  fontColorDark:
156
160
  wrapper.getAttribute("fontColorDark") || defaultConfig.fontColorDark,
@@ -219,6 +223,8 @@
219
223
  config.background = settings.oswColourBackgroundLight || config.background;
220
224
  config.backgroundDark =
221
225
  settings.oswColourBackgroundDark || config.backgroundDark;
226
+ // Update hasDarkMode if GraphQL provides dark background
227
+ config.hasDarkMode = config.hasDarkMode || !!settings.oswColourBackgroundDark;
222
228
  config.fontColor = settings.oswColourFontLight || config.fontColor;
223
229
  config.fontColorDark = settings.oswColourFontDark || config.fontColorDark;
224
230
  config.showNotification =
@@ -487,6 +493,7 @@
487
493
  }
488
494
  }
489
495
 
496
+ ${config.hasDarkMode ? `
490
497
  @media (prefers-color-scheme: dark){
491
498
  .df-btn {
492
499
  background-color: ${config.backgroundDark || "#171717"}
@@ -517,6 +524,7 @@
517
524
  border-top: 6px solid ${config.backgroundDark || "#171717"};
518
525
  }
519
526
  }
527
+ ` : ''}
520
528
 
521
529
  @keyframes shake {
522
530
  0%, 100% { transform: translateX(0); }
@@ -533,6 +541,26 @@
533
541
  config.shakeDuration / 1000
534
542
  }s cubic-bezier(.36,.07,.19,.97) both;
535
543
  }
544
+
545
+ .df-iframe-placeholder {
546
+ display: none;
547
+ }
548
+
549
+ .df-btn-loading .df-btn-text:after {
550
+ content: '';
551
+ display: inline-block;
552
+ width: 16px;
553
+ height: 16px;
554
+ margin-left: 8px;
555
+ border: 2px solid transparent;
556
+ border-top-color: currentColor;
557
+ border-radius: 50%;
558
+ animation: df-spin 0.8s linear infinite;
559
+ }
560
+
561
+ @keyframes df-spin {
562
+ to { transform: rotate(360deg); }
563
+ }
536
564
  `;
537
565
 
538
566
  document.head.appendChild(style);
@@ -572,9 +600,7 @@
572
600
  <div class="df-btn-header">
573
601
  <div class="df-btn-text">${config.openText || "Chat"}</div>
574
602
  </div>
575
- <iframe class="df-btn-content" src="${getChatUrl()}/${detectedLang}/?orgId=${
576
- config.orgId
577
- }" allow="microphone *"></iframe>
603
+ <div class="df-btn-content df-iframe-placeholder"></div>
578
604
  </button>
579
605
  `;
580
606
 
@@ -582,6 +608,7 @@
582
608
  document.body.insertAdjacentHTML("beforeend", buttonHTML);
583
609
 
584
610
  let dfToggled = false;
611
+ let iframeLoaded = false;
585
612
  let inactivityTimer = null;
586
613
  let shakeInterval = null;
587
614
 
@@ -673,6 +700,46 @@
673
700
  }
674
701
  };
675
702
 
703
+ // Create and inject the iframe on first open
704
+ function ensureIframeLoaded() {
705
+ return new Promise((resolve) => {
706
+ if (iframeLoaded) {
707
+ resolve();
708
+ return;
709
+ }
710
+
711
+ const btn = document.querySelector(".df-btn");
712
+ const placeholder = btn?.querySelector(".df-iframe-placeholder");
713
+
714
+ if (!placeholder) {
715
+ console.error("[OSW Widget] Placeholder not found");
716
+ resolve();
717
+ return;
718
+ }
719
+
720
+ const iframe = document.createElement("iframe");
721
+ iframe.className = "df-btn-content";
722
+ iframe.src = `${getChatUrl()}/${detectedLang}/?orgId=${config.orgId}`;
723
+ iframe.allow = "microphone *";
724
+ iframe.style.opacity = "0";
725
+
726
+ iframe.addEventListener("load", () => {
727
+ iframe.style.opacity = "";
728
+ iframeLoaded = true;
729
+ resolve();
730
+ });
731
+
732
+ setTimeout(() => {
733
+ iframe.style.opacity = "";
734
+ iframeLoaded = true;
735
+ resolve();
736
+ }, 5000);
737
+
738
+ placeholder.replaceWith(iframe);
739
+ console.log("[OSW Widget] Iframe created on first open");
740
+ });
741
+ }
742
+
676
743
  // Add close and maximize/minimize buttons dynamically when chat is open
677
744
  function updateHeaderButtons() {
678
745
  const header = document.querySelector(".df-btn-header");
@@ -699,6 +766,7 @@
699
766
  maxBtn.className = "maximize-minimize-btn";
700
767
  const maximized = btn.classList.contains("df-maximized");
701
768
  const isDarkMode =
769
+ config.hasDarkMode &&
702
770
  window.matchMedia &&
703
771
  window.matchMedia("(prefers-color-scheme: dark)").matches;
704
772
  maxBtn.innerHTML = `<img class="maximize-minimize-icon" src="${origin}/assets/${
@@ -811,7 +879,7 @@
811
879
  // Check if mobile for later use
812
880
  const isMobile = window.innerWidth <= 768;
813
881
 
814
- btn.addEventListener("click", () => {
882
+ btn.addEventListener("click", async () => {
815
883
  // Only toggle if chat is closed (popover mode)
816
884
  if (btn.classList.contains("df-closed")) {
817
885
  // Dismiss notification when opening chat
@@ -836,6 +904,11 @@
836
904
  );
837
905
  }
838
906
 
907
+ // Load iframe on first open
908
+ btn.classList.add("df-btn-loading");
909
+ await ensureIframeLoaded();
910
+ btn.classList.remove("df-btn-loading");
911
+
839
912
  const isMobile = window.innerWidth <= 768;
840
913
 
841
914
  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.19",
4
4
  "description": "A lightweight, customizable chat widget for websites",
5
5
  "main": "df-btn.js",
6
6
  "scripts": {