');
THUMB_PIC = $(this).attr('src');
$('.gallery .lightbox img').attr('src', THUMB_PIC);
$('.gallery .lightbox').fadeIn();
$('.gallery .lightbox .galler_overlay').fadeIn();
PIC_INDEX = index;
e.preventDefault();
});
});
//計算當頁縮圖數量
var PIC_NUM = $('.gallery .thumbnail').length;
// 下一張 function
function NEXT_MOV() {
//pic_index+1 如果小於 圖片數量
if (PIC_INDEX + 1 < PIC_NUM) {
//PIC_INDEX = (PIC_INDEX + 1) % PIC_NUM;//取餘數
PIC_INDEX++; //pic_index ++
//if(PIC_INDEX >= PIC_NUM){PIC_INDEX=0;}
} else {
PIC_INDEX = 0; //如果等於或大於圖片數量 pic_index =0 ,跳到第一張
}
THUMB_PIC = $('.gallery .thumbnail img').eq(PIC_INDEX).attr('src');
THUMB_H3 = $('.gallery .thumbnail img').eq(PIC_INDEX).attr('alt');
$('.gallery .lightbox .caption').html(THUMB_H3);
$('.gallery .lightbox img').hide();
$('.gallery .lightbox img').fadeIn();
$('.gallery .lightbox img').attr('src', THUMB_PIC);
//放入燈箱 img src
}
$('.gallery .light_next').click(function (e) {
NEXT_MOV();
e.preventDefault();
});
// 上一張 function
function PREV_MOV() {
if (PIC_INDEX + 1 > 1) {
//pic_index+1 如果大於 1
//PIC_INDEX = (PIC_INDEX + 1) % PIC_NUM;//取餘數
PIC_INDEX--; //pic_index --
//if(PIC_INDEX >= PIC_NUM){PIC_INDEX=0;}
} else {
PIC_INDEX = PIC_NUM - 1; //如果等於或小於圖片數量 pic_index =圖片數量-1 ,跳到最後一張
}
//取縮圖 img src
THUMB_PIC = $('.gallery .thumbnail img').eq(PIC_INDEX).attr('src');
THUMB_H3 = $('.gallery .thumbnail img').eq(PIC_INDEX).attr('alt');
$('.gallery .lightbox .caption').html(THUMB_H3);
$('.gallery .lightbox img').hide();
$('.gallery .lightbox img').fadeIn();
$('.gallery .lightbox img').attr('src', THUMB_PIC);
//放入燈箱 img src
}
$('.gallery .light_prev').click(function (e) {
PREV_MOV();
e.preventDefault();
});
//左右按鍵移動
if ((lightbox_Status = true)) {
_body.keydown(function (e) {
if (e.keyCode == 37) {
PREV_MOV();
} else if (e.keyCode == 39) {
NEXT_MOV();
} else if (e.keyCode == 27) {
$('.gallery .lightbox').hide();
$('body').removeClass('noscroll');
}
});
}
/*-----------------------------------*/
////////////////多組Tab////////////////
/*-----------------------------------*/
var resizeTimer1;
_window.resize(function () {
clearTimeout(resizeTimer1);
resizeTimer1 = setTimeout(function () {
ww = _window.outerWidth();
tabSet();
}, 50);
});
function tabSet() {
$('.tabs').each(function () {
var _tab = $(this),
_tabItem = _tab.find('.tabItem'),
_tabItemA = _tabItem.children('a'),
_tabContent = _tab.find('.tabContent'),
tabwidth = _tab.width(),
tabItemHeight = _tabItem.outerHeight(),
tabContentHeight = _tab.find('.active').next().innerHeight(),
tiGap = 0,
tabItemLength = _tabItem.length,
tabItemWidth;
_tab.find('.active').next('.tabContent').show();
if (ww >= wwSmall) {
_tabContent.css('top', tabItemHeight);
_tab.height(tabContentHeight + tabItemHeight);
tabItemWidth = (tabwidth - (tabItemLength - 1) * tiGap) / tabItemLength;
_tabItem.width(tabItemWidth).css('margin-left', tiGap);
_tabItem.first().css('margin-left', 0);
_tabItem.last().css({ position: 'absolute', top: 0, right: 0 }).width(tabItemWidth);
} else {
_tab.css('height', 'auto');
_tabItem.width(tabwidth);
_tabItem.css('margin-left', 0).last().css('position', 'relative');
}
_tabItemA.focus(tabs);
_tabItemA.click(tabs);
function tabs(e) {
var _tabItemNow = $(this).parent(),
tvp = _tab.offset().top,
tabIndex = _tabItemNow.index() / 2,
scollDistance = tvp + tabItemHeight * tabIndex - hh;
_tabItem.removeClass('active');
_tabItemNow.addClass('active');
if (ww <= wwSmall) {
_tabItem.not('.active').next().slideUp();
_tabItemNow.next().slideDown();
$('html,body').stop(true, false).animate({ scrollTop: scollDistance });
} else {
_tabItem.not('.active').next().hide();
_tabItemNow.next().show();
tabContentHeight = _tabItemNow.next().innerHeight();
_tab.height(tabContentHeight + tabItemHeight);
}
e.preventDefault();
}
});
}
$('.tabs>.tabItem:first-child>a').trigger('click');
tabSet();
/*-----------------------------------*/
///////////////置頂go to top////////////
/*-----------------------------------*/
$('.scrollToTop').attr('role', 'button');
$(window).bind('scroll', function () {
if ($(this).scrollTop() > 200) {
$('.scrollToTop').fadeIn();
} else {
$('.scrollToTop').fadeOut();
}
});
/*-----------------------------------*/
/////click event to scroll to top//////
/*-----------------------------------*/
// $('.scrollToTop').click(function (e) {
// $('html, body').animate({ scrollTop: 0 }, 400, 'easeOutQuint');
// e.preventDefault();
// });
// $('.scrollToTop').keydown(function (e) {
// _body.find('a:first').focus();
// e.preventDefault();
// });
$('.scrollToTop').click(function (e) {
e.preventDefault();
$('html, body').animate({ scrollTop: 0 }, 400, 'easeOutQuint');
});
$('.scrollToTop').keydown(function (e) {
// 13 是 Enter,32 是 空白鍵
if (e.which === 13 || e.which === 32) {
e.preventDefault(); // 避免按下空白鍵時網頁往下捲動
$(this).click(); // 觸發上面的 click 事件
}
});
/*--------------------------------------------------------*/
/////設定img 在IE9+ SAFARI FIREFOX CHROME 可以object-fit/////
/*--------------------------------------------------------*/
var userAgent, ieReg, ie;
userAgent = window.navigator.userAgent;
ieReg = /msie|Trident.*rv[ :]*11\./gi;
ie = ieReg.test(userAgent);
if (ie) {
$('.img-container').each(function () {
var imgUrl = $(this).children('img').attr('src');
var $container = $(this);
$container.has('.none').addClass('ie-object-none');
$container.has('.none').css('backgroundImage', 'url(' + imgUrl + ')');
$container.has('.cover').addClass('ie-object-cover');
$container.has('.cover').css('backgroundImage', 'url(' + imgUrl + ')');
$container.has('.fill').addClass('ie-object-fill');
$container.has('.fill').css('backgroundImage', 'url(' + imgUrl + ')');
$container.has('.contain').addClass('ie-object-contain');
$container.has('.contain').css('backgroundImage', 'url(' + imgUrl + ')');
});
}
/*-----------------------------*/
/////form表單 placeholder隱藏/////
/*-----------------------------*/
$('input,textarea').focus(function () {
$(this).removeAttr('placeholder');
});
/*------------------------------------*/
/////form表單 單個檔案上傳+多個檔案上傳/////
/*------------------------------------*/
$(document).on('change', '.check_file', function () {
var names = [];
var length = $(this).get(0).files.length;
for (var i = 0; i < $(this).get(0).files.length; ++i) {
names.push($(this).get(0).files[i].name);
}
// $('input[name=file]').val(names);
if (length > 2) {
var fileName = names.join(', ');
$(this)
.closest('.upload_grp')
.find('.upload_file')
.attr('value', length + ' files selected');
} else {
$(this).closest('.upload_grp').find('.upload_file').attr('value', names);
}
});
// /*------------------------------------*/
// /////cp table 加上響應式table wrapper/////
// /*------------------------------------*/
// $('.cp table').each(function(index, el) {
// //判斷沒有table_list
// if ($(this).parents('.table_list').length == 0) {
// $(this).wrap('
')
// }
// });
/*------------------------------------*/
//////////分享按鈕 share dropdwon////////
/*------------------------------------*/
// $('.function_panel .share').children('ul').hide();
// $('.function_panel .share').prepend('
分享按鈕');
// var _shareButton = $('.shareButton');
// _shareButton.off().click(function (e) {
// $(this).siblings('ul').stop(true, true).slideToggle();
// e.preventDefault();
// });
// _shareButton.keyup(function (event) {
// $(this).siblings('ul').stop(true, true).slideDown();
// });
// $('.function_panel .share')
// .find('li:last>a')
// .focusout(function (event) {
// $(this).parent().parent('ul').hide();
// });
// // 點外面關閉share
// $(document).on('touchend click', function (e) {
// var container = $('.function_panel .share');
// if (!container.is(e.target) && container.has(e.target).length === 0) {
// $('.share ul').hide();
// }
// });
/*------------------------------------*/
//////////分享按鈕 share dropdown (WCAG 加強版) ////////
/*------------------------------------*/
const $shareWrapper = $('.share');
const $shareUl = $shareWrapper.find('ul');
$shareUl.find('a').each(function () {
var $link = $(this);
var imgAlt = $link.find('img').attr('alt');
if (imgAlt) {
$link.attr('aria-label', '分享至 ' + imgAlt);
$link.find('img').attr('alt', '');
}
});
$shareUl.hide();
$shareWrapper.prepend('
分享按鈕');
const $shareBtn = $shareWrapper.find('.shareButton');
function toggleShareMenu(state) {
if (state === 'toggle') {
state = $shareUl.is(':hidden');
}
if (state) {
$shareUl.stop(true, true).slideDown(200);
$shareBtn.attr('aria-expanded', 'true');
} else {
$shareUl.stop(true, true).slideUp(200);
$shareBtn.attr('aria-expanded', 'false');
}
}
$shareBtn.on('click', function (e) {
e.preventDefault();
toggleShareMenu('toggle');
});
$shareWrapper.on('keydown', function (e) {
if (e.key === 'Escape') {
toggleShareMenu(false);
$shareBtn.focus();
}
});
$shareUl.find('li:last > a').on('blur', function () {
setTimeout(function () {
if (!$shareWrapper.find(':focus').length) {
toggleShareMenu(false);
}
}, 10);
});
$(document).on('click touchend', function (e) {
if (!$shareWrapper.is(e.target) && $shareWrapper.has(e.target).length === 0) {
toggleShareMenu(false);
}
});
/*------------------------------------*/
/////////////字型大小 font-size//////////
/*------------------------------------*/
// $('.font_size').find('.medium').addClass('active');
// $('.font_size')
// .find('.small')
// .click(function (e) {
// $(this).parent('li').siblings('li').find('a').removeClass('active');
// $('.main').removeClass('large_size').addClass('small_size');
// $(this).addClass('active');
// e.preventDefault();
// });
// $('.font_size')
// .find('.medium')
// .click(function (e) {
// $(this).parent('li').siblings('li').find('a').removeClass('active');
// $('.main').removeClass('large_size small_size');
// $(this).addClass('active');
// e.preventDefault();
// });
// $('.font_size')
// .find('.large')
// .click(function (e) {
// $(this).parent('li').siblings('li').find('a').removeClass('active');
// $('.main').removeClass('small_size').addClass('large_size');
// $(this).addClass('active');
// e.preventDefault();
// });
/*------------------------------------*/
/////////////字型大小 font-size//////////
/*------------------------------------*/
var $fontBtns = $('.font_size').find('a');
$fontBtns.attr('role', 'button');
$fontBtns.attr('aria-pressed', 'false');
$fontBtns.removeClass('active');
$('.font_size').find('.medium').addClass('active').attr('aria-pressed', 'true');
// 小字
$('.font_size')
.find('.small')
.click(function (e) {
e.preventDefault();
$(this).parent('li').siblings('li').find('a').removeClass('active').attr('aria-pressed', 'false');
$('.main').removeClass('large_size').addClass('small_size');
$(this).addClass('active').attr('aria-pressed', 'true');
});
// 中字
$('.font_size')
.find('.medium')
.click(function (e) {
e.preventDefault();
$(this).parent('li').siblings('li').find('a').removeClass('active').attr('aria-pressed', 'false');
$('.main').removeClass('large_size small_size');
$(this).addClass('active').attr('aria-pressed', 'true');
});
// 大字
$('.font_size')
.find('.large')
.click(function (e) {
e.preventDefault();
$(this).parent('li').siblings('li').find('a').removeClass('active').attr('aria-pressed', 'false');
$('.main').removeClass('small_size').addClass('large_size');
$(this).addClass('active').attr('aria-pressed', 'true');
});
$fontBtns.keydown(function (e) {
if (e.which === 13 || e.which === 32) {
// 13=Enter, 32=Space
e.preventDefault();
$(this).click();
}
});
/*-----------------------------------*/
/////////// category active //////////
/*-----------------------------------*/
$('.category')
.find('a')
.off()
.click(function (event) {
$(this).parent('li').siblings().find('a').removeClass('active');
$(this).addClass('active');
});
/*-----------------------------------*/
/////////// 無障礙快捷鍵盤組合 //////////
/*-----------------------------------*/
$(document).on('keydown', function (e) {
// alt+S 查詢
if (e.altKey && e.keyCode == 83) {
$('html, body').animate({ scrollTop: 0 }, 200, 'easeOutExpo');
$('.search').show();
$('.search').find('input[type="text"]').focus();
}
// alt+U header
if (e.altKey && e.keyCode == 85) {
$('html, body').animate({ scrollTop: 0 }, 200, 'easeOutExpo');
$('header').find('.accesskey').focus();
}
// alt+C 主要內容區
if (e.altKey && e.keyCode == 67) {
$('html, body')
.stop(true, true)
.animate({ scrollTop: $('.main').find('.accesskey').offset().top - 60 }, 800, 'easeOutExpo');
$('.main').find('.accesskey').focus();
}
// alt+Z footer
if (e.altKey && e.keyCode == 90) {
$('html, body')
.stop(true, true)
.animate({ scrollTop: $('footer').find('.accesskey').offset().top }, 800, 'easeOutExpo');
$('footer').find('.accesskey').focus();
}
if (e.keyCode == 27) {
_search.hide();
search_mode = false;
}
});
/*------------------------------------*/
/////gotoCenter on focus跳到 content/////
/*------------------------------------*/
// $('a.goCenter').keydown(function (e) {
// if (e.which == 13) {
// $('#aC').focus();
// $('html, body')
// .stop(true, true)
// .animate({ scrollTop: $('.main').find('.accesskey').offset().top }, 800, 'easeOutExpo');
// }
// });
/*------------------------------------*/
/////gotoCenter on focus跳到 content/////
/*------------------------------------*/
$('a.goCenter').on('click keydown', function (e) {
// 判斷:如果是鍵盤事件,確保按下的是 Enter(13) 或 空白鍵(32) 才執行
if (e.type === 'keydown' && e.which !== 13 && e.which !== 32) {
return;
}
e.preventDefault(); // 阻擋
標籤預設行為,避免畫面閃爍或亂跳
$('#aC').focus(); // 讓焦點移到主要內容區
// 執行滑動動畫
$('html, body')
.stop(true, true)
.animate({ scrollTop: $('.main').find('.accesskey').offset().top }, 800, 'easeOutExpo');
});
/*-----------------------------------*/
//////// 語言模組 無障礙遊走設定 ////////
/*-----------------------------------*/
$('.language').find('ul').hide();
var openLang = $('.language').children('a');
openLang.off().click(function (e) {
$(this).next('ul').stop(true, true).slideToggle();
e.preventDefault();
});
openLang.keyup(function () {
$(this).next('ul').stop(true, true).slideDown();
});
$('.language')
.find('ul li:last>a')
.focusout(function () {
$('.language').find('ul').hide();
});
$(document).on('touchend click', function (e) {
var target = e.target;
if (!$(target).is('.language a')) {
$('.language').find('ul').hide();
}
});
});