Skip to content
Merged
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
4 changes: 0 additions & 4 deletions fern/asset-source/css/03-support-launcher.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,3 @@
.sixmm-support-status[data-state="error"] .sixmm-support-spinner { display:none; }
@keyframes sixmm-support-spin { to { transform:rotate(360deg); } }
@media (prefers-reduced-motion:reduce) { .sixmm-support-spinner { animation:none; } }

.sixmm-support-launcher { position:fixed; z-index:999997; right:calc(24px + env(safe-area-inset-right, 0px)); bottom:calc(24px + env(safe-area-inset-bottom, 0px)); width:48px; height:48px; display:grid; place-items:center; border:0; border-radius:15px; background:var(--sixmm-accent); color:white; cursor:pointer; box-shadow:0 2px 8px #0002; }
.sixmm-support-launcher:focus-visible { outline:3px solid var(--sixmm-accent-strong); outline-offset:4px; }
.sixmm-support-launcher[aria-busy="true"] { opacity:.65; cursor:wait; }
15 changes: 0 additions & 15 deletions fern/asset-source/css/07-support-loading.css

This file was deleted.

2 changes: 0 additions & 2 deletions fern/asset-source/support/01-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ var observedWidgetContainer = null;
var widgetContainerObserver = null;
var observedWidgetBody = null;
var widgetBodyObserver = null;
var widgetRequested = false;
var openWhenReady = false;
var retainedModalStyles = null;
var supportFrame = null;
var supportStatus = null;
Expand Down
7 changes: 0 additions & 7 deletions fern/asset-source/support/02-status-and-accessibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,20 +211,13 @@ function setAttributeIfChanged(element, name, value) {
function syncWidgetAccessibility() {
var bubble = document.getElementById('cs-widget-bubble');
var container = document.getElementById('cs-widget-container');
var launcher = document.getElementById('sixmm-support-launcher');
if (launcher) setAttributeIfChanged(launcher, 'aria-label', supportLabels[currentDocsLocale() || 'en'] || supportLabels.en);
if (!bubble || !container) {
if (widgetContainerObserver) widgetContainerObserver.disconnect();
observedWidgetContainer = null;
return;
}
var frame = container.querySelector('iframe');
if (frame) ensureSupportStatus(container, frame);
if (launcher) launcher.remove();
if (openWhenReady && window.CSWidget && typeof window.CSWidget.open === 'function') {
openWhenReady = false;
window.CSWidget.open();
}
var open = container.style.display !== 'none';
var label = supportLabels[currentDocsLocale() || 'en'] || supportLabels.en;
setAttributeIfChanged(bubble, 'role', 'button');
Expand Down
8 changes: 3 additions & 5 deletions fern/asset-source/support/03-navigation-persistence.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ function prepareWidgetSwap(event) {
document.getElementById('cs-bubble-style'),
document.querySelector('script[data-sixmm-support-widget="true"]'),
document.getElementById('cs-widget-overlay'),
document.getElementById('sixmm-support-launcher'),
document.getElementById('cs-widget-greeting'),
document.getElementById('cs-widget-image-preview'),
];
Expand Down Expand Up @@ -68,13 +67,12 @@ function restoreWidgetAfterSwap() {
});
retainedModalStyles = null;
}
if (widgetRequested) loadWidget();
else ensureLauncher();
loadWidget();
syncWidgetAccessibility();
if (pendingWidgetDocsLocale !== null) {
confirmPendingWidgetDocsNavigation();
} else {
if (widgetRequested) syncWidgetLanguageFromHost(20, false);
syncWidgetLanguageFromHost(20, false);
}
if (widgetRequested) syncWidgetThemeFromHost(20, false);
syncWidgetThemeFromHost(20, false);
}
36 changes: 2 additions & 34 deletions fern/asset-source/support/05-sdk-loader.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
function loadWidget() {
if (document.querySelector('script[data-sixmm-support-widget="true"]')) {
document.documentElement.classList.remove('sixmm-support-widget-loading');
return;
}
if (document.querySelector('script[data-sixmm-support-widget="true"]')) return;

var initialLang = currentLang();
var initialTheme = currentTheme();
Expand All @@ -18,46 +15,19 @@ function loadWidget() {
script.dataset.color = currentAccentColor();
script.dataset.appKey = APP_KEY;
script.onload = function () {
document.documentElement.classList.remove('sixmm-support-widget-loading');
// The host may have changed while widget.js was loading.
syncWidgetLanguageFromHost(20, true);
syncWidgetThemeFromHost(20, true);
syncWidgetAccessibility();
};
script.onerror = function () {
document.documentElement.classList.remove('sixmm-support-widget-loading');
script.remove();
widgetRequested = false;
openWhenReady = false;
ensureLauncher();
};
lastTheme = initialTheme;
document.body.appendChild(script);
}

function ensureLauncher() {
if (document.getElementById('cs-widget-bubble')) return;
var launcher = document.getElementById('sixmm-support-launcher');
if (!launcher) {
launcher = document.createElement('button');
launcher.id = 'sixmm-support-launcher';
launcher.type = 'button';
launcher.className = 'sixmm-support-launcher';
launcher.innerHTML = '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M3 14v-3a9 9 0 0 1 18 0v3"/><rect x="1" y="13" width="4" height="7" rx="2"/><rect x="19" y="13" width="4" height="7" rx="2"/><path d="M21 18v1a3 3 0 0 1-3 3h-4"/></svg>';
launcher.addEventListener('click', function () {
widgetRequested = true;
openWhenReady = true;
launcher.setAttribute('aria-busy', 'true');
loadWidget();
});
document.body.appendChild(launcher);
}
launcher.setAttribute('aria-busy', widgetRequested ? 'true' : 'false');
syncWidgetAccessibility();
}

function syncHostNavigation() {
if (!widgetRequested) { syncWidgetAccessibility(); return; }
if (pendingWidgetDocsLocale !== null) { confirmPendingWidgetDocsNavigation(); return; }
syncWidgetLanguageFromHost(20, false);
}
Expand All @@ -69,18 +39,16 @@ function boot() {
document.addEventListener('astro:before-swap', prepareWidgetSwap);
document.addEventListener('astro:page-load', restoreWidgetAfterSwap);

ensureLauncher();
window.addEventListener('popstate', syncHostNavigation);
window.addEventListener('pageshow', syncHostNavigation);
// The SDK mounts the controls asynchronously as direct body children.
observeWidgetBody();
// Initialize in the background on every fresh page load, so the iframe can
// mount before the user opens support. Astro navigation retains this SDK.
widgetRequested = true;
loadWidget();

var observer = new MutationObserver(function () {
if (widgetRequested) syncWidgetThemeFromHost(20, false);
syncWidgetThemeFromHost(20, false);
});
observer.observe(document.documentElement, {
attributes: true,
Expand Down
20 changes: 0 additions & 20 deletions fern/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@
@keyframes sixmm-support-spin { to { transform:rotate(360deg); } }
@media (prefers-reduced-motion:reduce) { .sixmm-support-spinner { animation:none; } }

.sixmm-support-launcher { position:fixed; z-index:999997; right:calc(24px + env(safe-area-inset-right, 0px)); bottom:calc(24px + env(safe-area-inset-bottom, 0px)); width:48px; height:48px; display:grid; place-items:center; border:0; border-radius:15px; background:var(--sixmm-accent); color:white; cursor:pointer; box-shadow:0 2px 8px #0002; }
.sixmm-support-launcher:focus-visible { outline:3px solid var(--sixmm-accent-strong); outline-offset:4px; }
.sixmm-support-launcher[aria-busy="true"] { opacity:.65; cursor:wait; }

:root,
:root.dark {
accent-color: var(--sixmm-accent);
Expand Down Expand Up @@ -144,22 +140,6 @@ body::-webkit-scrollbar {
display: none;
}

html.sixmm-support-widget-loading body::after {
position: fixed;
z-index: 999997;
right: calc(24px + env(safe-area-inset-right, 0px));
bottom: calc(24px + env(safe-area-inset-bottom, 0px));
width: 48px;
height: 48px;
border-radius: 15px;
background-color: var(--sixmm-accent);
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 14v-3a9 9 0 0 1 18 0v3'/%3E%3Crect x='1' y='13' width='4' height='7' rx='2' fill='white'/%3E%3Crect x='19' y='13' width='4' height='7' rx='2' fill='white'/%3E%3Cpath d='M21 18v1a3 3 0 0 1-3 3h-4'/%3E%3C/svg%3E");
background-position: center;
background-repeat: no-repeat;
content: "";
pointer-events: none;
}

#fern-sidebar-scroll-area {
scrollbar-color: var(--sixmm-accent) transparent !important;
}
Expand Down
53 changes: 5 additions & 48 deletions fern/support-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
var widgetContainerObserver = null;
var observedWidgetBody = null;
var widgetBodyObserver = null;
var widgetRequested = false;
var openWhenReady = false;
var retainedModalStyles = null;
var supportFrame = null;
var supportStatus = null;
Expand Down Expand Up @@ -259,20 +257,13 @@
function syncWidgetAccessibility() {
var bubble = document.getElementById('cs-widget-bubble');
var container = document.getElementById('cs-widget-container');
var launcher = document.getElementById('sixmm-support-launcher');
if (launcher) setAttributeIfChanged(launcher, 'aria-label', supportLabels[currentDocsLocale() || 'en'] || supportLabels.en);
if (!bubble || !container) {
if (widgetContainerObserver) widgetContainerObserver.disconnect();
observedWidgetContainer = null;
return;
}
var frame = container.querySelector('iframe');
if (frame) ensureSupportStatus(container, frame);
if (launcher) launcher.remove();
if (openWhenReady && window.CSWidget && typeof window.CSWidget.open === 'function') {
openWhenReady = false;
window.CSWidget.open();
}
var open = container.style.display !== 'none';
var label = supportLabels[currentDocsLocale() || 'en'] || supportLabels.en;
setAttributeIfChanged(bubble, 'role', 'button');
Expand Down Expand Up @@ -329,7 +320,6 @@
document.getElementById('cs-bubble-style'),
document.querySelector('script[data-sixmm-support-widget="true"]'),
document.getElementById('cs-widget-overlay'),
document.getElementById('sixmm-support-launcher'),
document.getElementById('cs-widget-greeting'),
document.getElementById('cs-widget-image-preview'),
];
Expand Down Expand Up @@ -377,15 +367,14 @@
});
retainedModalStyles = null;
}
if (widgetRequested) loadWidget();
else ensureLauncher();
loadWidget();
syncWidgetAccessibility();
if (pendingWidgetDocsLocale !== null) {
confirmPendingWidgetDocsNavigation();
} else {
if (widgetRequested) syncWidgetLanguageFromHost(20, false);
syncWidgetLanguageFromHost(20, false);
}
if (widgetRequested) syncWidgetThemeFromHost(20, false);
syncWidgetThemeFromHost(20, false);
}

function normalizeLanguage(lang) {
Expand Down Expand Up @@ -568,10 +557,7 @@
}

function loadWidget() {
if (document.querySelector('script[data-sixmm-support-widget="true"]')) {
document.documentElement.classList.remove('sixmm-support-widget-loading');
return;
}
if (document.querySelector('script[data-sixmm-support-widget="true"]')) return;

var initialLang = currentLang();
var initialTheme = currentTheme();
Expand All @@ -587,46 +573,19 @@
script.dataset.color = currentAccentColor();
script.dataset.appKey = APP_KEY;
script.onload = function () {
document.documentElement.classList.remove('sixmm-support-widget-loading');
// The host may have changed while widget.js was loading.
syncWidgetLanguageFromHost(20, true);
syncWidgetThemeFromHost(20, true);
syncWidgetAccessibility();
};
script.onerror = function () {
document.documentElement.classList.remove('sixmm-support-widget-loading');
script.remove();
widgetRequested = false;
openWhenReady = false;
ensureLauncher();
};
lastTheme = initialTheme;
document.body.appendChild(script);
}

function ensureLauncher() {
if (document.getElementById('cs-widget-bubble')) return;
var launcher = document.getElementById('sixmm-support-launcher');
if (!launcher) {
launcher = document.createElement('button');
launcher.id = 'sixmm-support-launcher';
launcher.type = 'button';
launcher.className = 'sixmm-support-launcher';
launcher.innerHTML = '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M3 14v-3a9 9 0 0 1 18 0v3"/><rect x="1" y="13" width="4" height="7" rx="2"/><rect x="19" y="13" width="4" height="7" rx="2"/><path d="M21 18v1a3 3 0 0 1-3 3h-4"/></svg>';
launcher.addEventListener('click', function () {
widgetRequested = true;
openWhenReady = true;
launcher.setAttribute('aria-busy', 'true');
loadWidget();
});
document.body.appendChild(launcher);
}
launcher.setAttribute('aria-busy', widgetRequested ? 'true' : 'false');
syncWidgetAccessibility();
}

function syncHostNavigation() {
if (!widgetRequested) { syncWidgetAccessibility(); return; }
if (pendingWidgetDocsLocale !== null) { confirmPendingWidgetDocsNavigation(); return; }
syncWidgetLanguageFromHost(20, false);
}
Expand All @@ -638,18 +597,16 @@
document.addEventListener('astro:before-swap', prepareWidgetSwap);
document.addEventListener('astro:page-load', restoreWidgetAfterSwap);

ensureLauncher();
window.addEventListener('popstate', syncHostNavigation);
window.addEventListener('pageshow', syncHostNavigation);
// The SDK mounts the controls asynchronously as direct body children.
observeWidgetBody();
// Initialize in the background on every fresh page load, so the iframe can
// mount before the user opens support. Astro navigation retains this SDK.
widgetRequested = true;
loadWidget();

var observer = new MutationObserver(function () {
if (widgetRequested) syncWidgetThemeFromHost(20, false);
syncWidgetThemeFromHost(20, false);
});
observer.observe(document.documentElement, {
attributes: true,
Expand Down
9 changes: 3 additions & 6 deletions scripts/check-widget-sync.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,8 @@ assert.equal(appendedWidgetScript.dataset.appId, undefined, "Legacy appId must n
assert.equal(appendedWidgetScript.dataset.lang, "en");
assert.equal(appendedWidgetScript.dataset.theme, "light");
assert.equal(widgetOpenCalls,0,'Background initialization must not open the support panel');
const launcher = sandboxDocument.getElementById('sixmm-support-launcher');
assert.ok(launcher,'A keyboard-accessible support entry must remain visible before SDK load');
launcher.listeners.click(); launcher.listeners.click();
assert.ok(appendedWidgetScript, 'An early support click reuses the SDK already loading');
assert.equal(widgetScriptLoads,1,'Repeated clicks while loading must not duplicate the SDK');
assert.equal(sandboxDocument.getElementById('sixmm-support-launcher'), null, 'The docs must leave the launcher to the SDK');
assert.equal(widgetScriptLoads,1,'Background initialization loads one SDK');
assert.equal(appendedWidgetScript.dataset.astroExec, "",
"Astro's script runner must skip the already-executing retained SDK");
appendedWidgetScript.onload();
Expand Down Expand Up @@ -403,7 +400,7 @@ sandboxDocument.body.appendChild(bubble);
sandboxDocument.body.appendChild(container);
sandboxDocument.head.appendChild(widgetStyle);
observers.find((observer) => observer.target === sandboxDocument.body).listener();
assert.equal(widgetOpenCalls,1,'The SDK opens automatically once the first requested panel becomes ready');
assert.equal(widgetOpenCalls,0,'Mounting the SDK launcher must leave the panel closed');
const status=container.children.find(node=>node.className==='sixmm-support-status');
assert.equal(status.hidden,false,'Cover the empty iframe until the application mounts');
listeners.message({origin:'https://untrusted.example',source:container.iframe.contentWindow,data:{type:'cs-widget-ready'}});
Expand Down