var isH5 = true;
layer.config({
skin: 'demo-class'
});
var Onlinezt;
var taskCount = 0;//统计task数量
var cnUrlsite = '//cn.bio-protocol.org';
var enUrlsite = '//en.bio-protocol.org';
//根据langID返回语言
function getLangStr(strEN, StrCN) {
//0英文
//1中文
if (languageid == 1) {
if (StrCN == '') {
return strEN;
}
else {
return StrCN;
}
}
else {
return strEN;
}
}
$(function () {
layui.use('laytpl', function () {
var laytpl = layui.laytpl;
var nowdate = new Date();
$('.nowyearNumber').html(nowdate.getFullYear());
//$('body').attr('onresize', 'RefreshPage()');
BrowserVersion();
$('body').click(function () {
hideSetting();
});
$('#txtsearchchina').focus(function () {
SearchIsCheckedMobile();
});
$('#txtsearchchina2').focus(function () {
SearchIsCheckedMobile();
});
$('#txtTopSearch1').focus(function () {
SearchIsCheckedMobile();
});
//$('.HeadfixTop').addClass('adHeadnav');
//$('.bioSearch').addClass('adHeadSearch');
//setTimeout(function () {
$('.HeadfixTop').removeClass('adHeadnav');
$('.bioSearch').removeClass('adHeadSearch');
//$('.headerBanner').css('position', 'absolute');
var setdis = $('.SettingUser').css('display');
if (setdis == 'block') {
if ($(window).scrollTop() > 250) {
setting(1);
}
}
//}, 12000);
$(window).scroll(function () {
var scrollHeight = $(window).scrollTop();
if (scrollHeight > 250) {
$(".fixed").show();
$('.HeadfixTop').addClass('fixed-top');
$('.topspan').css('width', '10px');
EditSearchStyle();
EditGoogleSearch();
//var hbannerposition = $.trim($('.headerBanner').css('position'));
//if (hbannerposition == 'fixed') {
// $('.gssb_c').addClass('adHeadSearch');
//}
} else {
$(".fixed").hide();
$('.SettingUser').hide();
$('.HeadfixTop').removeClass('fixed-top');
HideSearchStyle();
HideGoogleSearch();
$('.gssb_c').removeClass('adHeadSearch');
}
});
LoginInfo(1);
//根据参数自动打开登录弹窗
CkParaLogin();
});
});
function ShowFields() {
$('.ResearchField').show();
}
function HideFields() {
$('.ResearchField').hide();
}
//根据参数自动打开登录页
function CkParaLogin() {
$.ajax({
url: '/smlog/userstatus.aspx?action=checklogin',
type: 'post',
dataType: 'json',
success: function (r) {
if (r.Online) {
Onlinezt = 1;
} else {
var lgn = $.getUrlVar('login');
if (lgn == 1) {
ShowLogin(0, 5);
} else if (lgn == 2) {
ShowSignUp(0, 5);
}
}
}
});
}
//判断浏览器版本
function BrowserVersion() {
if (window.File && window.FileReader && window.FileList && window.Blob) {
// Great success! All the File APIs are supported.浏览器支持html5
} else {
isH5 = false;
if ($.cookie('tixing') == 1) { } else {
var tishi = 'Your browser version is too low, please use the high version of the browser
';
tishi += 'You can download the following browsers
';
tishi += '';
tishi += '';
tishi += '';
tishi += '
';
tishi += ' ';
tishi += ' ';
tishi += '
';
layer.open({
title: 'Prompt',
area: '600px',
btn: 0,
content: tishi,
closeBtn: 0
});
}
}
}
//如果是谷歌搜索, 显示的时候替换搜索按钮图标( 注: 如果内容页样式修改,直接替换搜索按钮图片,此方法可以删除 )
function ChangeGoogleSearchButton() {
var enter = false;
$('.gsc-search-button-v2').each(function (index, data) {
var title = $.trim($(data).attr('title'));
if (title == 'search') {
enter = true;
$(data).attr('src', _ImgSrcURI + '/images/searchicons_blue.png');
}
});
if (!enter) {
setTimeout(function () {
ChangeGoogleSearchButton();
}, 500);
}
}
function LoginInfo(type) {
if (type == 1) {
$.ajax({
url: '/smlog/userstatus.aspx?action=checklogin',
type: 'post',
dataType: 'json',
success: function (r) {
var userinfo2 = "" + getLangStr('Log in / Register', '登录 / 注册') + '';
var userinfo1 = "" + getLangStr('Log in / Register', '登录 / 注册') + '';
if (r.Online) {
Onlinezt = 1;
$('#headerlogin').removeClass('padding-top').html(GetUserName(1));
var lgu = GetUserName(2);
$('#spanlogin').html(lgu);
if (lgu == '') {
$('#headerlogin').html(userinfo1);
$('#spanlogin').html(userinfo2);
}
} else {
$('#headerlogin').html(userinfo1);
$('#spanlogin').html(userinfo2);
}
}
});
} else if (type == 0) {
Onlinezt = 1;
$('#headerlogin').removeClass('padding-top').html(GetUserName(1));
$('#spanlogin').html(GetUserName(2));
}
}
//position 1 固定头部, 2不固定头部
function GetUserName(position) {
var userinfo = '';
if ($.cookie('username')) {
var redicon = '';//有task头像添加红点
var mt = position == 2 ? 'margin-top:-5px;' : '';
var dis = taskCount > 0 ? '' : 'display:none;';
redicon = '';
userinfo += '';
userinfo += decodeURIComponent($.cookie('username'));
//userinfo += '
' + decodeURIComponent($.cookie('job')) + '';
userinfo += '';
//userinfo += '' + redicon + '';
var eidtimg = position == 1 ? '/images/ComposeIcon.png' : '/images/ComposeIcon-white.png';
userinfo += '';
userinfo += ' ';
userinfo += '' + getLangStr('Log Out', '退出') + '';
}
return userinfo;
}
//type 0:no, 1:yes (后台获取参数加载)
function ShowInvite(type, code) {
var url = '';
if (type == 0) {
url = 'ifrinviten.aspx?cd=' + code;
} else if (type == 1) {
url = 'ifrinvitey.aspx?cd=' + code;
}
layer.open({
type: 2,
title: false,
closeBtn: 0,
skin: 'demo-skin-radius',
shadeClose: true,
scrollbar: false,
shade: 0.5,
area: ['520px', '540px'],
content: url
});
}
//task
function getUserInfoTitle() {
$.ajax({
url: '/usertask.aspx?action=getuserinfo',
type: 'post',
data: {
page: 1
},
dataType: 'json',
success: function (r) {
if (r && r.Online) {
if (r.ISSignature) {
$("#liSignature").show();
}
}
}
});
}
function detectZoom() {
var ratio = 0,
screen = window.screen,
ua = navigator.userAgent.toLowerCase();
if (window.devicePixelRatio !== undefined) {
ratio = window.devicePixelRatio;
}
else if (~ua.indexOf('msie')) {
if (screen.deviceXDPI && screen.logicalXDPI) {
ratio = screen.deviceXDPI / screen.logicalXDPI;
}
}
else if (window.outerWidth !== undefined && window.innerWidth !== undefined) {
ratio = window.outerWidth / window.innerWidth;
}
if (ratio) {
ratio = Math.round(ratio * 100);
}
return ratio;
};
//function JiSuanPointPosition() {
// var bt = $('#bannerLBtop').width() - 1920;
// if (bt > 0) {
// $('#navhead').find('.pointer').css('right', (80 + bt / 2) + 'px');
// }
//}
function MoveOutForAuthor() {
$('body').click();
}
//关闭提醒是否支持html5浏览器
function CloseRemind() {
var isflag = $("input[name='butixing']").is(':checked') == true ? 1 : 0;
layer.closeAll();
if (isflag == 1) {
$.ajax({
url: '/smlog/userstatus.aspx?action=remindcookie',
type: 'post',
data: {
isflag: isflag
},
success: function (r) {
}
});
}
}
function ShowSearchKeyword(id) {
SearchIsCheckedMobile();
$('#Searchdialogtop' + id).show();
$('#txtTopSearch' + id).focus();
}
function HideSearchKeyword(id) {
$('#Searchdialogtop' + id).hide();
}
//回车触发查询
function SearchPress(e) {
e = e || window.event;
if (e.keyCode == 13) {
SearchProtocol();
return false;
};
}
//搜索
function SearchProtocol() {
var sid = (new Date()).getTime() + '' + Math.floor(Math.random() * 900 + 100);
if ($.trim($('.sousuokumbndivinput').val()) != '') {
CountRecord_search($.trim($('.sousuokumbndivinput').val()), '/bio101/searchdb.aspx', 'HeadfixTop_search', '悬浮导航搜索');
window.location.href = "/bio101/searchdb.aspx?q=" + encodeURIComponent($('.sousuokumbndivinput').val()) + "&sid=" + sid;
} else {
layer.msg('Please enter keyword.', {
icon: 5
, shift: 6
});
}
}
//回车触发查询
function SearchPress2(e) {
e = e || window.event;
if (e.keyCode == 13) {
SearchProtocol2();
return false;
};
}
//搜索
function SearchProtocol2() {
var sid = (new Date()).getTime() + '' + Math.floor(Math.random() * 900 + 100);
if ($.trim($('#txtsearchchina2').val()) != '') {
CountRecord_search($.trim($('#txtsearchchina2').val()), '/bio101/searchdb.aspx', 'banner_search', '主banner搜索');
window.location.href = "/bio101/searchdb.aspx?q=" + encodeURIComponent($('#txtsearchchina2').val()) + '&sid=' + sid;
} else {
layer.msg('Please enter keyword.', {
icon: 5
, shift: 6
});
}
}
function TopSearchPress(e, id) {
e = e || window.event;
if (e.keyCode == 13) {
TopSearchKeyword(id);
return false;
};
}
function TopSearchKeyword(id) {
var sid = (new Date()).getTime() + '' + Math.floor(Math.random() * 900 + 100);
if ($.trim($('#txtTopSearch' + id).val()) != '') {
window.location.href = "/bio101/searchdb.aspx?q=" + encodeURIComponent($('#txtTopSearch' + id).val()) + "&sid=" + sid;
} else {
layer.msg(getLangStr('Please enter keyword.', '请输入关键字'), {
icon: 5
, shift: 6
});
}
}
//显示登录弹窗
function ShowLogin(way, position) {
var way = way || way == 0 ? '&way=' + way : '';
var p = position || position == 0 ? '&p=' + position : '';
//if (languageid == 1) {
location.href = '/nlogin.aspx?uri=' + encodeURIComponent(location.pathname + location.search) + p + way;
//} else {
// layer.open({
// type: 2,
// title: false,
// closeBtn: 0,
// skin: 'demo-skin-radius',
// //scrollbar: false,
// shadeClose: true,
// area: ['520px', '540px'],
// content: getLangStr('/', '/cn/') + 'ifrlogin.aspx?sign=in' + way + p,
// end: function () {
// location.reload();
// //LoadChangeLang();
// }
// });
//}
}
//显示注册弹窗
function ShowSignUp(way, position) {
var way = way ? '&way=' + way : '';
var p = position ? '&p=' + position : '';//位置
//if (languageid == 1) {
location.href = '/nsignup.aspx?uri=' + encodeURIComponent(location.pathname + location.search) + p + way;
//} else {
// layer.open({
// type: 2,
// title: false,
// shadeClose: true,
// scrollbar: false,
// closeBtn: 0,
// skin: 'demo-skin-radius',
// area: ['520px', '540px'],
// content: getLangStr('/', '/cn/') + 'ifrlogin.aspx?sign=up' + way + p,
// end: function () {
// location.reload();
// }
// });
//}
}
//滚动, 修改头部搜索框样式 显示
function EditSearchStyle() {
//$('#divSearchPan').show();
$('#divSearchPan2').hide();
//$('.searchChina').css('height', '34px').css("border-width", '1px');
//$('.btn-search-word').css('width', '85px').css('font-size', '14px');
//$('.bioSearch').addClass('headerfix');
//$('.topspan').css('width', '390px');
}
//滚动, 修改头部搜索框样式 隐藏
function HideSearchStyle() {
//$('#divSearchPan').hide();
$('#divSearchPan2').show();
////$('.searchChina').css('height', '60px').css("border-width", '3px');
////$('.btn-search-word').css('width', '174px').css('font-size', '25px');
////$('.bioSearch').removeClass('headerfix');
////$('.topspan').css('width', '10px');
}
function EditGoogleSearch() {
$('.gssb_c').addClass('headerfix fixtop');
ChangeGoogleSearchButton();
}
function HideGoogleSearch() {
$('.gssb_c').removeClass('headerfix fixtop');
}
//退出登录
function SignOut() {
$.ajax({
url: '/smlog/userstatus.aspx?action=signout&v=' + Math.floor(Math.random() * 10000),
success: function (r) {
if (r == 'ok') {
//var userinfo2 = "" + getLangStr('Log in / Register', '登录 / 注册') + "";
//var userinfo1 = "" + getLangStr('Log in / Register', '登录 / 注册') + "";
//$('#headerlogin').html(userinfo1);
//$('#spanlogin').html(userinfo2);
//$('.a_personinfo').attr('href', '/userhome.aspx');
Onlinezt = 0;
delCookie('photo');
delCookie('email');
delCookie('job');
delCookie('middlename');
delCookie('lastname');
delCookie('account');
window.location.href = location.origin + location.pathname + location.search;
}
}
});
}
function getCookie(name) {
var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
if (arr = document.cookie.match(reg))
return (arr[2]);
else
return null;
}
function delCookie(name) {
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval = getCookie(name);
if (cval != null) {
document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}
}
//设置
function setting(position) {
if (position == 2) {
var l = $('#spanlogin').offset().left - 30;
var t = 70 - $(window).scrollTop();
$('.SettingUser').css('top', t + 'px').css('left', l + 'px');
} else if (position == 1) {
var headfixtop = $('.HeadfixTop').css('top').replace('px', '');
if (headfixtop == 'auto') {
headfixtop = '0';
}
var toppx = 50 + parseInt(headfixtop);
$('.SettingUser').css('top', toppx + 'px').css('right', '50px').css('left', 'auto');
}
$('.SettingUser').show();
}
function hideSetting() {
$('.SettingUser').hide();
}
//关闭 cookie notice
function GotItCookieNotice() {
$.ajax({
url: '/smlog/userstatus.aspx?action=GotCookieNotice',
type: 'post',
data: {},
dataType: 'json',
success: function (r) {
if (r && r.Online) {
$('.fixedcookieNoice').remove();
}
}
});
}
var xhuan = 0;//最多循环加载3次, 超过3次, 停止加载
function GetLabs() {
$.ajax({
url: '?action=GetLabs',
type: 'get',
data: {
},
dataType: 'json',
success: function (r) {
if (r && r.Online) {
xhuan = 0;
var getTpl = scriptLabs.innerHTML
, view = document.getElementById('divlabs');
layui.laytpl(getTpl).render(r, function (html) {
view.innerHTML = html;
});
if (r.Data.length > 0) {
$('#panLab').show();
}
if (r.MoreLabs > 3) {
$('#morelab').show();
}
} else {
if (r.LongTime == 1 && xhuan < 3) {
xhuan++;
GetLabs();
}
}
}
});
}
//显示微信公众号二维码图片
function WenXinGZHQRCode() {
var html = '';
html += '
微信扫一扫关注我们
';
html += '
';
html += '
BioscienceProtocols | 一个有用的公众号推送最新的实验方案和期刊动态
';
html += '
';
layer.open({
type: 1,
shade: false,
title: false, //不显示标题
area: ['330px', '390px'],
content: html,
});
}
//修改密码
function ShowChangePassword() {
layer.open({
type: 2,
title: false,
//scrollbar: false,
closeBtn: false,
shadeClose: true,
skin: 'demo-skin-radius',
area: ['520px', '540px'],
content: getLangStr('', '/cn') + '/ifrchangepwd.aspx'
});
}
function indexvideoclosed() {
$('#indexvideoshow').remove();
$.ajax({
url: '/data/parsedata.aspx?action=CloseShortVideoAD',
type: 'get',
data: {},
success: function (r) { },
error: function () { }
});
}
//判断是否是移动端
function SearchIsCheckedMobile() {
if (languageid == 1) {
var shebei = $.trim(GetSheBei().toLowerCase());
if (shebei.indexOf('iphone') >= 0 || shebei.indexOf('android') >= 0) {
//移动端访问, 跳转
location.href = '/mv2/searchpage.aspx?url=' + encodeURIComponent(location.pathname + location.search);
}
}
}
//判断是否是移动端 跳转登录
function SearchIsCheckedMobileToLogin(position, way) {
var p = position ? '&p=' + position : '';
var way = way ? '&way=' + way : '';
if (languageid == 1) {
var shebei = $.trim(GetSheBei().toLowerCase());
if (shebei.indexOf('iphone') >= 0 || shebei.indexOf('android') >= 0) {
//移动端访问, 跳转
location.href = '/mv2/loginreg.aspx?url=' + encodeURIComponent(location.pathname + location.search) + p + way;
}
}
}
function SearchFuZhi(id, temp) {
var val = $(temp).val();
$('#' + id).val(val);
}
function CountRecord_search(text, link, className, module) {
localStorage.setItem("$bp_bio101_" + className, module);
localStorage.setItem("$bp_bio101_text" + className, $.trim(text));
localStorage.setItem("$bp_bio101_link" + className, $.trim(link));
}
function HrefDiv(href) {
CountRecord(this, '平台内容', 'defaultBody');
location.href = href;
}