Toya0421 commited on
Commit
30f9eea
·
verified ·
1 Parent(s): 82858c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -39
app.py CHANGED
@@ -659,42 +659,84 @@ def finish_or_retire(pages_json, current_page, pid, orig_lev, action, session_st
659
  # ======================================================
660
  # UI(タイトル表示を追加。それ以外は変更しない)
661
  # ★追加:パスワード付きログCSVダウンロード
662
- # ★追加:Group Radioの選択中ハイライトをJSで確実化
663
  # ======================================================
664
 
665
- # ★追加Group Radio専用ハイライトJS(DOM差を吸収して確実に効かせる
666
- radio_js = """
667
  () => {
668
  const root = document.getElementById("group_radio");
669
  if (!root) return;
670
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
671
  const update = () => {
672
- // labelを全て取得してクラスを外す(Gradioの構造差を吸収)
673
  const labels = root.querySelectorAll("label");
674
- labels.forEach(l => l.classList.remove("radio-selected"));
 
 
675
 
676
- // checkedなinputを探して、その親labelをハイライト
677
  const checked = root.querySelector('input[type="radio"]:checked');
678
- if (checked) {
679
- const label = checked.closest("label");
680
- if (label) label.classList.add("radio-selected");
681
- }
 
 
682
  };
683
 
684
- // 初期反映
685
  update();
686
 
687
- // 変更時反映
688
  root.addEventListener("change", update);
689
  root.addEventListener("click", update);
690
 
691
- // Gradioが描画を差し替える場合に備えて軽い再同期(短時間だけ)
692
  let n = 0;
693
  const t = setInterval(() => {
694
  update();
695
  n += 1;
696
- if (n >= 10) clearInterval(t); // 約2秒で停止
697
  }, 200);
 
 
 
 
 
 
698
  };
699
  """
700
 
@@ -826,30 +868,10 @@ custom_css = """
826
  }
827
  }
828
 
829
- /* ===============================
830
- ★追加:Group Radio の「選択中」を確実にハイライト(JSが付与するクラス)
831
- =============================== */
832
  #group_radio label {
833
- display: flex !important;
834
- align-items: center !important;
835
- gap: 10px !important;
836
- margin: 6px 0 !important;
837
- padding: 8px 10px !important;
838
- border-radius: 12px !important;
839
- }
840
-
841
- @media (prefers-color-scheme: light) {
842
- #group_radio label.radio-selected {
843
- background: #eef2ff !important;
844
- border: 2px solid #4f46e5 !important;
845
- }
846
- }
847
-
848
- @media (prefers-color-scheme: dark) {
849
- #group_radio label.radio-selected {
850
- background: #1f2937 !important;
851
- border: 2px solid #60a5fa !important;
852
- }
853
  }
854
  """
855
 
@@ -864,7 +886,7 @@ with gr.Blocks(css=custom_css, js=radio_js) as demo:
864
  choices=[("Group 1", 1), ("Group 2", 2)],
865
  label="実験グループを選択",
866
  value=2,
867
- elem_id="group_radio" # ★追加:CSS/JSで確実に狙うため
868
  )
869
 
870
  level_input = gr.Dropdown(
@@ -989,4 +1011,3 @@ with gr.Blocks(css=custom_css, js=radio_js) as demo:
989
 
990
  demo.queue(max_size=64)
991
  demo.launch()
992
-
 
659
  # ======================================================
660
  # UI(タイトル表示を追加。それ以外は変更しない)
661
  # ★追加:パスワード付きログCSVダウンロード
662
+ # ★改善Edgeでも確実に「Group選択中」が分かるようJSでstyle直当て
663
  # ======================================================
664
 
665
+ # ★差し替えEdgeでも確実に効くハイライトJS(style直書き
666
+ radio_js = r"""
667
  () => {
668
  const root = document.getElementById("group_radio");
669
  if (!root) return;
670
 
671
+ const getScheme = () => {
672
+ try {
673
+ return window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches
674
+ ? "dark" : "light";
675
+ } catch (e) {
676
+ return "light";
677
+ }
678
+ };
679
+
680
+ const clear = (labels) => {
681
+ labels.forEach(l => {
682
+ l.classList.remove("radio-selected");
683
+ l.style.background = "";
684
+ l.style.border = "";
685
+ l.style.boxShadow = "";
686
+ l.style.borderRadius = "";
687
+ l.style.padding = "";
688
+ });
689
+ };
690
+
691
+ const apply = (label) => {
692
+ const scheme = getScheme();
693
+ label.classList.add("radio-selected");
694
+
695
+ if (scheme === "dark") {
696
+ label.style.background = "#1f2937";
697
+ label.style.border = "2px solid #60a5fa";
698
+ label.style.boxShadow = "0 0 0 1px rgba(255,255,255,0.06) inset";
699
+ } else {
700
+ label.style.background = "#eef2ff";
701
+ label.style.border = "2px solid #4f46e5";
702
+ label.style.boxShadow = "0 0 0 1px rgba(0,0,0,0.04) inset";
703
+ }
704
+ label.style.borderRadius = "12px";
705
+ label.style.padding = "10px 12px";
706
+ };
707
+
708
  const update = () => {
 
709
  const labels = root.querySelectorAll("label");
710
+ if (!labels || labels.length === 0) return;
711
+
712
+ clear(labels);
713
 
 
714
  const checked = root.querySelector('input[type="radio"]:checked');
715
+ if (!checked) return;
716
+
717
+ const label = checked.closest("label");
718
+ if (!label) return;
719
+
720
+ apply(label);
721
  };
722
 
 
723
  update();
724
 
 
725
  root.addEventListener("change", update);
726
  root.addEventListener("click", update);
727
 
 
728
  let n = 0;
729
  const t = setInterval(() => {
730
  update();
731
  n += 1;
732
+ if (n >= 15) clearInterval(t);
733
  }, 200);
734
+
735
+ try {
736
+ const mq = window.matchMedia("(prefers-color-scheme: dark)");
737
+ mq.addEventListener?.("change", update);
738
+ mq.addListener?.(update);
739
+ } catch (e) {}
740
  };
741
  """
742
 
 
868
  }
869
  }
870
 
871
+ /* ★追加:Radio行が細くてハイライトが目立たない問題の保険(Edge向け) */
 
 
872
  #group_radio label {
873
+ width: 100% !important;
874
+ box-sizing: border-box !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
875
  }
876
  """
877
 
 
886
  choices=[("Group 1", 1), ("Group 2", 2)],
887
  label="実験グループを選択",
888
  value=2,
889
+ elem_id="group_radio" # ★追加:Edge確実に狙うため
890
  )
891
 
892
  level_input = gr.Dropdown(
 
1011
 
1012
  demo.queue(max_size=64)
1013
  demo.launch()