Spaces:
Sleeping
Sleeping
Fix Home tab routing from family pages
Browse files
app.py
CHANGED
|
@@ -1049,25 +1049,47 @@ gradio-app,
|
|
| 1049 |
|
| 1050 |
APP_JS = """
|
| 1051 |
() => {
|
| 1052 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1053 |
const tab = event.target && event.target.closest
|
| 1054 |
-
? event.target.closest('[role="tab"], .tab-nav button, button')
|
| 1055 |
: null;
|
| 1056 |
-
if (!tab) {
|
| 1057 |
-
return;
|
| 1058 |
-
}
|
| 1059 |
-
const label = (tab.innerText || tab.textContent || "").trim();
|
| 1060 |
-
if (label !== "Home") {
|
| 1061 |
return;
|
| 1062 |
}
|
| 1063 |
-
|
| 1064 |
-
if (window.location.search || window.location.hash) {
|
| 1065 |
event.preventDefault();
|
| 1066 |
event.stopPropagation();
|
| 1067 |
-
|
|
|
|
|
|
|
|
|
|
| 1068 |
}
|
| 1069 |
};
|
| 1070 |
-
document.addEventListener("
|
|
|
|
| 1071 |
}
|
| 1072 |
"""
|
| 1073 |
|
|
|
|
| 1049 |
|
| 1050 |
APP_JS = """
|
| 1051 |
() => {
|
| 1052 |
+
const cleanHomeUrl = () => `${window.location.origin}${window.location.pathname}`;
|
| 1053 |
+
const normalizedLabels = (element) => {
|
| 1054 |
+
if (!element) {
|
| 1055 |
+
return [];
|
| 1056 |
+
}
|
| 1057 |
+
return [
|
| 1058 |
+
element.getAttribute("aria-label"),
|
| 1059 |
+
element.innerText,
|
| 1060 |
+
element.textContent,
|
| 1061 |
+
].map((value) => (value || "").replace(/\\s+/g, " ").trim().toLowerCase()).filter(Boolean);
|
| 1062 |
+
};
|
| 1063 |
+
const isHomeControl = (element) => {
|
| 1064 |
+
if (!element) {
|
| 1065 |
+
return false;
|
| 1066 |
+
}
|
| 1067 |
+
const labels = normalizedLabels(element);
|
| 1068 |
+
if (labels.includes("home")) {
|
| 1069 |
+
return true;
|
| 1070 |
+
}
|
| 1071 |
+
const href = element.getAttribute && element.getAttribute("href");
|
| 1072 |
+
return href === "/" || href === "./" || href === cleanHomeUrl();
|
| 1073 |
+
};
|
| 1074 |
+
const isFamilyView = () => Boolean(document.querySelector(".family-title-card, .record-grid"));
|
| 1075 |
+
const goHomeIfNeeded = (event) => {
|
| 1076 |
const tab = event.target && event.target.closest
|
| 1077 |
+
? event.target.closest('[role="tab"], .tab-nav button, button, a')
|
| 1078 |
: null;
|
| 1079 |
+
if (!isHomeControl(tab)) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1080 |
return;
|
| 1081 |
}
|
| 1082 |
+
if (window.location.search || window.location.hash || isFamilyView()) {
|
|
|
|
| 1083 |
event.preventDefault();
|
| 1084 |
event.stopPropagation();
|
| 1085 |
+
if (event.stopImmediatePropagation) {
|
| 1086 |
+
event.stopImmediatePropagation();
|
| 1087 |
+
}
|
| 1088 |
+
window.location.assign(cleanHomeUrl());
|
| 1089 |
}
|
| 1090 |
};
|
| 1091 |
+
document.addEventListener("pointerdown", goHomeIfNeeded, true);
|
| 1092 |
+
document.addEventListener("click", goHomeIfNeeded, true);
|
| 1093 |
}
|
| 1094 |
"""
|
| 1095 |
|