// 裝置判斷
function DeviceIsTouch() {
const userAgent = navigator.userAgent
const regexp = /Android|iPhone|SymbianOS|Windows Phone|iPad|iPod|Touch|Mobile|Tablet|BlackBerry/gi
return !!userAgent.match(regexp)
}
// 判斷裝置觸控情況
;(function($) {
$(window).on('resize', function(e) {
$('.breadcrumb-wrapper .with-child').removeClass('in-active')
if(DeviceIsTouch()) {
$('body').removeClass('DeviceWithHover')
} else {
$('body').addClass('DeviceWithHover')
}
})
})($)
// breadcrumb 下拉選單
;(function($) {
$('.breadcrumb-wrapper').on('click', '.with-child > .link', function(e) {
if(DeviceIsTouch()) {
e.preventDefault()
$(this).parent('.with-child').toggleClass('in-active')
.siblings('.with-child').removeClass('in-active')
}
})
$(window).on('resize', function(e) {
$('.breadcrumb-wrapper .breadcrumb-children').each(function(i, item) {
const itemLeft = $(item).parents('.item').offset().left
const itemWidth = $(item).parents('.item').width()
const childWidth = $(item).width()
if(itemLeft + childWidth >= $('.breadcrumb-wrapper').width()) {
if(itemLeft + itemWidth - childWidth > 0) {
$(item).parents('.with-child').removeClass('theme-center').addClass('theme-right')
} else {
$(item).parents('.with-child').addClass('theme-center').removeClass('theme-right')
}
} else {
$(item).parents('.with-child').removeClass('theme-right theme-center')
}
})
})
})($)
$(function(){
$('.search .closer').on('click',function(e){
$('.search').removeClass('open');
$('body').removeClass('overflow-hidden')
});
$('#keywords').on('focus',function(e){
$('.search').addClass('in-focus');
}).on('blur', function(e) {
$('.search').removeClass('in-focus');
});
$(".menu_class_a, .menu_sub_a").mouseover(function(){
var pic = $(this).attr('pic');
var url = $(this).attr('url');
var href = (url)? url: 'javascript:;';
var h = (pic)? '': '';
$(this).parents('.item-subitembox').find('.picbox').html(h);
});
$(".menu_sub_a").mouseout(function(){
var pic = $(this).parents('.nav-item').find('.menu_class_a').attr('pic');
var url = $(this).parents('.nav-item').find('.menu_class_a').attr('url');
var href = (url)? url: 'javascript:;';
var h = (pic)? '
': '';
$(this).parents('.nav-item').find('.item-subitembox').children('.picbox').html(h);
});
// //天邊=搜尋
$('.search-toggle').on('click',function(){
$('.search').toggleClass('open');
$('.search input').focus();
$('body').toggleClass('overflow-hidden')
});
$('.marquee').owlCarousel({
loop : true,
responsive:{
0:{
items : 1
},
1023:{
items : 1
}
},
autoplay:true,
autoplayTimeout:3000,
nav :false,
navText : ['',''],
dots: false,
});
$(".Select_This_Country").on("click","li,label, button",function(){
$.post('/ajax/ajax_change_country.php', {ID: $(this).attr('sid')}, function(h){
if (typeof updatePage == "function"){
updatePage();
return false;
}
if(h){
window.location.reload();
}
}, 'html');
});
var _window = $(window);
var _body = $('body');
var change_1023 = 0;
var nav_item =$('#menu-nav .nav-item');
var scroll_switch=true;
var body_padding = 121;
var body_padding_s = 40;
var userAgent = navigator.userAgent;
var change = 0;
/* 手機平板 */
if(_window.width() <= 1024){
//天邊會員登入
var member_click_n=0;
$('.shopbox span.fa-user').on('click',function(){
if(member_click_n==0){
member_click_n=1;
$('.userbox').addClass('open');
}else{
member_click_n=0;
$('.userbox').removeClass('open');
}
});
var language_click_n=0;
$('.language_t').on('click','.wrapper ',function(){
if(language_click_n==0){
language_click_n=1;
$('.language_t').addClass('open');
}else{
language_click_n=0;
$('.language_t').removeClass('open');
}
});
//天邊會員登入
var language_click_n=0;
$('#language').on('click','.wrapper ',function(){
if(language_click_n==0){
language_click_n=1;
$('#language').addClass('open');
}else{
language_click_n=0;
$('#language').removeClass('open');
}
});
//搜尋
var search_dom=$("#Top_Search"),
search_n=0;
search_dom.on('click', '.fa-search', function(event) {
if(search_n==0){
search_n=1;
search_dom.addClass('open');
}else{
search_n=0;
search_dom.removeClass('open');
}
});
//menu開合
$('#menu-nav .hover').removeClass('hover');
if(/Windows/i.test(userAgent)){
$('#menu-nav').on('click','.item-title',function(){
var n = $(this).parent(".open").length;
$('#menu-nav .nav-item').removeClass('open');
$('#menu-nav .menu-item').removeClass('open-sub');
if(n == 0){
$(this).parent(".nav-item").addClass('open');
}
}).on(' click','.subtitle',function(){
var n = $(this).parent(".open-sub").length;
$('#menu-nav .menu-item').removeClass('open-sub');
if(n == 0){
$(this).parent(".menu-item").addClass('open-sub');
}
});
}else{
$('#menu-nav').on('click','.item-title',function(){
var n = $(this).parent(".open").length;
$('#menu-nav .nav-item').removeClass('open');
$('#menu-nav .menu-item').removeClass('open-sub');
if(n == 0){
$(this).parent(".nav-item").addClass('open');
}
}).on(' click','.subtitle',function(){
var n = $(this).parent(".open-sub").length;
$('#menu-nav .menu-item').removeClass('open-sub');
if(n == 0){
$(this).parent(".menu-item").addClass('open-sub');
}
});
}
}
/* 手機 */
if(_window.width() <= 480 && change_1023 != 480){
change_1023 = 480;
body_padding = 50;
/* 平板 */
}else if(_window.width() > 480 && _window.width() <= 1024 && change_1023 != 1024){
change_1023 = 1024;
body_padding = 75;
body_padding_s = 50;
nav_item.find('.subitem').attr('type','checkbox');
/* 電腦 */
}else if(_window.width() > 1024 && change_1023 != 1200){
change_1023 = 1200;
body_padding = 121;
body_padding_s = 40;
$('.menu-002 .menu-item:nth-child(2)').addClass('hover');
$('.menu-002').on('mouseenter','.subtitle',function(){
// console.log($('menu-item .hover'));
$('.menu-002').find('.hover').removeClass('hover');
$(this).parents('.menu-item').addClass('hover');
}).on('mouseleave',function(){
$('.menu-002').find('.hover').removeClass('hover');
$('.menu-002 .menu-item:nth-child(2)').addClass('hover');
});
//天邊會員登入hover下拉
$('.shopbox span.fa-user').on('mouseenter',function(){
$('.userbox').addClass('open');
});
//天邊購物車hover下拉
$('.shopbox #Shop_Cart_Total').on('mouseenter',function(){
$("#Header_Shopcart").load('/ajax/ajax_get_cart.php','');
$('.shopping-cartbox').addClass('open');
});
$('.shopbox').on('mouseleave',function(){
var _this_user=$(this).find('.userbox'),
_this_shop=$(this).find('.shopping-cartbox');
if(_this_user.length==1){
$('.userbox').removeClass('open');
}else if(_this_shop.length==1){
$('.shopping-cartbox').removeClass('open');
}
});
//hover menu-item change subitem height
$('#menu-nav .nav-item').hover(function(){
var subitemboxheight = $(this).find('.menu-002 .hover .subitembox').outerHeight();
if($(this).has('hover')){
if(subitemboxheight>340){
$(this).find('.menu-002').css({'min-height':subitemboxheight+1});
}
}
},function(){
$('.menu-002').removeAttr('style');
});
$('#menu-nav .menu-002 .menu-item').hover(function(){
if($(this).hasClass('hover')){
var subitemboxheight = $(this).find('.subitembox').outerHeight();
if(subitemboxheight>340){
$(this).parents('.menu-002').css({'min-height':subitemboxheight+1});
}
}
});
}
var time_id;
_window.on('resize',function(){
clearTimeout(time_id);
_window = $(window);
if(_window.width() <= 1024 && change_1023 ==1200){
// //上方廣告
$('.search').removeAttr('style');
$('.shopbox span.fa-user,.shopbox .fa-shopping-cart').off('mouseenter');
//天邊會員登入
var member_click_n=0;
$('.shopbox span.fa-user').on('click',function(){
if(member_click_n==0){
member_click_n=1;
$('.userbox').addClass('open');
}else{
member_click_n=0;
$('.userbox,.shopping-cartbox').removeClass('open');
}
});
$('.shopbox').off('mouseleave');
//off submenu-item 自動調整高度
$('#menu-nav .nav-item').off('hover');
$('#menu-nav .menu-002 .menu-item').off('hover');
$('#menu-nav .menu-item .hover').removeClass('hover');
//menu開合
// console.log(_window.width());
if(/Windows/i.test(userAgent)){
$('#menu-nav').on('click','.item-title',function(){
var n = $(this).parent(".open").length;
$('#menu-nav .nav-item').removeClass('open');
$('#menu-nav .menu-item').removeClass('open-sub');
if(n == 0){
$(this).parent(".nav-item").addClass('open');
}
}).on(' click','.subtitle',function(){
var n = $(this).parent(".open-sub").length;
$('#menu-nav .menu-item').removeClass('open-sub');
if(n == 0){
$(this).parent(".menu-item").addClass('open-sub');
}
});
}else{
$('#menu-nav').on('click','.item-title',function(){
var n = $(this).parent(".open").length;
$('#menu-nav .nav-item').removeClass('open');
$('#menu-nav .menu-item').removeClass('open-sub');
if(n == 0){
$(this).parent(".nav-item").addClass('open');
}
}).on(' click','.subtitle',function(){
var n = $(this).parent(".open-sub").length;
$('#menu-nav .menu-item').removeClass('open-sub');
if(n == 0){
$(this).parent(".menu-item").addClass('open-sub');
}
});
}
}
if(_window.width() <= 480 && change_1023 != 480){
change_1023 = 480;
body_padding = 50;
var scrollTop = _window.scrollTop();
}else if(_window.width() > 480 && _window.width() <= 1024 && change_1023 != 1024){
change_1023 = 1024;
body_padding = 75;
body_padding_s = 50;
var scrollTop = _window.scrollTop();
nav_item.find('.subitem').attr('type','checkbox');
$('.menu-item .subtitle').off('mouseenter');
$('.menu-002').off('mouseleave');
}else if(_window.width() > 1024 && change_1023 != 1200){
change_1023 = 1200;
body_padding = 121;
body_padding_s = 40;
var scrollTop = _window.scrollTop();
nav_item.find('.subitem').attr('type','radio');
$('.menu-002 .menu-item:nth-child(2)').addClass('hover');
$('.menu-item .subtitle').on('mouseenter',function(){
//console.log($('menu-item .hover'));
$('.menu-item.hover').removeClass('hover');
$(this).parents('.menu-item').addClass('hover');
});
$('.menu-002').on('mouseleave',function(){
$('.menu-item.hover').removeClass('hover');
$('.menu-002 .menu-item:nth-child(2)').addClass('hover');
});
$('.shopbox span.fa-user').off('click');
//天邊會員登入
$('.shopbox span.fa-user').on('mouseenter',function(){
$('.userbox').addClass('open');
});
//天邊購物車hover下拉
$('.shopbox .fa-shopping-cart').on('mouseenter',function(){
$("#Header_Shopcart").load('/ajax/ajax_get_cart.php','');
$('.shopping-cartbox').addClass('open');
});
$('.shopbox').on('mouseleave',function(){
$('.userbox,.shopping-cartbox').removeClass('open');
});
//移除menu開合事件
$('#menu-nav').off('click','.item-title').off('click','.subtitle');
//hover menu-item subitem 自動調整高度
$('#menu-nav .nav-item').hover(function(){
var subitemboxheight = $(this).find('.menu-002 .hover .subitembox').outerHeight();
if($(this).has('hover')){
if(subitemboxheight>340){
$(this).find('.menu-002').css({'min-height':subitemboxheight+1});
}
}
},function(){
$('.menu-002').removeAttr('style');
});
$('#menu-nav .menu-002 .menu-item').hover(function(){
if($(this).hasClass('hover')){
var subitemboxheight = $(this).find('.subitembox').outerHeight();
if(subitemboxheight>340){
$(this).parents('.menu-002').css({'min-height':subitemboxheight+1});
}
}
});
}
});
// ==========================================================
// 搜尋區點擊其他地方或下方空白(手機版)關閉
// ==========================================================
$(document).on("click",function(e){
if(!($(".search").is(e.target)) && !($(".search").has(e.target).length)){
if(!$(".search-group").has(e.target).length && $(".search.open").length > 0){
$('.search').removeClass('open')
$('body').removeClass('overflow-hidden')
}
}
})
$(".search-hide").on("click", function(){
$('.search').removeClass('open')
$('body').removeClass('overflow-hidden')
})
// ==========================================================
// 頁首次選單會員功能區塊
// ==========================================================
let resizeStep = '';
_window.on('resize', function(e) {
if($(this).width() > 1024 && resizeStep !== 'desktop') {
resizeStep = 'desktop';
let target = $('.member-group');
target
.removeClass('in-active')
//.off('click')
.on('mouseenter', function(e) {
target.addClass('in-active')
})
.on('mouseleave', function(e) {
target.removeClass('in-active')
})
.on('click', '.member-toggle', function(e) {
location.href = '/member-myaccount';
});
} else if($(this).width() <= 1024 && resizeStep !== 'mobile') {
resizeStep = 'mobile';
let clickStep = 0;
let target = $('.member-group');
target
.removeClass('in-active')
.off('mouseenter mouseleave')
.on('click', '.member-toggle', function(e) {
clickStep += 1;
if(clickStep % 2) {
target.addClass('in-active')
} else {
target.removeClass('in-active')
}
});
}
})
// var nav_n = false;
// $('.menu-b').on('click',function(){
// if(!nav_n){
// nav_n = true;
// $(this).addClass('close');
// $('.nav-bg,.navBox').addClass('open-nav');
// $('body').addClass('overflow-hidden');
// }else{
// nav_n = false;
// $(this).removeClass('close');
// $('.nav-bg,.navBox').removeClass('open-nav');
// $('body').removeClass('overflow-hidden');
// }
// });
// $('.nav-bg').on('click',function(){
// nav_n = false;
// $('.menu-b').removeClass('close');
// $('.nav-bg,.navBox').removeClass('open-nav');
// $('body').removeClass('overflow-hidden');
// });
$('.footer_menu').on('click','.menu-item',function(){
$(this).addClass('open');
});
$('.footer_menu').on('click','.open',function(){
$(this).removeClass('open');
});
//點擊率
$(".HITS_BT").on("click",function(e){
e.preventDefault();
if( $.isNumeric($(this).attr('hid')) && $.isNumeric($(this).attr('hdid')) ){
var hid = $(this).attr('hid');
var hdid = $(this).attr('hdid');
var url = $(this).attr('href');
var target = $(this).attr('target');
$.ajax({
url:"/ajax/ajax_add_ad_hits-p.php",
type:"POST",
cache:false,
async:false,
data:{Hid: hid , Hdid : hdid},
error:function(d){
alert('網路連線過慢,網頁請重新整理');
},
success:function(d){
if(url){
if(target == '_blank'){
window.open(url);
}else if( ( typeof target === 'undefined' ) || (target == '') ){
window.location = url;
}else{
}
}
}
});
}else{
alert(_jsLang.這是錯誤的連結);
}
});
//讚數加減
$(".Thumbs_BT").on("click",function(e){
e.preventDefault();
if( $.isNumeric($(this).attr('pdid')) ){
var h = $(this);
var ID = h.attr('pdid');
var Type = (h.attr('tbup')==1)?'Sub':'Add';
$.ajax({
url:"/ajax/ajax_add_thumbs-p.php",
type:"POST",
cache:false,
async:false,
dataType:"json",
data:{Type: Type , ID : ID},
error:function(d){
alert('網路連線過慢,網頁請重新整理');
},
success:function(d){
if(d.Thumbs_Up=='1'){
$('.content').find('.Thumbs'+ID).attr('tbup','1');
$('.content').find('.Thumbs'+ID).find('.Thumbs_icon').removeClass('fa-thumbs-o-up');
$('.content').find('.Thumbs'+ID).find('.Thumbs_icon').addClass('fa-thumbs-up');
}else{
$('.content').find('.Thumbs'+ID).attr('tbup','0');
$('.content').find('.Thumbs'+ID).find('.Thumbs_icon').removeClass('fa-thumbs-up');
$('.content').find('.Thumbs'+ID).find('.Thumbs_icon').addClass('fa-thumbs-o-up');
}
$('.content').find('.Thumbs'+ID).find('.Thumbs_Num').html(d.Thumbs_Num);
}
});
}else{
alert(_jsLang.這是錯誤的連結);
}
});
//點擊清空輸入框
$(".CLEAR_INPUT").one("click", function(){
$(this).attr('placeholder','');
});
//語系選擇
$(".Select_This_Lang").on("click","li,label,button",function(){
$.post('/ajax/ajax_change_language.php', {Name: $(this).attr('sid')}, function(h){
window.location.reload();
}, 'html');
});
//貨到通知改為連至門市
$(document).on('click','.informForPorter',function(){
window.location.href = '/store/';
});
// ==========================================================
// 商品相關折疊區塊
// ==========================================================
$('.collapse-list').on('click', '.collapse-list-toggle', function(e) {
$(this).parent('.collapse-list-item').toggleClass('in-active');
});
// ==========================================================
// .tag-list 按鈕滑過顏色變化
// ==========================================================
$('.tag-list .tag-list-item').each(function(i) {
const baseBackground = $(this).css('background-color');
const baseBorder = $(this).css('border-color');
const baseColor = $(this).css('color');
$(this).on('mouseenter', function(e) {
$(this).animate({
backgroundColor: baseBorder,
color:baseBackground
}, 250)
})
.on('mouseleave', function(e) {
console.log('moseleave')
$(this).animate({
backgroundColor: baseBackground,
color:baseColor
}, 150)
})
})
// ==========================================================
// 取得夥伴計畫分享連結
// ==========================================================
var shareOpened = false
$(document).on("click", ".getshare-btn", function(){
$.ajax({
url:"/ajax/ajax_get_referral_code.php",
type:"POST",
cache:false,
async:false,
dataType:"json",
data:{},
error:function(res){
alert('網路連線過慢,網頁請重新整理');
},
success:function(res){
if(!res.status){
switch(res.msg){
case "NO_LOGIN":
alert("請先登入")
break;
case "NO_REVENT":
alert("推薦碼錯誤")
break;
case "ERROR":
default:
alert("網路連線過慢,網頁請重新整理");
}
}else{
let sharePopup = $(".getshare-popup")
sharePopup.addClass("in-active")
if(!shareOpened){
shareOpened = true
//將連結刷新
let link = location.protocol + "//" + location.host + location.pathname + "?Referral_Code=" + res.msg
$(".getshare-copylink").text(link)
$(".getshare-social-fb").attr("href","https://www.facebook.com/sharer.php?u=" + link)
$(".getshare-social-line").attr("href","https://line.naver.jp/R/msg/text/?" + link)
//關閉按鈕
$(document).on("click", ".getshare-close", function(){
sharePopup.removeClass("in-active")
})
//黑背景關閉
$(document).on("click", ".getshare-popup", function(e){
if($(e.target).hasClass("getshare-popup")){
sharePopup.removeClass("in-active")
}
})
//點選複製
$(document).on("click", ".getshare-copylink", function(e){
window.navigator.clipboard.writeText($(this).text())
alert("複製成功")
})
}
}
}
})
})
//關閉抽獎提示
$(document).on("click", ".float-lottery-closer", function(){
$.ajax({
url:"/ajax/ajax_close_lottery_ad.php",
type:"POST",
cache:false,
async:false,
dataType:"json",
data:{},
error:function(res){
alert('網路連線過慢,網頁請重新整理');
},
success:function(res){
if(res.status == 'OK'){
$(".float-lottery-btn").remove()
}
}
})
})
_window.trigger('resize')
});
function errorbox(title,content,button){
var html='