search
This commit is contained in:
parent
ee8c668bf7
commit
1f959a8eac
|
|
@ -3242,6 +3242,51 @@ $(function() {
|
||||||
closeMenu();
|
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
|
// 執行 member等高計算,目前改用flexbox故mark掉 by ika 20160105
|
||||||
// $(window).load(function() {
|
// $(window).load(function() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue