$(function(){
$('.search .close').on('click',function(){
$('.search').removeClass('open');
});
$('#keywords').on('focus',function(){
$('.keywordsBox').slideDown(200);
});
$(".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-icon,.searchbox .show-1024').on('click',function(){
$('.searchbox').addClass('open');
$(document).on("click", checkClickElement)
function checkClickElement(event){
if(!$(event.target).closest(".searchbox").length > 0){
search_n=0;
$(".searchbox").removeClass("open")
$(document).off("click",checkClickElement)
}
}
$('.search input').focus();
});
$(".marquee").marquee();
//header跑馬燈
if(!sessionStorage.getItem("marquee") && $(".marquee-001").length > 0){
$(".marquee-001").removeClass("hide")
}
$(document).on("click", ".marquee-closer", function(){
sessionStorage.setItem("marquee", 1)
$(".marquee-001").remove()
})
$(".Select_This_Country").on("click","li,label",function(){
$.post('/tw/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;
/* 回頁首 */
$('.gotop').on('click',function(){
$("html,body").animate({scrollTop: 0},800);
});
//上方廣告
var button =0;
$('.top_adbox_button').on('click',function(){
if(_window.width() <= 1024){
$(".top_adbox").remove();
if(button == 1)button--;
}
else{
if(button==0){
$(".top_adbox").css('height', 'auto');
$('.top_adbox .fa').removeClass('fa-plus').addClass('fa-times');
$('.top_adbox .inner').stop().animate({'max-height': 800},1000,function(){
button++;
});
}else{
$('.top_adbox .fa').removeClass('fa-times').addClass('fa-plus');
$('.top_adbox .inner').stop().animate({'max-height': 0},1000,function(){
button--;
});
}
}
});
var change = 0;
noisePop();
/* 手機平板 */
if(_window.width() <= 1024){
//上方廣告
if($('.top_adbox').attr('tag-status') == '1'){
$('.top_adbox .fa').removeClass('fa-plus').addClass('fa-times');
$(".top_adbox").show();
};
//天邊會員登入
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');
}
});
//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');
$('.hall-content .wrapper').removeClass('open1');
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');
}
}).on(' click','.menu-item.big-title',function(){
var n = $(this).parent(".open1").length;
$('#menu-nav .menu-item').removeClass('open-sub');
$(this).parent(".hall-content .wrapper").removeClass('open1');
if(n == 0){
$(this).parent(".hall-content .wrapper").addClass('open1');
}
});
}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');
$('.hall-content .wrapper').removeClass('open1');
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');
}
}).on(' click','.menu-item.big-title',function(){
var n = $(this).parent(".open1").length;
$('#menu-nav .menu-item').removeClass('open-sub');
$(this).parent(".hall-content .wrapper").removeClass('open1');
if(n == 0){
$(this).parent(".hall-content .wrapper").addClass('open1');
}
});
}
}else{
//上方廣告
if($('.top_adbox').attr('tag-status') == '1'){
$(".top_adbox").show();
$(".top_adbox_button").trigger('click');
};
}
/* 手機 */
if(_window.width() <= 480 && change_1023 != 480){
change_1023 = 480;
body_padding = 50;
/* 平板 */
}else if(_window.width() > 480 && _window.width() <= 1024 && change_1023 != 1023){
change_1023 = 1023;
body_padding = 75;
body_padding_s = 50;
nav_item.find('.subitem').attr('type','checkbox');
/* 電腦 */
}else if(_window.width() > 1023 && 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(){
$('.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('/tw/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});
}
}
});
}
_window.on('scroll', function(event) {
var scrollTop = _window.scrollTop();
if(scrollTop>0){
$(".gotop").css("opacity","1");
$("body").addClass('is-sticky');
}else{
$(".gotop").css("opacity","0");
$("body").removeClass('is-sticky');
}
});
var time_id;
_window.on('resize',function(){
clearTimeout(time_id);
_window = $(window);
// noisePop();
if(_window.width() <= 1024 && change_1023 ==1200){
//上方廣告
$('.top_adbox .fa').removeClass('fa-plus').addClass('fa-times');
$('.top_adbox_button').on('click',function(){
$('.top_adbox').remove();
});
$('.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 != 1023){
change_1023 = 1023;
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() > 1023 && 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(){
$('.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('/tw/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});
}
}
});
}
});
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');
});
$("#Noise_Pop").on("click",".fa-times",function(e){
e.preventDefault();
$.ajax({
url:"/tw/ajax/ajax_get_noisePop.php",
type:"POST",
cache:false,
async:false,
data:{Type:'Cancel'},
error:function(d){
alert('網路連線過慢,網頁請重新整理');
},
success:function(d){
$("#Noise_Pop").remove();
}
});
});
//點擊率
$(".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:"/tw/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:"/tw/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",function(){
$.post('/tw/ajax/ajax_change_language.php', {Name: $(this).attr('sid')}, function(h){
window.location.reload();
}, 'html');
});
//貨到通知改為連至門市
$(document).on('click','.informForPorter',function(){
window.location.href = '/tw/'+$("#Website_Mall_ID").val()+'/store/';
});
//tag viewmore
$(".hashTags-viewmore").on("click", function(){
$(this).parents(".hashTags").removeClass("with-viewmore")
})
});
function errorbox(title,content,button){
var html='';
$('body').append(html);
$('body').on('click', '#popupBox .close', function(event) {
$('#popupBox').remove();
});
};
function noisePop(){
if($(window).width()>= 961){
nosise_animate = true;
var n = 30;//最大值
var r = Math.floor(Math.random()*n)+1;
setTimeout(function(){
$.ajax({
url:"/tw/ajax/ajax_get_noisePop.php",
type:"POST",
cache:false,
async:false,
data:{Type:'GET'},
success:function(d){
if(d){
$("#Noise_Pop").prepend(d);
setTimeout(function(){
$("#Noise_Pop .noise_box:last").remove();
},5000);
setTimeout(function(){
noisePop();
},r*1100);
}
}
});
},r*1000);
}
}
var _masonry_set = {
columnWidth: 15,
itemSelector: '.menu-item',
gutter: 20,
transitionDuration: 0
};
$('.nav-item').find('.item-subitembox .menu1-left').each(function() {
if ($(this).find('.menu-item').length <= 2) {
$(this).addClass('no-after');
}
})
$(window).resize(function() {
if ($(window).width() <= 1024) {
$('.nav-item').off('mouseenter');
$('.nav-item').find('.item-subitembox').each(function() {
$(this).removeAttr('style');
})
} else {
}
})
if ($(window).width() <= 1024) {
$('.nav-item').find('.item-subitembox').each(function() {
$(this).removeAttr('style');
})
} else {
}
$(".table-center").find(function(){
$(".menu_sub_a").parents(".subitembox").prevAll(".m-item-title").addClass("show-fa");
$(".menu_sub_a").parents(".subitembox").prevAll(".m-item-sub").addClass("show-fa");
})
$('main').on('click', '.club-aside', function(event) {
$('body').css('position','fixed');
});
$('main').on('click', '.close-m', function(event) {
$('body').removeAttr('style');
});
// ==========================================================
// search 功能
// ==========================================================
;(function($) {
$('#keywords').on('focus', function(e) {
const wrapper = $(this).parent('.search')
if(wrapper.find('.top_hot_keyword').length === 0) {
wrapper.append('')
}
}).on('blur', function(e) {
if(!$(this).val().length) {
$(this).parent('.search').find('.keywordsBox').remove()
$(this).parents('.searchbox').removeClass('in-focus')
}
}).on('keyup', function(e) {
})
})($)