Skip to content

Commit 76de9ec

Browse files
fix components
1 parent 66e9905 commit 76de9ec

File tree

7 files changed

+6074
-10
lines changed

7 files changed

+6074
-10
lines changed

content/knowrithm-widget.js

Lines changed: 149 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,156 @@
66
if (window.__knowrithmWidgetLoaded) return;
77
window.__knowrithmWidgetLoaded = true;
88

9+
var WIDGET_STYLE_ID = 'knowrithm-widget-style';
10+
var WIDGET_STYLE_HREF = '/styles/chat-widget-custom.css';
11+
var NAV_ELEMENTS = [
12+
{ id: 'navbar', minWidth: 0, display: 'block', zIndex: 90 },
13+
{ id: 'sidebar', minWidth: 1024, display: 'block', zIndex: 80 },
14+
{ id: 'content-side-layout', minWidth: 1280, display: 'flex', zIndex: 70 },
15+
{ id: 'table-of-contents-layout', minWidth: 1280, display: 'flex', zIndex: 70 },
16+
{ id: 'table-of-contents', minWidth: 1280, display: 'block', zIndex: 70 }
17+
];
18+
var navVisibilityGuardAttached = false;
19+
var navMutationObserver = null;
20+
var navElementObservers = {};
21+
22+
function observeNavElement(ruleId, element) {
23+
if (typeof MutationObserver === 'undefined' || !element) {
24+
return;
25+
}
26+
27+
var existing = navElementObservers[ruleId];
28+
if (existing && existing.element === element) {
29+
return;
30+
}
31+
32+
if (existing && existing.observer) {
33+
existing.observer.disconnect();
34+
}
35+
36+
var observer = new MutationObserver(function () {
37+
applyAllNavigationRules();
38+
});
39+
40+
observer.observe(element, { attributes: true, attributeFilter: ['class', 'style', 'hidden'] });
41+
navElementObservers[ruleId] = { observer: observer, element: element };
42+
}
43+
44+
function applyNavigationRule(rule) {
45+
var element = document.getElementById(rule.id);
46+
if (!element) return;
47+
48+
var meetsBreakpoint = true;
49+
if (rule.minWidth) {
50+
if (typeof window.matchMedia === 'function') {
51+
meetsBreakpoint = window.matchMedia('(min-width: ' + rule.minWidth + 'px)').matches;
52+
} else {
53+
meetsBreakpoint = window.innerWidth >= rule.minWidth;
54+
}
55+
}
56+
57+
if (meetsBreakpoint) {
58+
var displayValue = rule.display || 'block';
59+
element.style.setProperty('display', displayValue, 'important');
60+
element.style.setProperty('visibility', 'visible', 'important');
61+
element.style.setProperty('opacity', '1', 'important');
62+
element.style.setProperty('pointer-events', 'auto', 'important');
63+
if (typeof rule.zIndex === 'number') {
64+
element.style.setProperty('z-index', String(rule.zIndex), 'important');
65+
}
66+
if (element.hasAttribute('hidden')) {
67+
element.removeAttribute('hidden');
68+
}
69+
} else {
70+
['display', 'visibility', 'opacity', 'pointer-events', 'z-index'].forEach(function (prop) {
71+
element.style.removeProperty(prop);
72+
});
73+
}
74+
75+
observeNavElement(rule.id, element);
76+
}
77+
78+
function applyAllNavigationRules() {
79+
NAV_ELEMENTS.forEach(applyNavigationRule);
80+
}
81+
82+
function maintainNavigationVisibility() {
83+
if (typeof window === 'undefined' || typeof document === 'undefined') return;
84+
85+
applyAllNavigationRules();
86+
87+
if (navVisibilityGuardAttached) {
88+
return;
89+
}
90+
navVisibilityGuardAttached = true;
91+
92+
var queries = NAV_ELEMENTS
93+
.filter(function (rule) { return rule.minWidth; })
94+
.map(function (rule) { return '(min-width: ' + rule.minWidth + 'px)'; })
95+
.filter(function (query, index, self) { return self.indexOf(query) === index; });
96+
97+
function handleViewportChange() {
98+
applyAllNavigationRules();
99+
}
100+
101+
if (queries.length && typeof window.matchMedia === 'function') {
102+
queries.forEach(function (query) {
103+
var mediaQuery = window.matchMedia(query);
104+
if (typeof mediaQuery.addEventListener === 'function') {
105+
mediaQuery.addEventListener('change', handleViewportChange);
106+
} else if (typeof mediaQuery.addListener === 'function') {
107+
mediaQuery.addListener(handleViewportChange);
108+
}
109+
});
110+
} else {
111+
window.addEventListener('resize', handleViewportChange, { passive: true });
112+
}
113+
114+
if (typeof MutationObserver !== 'undefined') {
115+
NAV_ELEMENTS.forEach(function (rule) {
116+
var target = document.getElementById(rule.id);
117+
if (target) {
118+
var observer = new MutationObserver(handleViewportChange);
119+
observer.observe(target, { attributes: true, attributeFilter: ['class', 'style'] });
120+
}
121+
});
122+
123+
if (!navMutationObserver) {
124+
navMutationObserver = new MutationObserver(function () {
125+
applyAllNavigationRules();
126+
});
127+
128+
if (document.body) {
129+
navMutationObserver.observe(document.body, { childList: true, subtree: true });
130+
} else {
131+
document.addEventListener('DOMContentLoaded', function () {
132+
if (!navMutationObserver) return;
133+
navMutationObserver.observe(document.body, { childList: true, subtree: true });
134+
});
135+
}
136+
}
137+
}
138+
}
139+
9140
// Wait for DOM to be ready
10141
function initWidget() {
142+
maintainNavigationVisibility();
143+
144+
// Ensure the scoped widget stylesheet is loaded once
145+
if (!document.getElementById(WIDGET_STYLE_ID)) {
146+
var link = document.createElement('link');
147+
link.id = WIDGET_STYLE_ID;
148+
link.rel = 'stylesheet';
149+
link.href = WIDGET_STYLE_HREF;
150+
link.type = 'text/css';
151+
link.media = 'all';
152+
link.onerror = function (error) {
153+
console.error('Failed to load Knowrithm widget styles:', error);
154+
};
155+
156+
(document.head || document.body).appendChild(link);
157+
}
158+
11159
// Configure the widget BEFORE loading the script
12160
window.AIChatWidget = {
13161
agentId: "2b041b45-a585-47e9-abaf-ebaad766bce9",
@@ -40,7 +188,7 @@
40188
},
41189
assets: {
42190
scriptUrl: "https://app.knowrithm.org/api/widget.js",
43-
styleUrl: "https://minio.knowrithm.org/knowrithm-bucket/chat-widget.css"
191+
styleUrl: WIDGET_STYLE_HREF
44192
}
45193
};
46194

docs.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"theme": "mint",
44
"name": "Knowrithm Documentation",
55
"colors": {
6-
"primary": "#6366f1",
7-
"light": "#818cf8",
8-
"dark": "#4f46e5"
6+
"primary": "#0ea5e9",
7+
"light": "#38bdf8",
8+
"dark": "#0369a1"
99
},
1010
"favicon": "/favicon.svg",
1111
"navigation": {
@@ -107,4 +107,4 @@
107107
"linkedin": "https://www.linkedin.com/company/knowrithm"
108108
}
109109
}
110-
}
110+
}

site.html

Lines changed: 763 additions & 0 deletions
Large diffs are not rendered by default.

styles/chat-widget-custom.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@
149149
word-wrap: break-word;
150150
}
151151

152+
/* Ensure bot responses have high-contrast body text */
153+
.ai-chat-widget-message:not(.user) .ai-chat-widget-message-content {
154+
color: #1A1A1A;
155+
}
156+
152157
.ai-chat-widget-message.user .ai-chat-widget-message-content {
153158
background: var(--widget-primary-color);
154159
color: white;
@@ -277,4 +282,4 @@
277282

278283
/* NOTE: The generic ".button" selector from the original widget CSS has been removed to avoid overriding site-wide button styles. */
279284

280-
/* End of custom widget CSS */
285+
/* End of custom widget CSS */

styles/global.css

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,53 @@ a[class*="button"] {
142142
display: inline-flex !important;
143143
align-items: center !important;
144144
justify-content: center !important;
145-
}
145+
}
146+
147+
/* ============================================
148+
Chat Widget Overrides
149+
============================================ */
150+
.ai-chat-widget {
151+
z-index: 60 !important;
152+
}
153+
154+
.ai-chat-widget .ai-chat-message.assistant .ai-chat-message-content,
155+
.ai-chat-widget .ai-chat-message.assistant .ai-chat-message-content :is(p, li, span, strong, em, a, code, ul, ol) {
156+
color: #1A1A1A !important;
157+
}
158+
159+
@media (min-width: 1024px) {
160+
#sidebar {
161+
display: block !important;
162+
visibility: visible !important;
163+
opacity: 1 !important;
164+
pointer-events: auto !important;
165+
z-index: 80 !important;
166+
}
167+
}
168+
169+
#navbar {
170+
display: block !important;
171+
visibility: visible !important;
172+
opacity: 1 !important;
173+
pointer-events: auto !important;
174+
z-index: 90 !important;
175+
}
176+
177+
@media (min-width: 1280px) {
178+
#content-side-layout,
179+
#table-of-contents-layout {
180+
display: flex !important;
181+
visibility: visible !important;
182+
opacity: 1 !important;
183+
pointer-events: auto !important;
184+
z-index: 70 !important;
185+
}
186+
187+
#table-of-contents {
188+
display: block !important;
189+
visibility: visible !important;
190+
opacity: 1 !important;
191+
pointer-events: auto !important;
192+
z-index: 70 !important;
193+
}
194+
}

temp_docsjson.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"theme": "mint",
44
"name": "knowrithm-docs",
55
"colors": {
6-
"primary": "#16A34A",
7-
"light": "#07C983",
8-
"dark": "#15803D"
6+
"primary": "#0ea5e9",
7+
"light": "#38bdf8",
8+
"dark": "#0369a1"
99
},
1010
"favicon": "/favicon.svg",
1111
"navigation": {

0 commit comments

Comments
 (0)