內沒有文字節點 (避免重複添加)
if ($this.text().trim() === "") {
$this.append('公告圖片');
}
});
$(".widget-link__widget-title").each(function () {
if ($(this).text().trim() === "") {
$(this).append('公告標題');
}
});
$(".sitemenu-title").each(function () {
if ($(this).text().trim() === "") {
$(this).append('次選單');
}
});
$(".annc-title").each(function () {
if ($(this).text().trim() === "") {
$(this).append('內頁公告標題');
}
});
$(".event-annc-title").each(function () {
if ($(this).text().trim() === "") {
$(this).append('內頁活動公告標題');
}
});
$(".show-title").each(function () {
if ($(this).text().trim() === "") {
$(this).append('內頁活動公告標題');
}
});
$(".w-annc__widget-title").each(function () {
if ($(this).text().trim() === "") {
$(this).append('公告標題');
}
});
$(".widget-title").each(function () {
if ($(this).text().trim() === "") {
$(this).append('網路資源標題');
}
});
$(".widget-title").each(function () {
if ($(this).text().trim() === "") {
$(this).append('網路資源標題');
}
});
$('input').each(function() {
var $this = $(this);
if (!$this.attr('title') || $this.attr('title').trim() === '') {
$this.attr('title', '網內搜尋');
}
});
$('.rucaptcha-image').each(function() {
var $button = $(this).next('button'); // 取得緊接在 .rucaptcha-image 之後的 button
if ($button.length && !$button.attr('aria-label')) {
$button.attr('aria-label', '播放驗證碼語音');
}
});
//有連結目的之所有a標籤加上aria-label和title
$('a').each(function () {
var $a = $(this);
var href = $a.attr('href');
if (!href) return;
var hasSrOnly = $a.find('.sr-only').length > 0;
// 若有 .sr-only,移除 aria-label 和 title 避免重複朗讀
if (hasSrOnly) {
$a.removeAttr('aria-label');
$a.removeAttr('title');
return; // 有 .sr-only 就不做其他處理
}
// ----- aria-label 邏輯 -----
if (!$a.attr('aria-label')) {
let ariaLabel = '';
// 加入開啟方式
if ($a.attr('target') === '_blank') {
ariaLabel += '在新視窗開啟 ';
} else if ($a.attr('target') === '_self') {
ariaLabel += '在本視窗開啟 ';
}
// 如果包含圖片且有圖片 title
if ($a.find('img').length) {
const imgTitle = $a.find('img').attr('title');
if (imgTitle) ariaLabel = imgTitle;
} else {
const text = $a.text().trim();
if (text) {
ariaLabel += text;
} else if ($a.children('span').length === 1) {
ariaLabel += $a.children('span').text().trim();
}
}
if (ariaLabel) {
$a.attr('aria-label', ariaLabel);
}
}
// ----- title 邏輯 -----
if (!$a.attr('title')) {
let titleStr = '';
if ($a.attr('target') === '_blank') {
titleStr += '在新視窗開啟 ';
} else if ($a.attr('target') === '_self') {
titleStr += '在本視窗開啟 ';
}
if ($a.find('img').length) {
titleStr = '這是一張照片';
} else {
const text = $a.text().trim();
if (text) {
titleStr += text;
} else if ($a.children('span').length === 1) {
titleStr += $a.children('span').text().trim();
}
}
if (titleStr) {
$a.attr('title', titleStr);
}
}
});
// 刪除banner-slide的空連結和空連結目標
for(var i=0;i<$('.w-ba-banner__slide a').length;i++){
if($('.w-ba-banner__slide a').eq(i).attr('href')=="")
$('.w-ba-banner__slide a').eq(i).removeAttr('href');
if($('.w-ba-banner__slide a').eq(i).attr('target') == "")
$('.w-ba-banner__slide a').eq(i).removeAttr('target');
};
// 幫無標題之iframe加上title
for(var i=0;i<$('iframe').length;i++)
if($('iframe').eq(i).attr('title')=="" || $('iframe').eq(i).attr('title')== undefined ){
if($('iframe').eq(i).attr('src').search('facebook') != -1 )
$('iframe').eq(i).attr('title','facebook');
else if($('iframe').eq(i).attr('src').search('google') != -1 )
$('iframe').eq(i).attr('title','google');
else if($('iframe').eq(i).attr('src').search('youtube') != -1 )
$('iframe').eq(i).attr('title','youtube');
else if($('iframe').eq(i).attr('src').search('twitframe') != -1 )
$('iframe').eq(i).attr('title','twitter');
else
$('iframe').eq(i).attr('title','unknown');
};
//button是空的就加上內容
$('button').each(function() {
var $this = $(this);
var titleText = $this.attr('title') || '';
// 檢查 button 是否是空的(沒有可見文字或子元素)
if ($this.text().trim() === '' && !$this.children().length && titleText) {
// 新增隱藏的 span,內容為 title
$this.append('' + titleText + '');
}
});
// 刪除空的檔案室
var archievelen = $('dd a.i-archive-files-item').length;
for(i=archievelen-1;i>=0;i--)
if($('dd a.i-archive-files-item').eq(i).html().trim()=="")
$('dd a.i-archive-files-item').eq(i).parent('dd').remove();
// 刪除具有空連結欄位的橫列
for(var i = 0;i < $('*[data-list] tr td a').length ; i++)
if($('*[data-list] tr td a').eq(i).html().trim()=="")
$('*[data-list] tr td a').eq(i).parent('td').parent('tr').remove();
// tab按鍵選到menu,會顯示下層的menu(為了符合無障礙)
$('.nav-level-0>li>a').focus(function(e) {
e.stopPropagation();
$(this).parent().focus();
if ($(this).parent().find('.nav-level-1').hasClass('show')) {
} else {
$('.nav-level-1').removeClass('show');
$(this).parent().find('.nav-level-1').addClass('show');
}
});
$('.nav-level-1>li>a').focus(function(e) {
e.stopPropagation();
if ($(this).parent().find('.nav-level-2').hasClass('show')) {
}else{
$('.nav-level-2').removeClass('show');
$(this).parent().find('.nav-level-2').addClass('show');
}
});
$('show').parent('li').focus();
}
forFreeGo();
//背景widget設定
if ( location.href.search('editmode=on') != -1 ) {
$('.background').css({'z-index': '0', 'position': 'relative'});
} else {
$('.background').css('z-index','-1');
};
//header banner setting
if ( location.href.search('editmode=on') != -1 ) {
$('.header-banner').css('z-index','2');
} else {
$('.header-banner').css({
'position': 'absolute',
'top': '0',
'z-index': '-2',
});
};
var url = window.location.search;
if (url == "?editmode=on") {
$('.tab_content').css({'position': 'relative','display':'block'});
}
//切換語言停留在同一頁
if(window.location.pathname!="/")
$("#en").attr("href",window.location.pathname.replace("zh_tw","en"))
//檔案室 下載檔案 hover 彈出備註訊息
$('[data-toggle="tooltip"]').tooltip()
//下載檔案格式dot pdf分色
$(".i-archive .label.label-primary").each(function() {
var downloadType = $(this).text();
$(this).addClass(downloadType);
})
//檔案室模組 Widget 手風琴
function extendPanelWidget() {
var len = $('.panel-title').length;
var i = -1;
if (len > 0) {
// 新增數字到要對應的panel按鈕id及href上面
for (i = 0; i < len; i++) {
$('.panel-title:eq(' + i + ') .collapsed').attr('href', '#collapse' + i);
$('.panel-collapse:eq(' + i + ')').attr('id', 'collapse' + i);
}
}
}
extendPanelWidget();
// member show tab scroll
$('.nav-pills').scrollingTabs({
scrollToTabEdge: true,
enableSwiping: true,
leftArrowContent: [
'',
'
'
].join(''),
rightArrowContent: [
'',
'
'
].join('')
});
}
$(document).ready(function () {
// 移除 onload 屬性
$('.rucaptcha-image').removeAttr('onload');
// 檢查是否已插入過
if (!$('#captcha_audio').length) {
const audioButton = $(`
`);
const audio = $('');
$('.rucaptcha-image').after(audioButton, audio);
}
});
$(document).ready(function () {
$('.searchbtn2').click(function (event) {
event.preventDefault(); // 防止預設行為
$(".searchbox").slideToggle(300, function () {
updateAriaExpanded();
});
$(this).closest('.ken-click').toggleClass('ken-click2');
});
let triggeredByFocus = false; //預留變數,用來處理「focus 觸發 click」的情況(目前未使用)
function updateAriaExpanded() {
const isVisible = $(".searchbox").is(":visible");
$(".searchbtn2").attr("aria-expanded", isVisible ? "true" : "false");
}
// 預設 aria-expanded 為 false
$(".searchbtn2").attr("aria-expanded", "false");
});
// 當文件物件模型(DOM)載入後,執行init函數
$(document).ready(function(){
$('#search'). attr('title', '另開新視窗');
$('button.fas.fa-volume-up').attr('aria-label', '播放驗證碼語音');
$('.i-annc__page-title').after($('.sitemenu-wrap2'));
$('.i-archive-title').after($('.sitemenu-wrap2'));
$('.page-module-title').after($('.sitemenu-wrap2'));
if ($(window).width() < 769) {
$('.modules-menu-level-0').after($('.header-nav'));
}else{
$('.orbit-bar-menu').after($('.header-nav'));
};
// $(".navbar-brand").append("Institute of Transportation, MOTC
");
/////////////fatfooter開關/////////////
/*-----------------------------------*/
$('.btn-fatfooter').click(function(e) {
$(this).parent('.container').find('nav>ul>li>ul').stop(true, true).slideToggle(function() {
if ($(this).is(':visible')) {
$('.btn-fatfooter').html("收合");
$('.btn-fatfooter').attr('name', '收合選單/CLOSE');
$('.btn-fatfooter').attr('aria-pressed', 'true');
} else {
$('.btn-fatfooter').html("展開");
$('.btn-fatfooter').attr('name', '展開選單/OPEN');
$('.btn-fatfooter').attr('aria-pressed', 'false');
}
});
$(this).stop(true, true).toggleClass('close');
});
$('.w-annc__widget-title>span>.nav_tabs_filter').before($('.kenItem'));
//RWD 自動縮放headerbannner
function headerH() {
if ($(window).width() < 769) {
var navH = $('.layout-header .navbar-header').outerHeight();
$('.orbit-bar-menu').css('height', navH );
}
}
headerH();
$(window).resize(function() {
headerH();
if ($(window).width() < 769) {
$('.modules-menu-level-0').after($('.header-nav'));
}else{
$('.orbit-bar-menu').after($('.header-nav'));
};
})
$(window).scroll(function() {
initdata1();
});
init();
});
$(document).ready(function () {
let isArranged = false; // 追蹤是否已經排列過
function arrangeInCircle(containerSelector, radius) {
const $items = $(containerSelector + ' > .sitemenu-item');
const total = $items.length;
$items.each(function (index) {
const angle = (2 * Math.PI / total) * index;
const x = radius * Math.cos(angle);
const y = radius * Math.sin(angle);
$(this).css({
position: 'absolute',
left: '50%',
top: '50%',
transform: `translate(-50%, -50%) translate(${x}px, ${y}px)`
});
});
}
function clearTransforms(containerSelector) {
$(containerSelector + ' > .sitemenu-item').removeAttr('style');
}
function handleResize() {
const containerSelector = '.sitemenu-horizontal-ken .sitemenu-list.level-1';
if (window.innerWidth > 767) {
if (!isArranged) {
arrangeInCircle(containerSelector, 220);
isArranged = true;
}
} else {
if (isArranged) {
clearTransforms(containerSelector);
isArranged = false;
}
}
}
// 初次執行
handleResize();
// 監聽視窗縮放
$(window).on('resize', function () {
handleResize();
});
});
//orbitbar無障礙
$(document).ready(function() {
const isEnglish = document.documentElement.lang === 'en';
if (isEnglish) {
$('.navbar-toggle').attr({
title: 'menu',
'aria-label': 'menu'
});
$('label[for="open-orbit-nav"]').attr({
title: 'Site search and language menu',
'aria-label': 'Site search and language menu'
});
$('.mobile-button').attr({
title: 'Language menu',
'aria-label': 'Language menu'
});
} else {
$('label[for="open-orbit-nav"]').attr({
title: '全站収尋及語言切換選單',
'aria-label': '全站収尋及語言切換選單'
});
$('.mobile-button').attr({
title: '語言切換選單',
'aria-label': '語言切換選單'
});
}
$('label[for="open-orbit-login"]').removeAttr('tabindex');
$('#orbit-bar').find('li').each(function() {
var $li = $(this);
// 如果 中没有 元素,则为 设置 tabindex="0"
if ($li.children('a').length === 0) {
$li.attr('tabindex', '0');
} else {
// 如果 中有 元素,则确保 有 tabindex="0"
$li.find('a').attr('tabindex', '0');
// 确保 不影响焦点管理,移除 的 tabindex
$li.removeAttr('tabindex');
// 如果 被聚焦,自动跳转到 元素
$li.on('focus', function() {
$(this).find('a').focus();
});
}
});
$('label[for="open-orbit-nav"]').attr('tabindex', '0');
// 当屏幕宽度小于 768px 时,将 .orbit-bar-search-sign-language 移动到