Skip to content
Open
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
176 changes: 176 additions & 0 deletions examples/web/demo-multi.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
<!-- Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license -->

<html lang="en" data-theme="light">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ HIGH: The new page is missing a <!DOCTYPE html> declaration. Without it, browsers can fall back to quirks mode, which causes inconsistent layout/box-model behavior compared to the single-page demo. Add the HTML5 DOCTYPE before the opening <html> tag so both demos render in standards mode.

<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, viewport-fit=cover, interactive-widget=overlays-content"
/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
<meta name="mobile-web-app-capable" content="yes" />
<meta name="format-detection" content="telephone=no, address=no, email=no" />
<meta
name="description"
content="Ultralytics Chat Widget Multi-Page Demo - keep the chat pill visible across navigations"
/>
<meta name="color-scheme" content="light dark" />
<meta name="theme-color" content="#ffffff" media="(prefers-color-scheme: light)" />
<meta name="theme-color" content="#0a0a0b" media="(prefers-color-scheme: dark)" />
<title>Ultralytics Chat — Multi-Page Demo</title>
<link
rel="icon"
type="image/png"
href="https://raw.githubusercontent.com/ultralytics/assets/refs/heads/main/logo/favicon-yolo.png"
/>
<link rel="stylesheet" href="demo.css" />
</head>
<body>
<!-- Top bar -->
<header class="topbar">
<div class="topbar-inner">
<div class="brand">
<a href="https://www.ultralytics.com" target="_blank" rel="noopener">
<img
src="https://cdn.prod.website-files.com/680a070c3b99253410dd3dcf/68e4eb1e9893320b26cc02c3_Ultralytics%20Logo.png.svg"
alt="Ultralytics"
loading="lazy"
decoding="async"
/>
</a>
</div>
<div class="toolbar">
<a class="btn primary" href="demo.html">Single-page demo</a>
</div>
</div>
</header>

<main class="page">
<aside class="sidebar" aria-label="Multi-page navigation">
<div class="nav-title">Jump between pages</div>
<ul class="nav">
<li><a href="demo-multi.html">Multi-page demo (you are here)</a></li>
<li><a href="demo.html">Original demo</a></li>
</ul>
</aside>
<section class="content">
<div class="hero" id="intro">
<h1>Multi-page navigation test</h1>
<p class="lead">
Navigate between this page and the original demo while the chat pill remains visible. This shows how the
widget survives DOM swaps.
</p>
<div class="toolbar">
<button class="btn" onclick="openChat()" aria-label="Open chat">Open Chat</button>
<span class="btn" style="pointer-events: none; opacity: 0.72">Press ⌘ + K to open</span>
<a class="btn primary" href="demo.html">Back to single-page demo</a>
</div>
</div>

<div class="card">
<h3>Multi-page steps</h3>
<ol>
<li>Open the chat with the <strong>Open Chat</strong> button.</li>
<li>Switch to <a href="demo.html">the original demo</a> (same domain, different page).</li>
<li>Watch for the pill/modal—they should stay visible without rebuilding the DOM elements.</li>
<li>
Go back to this page and open the chat again to confirm the session persisted via
<code>localStorage</code>.
</li>
</ol>
</div>

<div class="card">
<h3>Why this demo exists</h3>
<p>
Some frameworks replace the <code>&lt;body&gt;</code> and <code>&lt;head&gt;</code> on each navigation. The
chat widget now marks its elements as permanent and watches for missing parents so the UI never flashes
away.
</p>
<p class="lead">
Feel free to script rapid navigation between these pages to reproduce the bug you observed.
</p>
</div>
</section>
</main>

<footer class="footer">
<span>Need help?</span>
<a href="#" onclick="openChat();return false;">Ask Ultralytics AI</a>
</footer>

<!-- Chat client -->
<script src="../../js/chat.js"></script>
<script>
let chatInstance;

function applySystemTheme() {
const dark = window.matchMedia("(prefers-color-scheme: dark)").matches;
const theme = dark ? "dark" : "light";
document.documentElement.setAttribute("data-theme", theme);
}

(function bindSystemThemeListener() {
const mql = window.matchMedia("(prefers-color-scheme: dark)");
try {
mql.addEventListener("change", applySystemTheme);
} catch {
mql.addListener(applySystemTheme);
}
})();

function openChat() {
if (chatInstance) chatInstance.toggle(true, "chat");
}
function openSearch() {
if (chatInstance) chatInstance.toggle(true, "search");
}

document.addEventListener(
"touchmove",
(e) => {
const el = e.target.closest("pre, table, .sidebar");
if (el) return;
},
{ passive: true },
);

window.addEventListener("DOMContentLoaded", () => {
applySystemTheme();
chatInstance = new UltralyticsChat({
branding: {
name: "Ultralytics AI",
tagline: "Ask anything about Ultralytics, YOLO, and more",
logo: "https://cdn.prod.website-files.com/680a070c3b99253410dd3dcf/68e4eb1e9893320b26cc02c3_Ultralytics%20Logo.png.svg",
logomark:
"https://storage.googleapis.com/organization-image-assets/ultralytics-botAvatarSrcUrl-1729379860806.svg",
pillText: "Ask AI",
},
theme: {
primary: "#042AFF",
dark: "#111F68",
yellow: "#E1FF25",
text: "#0b0b0f",
},
welcome: {
title: "Hello 👋",
message: "I'm an AI assistant trained on Ultralytics documentation - ask me anything!",
chatExamples: [
"What's new in SAM 3?",
"How do I get started with YOLO?",
"Tell me about Enterprise Licensing",
],
searchExamples: ["YOLO quickstart", "model training parameters", "export formats", "dataset configuration"],
},
ui: {
placeholder: "Ask anything…",
copyText: "Copy thread",
downloadText: "Download thread",
clearText: "New chat",
},
});
});
</script>
</body>
</html>
Loading