This commit is contained in:
parent
eff1fde007
commit
949b3b864a
|
|
@ -3631,5 +3631,45 @@ function fixGoogleMapIframeTitle(){
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
fixGoogleMapIframeTitle();
|
fixGoogleMapIframeTitle();
|
||||||
});
|
});
|
||||||
|
$(function() {
|
||||||
|
// 點擊/Enter/Space 按鈕:獨立切換子選單展開狀態,不影響上方連結的跳轉行為
|
||||||
|
$(document).on('click', '#main-nav .submenu-toggle', function(e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
var $btn = $(this);
|
||||||
|
var $li = $btn.closest('li');
|
||||||
|
var expanded = $btn.attr('aria-expanded') === 'true';
|
||||||
|
|
||||||
|
$btn.attr('aria-expanded', String(!expanded));
|
||||||
|
$li.toggleClass('submenu-open', !expanded);
|
||||||
|
// 這裡同步你原本用來顯示/隱藏子選單的 class 或邏輯
|
||||||
|
});
|
||||||
|
|
||||||
|
// 鍵盤焦點移入連結時,維持原本的自動展開行為(方便直接 Tab 進子選單)
|
||||||
|
$(document).on('focusin', '#main-nav li', function() {
|
||||||
|
var $li = $(this);
|
||||||
|
var $btn = $li.children('.submenu-toggle').first();
|
||||||
|
if ($btn.length) {
|
||||||
|
$btn.attr('aria-expanded', 'true');
|
||||||
|
$li.addClass('submenu-open');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).on('focusout', '#main-nav li', function() {
|
||||||
|
var $li = this;
|
||||||
|
setTimeout(function() {
|
||||||
|
if (!$.contains($li, document.activeElement) && document.activeElement !== $li) {
|
||||||
|
var $btn = $($li).children('.submenu-toggle').first();
|
||||||
|
if ($btn.length) {
|
||||||
|
$btn.attr('aria-expanded', 'false');
|
||||||
|
$($li).removeClass('submenu-open');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}(jQuery, window));
|
}(jQuery, window));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue