// ==========================================================
// 重設 baike 定位值
// ==========================================================
;(function ($) {
$('.navBox').on('click', '.menu_class_a', function (e) {
const menuLink = $(this).attr('href')
if (menuLink === '/baike/') {
sessionStorage.setItem('baikeOffset', 0)
}
})
})($)
$(function () {
/*後端*/
$(".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);
});
$(".marquee").marquee();
$("#Select_This_Country").on("click", "li", function () {
$.post('/ajax/ajax_change_country.php', {ID: $(this).attr('sid')}, function (h) {
if (typeof updatePage == "function") {
updatePage();
return false;
}
if (h) {
//$("#This_Country_Pic").attr("src","/upload_files/fonlego-rwd/website/"+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;
// scroll_switch=nav_censor(scroll_switch);
var body_padding = 121;
var body_padding_s = 40;
var userAgent = navigator.userAgent;
/* 網頁loading */
// _window.on('load',function(){
// $(".loading").hide();
// });
/* 回頁首 */
$('.gotop').on('click', function () {
$("#wrapper").animate({scrollTop: 0}, 800);
});
//上方廣告
var button = 0;
$('.top_adbox_button').on('click', function () {
if (_window.width() <= 1023) {
$(".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();
$(".heartList").owlCarousel({
nav: true,
responsive: {
0: {
items: 3
},
768: {
items: 4
},
1024: {
items: 6
}
},
});
/* 手機平板 */
if (_window.width() <= 1024) {
//上方廣告
if ($('.top_adbox').attr('tag-status') == '1') {
$('.top_adbox .fa').removeClass('fa-plus').addClass('fa-times');
$(".top_adbox").show().find('.inner').css('max-height', 800)
}
;
//menu開合
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');
}
});
}
} 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() <= 1023 && 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 () {
// 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});
}
}
});
}
$('#wrapper').on('scroll', function (event) {
var scrollTop = $('#wrapper').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);
// time_id = setTimeout(nav_censor(scroll_switch),500);
_window = $(window);
// noisePop();
if (_window.width() <= 1023 && change_1023 == 1200) {
//上方廣告
$('.top_adbox .fa').removeClass('fa-plus').addClass('fa-times');
$('.top_adbox_button').on('click', function () {
$('.top_adbox').remove();
});
$('.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-007 .menu-item').off('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() <= 1023 && 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-007').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-007 .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-007').on('mouseleave', function () {
$('.menu-item.hover').removeClass('hover');
$('.menu-007 .menu-item:nth-child(2)').addClass('hover');
});
//移除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});
}
}
});
}
});
function nav_censor(scroll_switch) {
if (scroll_switch) {
for (var i = 1; i < nav_item.length; i++) {
if (nav_item.eq(i).find('h3').height() > 45 || nav_item.eq(i).find('a.item-title').height() > 45) {
nav_item.eq(i).addClass('nav-item-big');
scroll_switch = false;
}
}
}
return scroll_switch;
}
var nav_n = false;
var overflowTop = 0
$('.menu-b').on('click', function () {
if (!nav_n) {
nav_n = true;
$(this).addClass('close');
$('.nav-bg,.navBox').addClass('open-nav');
overflowTop = $('#wrapper').scrollTop()
$('#wrapper').addClass('overflow-hidden')
} else {
nav_n = false;
$(this).removeClass('close');
$('.nav-bg,.navBox').removeClass('open-nav');
$('#wrapper').removeClass('overflow-hidden').scrollTop(0)
$('#wrapper').scrollTop(overflowTop)
}
});
$('.navBox').on('click', function (e) {
if (e.target === e.currentTarget) {
nav_n = false;
$('.menu-b').removeClass('close');
$('.nav-bg,.navBox').removeClass('open-nav');
$('#wrapper').removeClass('overflow-hidden').scrollTop(0)
$('#wrapper').scrollTop(overflowTop)
}
});
$('body.overflow-hidden').on('scroll', function (e) {
e.preventDefault()
})
$("#Noise_Pop").on("click", ".fa-times", function (e) {
e.preventDefault();
$.ajax({
url: "/ajax/ajax_get_noisePop.php",
type: "POST",
cache: false,
async: false,
data: {Type: 'Cancel'},
success: function (d) {
$("#Noise_Pop").remove();
}
});
});
$(document).on("click", '.HITS_BT', 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},
success: function (d) {
if (url) {
if (target == '_blank') {
window.open(url);
} else if ((typeof target === 'undefined') || (target == '')) {
window.location = url;
} else {
}
}
}
});
} else {
alert("這是錯誤的連結");
}
});
$(document).on("click", '.Collect_BT', function (e) {
e.preventDefault();
if ($.isNumeric($(this).attr('Type')) && $.isNumeric($(this).attr('Collection_ID'))) {
var Type = $(this).attr('Type');
var Collection_ID = $(this).attr('Collection_ID');
var _this = $(this);
if (Type != 4) {
$.ajax({
url: "/ajax/ajax_add_collection-p.php",
type: "POST",
cache: false,
async: false,
data: {"Type": Type, "Collection_ID": Collection_ID},
success: function (d) {
if (d == "OK") {
_this.addClass('click');
alert('收藏成功');
} else if (d == "Already") {
alert("已收藏過!");
} else if (d == "ERROR") {
alert('請先登入會員');
}
}
});
} else {
$.ajax({
url: "/ajax/ajax_add_wish_list.php",
type: "POST",
cache: false,
async: false,
data: {"Type": 'Add', "SID": Collection_ID},
success: function (d) {
if (d == "OK") {
_this.addClass('click');
alert('收藏成功');
} else if (d == "NO_MEMBER") {
alert('請先登入會員');
}
}
});
}
} else {
alert("這是錯誤的連結");
}
});
$(document).on('click', '.Collect_Del_BT', function (e) {
e.preventDefault();
var ID = $(this).data('id');
$.ajax({
url: "/ajax/ajax_del_collection-p.php",
type: "POST",
cache: false,
async: false,
data: {"ID": ID},
success: function (d) {
if (d == "OK") {
alert('取消收藏成功');
location.reload();
}
}
})
})
});
function errorbox(title, content, button) {
var html = '