This commit is contained in:
ken 2026-08-20 18:43:58 +08:00
parent 2f4a1141da
commit 5b7edb446b
1 changed files with 12 additions and 10 deletions

View File

@ -3220,10 +3220,12 @@ $(document).ready(function () {
$(function() {
function fixOrbitBarLabelToButton() {
setTimeout(function() {
// ✅ 只在 RWD < 768px 時執行
if ($(window).width() >= 768) return;
var $label = $('label[for="open-orbit-nav"]');
if ($label.length === 0) return;
// ✅ 建立 button 取代 label
var $btn = $('<button></button>');
$btn.attr({
'type': 'button',
@ -3237,14 +3239,9 @@ $(function() {
});
$btn.html($label.html());
$btn.addClass($label.attr('class') || '');
// ✅ 複製原本 label 的樣式
$btn.attr('style', $label.attr('style') || '');
// ✅ 替換 label
$label.replaceWith($btn);
// ✅ 取得 checkbox 狀態同步 aria-expanded
var $checkbox = $('#open-orbit-nav');
function syncAriaExpanded() {
@ -3252,13 +3249,11 @@ $(function() {
$('#open-orbit-nav-btn').attr('aria-expanded', isChecked ? 'true' : 'false');
}
// ✅ button 點擊時觸發 checkbox toggle並同步 aria-expanded
$(document).on('click', '#open-orbit-nav-btn', function() {
$checkbox.prop('checked', !$checkbox.prop('checked'));
syncAriaExpanded();
});
// ✅ Enter / Space 鍵觸發
$(document).on('keydown', '#open-orbit-nav-btn', function(e) {
if (e.which === 13 || e.which === 32) {
e.preventDefault();
@ -3266,18 +3261,25 @@ $(function() {
}
});
// ✅ 監聽 checkbox 變化(可能有其他地方觸發)同步狀態
$checkbox.on('change', function() {
syncAriaExpanded();
});
// ✅ 初始化同步
syncAriaExpanded();
}, 500);
}
fixOrbitBarLabelToButton();
// ✅ resize 時若跨越 768 臨界點也重新判斷
var resizeTimer;
$(window).on('resize', function() {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(function() {
fixOrbitBarLabelToButton();
}, 200);
});
});
// 執行 member等高計算目前改用flexbox故mark掉 by ika 20160105
// $(window).load(function() {