");
$("form").submit(function(e) {
/*emoji表情导致询盘内容无法收全,emoji表情过滤*/
let eRegStr = /[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF][\u200D|\uFE0F]|[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF]|[0-9|*|#]\uFE0F\u20E3|[0-9|#]\u20E3|[\u203C-\u3299]\uFE0F\u200D|[\u203C-\u3299]\uFE0F|[\u2122-\u2B55]|\u303D|[\A9|\AE]\u3030|\uA9|\uAE|\u3030/ig;
// e.preventDefault();
var emailEl = $(this).find("[name='email']");
var messageEl = $(this).find("[name='message']");
var telEl = $(this).find("[name='contact[tel]']");
var emailValid = false,
messageValid = false,
telValid = false;
function formErrMsg(errText) {
$(".error-msg").html(errText);
$(".error-msg").stop().fadeIn(100);
setTimeout(() => {
$(".error-msg").stop().fadeOut(1000);
}, 3000);
}
if (emailEl.length) {
if (!/[-\w\.]+@[-\w\.]+(\.[-\w]+)+/.test(emailEl.val())) {
e.preventDefault();
formErrMsg("Please enter the correct email address!");
} else {
emailValid = true;
}
}
if (emailValid) {
if (messageEl.length) {
// var value = messageEl.val().trim();
var value = messageEl.val();
if (!/\S{10,}/g.test(value.replace(/\s/g, ""))) {
e.preventDefault();
formErrMsg("Please enter your message with more than 10 characters!");
} else {
messageEl.val(value.replace(eRegStr, ''));
messageValid = true;
}
}
}
if (emailValid && messageValid) {
var host = window.location.host;
if (telEl.length) {
var value = telEl.val().trim();
if (/^(zh\-cn\.)/.test(host) || /\.risingcn\./.test(host)) {
if (!/^1[3456789]\d{9}$/.test(value)) {
e.preventDefault();
formErrMsg("Please enter the correct mobile phone number!");
}
} else {
if (value.length) {
/*
if ( isNaN(value) ) {
e.preventDefault();
formErrMsg("Please enter the correct mobile phone number");
}
*/
} else {
/*
e.preventDefault();
formErrMsg("Please enter your phone number");
*/
}
}
}
}
// 设置 cookie
function setCookie(name, value, days) {
let expires = "";
if (days) {
let date = new Date();
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000); // 过期时间
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + encodeURIComponent(value) + expires + "; path=/";
}
if (e.currentTarget.id == "homeForm") {
// alert("asd1f2s1df");
e.preventDefault();
let flag = false;
let protocol = window.location.protocol;
let backpage = protocol + "//" + document.location.hostname + "/inquiryok?back=" + document.location.pathname;
if (emailValid && messageValid) {
flag = true;
setCookie("inquirySuccess", "1", 7);
}
if (flag) {
$.post(protocol + "//inquiry.digoodcms.com/api/byspray", $(this).serialize(), function(res, status) {
if (res.indexOf('Inquiry Send Success') >= 0) {
window.location.href = backpage;
$("#homeForm").hide();
$(".submit-success").show();
}
});
}
} else if (e.currentTarget.id == "InquiryForm") {
e.preventDefault();
let flag = false;
let protocol = window.location.protocol;
if (emailValid && messageValid) {
flag = true;
setCookie("inquirySuccess", "1", 7);
}
if (flag) {
$.post(protocol + "//inquiry.digoodcms.com/api/save/byspray", $(this).serialize(), function(res, status) {
if (res.indexOf('Inquiry Send Success') >= 0) {
window.location.href = '/inquiryok.html?back=' + document.location.pathname;
$("#homeForm").hide();
$(".submit-success").show();
}
});
}
}
});
})(jQuery);
$(function() {
const $area = $('.best-selling-area');
const $stageOuter = $area.find('.best-selling-active-2 .owl-stage-outer.owl-height');
function updateStageHeight($bundle) {
// 等浏览器完成一次布局再量,避免读到过时高度
(window.requestAnimationFrame || function(cb) {
setTimeout(cb, 0);
})(function() {
const h = $bundle.outerHeight(true);
$stageOuter.height(h + 65);
});
}
$area.on('click', '.best-selling-pro-wrapper .desc_down_btn', function() {
const $btn = $(this);
const $bundle = $btn.closest('.best-selling-bundle-2');
const $content = $bundle.find('.product-content.best-pro-content.best-selling-style-2');
// 清空队列,避免多次快速点击导致高度错乱
$content.stop(true, true);
if ($btn.hasClass('active')) {
$btn.removeClass('active');
$content.slideUp('slow', function() {
updateStageHeight($bundle);
});
} else {
// 激活当前,关闭其它
$btn.addClass('active');
$area.find('.best-selling-pro-wrapper .desc_down_btn').not($btn).removeClass('active');
$area.find('.product-content.best-pro-content.best-selling-style-2').not($content).stop(true, true).slideUp('slow');
$content.slideDown('slow', function() {
updateStageHeight($bundle);
// 若内容里有图片,图片加载后再补一次计算
$bundle.find('img').each(function() {
if (this.complete) return;
$(this).one('load', function() {
updateStageHeight($bundle);
});
});
});
}
});
})