function initassoccommonclsgiant(moduleid, layout,showsecondary) {
function clearlayoutremain(sarr) {
for (var i = 0; i < sarr.length; i++) {
if ($(sarr[i]).length != 0) {
$(sarr[i]).remove()
}
}
}
if (showsecondary == '1') {
$("#module_" + moduleid + " .sub-class-item-box").css('display', 'block')
$("#module_" + moduleid + " .main-class-item").find('.main-class-icon').addclass("active")
} else if (number(showsecondary) >= 20) {
var num = number(showsecondary.tostring().substring(1, showsecondary.length))
for (var i = 0; i < num; i++) {
$("#module_" + moduleid + " .sub-class-item-box").eq(i).css('display', 'block')
$("#module_" + moduleid + " .main-class-item").eq(i).find('.main-class-icon').addclass("active");
}
}
clearlayoutremain(["#clone_module_" + moduleid, "#clone_module_" + moduleid, '.layout-104dialog' + moduleid, '.layout-109dialog' + moduleid, '.layout-108dialog' + moduleid, '.layout-110dialog' + moduleid, "#clone_mob_module_" + moduleid, '#pro-106-shade' + moduleid, '#pro-107-shade' + moduleid])//每次初始化删除apped到body的东西
var curclass = null;
if($.inarray(layout,['101','102','103','104','105','108','109']) > -1){
$("#module_" + moduleid + " .main-class-item-box").mouseenter(function(){
$("#module_" + moduleid + " .main-class-line").not('[iscurrent=1]').removeclass("active");
$(this).find('.main-class-line').addclass("active");
}).mouseleave(function(){
$("#module_" + moduleid + " .main-class-line").not('[iscurrent=1]').removeclass("active");
});
$("#module_" + moduleid + " .main-class-item").mouseenter(function(){
$("#module_" + moduleid + " .main-class-item").not('[iscurrent=1]').removeclass("active");
$("#module_" + moduleid + " .sub-class-item").not('[iscurrent=1]').removeclass("active");
$(this).addclass("active");
}).mouseleave(function(){
$(this).not('[iscurrent=1]').removeclass("active");
$("#module_" + moduleid + " .main-class-item").not('[iscurrent=1]').removeclass("active");
$("#module_" + moduleid + " .sub-class-item").not('[iscurrent=1]').removeclass("active");
});
$("#module_" + moduleid + " .sub-class-item").mouseenter(function(){
$("#module_" + moduleid + " .main-class-item").not('[iscurrent=1]').removeclass("active");
$("#module_" + moduleid + " .sub-class-item").not('[iscurrent=1]').removeclass("active");
$(this).closest('.main-class-item-box').find('.main-class-item').addclass("active");
$(this).addclass("active");
}).mouseleave(function(){
$("#module_" + moduleid + " .main-class-item").not('[iscurrent=1]').removeclass("active");
$("#module_" + moduleid + " .sub-class-item").not('[iscurrent=1]').removeclass("active");
$(this).not('[iscurrent=1]').removeclass("active");
});
$("#module_" + moduleid).find('.main-class-item a,.sub-class-item a,.third-class-item a').each(function () {
var ismatch = matchcurrentclass($(this).prop('href'));
if (ismatch) {
if ($(this).closest('.main-class-item').length>0) {
curclass = $(this).closest('.main-class-item');
} else if ($(this).closest('.sub-class-item').length>0) {
curclass = $(this).closest('.sub-class-item');
} else if ($(this).closest('.third-class-item').length>0) {
curclass = $(this).closest('.third-class-item');
}
}
});
if($.inarray(layout,['104','108']) > -1 && showsecondary != '0') curclass = null
if(curclass != null) curclass.attr('iscurrent','1').addclass("active");
if($.inarray(layout,['104','108','109','110']) > -1){
if(curclass != null && curclass.hasclass('sub-class-item')){
curclass.closest('.main-class-item-box').find(".main-class-item").attr('iscurrent','1').addclass("active");
curclass.closest('.main-class-item-box').find(".main-class-line").attr('iscurrent','1').addclass("active");
} else if (curclass != null && curclass.hasclass('third-class-item')) {
curclass.closest('.main-class-item-box').find(".main-class-item").attr('iscurrent','1').addclass("active");
curclass.closest('.main-class-item-box').find(".main-class-line").attr('iscurrent','1').addclass("active");
curclass.closest('.main-class-item-box').find(".sub-class-item").attr('iscurrent','1').addclass("active");
curclass.closest('.main-class-item-box').find(".sub-class-line").attr('iscurrent','1').addclass("active");
}
}
if($.inarray(layout,['109']) > -1){
$("#module_" + moduleid + " .third-class-item").mouseenter(function(){
$("#module_" + moduleid + " .sub-class-item").not('[iscurrent=1]').removeclass("active");
$("#module_" + moduleid + " .third-class-item").not('[iscurrent=1]').removeclass("active");
$(this).closest('.third-class-item-box').prev('.sub-class-item').addclass("active");
$(this).addclass("active");
}).mouseleave(function(){
$("#module_" + moduleid + " .sub-class-item").not('[iscurrent=1]').removeclass("active");
$("#module_" + moduleid + " .third-class-item").not('[iscurrent=1]').removeclass("active");
});
}
// 二层分类,若无子菜单,则不显示箭头
if($.inarray(layout,['104','108']) > -1){
$("#module_" + moduleid + " .main-class-item.classify").each(function (index,el) {
var length = $(this).next().children(".sub-class-item").length;
if(length > 0){
$(this).children(".main-class-icon.iconfont.icon-jiantou1").show();
}else{
$(this).children(".main-class-icon.iconfont.icon-jiantou1").hide();
}
});
}
}
if ($.inarray(layout,['101','102']) > -1) {
//给titel绑定事件·
var windowchange = function () {
var windowwidth = $(window).width();
if (windowwidth < 768) {
//小屏
$('#module_' + moduleid + ' .classify').off('click.classify101_102').on('click.classify101_102', function () {
var _this = $(this);
//切换icon图标
if(layout=='101'){
_this.find('.class-title-icon').toggleclass('active');
}else if(layout == '102'){
if(_this.attr('unfold')=='true'){
_this.find('.class-title-icon').removeclass('icon-jian').addclass('icon-jia');
_this.attr('unfold','false');
}else{
_this.find('.class-title-icon').removeclass('icon-jia').addclass('icon-jian');
_this.attr('unfold','true');
}
};
_this.next().stop().slidetoggle(400);
});
} else {
//大屏
$('#module_' + moduleid + ' .classify').off('click');
};
}
$(window).off('resize.' + moduleid).on('resize.' + moduleid, function () {
windowchange();
});
windowchange();
//移动端点击显示下一级
} else if ($.inarray(layout,['103']) > -1) {
$(window).on('resize', function () {
windowchange103();
});
windowchange103();
//给titel绑定事件
function windowchange103() {
var windowwidth = $(window).width();
if (windowwidth < 768) {
$('#module_' + moduleid + '.main-class-item').off('click').on('click', function () {
var _this = $(this);
$('#module_' + moduleid + '.main-class-item').removeclass('active')
_this.toggleclass('active');
});
}
}
} else if ($.inarray(layout,['104','108','109','110']) > -1) {
$(window).off('resize.commoncls' + layout + '_' + moduleid).on('resize.commoncls' + layout + '_' + moduleid, function () {
windowchange();
});
//给titel绑定事件
var windowchange = function () {
var windowwidth = window.innerwidth;
if (windowwidth < 768) {
var documentscrootop = 0;
//生成遮罩层和弹窗内容放入body
$('.mask-layermask-layer').remove();
if ($('.layout-' + layout + 'dialog'+moduleid).length <= 0) { /* style="padding-top:50px"要判断是否有头部*/
$('body').append('
' + $('#module_'+moduleid+' .main-class-container-mobile').html() + '
');
$('body').append('');
}else{
$('.layout-' + layout + 'dialog'+ moduleid).removeclass('dialog-show').addclass('dialog-hide goback')
}
if($('.mask-layermask-layer'+moduleid).length<=0){
$('body').append('');
}
$('.layout-' + layout + 'dialog' + moduleid).find('.main-class-item').show();
//点击全部分类弹窗出现
$('#module_' + moduleid + ' .class-title').off('click').on('click', function () {
// 判断是否存在响应处理
if ($('meta[name="viewport"]').length <= 0 && (layout == '108' || layout == '110' || layout == '104' || layout == '109')) {
return
}
$('.layout-' + layout + 'dialog'+ moduleid).css({
'margin': '0',
'display': 'block'
}).removeclass('dialog-hide goback').addclass('dialog-show');
if($('.mask-layermask-layer').length<=0){
$('body').append('');
}
$('.mask-layermask-layer').fadein();
documentscrootop = $(document).scrolltop();
});
$('.layout-' + layout + 'dialog' + moduleid + ' .classify').off('click.classify109').on('click.classify109 touch',{multiple:false}, function (e) {
//给二级添加事件(显示掩藏)
var _this = $(this);
_this.parent().toggleclass('on');
_this.find('.main-class-icon').toggleclass('active');
_this.next('.sub-class-item-box').stop().slidetoggle('slow');
if ($.inarray(layout, ['110','109','108']) > -1) {
if (!e.data.multiple) {
var inlayout = _this.parents('div[class^="inlayout"]');
//将不是当前的ul收回去顺便removecalss.
if(layout == '110'){
if (_this.parent().hasclass('main-class-item')) {
inlayout.find('.sub-class-item-box').not(_this.parent('.on').find('.sub-class-item-box').eq(0)).slideup().parent().removeclass('on').find('.main-class-icon.active').removeclass('active')
} else if (_this.parent().hasclass('child-item')) {
//关闭自己的兄弟
_this.parent().siblings().find('.sub-class-item-box').slideup().parent().removeclass('on').find('.main-class-icon.active').removeclass('active');
}
}else if(layout == '109' || layout == '108'){
if (_this.hasclass('main-class-item')) {
inlayout.find('.sub-class-item-box,.third-class-item-box').not(_this.parent('.on').find('.sub-class-item-box').eq(0)).slideup().parent().removeclass('on').find('.main-class-icon.active,.sub-class-icon.active').removeclass('active')
}
}
}
}
});
if ($.inarray(layout,['109']) > -1) {
// debugger
$('.layout-' + layout + 'dialog' + moduleid + ' .sub-class-item').off('click.sub-class-item-109').on('click.sub-class-item-109 touch', function () {
// debugger
//给三级添加事件(显示掩藏)
var _this = $(this);
_this.parent().toggleclass('on');
_this.find('.sub-class-icon').toggleclass('active');
_this.next('.third-class-item-box').stop().slidetoggle('slow');
if(_this.parent().hasclass('two-classify')){
//关闭自己的兄弟
_this.parent().find('.third-class-item-box').not(_this.next()).slideup().prev().find('.sub-class-icon.active').removeclass('active');
}
//return false;
});
}
/*点击左侧关闭弹窗*/
$('.layout-' + layout + 'dialog' + moduleid + ' .layout' + layout + 'dialog-left').off('click').on('click',function(){
//$('.layout-' + layout + 'dialog' + moduleid).
$('.layout-' + layout + 'dialog' + moduleid).addclass('dialog-hide');
$('.mask-layermask-layer').fadeout('normal',function(){
$('.layout-' + layout + 'dialog' + moduleid).hide();
});
})
var startx = 0;
var starty = 0
var cha = 0;
var chay = 0;
var currenty = 0;
var maxheight = 0;
var parentheight = 0;
function touchstart(e) {
e = window.event || e;
// startx=e.targettouches[0].clientx;
if (e.touches) {
startx = e.targettouches[0].clientx;
starty = e.targettouches[0].clienty;
} else {
startx = e.clientx;
starty = e.clienty;
};
$('.layout-' + layout + 'dialog' + moduleid).off('mousemove').on('mousemove', touchmove);
var itembox = $(this).find('.main-class-item-box');
parentheight = $(this).height();
maxheight = $('.inlayout-' + layout + 'dialog' + moduleid).height();
}
function touchmove(e) {
//防止出现滚动条
//$('body').css('overflow', 'hidden');
$(document).scrolltop(documentscrootop);
e = window.event || e;
e.stoppropagation();
e.preventdefault();
if (e.touches) {
//移动端
cha = e.targettouches[0].clientx - startx;
chay = e.targettouches[0].clienty - starty;
$(this).removeclass('dialog-show goback').css('margin-left', cha);
if(maxheight>parentheight-100){
$(this).find('.inlayout-' + layout + 'dialog'+moduleid).css('top',chay+currenty);
}
} else {
//pc端
cha = e.clientx - startx;
chay = e.clienty - starty;
$(this).removeclass('dialog-show goback').css('margin-left', cha);
if(maxheight>parentheight-100){
$(this).find('.inlayout-' + layout + 'dialog'+moduleid).css('top',chay+currenty);
}
};
//向右边移动才会动,并设置灵敏度为80
if (cha > 80) {
$(this).addclass('dialog-hide');
$('.mask-layermask-layer' + moduleid).fadeout('normal',function(){
$('.layout-' + layout + 'dialog' + moduleid).hide();
});
$('.layout-' + layout + 'dialog' + moduleid).off('mousemove');
} else {
$(this).addclass('goback');
};
}
function touchend(e) {
$(document).scrolltop(documentscrootop);
e = window.event || e;
e.stoppropagation();
//向右边移动才会动,并设置灵敏度为50
var endx = 0;
var endy = 0;
if (e.changedtouches) {
endx = e.changedtouches[0].clientx;
//endx = e.originalevent.changedtouches[0];
endy = e.changedtouches[0].clienty;
} else {
endx = e.clientx;
endy = e.clienty;
};
currenty = $('.layout-' + layout + 'dialog' + moduleid).find('.inlayout-' + layout + 'dialog'+moduleid).position().top;
if(currenty<0 && maxheight>parentheight-100 && parentheight-maxheight-95 > currenty){
$('.layout-' + layout + 'dialog' + moduleid).find('.inlayout-' + layout + 'dialog'+moduleid).stop().animate({'top':parentheight-maxheight-100},function(){
currenty = parentheight-maxheight-100;
});
};
if(maxheight>parentheight-95 && currenty>0){
$('.layout-' + layout + 'dialog' + moduleid).find('.inlayout-' + layout + 'dialog'+moduleid).stop().animate({'top':0},function(){
currenty = 0;
})
}
if (endx - startx > 50 && endx - startx>endy-currenty) {
$(this).addclass('dialog-hide');
$('.mask-layermask-layer' + moduleid).fadeout('normal',function(){
$('.layout-' + layout + 'dialog' + moduleid).hide();
});
} else {
//移动距离少于50就会到原位
$(this).addclass('goback');
}
$('.layout-' + layout + 'dialog' + moduleid).off('mousemove');
}
$('.layout-' + layout + 'dialog' + moduleid).off('touchstart').on('touchstart', touchstart)
$('.layout-' + layout + 'dialog' + moduleid).off('touchmove').on('touchmove', touchmove);
$('.layout-' + layout + 'dialog' + moduleid).off('touchend').on('touchend', touchend);
$('.layout-' + layout + 'dialog' + moduleid).off('mousedown').on('mousedown', touchstart);
$('.layout-' + layout + 'dialog' + moduleid).off('mouseup').on('mouseup', touchend);
} else {
$('.mask-layermask-layer').remove();
$('.layout-' + layout + 'dialog' + moduleid).hide();
if ((layout == '110' && window.innerwidth<1200) || layout != '110') {
$('#module_' + moduleid + ' .classify').off('click.classify110').on('click.classify110', function () {
var _this = $(this);
_this.find('.main-class-icon').toggleclass('active');
_this.next('.sub-class-item-box').stop().slidetoggle('slow');
});
}
if ($.inarray(layout,['109']) > -1) {
$('#module_' + moduleid + ' .sub-class-item').off('click').on('click', function () {
var _this = $(this);
_this.find('.sub-class-icon').toggleclass('active');
_this.next('.third-class-item-box').stop().slidetoggle('slow');
})
}
};
}
windowchange();
if(curclass != null){
curclass.closest('.main-class-item-box').find('.classify').click();
// 当是第三级分类选中时展开三级
if (curclass.hasclass('third-class-item')) {
curclass.closest('.sub-class-item-box').queue(function() {
curclass.closest('.sub-class-item-box').find('.sub-class-item').click();
$(this).dequeue();
})
}
}
if(layout == '110'){
initcommonclspc110(moduleid)
}
// 判断是否存在响应处理
if ($('meta[name="viewport"]').length <= 0 && (layout == '108' || layout == '110' || layout == '104' || layout == '109')) {
$('.moduleassoccommonclsgiant .main-class-container-mobile').css('display', 'block');
$('.moduleassoccommonclsgiant .class-title .class-title-icon').css('display', 'none');
}
} else if (layout == '106') {
initcommoncls106(moduleid);
} else if (layout == '107') {
initcommoncls107(moduleid);
}
}
function initcommoncls106(moduleid) {
$(window).off('resize.commoncls106_' + moduleid).on('resize.commoncls106_' + moduleid, function () {
var windowwidth = $(window).width();
//大屏和小屏事件不同
if (windowwidth >= 768) {
if ($("#clone_mob_module_" + moduleid).length > 0) {
$("#clone_mob_module_" + moduleid).hide();
};
$('#pro-106-shade'+moduleid).hide();
} else {
if ($("#clone_mob_module_" + moduleid).length > 0) {
$("#clone_mob_module_" + moduleid).show();
};
};
})
initcommonclspc106(moduleid);
initcommonclsmob106(moduleid);
}
// 106通用分类模块
function initcommonclspc106(moduleid) {
var moduleidselector = "#module_" + moduleid;
var cloneid = "#clone_module_" + moduleid;
var mainitemsrow = document.queryselectorall(moduleidselector + ' .main-class-container .main-class-content>ul.main-class-all-item>.main-class-row');
var mainitemsbox = document.queryselectorall(moduleidselector + ' .main-class-container .main-class-content');
// 遍历节点,判断是否有下级菜单,如果没有,那么就把【下级菜单的箭头 icon 图标】 隐藏掉
$(moduleidselector + ' .main-class-container .sub-class-content .sub-class-items').each(function (index) {
if ($(this).find('.sub-class-row').length === 0) {
$(moduleidselector + ' .main-class-container .main-class-content>ul.main-class-all-item>.main-class-row').eq(index).find('.main-class-icon').hide()
}
});
// 判断是否存在响应处理
if ($('meta[name="viewport"]').length <= 0) {
$('.moduleassoccommonclsgiant.layout-106 .main-class-container').css('display', 'block');
$('.moduleassoccommonclsgiant.layout-106 .main-class-all-classify').css('display', 'none');
}
$(mainitemsrow).off('mouseenter').on('mouseenter',function(){
var _this = $(this);
// 获取侧边导航
$(cloneid).remove();
//每次移入都生成克隆
var clone = $("");
clone.appendto("body");
$(moduleidselector + ' .main-class-container .sub-class-content').clone().appendto($(cloneid).find(' .main-class-container .main-class-content'));
$(cloneid).find('.sub-class-items').hide();
$(mainitemsrow).removeclass('current');
// 判断是否存在响应处理
if ($('meta[name="viewport"]').length <= 0) {
$('.moduleassoccommonclsgiant.layout-106 .main-class-container').css('display', 'block');
}
if($(cloneid).find('.sub-class-items').eq($(this).index()).children().length<=0){
return
};
$(cloneid).find('.sub-class-items').eq($(this).index()).show();
$(this).addclass('current');
$(cloneid).css({
'position': 'absolute',
'left': ($(this).closest('ul').offset().left + $(this).outerwidth()) + 'px',
'top': $(this).closest('ul').offset().top + 'px',
'z-index':'99',
});
$(cloneid).find('.sub-class-content').show().css('min-height',$(this).offset().top - $(mainitemsbox).offset().top + $(this).outerheight())
$(cloneid).show();
$(cloneid).off('mouseenter').on('mouseenter',function(){
$(this).show();
_this.addclass('current');
})
// debugger
$(moduleidselector+','+cloneid).off('mouseleave').on('mouseleave',function(){
$(this).remove();
$(mainitemsrow).removeclass('current');
})
$(moduleidselector).off('mouseleave').on('mouseleave',function(event){
if (event.toelement && !event.toelement
.classlist.contains('sub-class-content')) {
$('#clone_module_'+moduleid).remove();
$(mainitemsrow).removeclass('current');
}
})
});
}
function initcommonclsmob106(moduleid) {
var cloneidmob = "#clone_mob_module_" + moduleid;
if($(cloneidmob).length){
$(cloneidmob).remove();
}
var moduleclass = $('#module_' + moduleid).children().attr('class') || '';
// 移动端处理
var clonemob = $("");
clonemob.append($("#module_" + moduleid + " .main-class-container-mobile").clone(true));
clonemob.appendto("body");
var leftlucency = $(clonemob).find('.leftlucency');
var ulboxparent = document.queryselector(cloneidmob + " .main-class-container-mobile .main-class-list-title");
// 一级导航元素的父盒子
var ulbox = document.queryselector(cloneidmob + " .main-class-container-mobile .main-class-list-title>.list-title-all");
// 获取一级导航元素
var lis = ulbox.queryselectorall(cloneidmob + " .main-class-container-mobile .main-class-item");
// 移动端最大的父盒子
var mobilebox = document.queryselector(cloneidmob + " .main-class-container-mobile");
// 透明区域块
var transparentbox = document.queryselector(cloneidmob + " .main-class-container-mobile>.transparentbox");
var showbox = document.queryselector('#module_' + moduleid + ' .main-class-all-classify');
// 获取分类内容区域盒子
var parentttems = document.queryselector(cloneidmob + " .main-class-container-mobile .main-class-list-content");
// 获取分类内容区域子盒子
var items = document.queryselectorall(cloneidmob + " .main-class-container-mobile .main-class-list-content .main-class-content-item");
// 封装循环
var each = function (arr, fn) {
for (var i = 0; i < arr.length; i++) {
fn.call(arr[i], i, arr[i]);
}
};
// 给需要滚动的盒子的父盒子添加高度
parentaddheight();
$(transparentbox).attr('id','pro-106-shade'+moduleid);
$('body').append($(transparentbox));
function parentaddheight() {
var bodyheight;
if (document.body.clientheight) {
bodyheight = document.body.clientheight
} else {
bodyheight = document.documentelement.clientheight;
}
var topparent = parentttems.offsettop;
var showheight = bodyheight - topparent;
each(items, function (i, val) {
val.style.height = showheight + 'px';
});
ulboxparent.style.height = showheight + 'px';
}
// 记录索引
var index;
// 侧边栏事件触发
slideholdhk.tap(ulbox, function (e) {
if ($(e.target).attr("dataid")) {
$(mobilebox).fadeout(300);
mobilebox.style.transform = 'translatex(100%)';
$('#pro-106-shade'+moduleid).fadeout();
leftlucency.hide();
} else {
e.stoppropagation();
var lia = e.target;
each(lis, function (i, val) {
var libox = this;
libox.classlist.remove("active");
if (lia == val) {
index = i;
}
});
each(items, function (i, val) {
var itembox = this;
itembox.classlist.remove("current");
if (lia == val) {
index = i;
};
});
lia.classlist.add("active");
items[index].classlist.add("current");
slideholdhk.myslide(cloneidmob + " .main-class-container-mobile .main-class-list-content .main-class-content-item.current", 50);
}
});
// 点击阴影部分收缩
slideholdhk.tap(transparentbox, function () {
$(mobilebox).fadeout(300);
mobilebox.style.transform = 'translatex(100%)';
});
// 弹框滑动
slideholdhk.boxslidex(cloneidmob + ' .main-class-container-mobile');
// 关闭按钮
document.queryselector(cloneidmob + " .main-class-container-mobile .main-class-content-title .close").onclick = function () {
$(mobilebox).fadeout(300);
mobilebox.style.transform = 'translatex(100%)';
$('#pro-106-shade'+moduleid).fadeout();
leftlucency.hide();
};
//点击侧边关闭弹窗
leftlucency.off('click').on('click',function(){
$(cloneidmob + " .main-class-container-mobile .main-class-content-title .close").click();
})
// 按钮显示
showbox.onclick = function () {
mobilebox.style.display = 'block';
$('#pro-106-shade'+moduleid).fadein();
// 侧边栏
slideholdhk.myslide(cloneidmob + " .main-class-container-mobile .main-class-list-title", 50);
// 内容展示
slideholdhk.myslide(cloneidmob + " .main-class-container-mobile .main-class-list-content .main-class-content-item.current", 50);
mobilebox.style.transform = 'translatex(0%)';
mobilebox.children[0].style.left = "20%";
//mobilebox
leftlucency.show();
settimeout(function(){
resetheightthreeimg(moduleid,'106');
},400);
};
//窗口改变大小时
window.addeventlistener('resize', function (e) {
if (e.target === window) {
// 侧边栏
slideholdhk.myslide(cloneidmob + " .main-class-container-mobile .main-class-list-title", 50);
// 内容展示
slideholdhk.myslide(cloneidmob + " .main-class-container-mobile .main-class-list-content .main-class-content-item.current", 50);
if($(cloneidmob).length>0){
$(cloneidmob).hide()
};
}else{
if($(cloneidmob).length>0){
$(cloneidmob).show()
};
}
});
};
function initcommoncls107(moduleid) {
$(window).off('resize.commoncls107_' + moduleid).on('resize.commoncls107_' + moduleid, function () {
var windowwidth = $(window).width();
//大屏和小屏事件不同
if (windowwidth >= 768) {
if ($("#clone_mob_module_" + moduleid).length > 0) {
$("#clone_mob_module_" + moduleid).hide();
};
} else {
if ($("#clone_mob_module_" + moduleid).length > 0) {
$("#clone_mob_module_" + moduleid).show();
};
};
})
initcommonclspc107(moduleid);
initcommonclsmob107(moduleid);
navshowsubandstyle(moduleid);
// 判断是否存在响应处理
if ($('meta[name="viewport"]').length <= 0) {
$('.moduleassoccommonclsgiant.layout-107 .main-class-container').css('display', 'block');
$('.moduleassoccommonclsgiant.layout-107 .main-class-all-classify').css('display', 'none');
}
}
function initcommonclspc107(moduleid) {
var moduleidselector = "#module_" + moduleid;
var cloneid = "#clone_module_" + moduleid;
var clone = $(""
);
clone.appendto('body');
clone.find('.main-class-container').append($(moduleidselector).find(".sub-class-content-main-show").clone());
}
function initcommonclspc110(moduleid) {
var moduleidselector = "#module_" + moduleid;
var cloneid = "clone_module_" + moduleid;
$(moduleidselector+' .main-class-item').off('mouseenter mouseleave').on('mouseenter', function () {
$(this).addclass("active");
var clone = $(this).find(".two-outsize").clone();
clone.attr('id',cloneid).addclass('moduleassoccommonclsgiant').addclass('layout-110').addclass('assoc-cls-listener-a');
clone.appendto('body');
//追加到body里面去之后再让它显示出来
var ldistance = $(this).offset().left+$(this).outerwidth();
var tdistance = $(this).offset().top;
clone.css({left:ldistance,top:tdistance,"position":"absolute","z-index":"9999","opacity":"1"});
clone.find('.two-classify').css("display","block");
}).on('mouseleave', function (evt) {
var _this = this;
evt = evt || window.event;
var relatedtarget = evt.relatedtarget || evt.toelement;
if ($(relatedtarget).is('#'+cloneid)) {
$(relatedtarget).on('mouseleave', function () {
$(_this).removeclass("active");
$(this).remove();
});
return false;
}else{
$(this).removeclass("active");
$('#'+cloneid).remove();
}
});
}
function initcommonclsmob107(moduleid) {
var cloneidmob = "#clone_mob_module_" + moduleid;
// 移动端处理·
var clonemob = $("");
clonemob.append($("#module_" + moduleid + " .main-class-container-mobile").clone(true));
clonemob.appendto("body");
//点击侧边关闭弹窗
var leftlucency = clonemob.find('.leftlucency');
var ulboxparent = document.queryselector(cloneidmob + " .main-class-container-mobile .main-class-list-title");
// 一级导航元素的父盒子
var ulbox = document.queryselector(cloneidmob +
" .main-class-container-mobile .main-class-list-title>.list-title-all");
// 获取一级导航元素
var lis = ulbox.queryselectorall(cloneidmob + " .main-class-container-mobile .main-class-item");
// 移动端最大的父盒子
var mobilebox = document.queryselector(cloneidmob + " .main-class-container-mobile");
// 透明区域块
var transparentbox = document.queryselector(cloneidmob + " .main-class-container-mobile>.transparentbox");
var showbox = document.queryselector('#module_' + moduleid + ' .main-class-all-classify');
// 获取分类内容区域盒子
var parentttems = document.queryselector(cloneidmob + " .main-class-container-mobile .main-class-list-content");
// 获取分类内容区域子盒子
var items = document.queryselectorall(cloneidmob +
" .main-class-container-mobile .main-class-list-content .main-class-content-item");
// 封装循环
var each = function (arr, fn) {
for (var i = 0; i < arr.length; i++) {
fn.call(arr[i], i, arr[i]);
}
};
// 给需要滚动的盒子的父盒子添加高度
parentaddheight();
$(transparentbox).attr('id','pro-107-shade'+moduleid)
$('body').append($(transparentbox));
function parentaddheight() {
var bodyheight;
if (document.body.clientheight) {
bodyheight = document.body.clientheight
} else {
bodyheight = document.documentelement.clientheight;
}
var topparent = parentttems.offsettop;
var showheight = bodyheight - topparent;
each(items, function (i, val) {
val.style.height = showheight + 'px';
});
ulboxparent.style.height = showheight + 'px';
}
// 记录索引
var index;
// 侧边栏事件触发
slideholdhk.tap(ulbox, function (e) {
if ($(e.target).attr("dataid")) {
$(mobilebox).fadeout(300);
$('#pro-107-shade'+moduleid).fadeout();
leftlucency.hide();
mobilebox.style.transform = 'translatex(100%)';
} else {
e.stoppropagation();
var lia = e.target;
each(lis, function (i, val) {
var libox = this;
libox.classlist.remove("active");
if (lia == val) {
index = i;
}
});
each(items, function (i, val) {
var itembox = this;
itembox.classlist.remove("current");
if (lia == val) {
index = i;
};
});
lia.classlist.add("active");
items[index].classlist.add("current");
slideholdhk.myslide(cloneidmob +
" .main-class-container-mobile .main-class-list-content .main-class-content-item.current",
50);
}
});
// 点击阴影部分收缩
slideholdhk.tap(transparentbox, function () {
$(mobilebox).fadeout(300);
mobilebox.style.transform = 'translatex(100%)';
});
// 弹框滑动
slideholdhk.boxslidex(cloneidmob + ' .main-class-container-mobile');
// 关闭按钮
document.queryselector(cloneidmob + " .main-class-container-mobile .main-class-content-title .close").onclick =
function () {
$(mobilebox).fadeout(300);
$('#pro-107-shade'+moduleid).fadeout();
leftlucency.hide();
mobilebox.style.transform = 'translatex(100%)';
};
//点击侧边关闭弹窗
leftlucency.off('click').on('click',function(){
$(cloneidmob + " .main-class-container-mobile .main-class-content-title .close").click();
})
// 按钮显示
showbox.onclick = function () {
mobilebox.style.display = 'block';
$('#pro-107-shade'+moduleid).fadein();
// 侧边栏
slideholdhk.myslide(cloneidmob + " .main-class-container-mobile .main-class-list-title", 50);
// 内容展示
slideholdhk.myslide(cloneidmob + " .main-class-container-mobile .main-class-list-content .main-class-content-item.current", 50);
clonemob.show();
mobilebox.style.transform = 'translatex(0%)';
mobilebox.children[0].style.left = "20%";
leftlucency.show();
settimeout(function(){
resetheightthreeimg(moduleid,'107');
},400);
};
//窗口改变大小时
window.addeventlistener('resize', function (e) {
if (e.target === window) {
$(cloneidmob + " .main-class-container-mobile .main-class-content-title .close").click()
}
});
};
// 切换显示导航内容
function navshowsubandstyle(moduleid) {
var moduleidselector = "#module_" + moduleid;
var cloneid = "#clone_module_" + moduleid;
var subshow = $(cloneid + ' .main-class-container .sub-class-content-main-show .sub-class-content');
var mainnav = $(moduleidselector + ' .main-class-container .mainsub-class-box');
subshow.find('.third-class-content').each(function(index, el) {
if($(el).children().length<=0){
$(el).remove();
}
});
mainnav.off('mouseenter mouseleave').on('mouseenter', function () {
subshow.hide();
if (subshow.eq($(this).index()).children().length > 0) {
subshow.eq($(this).index()).css({
'display': 'block',
'position': 'absolute',
'top': mainnav.offset().top,
'left': mainnav.offset().left + mainnav.outerwidth(),
'height': mainnav.parent().outerheight(),
'z-index': 99
});
};
mainnav.removeclass('active');
if($(this).find('.sub-class-content').children().length<=0){
return;
}
$(this).addclass('active').siblings().removeclass('active');
subshow.eq($(this).index()).addclass('active').siblings().removeclass('active');
subshow.eq($(this).index()).parent().show();
}).on('mouseleave', function (evt) {
// 移除鼠标后出发
evt = evt || window.event;
var relatedtarget = evt.relatedtarget || evt.toelement;
if ($(relatedtarget).is('.main-class-content,.sub-class-content') || $(relatedtarget).closest('.main-class-content,.sub-class-content').length > 0) {
return false;
}
$(subshow).mouseleave();
});
subshow.off('mouseleave').on('mouseleave', function () {
mainnav.removeclass('active');
subshow.eq($(this).index()).parent().hide();
});
}
//当选择有三级分类时 重置三级分类的图片的高度(1:1)
function resetheightthreeimg(moduleid,layout){
var clonebox = '#clone_mob_module_'+moduleid;
var threeimg = $(clonebox).find('.third-class-item-hasimg img');
threeimg.stop().animate({'height':threeimg.width()})
}
// 匹配当前选中的分类
function matchcurrentclass(href){
if(typeof href == 'undefined')return false;
var re_nav = new regexp('^.*' + location.host, 'i');
var menuhref = href.replace(/\?.*$/, '').replace(/\/*$/, '');
var homeurl = location.protocol + "//" + location.hostname.replace(/\/*$/, '');
var homeurlarr = [];
homeurlarr.push(homeurl);
homeurlarr.push(homeurl + "/index");
homeurlarr.push(homeurl + "/home/index");
homeurlarr.push(homeurl + "/" + getcookie('lang'));
homeurlarr.push(homeurl + "/index.php");
homeurlarr.push(homeurl + "/home/index.php");
homeurlarr.push(homeurl + "/" + getcookie('lang') + "/index.php");
var ismatch = false;
if ($.inarray(menuhref, homeurlarr) > -1) {
if ($.inarray(location.href.replace(/\?.*$/, '').replace(/\/*$/, ''), homeurlarr) > -1) {
ismatch = true;
}
} else if (location.href.indexof(href) > -1 && location.href.replace(/(\?|#).*$/, '') == href.replace(/(\?|#).*$/, '') && location.pathname.indexof('-') == href.replace(re_nav, '').indexof('-')) {
ismatch = true;
}
return ismatch;
}
if (!window.slideholdhk) {
/**
* created by huangke on 2017/05/06.
*/
slideholdhk = {};
/**
* 纵轴滑动效果
* @param dom 父元素盒类名 该元素下只有一个子元素
* @param num 弹框范围
*/
slideholdhk.myslide = function (dom, scope) {
scope = math.abs(scope);
var parentbox = document.queryselector(dom);
var maincontent = parentbox.children[0];
if (!maincontent) {
return;
}
var parentheight = parentbox.offsetheight;
var maincontentheight = 0;
// 距离顶部的距离
var parenttop;
//可视区域高度
var bodyheight;
if (document.body.clientheight) {
bodyheight = document.body.clientheight
} else {
bodyheight = document.documentelement.clientheight;
}
// 显示区域与内容高度的差值
var chaheight = 0;
//设置全局变量
var starty = 0;
var movey = 0;
var chaa = 0;
//当前的值
var current = 0;
// 记录最小值
var minheight = 0;
// 最大值
var maxheight = 0;
//过渡设置
var opentransition = function () {
maincontent.style.transition = "all .2s"
maincontent.style.webkittransition = "all .2s"
}
var closetransition = function () {
maincontent.style.transition = "none"
maincontent.style.webkittransition = "none"
}
//设置偏移
var settransform = function (num) {
maincontent.style.transform = "translatey(" + (num) + "px)";
}
//触摸事件
//开始
maincontent.addeventlistener("touchstart", function (e) {
parenttop = parentbox.offsettop;
starty = e.touches[0].clienty;
maincontentheight = maincontent.offsetheight+60;
/*子容器没有父容器大的时候*/
if (maincontentheight < parentheight) {
maincontent.style.height = parentheight + 'px';
maincontentheight = parentheight;
}
chaheight = bodyheight - maincontentheight;
minheight = chaheight < 0 ? chaheight - parenttop : 0;
});
//移动
maincontent.addeventlistener("touchmove", function (e) {
e.stoppropagation();
e.preventdefault();
movey = e.touches[0].clienty;
chaa = movey - starty;
// 当前的值加上移动的值大于最大高度加弹性值时返回
// 当前的值加上移动的值小于最小值减去弹性值时返回
if (current + chaa > maxheight + scope || current + chaa < minheight - scope) {
return;
}
closetransition();
settransform(current + chaa);
});
//结束
maincontent.addeventlistener("touchend", function (e) {
// 如果移动的值加上移动过的值小于最小值返回最小值
if (current + chaa < minheight) {
current = minheight;
opentransition();
settransform(minheight);
} else if (current + chaa > maxheight) {
current = maxheight;
opentransition();
settransform(maxheight);
} else {
current += chaa;
}
});
};
// 动画结束后触发的事件
slideholdhk.transitiona = function (dom, fn) {
if (dom != null && typeof dom == "object") {
dom.addeventlistener("transitionend", function () {
fn && fn()
});
dom.addeventlistener("webkittransitionend", function () {
fn && fn()
});
}
};
/**
* 移动端优化的点击事件
* @param dom 触发事件的元素
* @param fn 回调函数
*/
slideholdhk.tap = function (dom, fn) {
var type = ismobilebroswer();
if (ismobilebroswer()) {
var isflag = false;
var st = 0;
dom.addeventlistener("touchstart", function (e) {
st = date.now();
});
dom.addeventlistener("touchmove", function (e) {
isflag = true;
});
dom.addeventlistener("touchend", function (e) {
if (isflag == false && (date.now() - st) < 150) {
fn && fn(e);
}
isflag = false;
});
} else {
dom.addeventlistener("click", function (e) {
fn && fn(e);
});
}
};
/**
* [boxslidex description]
* @param {[type]} dom [description] 父元素盒子 确保这个父元素的第一个子元素是需要滑动的盒子
* @return {[type]} [description]
*/
slideholdhk.boxslidex = function (dom) {
var parentbox = document.queryselector(dom);
// 获取子元素
var itembox = parentbox.children[0];
// 记录值
var startx = 0;
var movex = 0;
var chaa = 0;
var leftnum = 0;
//过渡设置
var opentransition = function () {
itembox.style.transition = "all .2s"
itembox.style.webkittransition = "all .2s"
}
var closetransition = function () {
itembox.style.transition = "none"
itembox.style.webkittransition = "none"
}
//设置偏移
var settransform = function (num) {
itembox.style.left = num;
}
//开始
itembox.addeventlistener("touchstart", function (e) {
startx = e.touches[0].clientx;
leftnum = itembox.offsetleft;
});
//移动
itembox.addeventlistener("touchmove", function (e) {
e.preventdefault();
movex = e.touches[0].clientx;
chaa = movex - startx;
if (math.abs(chaa) >= 50) {
return;
}
closetransition();
settransform((leftnum + chaa) + "px");
});
//结束
itembox.addeventlistener("touchend", function (e) {
if (chaa < -50) {
opentransition();
settransform(leftnum + "px");
} else if (chaa > 30) {
opentransition();
settransform('100%');
$(parentbox).fadeout(300);
parentbox.style.transform = 'translatex(100%)';
$('#pro-107-shade'+$(parentbox).closest('.moduleassoccommonclsgiant').attr('id').replace('clone_mob_module_','')).fadeout(300);
$('#pro-106-shade'+$(parentbox).closest('.moduleassoccommonclsgiant').attr('id').replace('clone_mob_module_','')).fadeout(300);
} else {
opentransition();
settransform(leftnum + "px");
}
});
}
};