/**
* 商品影片共用處理(商品詳細頁、活動詳細頁共用)
* - 定義在最外層,讓 defer 執行的 products_detail.js / activities_detail.js 與 list.js 都取得到
* - 影片元素會在切換規格時被重新產生,所以一律在使用當下才以 id 取得,不保留參考
*/
var prod_video = {
//目前的影片元素
el: function () {
return document.getElementById("Video");
},
//依影片「實際」狀態切換小圖的播放/暫停 icon
syncIcon: function () {
var video = prod_video.el();
if (!video) { return; }
$(".moreview .video_control")
.toggleClass('fa-pause', !video.paused)
.toggleClass('fa-play', video.paused);
},
//播放;被瀏覽器 autoplay policy 阻擋時靜音重試
play: function () {
var video = prod_video.el();
if (!video) { return; }
var pp = video.play();
if (pp && pp.catch) {
pp.catch(function () {
video.muted = true;
var retry = video.play();
if (retry && retry.catch) { retry.catch(function () { }); }
});
}
},
//依主圖目前有沒有顯示影片決定播放/暫停
//用 :visible 判斷,可同時涵蓋商品詳細頁(zoonbox 的 now class)與活動詳細頁(inline display)兩種切換方式
syncPlayback: function () {
var video = prod_video.el();
if (!video) { return; }
if ($(video).is(':visible')) {
prod_video.play();
} else {
video.pause();
}
},
//切換播放狀態(點小圖或點影片本身都會呼叫);icon 交由 play/pause 事件同步
toggle: function () {
var video = prod_video.el();
if (!video) { return; }
if (video.paused) {
prod_video.play();
} else {
video.pause();
}
},
//以影片畫面當小圖封面:等比放大填滿 canvas 後置中裁切,避免影片與小圖比例不同時變形
drawCover: function () {
var video = prod_video.el(),
canvas = document.getElementById("video_review");
//部分版型的小圖不是 canvas
if (!video || !canvas || !canvas.getContext) { return; }
//readyState < 2 (HAVE_CURRENT_DATA) 代表還沒有可用的畫格,畫出來會是空白
if (!video.videoWidth || video.readyState < 2) { return; }
var scale = Math.max(canvas.width / video.videoWidth, canvas.height / video.videoHeight),
w = video.videoWidth * scale,
h = video.videoHeight * scale;
canvas.getContext('2d').drawImage(video, (canvas.width - w) / 2, (canvas.height - h) / 2, w, h);
},
//小圖封面的 canvas 標籤;活動詳細頁(type 3)的小圖較小,尺寸與各頁 PHP 產出一致
coverTag: function (type) {
return (type == 3)
? ''
: '';
},
//初始化影片:綁狀態事件、畫小圖封面,並依大圖目前顯示的內容決定要不要播放。切換規格重新產生影片後可重複呼叫
init: function () {
var video = prod_video.el();
if (!video) { return; }
//icon 一律跟著影片實際狀態走,不論是自動播放、點擊或瀏覽器自行暫停
//同一個元素重複 addEventListener 同一個函式參考不會重複註冊
video.addEventListener('play', prod_video.syncIcon);
video.addEventListener('pause', prod_video.syncIcon);
//影片預設不播放,只能等預載到有畫格時才畫得出封面。
//各瀏覽器到達 HAVE_CURRENT_DATA 時送出的事件時機不一,多綁幾個;drawCover 本身有 readyState 判斷,重複呼叫無妨
video.addEventListener('loadeddata', prod_video.drawCover);
video.addEventListener('canplay', prod_video.drawCover);
video.addEventListener('seeked', prod_video.drawCover);
prod_video.drawCover();
prod_video.syncIcon();
//預設顯示的是第一張主圖,影片要等切過去才播放
prod_video.syncPlayback();
},
//綁定點擊事件;委派到 document,避免小圖容器被輪播套件搬移或重建時漏綁
bind: function () {
$(document).off('click.prodVideo')
.on('click.prodVideo', '.moreview .video_control', prod_video.toggle) //點小圖
.on('click.prodVideo', '.productView video#Video', prod_video.toggle); //點影片本身
}
};
$(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);
});
$("#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) {
window.location.reload();
}
}, 'html');
});
$('.lazyimg').lazyload({
effect: 'fadeIn',
});
$("body").on("click", ".rack_detail", function () {
var sid = $(this).attr("store_sid");
var serial_no = $(this).attr("serial");
var flag = $(this).attr("data_id");
var box = $(this);
if (!sid) {
sid = $(this).attr("sid");
}
if (sid && flag != sid) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
$.ajax({
url: '/products/ajax/detail/ajax_get_mobile_data.php',
type: 'POST',
async: false,
data: {
lat: position.coords.latitude,
lng: position.coords.longitude,
serial_no: serial_no
},
error: function (d) {
alert(d.responseText);
},
success: function (d) {
box.attr('data_id', sid);
$("#stockCheck").find(".modal-content").html(d);
}
});
}, function () {
$.ajax({
url: '/products/ajax/detail/ajax_get_mobile_data.php',
type: 'POST',
async: false,
data: {
serial_no: serial_no
},
error: function (d) {
alert(d.responseText);
},
success: function (d) {
box.attr('data_id', sid);
$("#stockCheck").find(".modal-content").html(d);
}
});
if (typeof handleLocationError == 'function') {
handleLocationError(true, infoWindow, map.getCenter());
}
});
} else {
console.log('error');
// Browser doesn't support Geolocation
if (typeof handleLocationError == 'function') {
handleLocationError(true, infoWindow, map.getCenter());
}
}
}
});
//門市資料
$("body").on('change', '.stock-drop', function () {
$('.CityList').hide();
$('.Main-City' + $(this).val()).show();
});
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;
/* 回頁首 */
$('.gotop').on('click', function () {
$("html,body").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': '100vh'
}, 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 || $(".header-01").hasClass("theme-act")) {
//上方廣告
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)) {
// console.log(`device1`)
$('#menu-nav').on('click', '.item-title', function (e) {
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');
}
menuOpenStyle('#menu-nav a.item-title')
}).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 {
// console.log(`device2`)
$('#menu-nav').on('click', '.item-title', function (e) {
console.log(e.currentTarget)
var n = $(this).parent(".open").length;
var t = $(this).attr("type");
if (t == '') {
$('#menu-nav .nav-item').removeClass('open');
$('#menu-nav .menu-item').removeClass('open-sub');
$(".subitembox").removeClass('open-sub');
if (n == 0) {
$(this).parent(".nav-item").addClass('open');
}
} else {
$('#menu-nav .nav-item').removeClass('open');
$('#menu-nav .menu-item').removeClass('open-sub');
$(".subitembox").removeClass('open-sub');
if (n == 0) {
$(this).parent(".nav-item").find("#subitembox" + t).addClass('open-sub');
$(this).parent(".nav-item").addClass('open');
}
}
menuOpenStyle('#menu-nav a.item-title')
}).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() <= 1024 && change_1023 != 1024) {
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;
//天邊會員登入hover下拉
$('.shopbox span.fa-user').on('mouseenter', function () {
$('.userbox').addClass('open');
});
//天邊購物車hover下拉
$(document).on('mouseenter', 'body:not(.hidden-store) .shopbox #Shop_Cart_Total', 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');
}
});
}
let windowScroll = 0,
isChangeClass = false
_window.on('scroll', throttle(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');
}
//向上滑
if (!isChangeClass) {
if (windowScroll > scrollTop) {
isChangeClass = true
$("body").addClass('is-upwards');
} else {
isChangeClass = true
$("body").removeClass('is-upwards');
}
setTimeout(function () {
isChangeClass = false
}, 150)
}
windowScroll = scrollTop
}, 100));
_window.trigger('scroll')
var time_id;
_window.on('resize', function () {
clearTimeout(time_id);
time_id = setTimeout(nav_censor(scroll_switch), 500);
_window = $(window);
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');
}
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');
} 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');
$('.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');
}
});
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;
$('.menu-b').on('click', function () {
if (!nav_n) {
nav_n = true;
$('body').addClass('overflow-hidden').addClass('open-nav')
} else {
nav_n = false;
$('body').removeClass('overflow-hidden').removeClass('open-nav')
}
});
$('.navBox').on('click', function (e) {
if (e.target === e.currentTarget) {
nav_n = false;
$('body').removeClass('overflow-hidden').removeClass('open-nav')
}
});
$('.close-menu').on('click', function (e) {
nav_n = false;
$('body').removeClass('overflow-hidden').removeClass('open-nav')
});
$('.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: "/ajax/ajax_get_noisePop.php",
type: "POST",
cache: false,
async: false,
data: {
Type: 'Cancel'
},
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: "/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(_jsLang.這是錯誤的連結);
}
});
//點擊清空輸入框
$(".CLEAR_INPUT").one("click", function () {
$(this).attr('placeholder', '');
});
//語系選擇
$("#Select_This_Lang").on("click", "li", function () {
$.post('/ajax/ajax_change_language.php', {
Name: $(this).attr('sid')
}, function (h) {
window.location.reload();
}, 'html');
});
//語系選擇
$("#Select_This_Lang3").on("click", "a", function () {
let pageShopId = $("#Page_Shop_ID").val();
$.ajax({
url: "/ajax/ajax_change_language.php",
type: "POST",
cache: false,
async: false,
data: {
Name: $(this).attr('sid'),
PageShopId: pageShopId
},
success: function (d) {
window.location.reload();
}
});
});
if ($(".rosetta-products.theme-carousel").length > 0) {
$(".rosetta-products.theme-carousel").owlCarousel({
nav: true,
responsive: {
0: {
items: 2,
margin: 16,
stagePadding: 30
},
768: {
items: 4,
margin: 16,
},
}
})
}
});
function PDA_AddToCart(Serial_No) {
window.dotq = window.dotq || [];
window.dotq.push({
'projectId': '10000',
'properties': {
'pixelId': '10095723',
'qstrings': {
'et': 'custom',
'ea': 'AddToCart',
'product_id': Serial_No,
}
}
});
window.dotq = window.dotq || [];
window.dotq.push({
'projectId': '10000',
'properties': {
'pixelId': '10146549',
'qstrings': {
'et': 'custom',
'ea': 'AddToCart',
'product_id': Serial_No,
}
}
});
}
function Rosetta_AddToCart(Pos_No) {
if (Pos_No && typeof rosetta == 'function') {
const param = {
type: 'select',
target: Pos_No
};
rosetta('event', param);
console.log('rosetta.event.select');
console.log(param);
console.log(123);
}
}
function Avivid_AddToCart(Datas) {
if (Datas) {
var num = Datas.length;
var string = '';
for (i = 0; i < num; i++) {
string += '[' + Datas[i] + '],';
}
console.log(string.substring(0, string.length - 1));
if (typeof AviviD == 'function') {
setTimeout(function () {
AviviD.analysis(1, [string.substring(0, string.length - 1)]);
}, 5000);
}
}
}
function Avivid_StartCart(Datas) {
if (typeof AviviD == 'function') {
setTimeout(function () {
AviviD.analysis(2, [Datas]);
}, 5000);
}
}
function Avivid_Purchase(Datas) {
if (typeof AviviD == 'function') {
setTimeout(function () {
AviviD.analysis(3, [Datas]);
}, 5000);
}
}
function SAYA_AddToCart() {
var noscript = '';
$("#SAYA_noscript").append(noscript);
var axel = Math.random() + "";
var a = axel * 10000000000000;
$("#SAYA_Div").append('
');
}
//結帳
function SAYA_Purchase() {
var noscript = '';
$("#SAYA_noscript").append(noscript);
var axel = Math.random() + "";
var a = axel * 10000000000000;
$("#SAYA_Div").append('
');
}
//訂單完成
function SAYA_OrderSuccess() {
var noscript = '';
$("#SAYA_noscript").append(noscript);
var axel = Math.random() + "";
var a = axel * 10000000000000;
$("#SAYA_Div").append('
');
}
//訂單完成頁
function SAYA_ShopcartOrder() {
var noscript = '';
$("#SAYA_noscript").append(noscript);
var axel = Math.random() + "";
var a = axel * 10000000000000;
$("#SAYA_Div").append('
');
}
function Set_Box_Files(_item, $this, d) {
if (d.R_Name) _item.find(".box_name").html(d.R_Name);
if (d.Color) _item.find(".colorbox").html(d.Color);
if (d.Color_Name) {
_item.find(".box_color").html('顏色 / ' + d.Color_Name);
}
if (d.Prod_No) {
_item.find(".prodnoBox").html(d.Prod_No);
}
if (d.Size_Name) {
_item.find(".box_size").html('尺寸 / ' + d.Size_Name);
}
if (d.Size_Button) _item.find(".sizebox").html(d.Size_Button);
if (d.Max_Stock) {
//if(d.Max_Stock > 10){d.Max_Stock=10}
_item.find(".amountBox").attr('max', d.Max_Stock);
_item.find(".amountBox").val('1');
}
if (d.Price2) _item.find(".font-delete").html(d.Price2);
if (d.R_Price) _item.find(".font-big").html('NT$' + d.R_Price);
for ($i = 1; $i <= 3; $i++) {
if (d.Button[$i]) _item.find(".Add_Button" + $i).html(d.Button[$i]);
}
if (d.ID) {
_item.find(".stock-icon").attr("sid", d.ID);
_item.find(".wishButton").attr("sid", d.ID);
_item.find(".Add_Reservation_List").attr("sid", d.ID);
}
if (d.Box_Pic) {
let picWrapper = _item.find(".bounce-product-left")
picWrapper.empty()
picWrapper.append('