This commit is contained in:
ken 2026-07-21 15:41:02 +08:00
parent ee8c668bf7
commit 1f959a8eac
1 changed files with 45 additions and 0 deletions

View File

@ -3242,6 +3242,51 @@ $(function() {
closeMenu();
}
});
});
$(document).ready(function () {
var $searchBox = $('.search-box');
var $btn = $('.btn-search');
var $input = $('.input-search');
// 點擊按鈕展開/收合
$btn.on('click', function () {
var isExpanded = $btn.attr('aria-expanded') === 'true';
if (isExpanded) {
$btn.attr('aria-expanded', 'false');
$searchBox.removeClass('searching');
$input.blur();
} else {
$btn.attr('aria-expanded', 'true');
$searchBox.addClass('searching');
$input.focus();
}
});
// ✅ 監聽整個 search-box 的焦點進入(含 Tab 鍵進入 input
$searchBox.on('focusin', function () {
$btn.attr('aria-expanded', 'true');
$searchBox.addClass('searching');
});
// ✅ 監聽整個 search-box 的焦點離開
$searchBox.on('focusout', function () {
// 延遲確認焦點是否還在 search-box 內
setTimeout(function () {
if (!$searchBox.find(':focus').length) {
$btn.attr('aria-expanded', 'false');
$searchBox.removeClass('searching');
}
}, 150);
});
// Escape 收合並返回按鈕
$input.on('keydown', function (e) {
if (e.keyCode === 27) {
$btn.attr('aria-expanded', 'false');
$searchBox.removeClass('searching');
$btn.focus();
}
});
});
// 執行 member等高計算目前改用flexbox故mark掉 by ika 20160105
// $(window).load(function() {