window.Base = window.Base || function () {};
window.console = window.console || {
log: function () {},
warn: function () {},
error: function () {},
info: function () {}
}
// v2版二级导航及面包屑
Base.prototype.fixedNav = function () {
// 基础对象
var winW = $(window).width();
// 对象
var $module = $('.layout-fixed-nav');
var $head = $('.zl-pc-header');
var $breadcrumbsV2Wrap = $module;
var $breadcrumbsV2FixWrap = $module.find('.fixed-nav-box');
var $breadcrumbsNav = $breadcrumbsV2Wrap.find('.fixed-nav');
var $breadcrumbsNavLi = $breadcrumbsNav.find("li")
var $anchorPoint = $('.anchorpoint');
// 移动端获取对象
if (winW < 1200) {
var $wapController = $module.find('.wap-nav-controller')
var $titleObj = $module.find('.wap-nav-title');
var $iconfontObj = $module.find('.wap-nav-controller span.iconfont');
}
/**
把样式转float
*/
function toFloat(obj, name) {
return parseFloat(obj.css(name), 10) || 0
}
/**
把样式转initBtn
*/
function initBtn() {
// 获取对象
var oUl = $module.find('.btn .contact ul');
var oBox = $module.find('.btn .contact .more-box');
// 获取高度
oBox.attr('data-height', oUl.outerHeight(true));
$module.find('.btn .contact').hover(function () {
oBox.height(oBox.attr('data-height'));
}, function () {
oBox.height(2);
})
}
/**
获取锚点
*/
function GetAnchorpoint() {
//如果没有二级导航的结构
if ($breadcrumbsNav.length < 1) return;
//如果没有定位点
if ($anchorPoint.length < 1) {
$module.remove();
return;
}
//如果页面出现这个标记那么使用新的面包屑Point获取方法
var hidNewBreadcrumbPoint = $("#hidNewBreadcrumbPoint").val();
if (hidNewBreadcrumbPoint != undefined && hidNewBreadcrumbPoint != "undefined" && hidNewBreadcrumbPoint != "") {
var $configAnchorPoint = $("input[data-type='anchorpoint']");
if ($configAnchorPoint.length < 1) {
$module.remove();
return;
}
$configAnchorPoint.each(function (i, va) {
if (i == 0) {
var summaryValue = $(this).val();
if (summaryValue != undefined && summaryValue != "undefined" && summaryValue != "") {
$(".wap-nav-title").html($(this).val());
}
}
$("#sectionCollection").append('
' + $(this).val() + '');
});
var _index = 0;
$anchorPoint.each(function () {
$(this).attr('data-index', _index);
if ($(this).is(':hidden')) {
$breadcrumbsNav.find('li').eq(_index).remove();
$(this).removeClass('anchorpoint');
}
_index++;
})
} else {
var templateid = $("#hidtemplateid").val();
if (templateid == "{EBAD1408-BE02-465C-98E7-062918195BD1}") {
$("#sectionCollection").append('' + $("#hidSummaryValue").val() + '');
$(".wap-nav-title").html($("#hidSummaryValue").val());
$anchorPoint.each(function (i, va) {
var strArray = $anchorPoint[i].className.split(' ');
for (var j = 0; j < strArray.length; j++) {
if (strArray[j] == "js_section_2") {
$("#sectionCollection").append('' + $("#hidBenefit").val() + '');
break;
} else if (strArray[j] == "js_section_3") {
$("#sectionCollection").append('' + $("#hidSolutionsVideo").val() + '');
break;
} else if (strArray[j] == "js_section_4") {
$("#sectionCollection").append('' + $("#hidSubSolutions").val() + '');
break;
} else if (strArray[j] == "js_section_5") {
$("#sectionCollection").append('' + $("#hidTechSupport").val() + '');
break;
} else if (strArray[j] == "js_section_7") {
$("#sectionCollection").append('' + $("#hidCaseStudies").val() + '');
break;
} else if (strArray[j] == "js_section_9") {
$("#sectionCollection").append('' + $("#hidMoreResources").val() + '');
break;
} else if (strArray[j] == "js_section_10") {
$("#sectionCollection").append('' + $("#hidRecommendDocument").val() + '');
break;
} else if (strArray[j] == "js_section_11") {
$("#sectionCollection").append('' + $("#hidExpertModule").val() + '');
break;
} else if (strArray[j] == "js_section_16") {
$("#sectionCollection").append('' + $("#hidRelateProduct").val() + '');
break;
}
}
});
}
if (templateid == "{A2961078-DE07-4E0E-8156-A24A30D85ED2}") {
$("#sectionCollection").append('' + $("#hidSummaryValue").val() + '');
$(".wap-nav-title").html($("#hidSummaryValue").val());
$anchorPoint.each(function (i, va) {
var strArray = $anchorPoint[i].className.split(' ');
for (var j = 0; j < strArray.length; j++) {
if (strArray[j] == "js_section_2") {
$("#sectionCollection").append('' + $("#hidFeatures").val() + '');
break;
} else if (strArray[j] == "js_section_3") {
$("#sectionCollection").append('' + $("#hidSpecifications").val() + '');
break;
} else if (strArray[j] == "js_section_5") {
$("#sectionCollection").append('' + $("#hidTechSupport").val() + '');
break;
} else if (strArray[j] == "js_section_6") {
$("#sectionCollection").append('' + $("#hidRelateResource").val() + '');
break;
} else if (strArray[j] == "js_section_9") {
$("#sectionCollection").append('' + $("#hidMoreResources").val() + '');
break;
} else if (strArray[j] == "js_section_10") {
$("#sectionCollection").append('' + $("#hidRecommendDocument").val() + '');
break;
}
}
});
}
}
if ($breadcrumbsNav.find("li").length < 2) $module.remove();
var summaryValue = $module.find(".wap-nav-title").html();
if (summaryValue != undefined && summaryValue != "undefined" && summaryValue != "" && winW < 1200) {
$module.find(".wap-nav-title").show();
$module.find(".wap-nav-icon").show();
}
}
/**
确认是否可以滚动
*/
function updateAllowScroll() {
$module = $('.layout-fixed-nav');
$head = $('.zl-pc-header');
$breadcrumbsV2Wrap = $module;
$breadcrumbsV2FixWrap = $module.find('.fixed-nav-box');
$breadcrumbsNav = $breadcrumbsV2Wrap.find('.fixed-nav');
$breadcrumbsNavLi = $breadcrumbsNav.find("li")
$anchorPoint = $('.anchorpoint');
return ($anchorPoint.length == 0 || $breadcrumbsNav.length == 0)
}
/**
滚动事件和点击事件
*/
function initEvent() {
var perScrollTop = 0;
var scollStatus = "top";
var scrollLock = false; //区分是鼠标滚动还是自动滚动
//没有面包屑导航
var allowScroll = updateAllowScroll() ? false : true;
// 初始化
var anchor_point_t = [];
$(window).scroll(function () {
if (!allowScroll || scrollLock || $head.data("scroll-lockv2")) {
return;
}
var head_h = $head.height() + 1;
var scrollTop = $(window).scrollTop();
var breadcrumbsTop = ($breadcrumbsV2Wrap.length && $breadcrumbsV2Wrap.offset().top) || 0;
var headfixTop = toFloat($head, "top");
var docH = $(document).height();
var winH = $(window).height();
if (scrollTop >= (breadcrumbsTop - head_h)) {
//顶部交界处
if (scrollTop <= (breadcrumbsTop)) {
$head.stop(true, true).delay(100).animate({
'top': breadcrumbsTop - head_h - scrollTop
}, 300, function () {
scrollRecalculate();
});
if (allowScroll) {
$breadcrumbsV2FixWrap.css({
'position': 'static'
});
// showBreadCrumbV2(true);
} else {
// showBreadCrumbV2(false);
}
scollStatus = "topBoundary";
//底部交界处
} else if ((docH - scrollTop) <= (winH + head_h)) {
scollStatus = "bottomBoundary";
//向上且不是从中间位置向上(中间位置向上头部已经显示出来了)或者是向下
if ((scrollTop - perScrollTop < 0 && headfixTop < 0) || (scrollTop - perScrollTop >= 0)) {
$head.stop(true, true).delay(100).animate({
'top': winH - docH + scrollTop
}, 300, function () {
scrollRecalculate();
});
if (allowScroll) {
$breadcrumbsV2FixWrap.stop(true, true).delay(100).animate({
'top': head_h + winH - docH + scrollTop
}, 300);
}
}
// showBreadCrumbV2(false);
//中间位置
} else {
if (allowScroll && $breadcrumbsV2FixWrap.css('position') !== "fixed") {
$breadcrumbsV2FixWrap.css({
'position': 'fixed',
top: 0
});
}
//向下
if (scrollTop - perScrollTop >= 3) {
if (scollStatus != "middleDown") {
$head.stop(true, true).animate({
'top': -head_h
}, 300, function () {
scrollRecalculate();
});
if (allowScroll) {
$breadcrumbsV2FixWrap.stop(true, true).animate({
'top': 0
}, 300);
}
}
scollStatus = "middleDown";
//向上
} else if (scrollTop - perScrollTop <= -3) {
if (scollStatus != "middleUp") {
$head.stop(true, true).animate({
'top': 0
}, 300, function () {
scrollRecalculate();
});
if (allowScroll) {
$breadcrumbsV2FixWrap.stop(true, true).animate({
'top': head_h
}, 300);
}
}
scollStatus = "middleUp";
}
// showBreadCrumbV2(false);
}
//在顶部
} else {
if (allowScroll) {
$breadcrumbsV2FixWrap.css({
'position': 'static'
});
}
// showBreadCrumbV2(true);
if (scollStatus !== "top" || (scrollTop == 0 && toFloat($head, "top") != 0)) {
$head.stop(true, true).animate({
'top': 0
}, 300, function () {
scrollRecalculate();
});
}
scollStatus = "top";
}
perScrollTop = scrollTop
scrollRecalculate();
})
// 点击二级导航的li
var scrollLockTimer
$breadcrumbsNavLi.on('click', function (e) {
// 阻止时间冒泡
e.stopPropagation();
var li_index = $(this).index();
var head_h = $head.height();
var breadcrumbsHeight = $breadcrumbsV2FixWrap.height();
var breadcrumbsTop = $breadcrumbsV2Wrap.offset().top;
if (allowScroll) {
if ($breadcrumbsV2FixWrap.css('position') !== "fixed") {
$breadcrumbsV2FixWrap.css({
'position': 'fixed',
top: 0
});
$head.stop(true, true).animate({
'top': -head_h
}, 300)
} else {
$head.stop(true, true).animate({
'top': -head_h
}, 300);
$breadcrumbsV2FixWrap.stop(true, true).animate({
'top': 0
}, 300);
}
}
anchor_point_t = [];
$anchorPoint.each(function () {
anchor_point_t.push($(this).offset().top - breadcrumbsHeight);
});
var willScrollTop = anchor_point_t[li_index];
scrollLock = true;
//向下且没有滚动到底部
clearTimeout(scrollLockTimer);
$("body,html").stop(true, true).animate({
"scrollTop": willScrollTop
}, 300, function () {
clearTimeout(scrollLockTimer);
scrollLockTimer = setTimeout(function () {
scrollLock = false;
}, 200);
});
// showBreadCrumbV2(false);
highlightNav(willScrollTop + 1);
if (winW < 1200) {
// 移动端点击定位导航需要收起
$(this).parent('.fixed-nav').slideUp();
// 当前定位到哪里,需要把文字复制到当前
$titleObj.text($(this).text());
arrowFun($('.layout-fixed-nav .iconfont'));
}
})
// 有搜索框
if ($('.nav-search').length > 0) {
//$('.layout-fixed-nav').addClass('layout-fixed-nav-search');
var navSW = $('.layout-fixed-nav-search .nav-search').width();
var cisTenW = $('.layout-fixed-nav-search .cistern').width();
// 搜索事件
$('.search-input').on('click', function (e) {
e.stopPropagation();
$(this).addClass('on-focus');
$(this).find('.s_input').addClass('focus');
$('.focus').attr('placeholder', $("#CaseSearchPlaceholder").val());
if (winW <= 920) {
$(this).parent('.nav-search').addClass('on-focus');
$('.page-nav').addClass('on-focus');
$('.nav-list').hide();
$('.mobile-select').hide();
$('.nav-search .btn-view-02').hide();
$('.mobile-clear').click(function (e) {
e.stopPropagation();
$('.search-input').removeClass('on-focus');
$('.page-nav').removeClass('on-focus');
$('.nav-search').removeClass('on-focus');
$('.s_input').attr('placeholder', "");
$('.s_input').removeClass('focus');
$('.mobile-select').delay(400).show();
$('.nav-search .btn-view-02').delay(400).show();
$('.search-input .s_input').val('');
})
if (!$module.find('.fixed-nav').is(':hidden')) {
$module.find('.fixed-nav').slideToggle();
arrowFun($('.layout-fixed-nav span.iconfont'));
$('.wap-nav-controller').css('width', (cisTenW - navSW - 20) + 'px');
}
} else {
$('.fixed-nav').css('width', (cisTenW - navSW - 280) + 'px');
}
})
$('.search-input .s_input').keyup(function(event) {
var $val = $('.search-input .s_input').val();
if (event.keyCode == 13 && $val != ''&&$val!=undefined) {
SiteSearch();
//console.log($val);
}
});
// 点击放大搜索
$('.SiteSearch').on('click', function(e) {
if ($('.search-input').hasClass('on-focus')) {
e.stopPropagation();
var $val = $('.search-input .s_input').val();
if ($val == ""||$val==undefined) {
return;
}
else {
SiteSearch();
}
}
})
//全站搜索
function SiteSearch()
{
var type = $('.productSupportDivNew').data("type");
var key = encodeURIComponent($('.search-input .s_input').val()); ///关键字
var lang = $(".Find_Language").val();///语言
if (lang == undefined || lang == "") {
lang = "en";
}
if (type == "all") {
OpenTheCaseSearch();
} else {
window.open(supportUrl + "/enterprisesearch?lang=" + lang + "#type=searchAll&keyword=" + key);
}
}
function OpenTheCaseSearch() {
var keyword = encodeURIComponent($('.search-input .s_input').val());
try {
if ($("#categorytype").val() != undefined && $("#categorytype").val() != '') {
window.open("http://e.huawei.com/enterprisesearch?lang=" + $("#gSupportLang1").val() + "#lang=" + $("#gSupportLang2").val() + "&type=" + $("#categorytype").val() + "&keyword=" + keyword);
} else {
window.open("http://e.huawei.com/enterprisesearch?lang=" + $("#gSupportLang1").val() + "#lang=" + $("#gSupportLang2").val() + "&type=ALL&keyword=" + keyword);
}
} catch (ex) {
window.open("http://e.huawei.com/enterprisesearch?lang=" + $("#gSupportLang1").val() + "#lang=" + $("#gSupportLang2").val() + "&type=ALL&keyword=" + keyword);
}
}
if (winW > 1200) {
$('.fixed-nav').css('width', (cisTenW - navSW - 50) + 'px');
} else if (winW <= 1200 && winW > 920) {
$('.wap-nav-controller').addClass('inline-box')
$('.wap-nav-controller').css('width', (cisTenW - navSW - 280) + 'px');
}
}
$(document).click(function (e) {
if (winW > 920) {
if ($('.nav-search')) {
$('.search-input').removeClass('on-focus');
$('.s_input').removeClass('focus');
$('.s_input').attr('placeholder', "");
$('.search-input .s_input').val('');
var timer = null;
timer = setTimeout(function () {
$('.fixed-nav').css('width', (cisTenW - navSW - 100) + 'px');
clearTimeout(timer);
}, 400)
}
} else {
// 判断手机端上边选项下拉
var nacListC = $('.nav-list').css('display');
if (nacListC == 'block') {
$('.nav-list').hide();
} else {}
$('.mobile-select').removeClass('show-list');
}
})
if (winW < 1200) {
//移动端点击显示二级导航栏的标题,展开定位下拉
$wapController.on('click', function (e) {
// 阻止时间冒泡
e.stopPropagation();
$(this).nextAll('.fixed-nav').slideToggle();
arrowFun($(this).find('span.iconfont'));
})
// 点击箭头,展开定位
$iconfontObj.on('click', function (e) {
// 阻止时间冒泡
e.stopPropagation();
$(this).parent('.wap-nav-controller').nextAll('.fixed-nav').slideToggle();
arrowFun($(this));
})
// 移动端点击body,如果定位导航展开,需要收起
$('body').on('click', function () {
if (!$module.find('.fixed-nav').is(':hidden')) {
$module.find('.fixed-nav').slideToggle();
arrowFun($('.layout-fixed-nav span.iconfont'));
}
})
}
// 移动端暂开下拉的菜单的箭头切换
function arrowFun(obj) {
if (obj.hasClass('active')) {
obj.removeClass('active');
obj.removeClass('icon-up').addClass('icon-down');
} else {
obj.addClass('active');
obj.removeClass('icon-down').addClass('icon-up');
}
}
}
/**
重新计算 高亮显示当前导航
*/
function scrollRecalculate() {
if ($breadcrumbsV2Wrap.length == 0) {
return
}
var scrollTop = $(window).scrollTop();
highlightNav(scrollTop);
}
/**
高亮显示当前导航
*/
var perLightHighIndex = -2;
var innerNavKey;
function highlightNav(scrollTop) {
if ($breadcrumbsV2Wrap.length == 0) {
return
}
var breadcrumbsHeight = $breadcrumbsV2FixWrap.height();
var breadcrumbsfixTop = toFloat($breadcrumbsV2FixWrap, "top");
var anchorpointArr = [];
$anchorPoint.each(function () {
//已经到达内容的一半的距离
anchorpointArr.push($(this).offset().top + $(this).height() - breadcrumbsHeight - breadcrumbsfixTop);
})
var anchorLen = anchorpointArr.length;
for (var i = 0; i < anchorLen; i++) {
if (scrollTop <= anchorpointArr[i]) {
//高亮发生改变
if (perLightHighIndex != i) {
$breadcrumbsNavLi.eq(i).addClass('current').siblings().removeClass('current');
//自动居中
clearTimeout(innerNavKey);
innerNavKey = setTimeout(function () {
// navBtnCenterV2(recalculate());
// recalculate()
}, 200);
perLightHighIndex = i;
}
break;
}
}
// 滚动时移动端title显示当前板块
if (winW < 1200) {
if ($breadcrumbsNavLi.eq(perLightHighIndex).text() != '') {
$titleObj.text($breadcrumbsNavLi.eq(perLightHighIndex).text());
}
}
}
// 锚点定位函数
function anchorFun() {
var queryStr = getQueryString("section");
if (queryStr == undefined) return
// 清除滚动条默认位置
if ('scrollRestoration' in history) {
history.scrollRestoration = 'manual';
}
$breadcrumbsNavLi.each(function () {
var _this = $(this);
if (_this.data('key') == queryStr) {
setTimeout(function () {
_this.trigger('click');
}, 500)
}
})
}
// 获取链接参数
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]);
}
/**
v3版本二级导航
*/
function init() {
//后台配置
GetAnchorpoint();
initBtn();
//必须要有头部
if ($head.length == 0) {
//小语种头部
$head = $(".nav-section .nav");
}
if ($head.length == 0) {
return;
}
//滚动事件和点击事件
initEvent();
// 锚点定位,如果链接有带参数,自动触发点击事件
anchorFun();
}
//entry
init();
}
//end
/*初始化*/
$(function () {
var newBaseFixedNav = new Base();
newBaseFixedNav.fixedNav();
});