From 5b7edb446bf699c9d9328f04369acbcd78eb7227 Mon Sep 17 00:00:00 2001 From: ken Date: Thu, 20 Aug 2026 18:43:58 +0800 Subject: [PATCH] js --- assets/javascripts/app.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/assets/javascripts/app.js b/assets/javascripts/app.js index 4f2892f..07c5a43 100644 --- a/assets/javascripts/app.js +++ b/assets/javascripts/app.js @@ -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 = $(''); $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() {