Spaces:
Running
Running
openhands
commited on
Commit
·
7962903
1
Parent(s):
ee912b9
Use JavaScript to swap OpenHands logos based on dark mode
Browse files- Added logo_swap_script that uses MutationObserver to detect dark mode changes
- JavaScript directly sets display:none on the appropriate logo
- Simplified CSS to just remove filters from OpenHands logos
- More reliable than CSS attribute selectors on Plotly images
- app.py +46 -1
- content.py +6 -21
app.py
CHANGED
|
@@ -134,6 +134,51 @@ const tooltipInterval = setInterval(() => {
|
|
| 134 |
}, 200);
|
| 135 |
</script>
|
| 136 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
# --- Theme Definition ---
|
| 138 |
# Color scheme aligned with OpenHands brand (from openhands-ui/tokens.css)
|
| 139 |
# Primary: Yellow (#FFE165), Neutral: Grey scale, Accents: Green (#BCFF8C), Red (#FF684E)
|
|
@@ -261,7 +306,7 @@ logger.info("Creating Gradio application")
|
|
| 261 |
demo = gr.Blocks(
|
| 262 |
theme=theme,
|
| 263 |
css=final_css,
|
| 264 |
-
head=posthog_script + scroll_script + redirect_script + tooltip_script,
|
| 265 |
title="OpenHands Index",
|
| 266 |
)
|
| 267 |
|
|
|
|
| 134 |
}, 200);
|
| 135 |
</script>
|
| 136 |
"""
|
| 137 |
+
|
| 138 |
+
# JavaScript to swap OpenHands logos based on dark mode
|
| 139 |
+
logo_swap_script = """
|
| 140 |
+
<script>
|
| 141 |
+
function updateOpenHandsLogos() {
|
| 142 |
+
const isDark = document.body.classList.contains('dark');
|
| 143 |
+
|
| 144 |
+
// Find all Plotly chart images
|
| 145 |
+
const images = document.querySelectorAll('.js-plotly-plot image');
|
| 146 |
+
|
| 147 |
+
images.forEach(img => {
|
| 148 |
+
const href = img.getAttribute('href') || img.getAttribute('xlink:href') || '';
|
| 149 |
+
|
| 150 |
+
// Check if this is an OpenHands logo
|
| 151 |
+
if (href.includes('openhands=lightlogo')) {
|
| 152 |
+
// Light logo - show in light mode, hide in dark mode
|
| 153 |
+
img.style.display = isDark ? 'none' : '';
|
| 154 |
+
} else if (href.includes('openhands=darklogo')) {
|
| 155 |
+
// Dark logo - show in dark mode, hide in light mode
|
| 156 |
+
img.style.display = isDark ? '' : 'none';
|
| 157 |
+
}
|
| 158 |
+
});
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
// Run on page load
|
| 162 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 163 |
+
// Initial update after a short delay to let Plotly render
|
| 164 |
+
setTimeout(updateOpenHandsLogos, 500);
|
| 165 |
+
|
| 166 |
+
// Watch for dark mode changes using MutationObserver on body class
|
| 167 |
+
const observer = new MutationObserver((mutations) => {
|
| 168 |
+
mutations.forEach((mutation) => {
|
| 169 |
+
if (mutation.attributeName === 'class') {
|
| 170 |
+
updateOpenHandsLogos();
|
| 171 |
+
}
|
| 172 |
+
});
|
| 173 |
+
});
|
| 174 |
+
|
| 175 |
+
observer.observe(document.body, { attributes: true });
|
| 176 |
+
|
| 177 |
+
// Also periodically check for new charts being added
|
| 178 |
+
setInterval(updateOpenHandsLogos, 1000);
|
| 179 |
+
});
|
| 180 |
+
</script>
|
| 181 |
+
"""
|
| 182 |
# --- Theme Definition ---
|
| 183 |
# Color scheme aligned with OpenHands brand (from openhands-ui/tokens.css)
|
| 184 |
# Primary: Yellow (#FFE165), Neutral: Grey scale, Accents: Green (#BCFF8C), Red (#FF684E)
|
|
|
|
| 306 |
demo = gr.Blocks(
|
| 307 |
theme=theme,
|
| 308 |
css=final_css,
|
| 309 |
+
head=posthog_script + scroll_script + redirect_script + tooltip_script + logo_swap_script,
|
| 310 |
title="OpenHands Index",
|
| 311 |
)
|
| 312 |
|
content.py
CHANGED
|
@@ -1144,32 +1144,17 @@ h3 .header-link-icon {
|
|
| 1144 |
}
|
| 1145 |
|
| 1146 |
/* Re-invert all images so they display correctly (no glow) */
|
| 1147 |
-
/* Exclude OpenHands logos which are handled
|
| 1148 |
.dark .js-plotly-plot .layer-above image:not([href*="openhands="]):not([xlink\\:href*="openhands="]),
|
| 1149 |
.dark .js-plotly-plot .imagelayer image:not([href*="openhands="]):not([xlink\\:href*="openhands="]) {
|
| 1150 |
filter: invert(1) hue-rotate(180deg);
|
| 1151 |
}
|
| 1152 |
|
| 1153 |
-
/*
|
| 1154 |
-
.js-plotly-plot image[href*="openhands=
|
| 1155 |
-
.js-plotly-plot image[xlink\\:href*="openhands=
|
| 1156 |
-
|
| 1157 |
-
|
| 1158 |
-
|
| 1159 |
-
/* Dark mode: hide the light logo */
|
| 1160 |
-
.dark .js-plotly-plot .layer-above image[href*="openhands=lightlogo"],
|
| 1161 |
-
.dark .js-plotly-plot .layer-above image[xlink\\:href*="openhands=lightlogo"],
|
| 1162 |
-
.dark .js-plotly-plot .imagelayer image[href*="openhands=lightlogo"],
|
| 1163 |
-
.dark .js-plotly-plot .imagelayer image[xlink\\:href*="openhands=lightlogo"] {
|
| 1164 |
-
display: none !important;
|
| 1165 |
-
}
|
| 1166 |
-
|
| 1167 |
-
/* Dark mode: show the dark logo without any filter (it's already designed for dark backgrounds) */
|
| 1168 |
-
.dark .js-plotly-plot .layer-above image[href*="openhands=darklogo"],
|
| 1169 |
-
.dark .js-plotly-plot .layer-above image[xlink\\:href*="openhands=darklogo"],
|
| 1170 |
-
.dark .js-plotly-plot .imagelayer image[href*="openhands=darklogo"],
|
| 1171 |
-
.dark .js-plotly-plot .imagelayer image[xlink\\:href*="openhands=darklogo"] {
|
| 1172 |
-
display: block !important;
|
| 1173 |
filter: none !important;
|
| 1174 |
}
|
| 1175 |
|
|
|
|
| 1144 |
}
|
| 1145 |
|
| 1146 |
/* Re-invert all images so they display correctly (no glow) */
|
| 1147 |
+
/* Exclude OpenHands logos which are handled by JavaScript */
|
| 1148 |
.dark .js-plotly-plot .layer-above image:not([href*="openhands="]):not([xlink\\:href*="openhands="]),
|
| 1149 |
.dark .js-plotly-plot .imagelayer image:not([href*="openhands="]):not([xlink\\:href*="openhands="]) {
|
| 1150 |
filter: invert(1) hue-rotate(180deg);
|
| 1151 |
}
|
| 1152 |
|
| 1153 |
+
/* OpenHands logos: JavaScript handles visibility, CSS just removes any filters */
|
| 1154 |
+
.dark .js-plotly-plot .layer-above image[href*="openhands="],
|
| 1155 |
+
.dark .js-plotly-plot .layer-above image[xlink\\:href*="openhands="],
|
| 1156 |
+
.dark .js-plotly-plot .imagelayer image[href*="openhands="],
|
| 1157 |
+
.dark .js-plotly-plot .imagelayer image[xlink\\:href*="openhands="] {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1158 |
filter: none !important;
|
| 1159 |
}
|
| 1160 |
|