/**
* mobile common.js 2022
* author zhujun
*/
(function (doc, win) {
var docEl = doc.documentElement,
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
recalc = function () {
var clientWidth = docEl.clientWidth;
if (clientWidth > 750) {
clientWidth = 750;
docEl.style.fontSize = 67.5 + 'px';
// return;
}
if (!clientWidth) return;
docEl.style.fontSize = 100 * (clientWidth / 750) + 'px';
};
recalc();
if (!doc.addEventListener) return;
win.addEventListener(resizeEvt, recalc, false);
// deviceWidth = document.documentElement.clientWidth;
})(document, window);
var t = null
function showMessage(msg,times){
$(".topMessage").remove()
// $(".topMessage").animate({top:'45vh',opacity:'0'},'fast')
clearTimeout(t)
$("body").append('
')
$(".topMessage").animate({opacity:'1'},'fast')
t = setTimeout(function(){
$(".topMessage").animate({opacity:'0'},'fast')
},times)
}
$(document).on("click",".menuicon",function(){
var language_type = getCookie("think_language");
var userAgent = /Safari/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent);
if (userAgent && language_type === "en-us") {
$(".searcher span").css("margin-top", "-0.05rem")
}
var unfold = $(".submenu span").hasClass("cur_page");
var isActive = $(".menuicon .target").hasClass("active");
var isLangActive = $("#langSelect").hasClass("langActive");
// var isActive = $(".menuicon .point").hasClass("active");
var scrolltop = document.scrollingElement.scrollTop || document.body.scrolltop;
if (unfold) {
$(".submenu .cur_page").parent().parent().parent().addClass("unfold")
}
if (isActive) {
$(".head .links").slideUp(500)
// $("body").css("overflow", "auto")
$("body").removeClass("open")
// $(".menuicon .point").removeClass("active")
$(".menuicon .target").removeClass("active")
document.body.style.top = scrolltop + 'px';
} else {
$(".head .links").slideDown(500)
// $(".links").on("touchmove", function (e) {
// e.preventDefault();
// })
$("body").addClass("open")
document.body.style.top = -scrolltop + 'px';
// $(".menuicon .point").addClass("active")
$(".menuicon .target").addClass("active")
}
if(isActive && isLangActive) {
$(".head .langSelect").removeClass("langActive");
$(".head .links").css("display", "none");
}
})
$(document).on("click", ".ul li", function () {
var isCurrent = $(this).hasClass("current")
var isUnfold = $(this).find("div").hasClass("unfold")
// if (isUnfold) {
// var unfold = $(this).find("div").eq(1).removeClass("unfold")
// console.log("unfold", unfold);
// }
if (isCurrent) {
$(this).removeClass("current")
} else if(isCurrent === false && isUnfold === false) {
$(this).addClass('current')
}
$(this).find("div").removeClass("unfold")
// $(this).addClass('current')
$(this).siblings().find("div").removeClass("unfold")
$(this).siblings().removeClass('current')
})
function toSearcher() {
window.location.href = "/Index/search.html"
}
$(document).on("click", ".langSelect .list span", function () {
var type = "zh-cn";
var redirect = getCookie("url"); // 閲嶅畾鍚戦摼鎺
var pathName = window.location.pathname;
// var lang = "{$Think.cookie.think_language}";
var lang = getCookie("think_language");
var is_english =$(this).hasClass("english");
if (lang === "zh-cn" && is_english === true) {
// showMessage("鑻辨枃鐗堝崌绾т腑锛屾暚璇锋湡寰呫€?,3000); return
type = "en-us"
} else if(lang === "zh-cn" && is_english === false) {
return;
} else if (lang === "en-us" && is_english === false) {
type = "zh-cn"
} else if (lang ==="en-us" && is_english === true) {
// showMessage("鑻辨枃鐗堝崌绾т腑锛屾暚璇锋湡寰呫€?,3000); return
type = "en-us"
}
// 鍏煎娴嬭瘯鐜鎴栨湰鍦
if (redirect.indexOf('https://cn-np') == -1 && redirect.indexOf('https://www.cn-np') == -1 && redirect.indexOf('https://en.cn-np') == -1 && redirect.indexOf('https://en.cornexbattery') == -1 && redirect.indexOf('https://cornexbattery') == -1) {
pathName += '?l=' + type;
}
if( type === "zh-cn"){
redirect = getCookie('url_cn');
}else{
redirect = getCookie('url_en');
}
// redirect += '?l=' + type;
// window.location.href = redirect + pathName
// 浠绘剰鍐呴〉璺宠浆v3.0鑻辨枃鐗堥椤
window.location.href = redirect;
})
// $(document).on("click",".menuicon",function(){
// var lang = getCookie("think_language");
// if (lang === "en-us") {
// $(".globalswitch").find('span').text("涓枃")
// } else {
// $(".globalswitch").find('span').text("English")
// }
// })
$(document).on("click", ".globalswitch", function () {
var lang = getCookie("think_language");
if (lang === "zh-cn") {
$("#chinese").addClass("current").siblings("span").removeClass("current");
} else {
$("#english").addClass("current").siblings("span").removeClass("current");
}
$("#langSelect").addClass("langActive");
// var url = window.location.href;
// var pathName = window.location.pathname;
// var language_type = getCookie("think_language");
// var redirect = getCookie("url"); // 閲嶅畾鍚戦摼鎺
// var type = '';
// if (language_type === "en-us") {
// $(this).find('span').text("涓枃")
// type = 'zh-cn';
// } else {
// $(this).find('span').text("English")
// type = 'en-us';
// }
// // 鍏煎娴嬭瘯鐜鎴栨湰鍦
// if (redirect.indexOf('https://cn-np') == -1 && redirect.indexOf('https://www.cn-np') == -1 && redirect.indexOf('https://en.cn-np') == -1 && redirect.indexOf('https://en.cornexbattery') == -1 && redirect.indexOf('https://cornexbattery') == -1) {
// pathName += '?l=' + type;
// }
// window.location.href = redirect + pathName
})
//鎵嬫満妯珫灞忕姸鎬侊細
// function hengshuping(address){
// if(window.orientation==180||window.orientation==0){
// //
// }
// if(window.orientation==90||window.orientation==-90){
// // alert(target)
// showMessage('clientWidth '+address, 3000)
// if (deviceWidth >= 768) {
// var path;
// switch (target) {
// case 'index':
// path = 'index.html'
// break;
// default:
// break;
// }
// window.location.href = '/Index/' + path
// }
// }
// }
// window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", hengshuping, false);
// var _address;
// function orient(address, orient) {
// _address = address;
// if (window.orientation == 90 || window.orientation == -90) {
// // showMessage('clientWidth '+address, 3000)
// if (deviceWidth >= 768) {
// var path;
// switch (orient) {
// case 'index':
// path = 'index.html'
// break;
// default:
// break;
// }
// window.location.href = '/Index/' + path
// alert('/Index/' + path)
// }
// return false;
// } else if (window.orientation == 0 || window.orientation == 180) {
// return false;
// }
// }
//鐢ㄦ埛鍙樺寲灞忓箷鏂瑰悜鏃惰皟鐢
// $(window).bind( 'orientationchange', function(e){
// // alert(_address)
// orient('', _address);
// });