升级.net8
This commit is contained in:
@ -48,7 +48,7 @@ layui.define('jquery', function(exports){
|
||||
}() +'>'+ (options.title || 'unnaming') +'</li>';
|
||||
|
||||
barElem[0] ? barElem.before(li) : titElem.append(li);
|
||||
contElem.append('<div class="layui-tab-item">'+ (options.content || '') +'</div>');
|
||||
contElem.append('<div class="layui-tab-item" ' + (options.id ? 'lay-id="' + options.id + '"' : '') + '>'+ (options.content || '') +'</div>');
|
||||
// call.hideTabMore(true);
|
||||
// 是否添加即切换
|
||||
options.change && this.tabChange(filter, options.id);
|
||||
@ -66,14 +66,21 @@ layui.define('jquery', function(exports){
|
||||
return this;
|
||||
};
|
||||
|
||||
// 外部 Tab 切换
|
||||
Element.prototype.tabChange = function(filter, layid){
|
||||
/**
|
||||
* 外部 Tab 切换
|
||||
* @param {string} filter - 标签主容器 lay-filter 值
|
||||
* @param {string} layid - 标签头 lay-id 值
|
||||
* @param {boolean} force - 是否强制切换
|
||||
* @returns {this}
|
||||
*/
|
||||
Element.prototype.tabChange = function(filter, layid, force){
|
||||
var tabElem = $('.layui-tab[lay-filter='+ filter +']');
|
||||
var titElem = tabElem.children(TITLE);
|
||||
var liElem = titElem.find('>li[lay-id="'+ layid +'"]');
|
||||
|
||||
call.tabClick.call(liElem[0], {
|
||||
liElem: liElem
|
||||
liElem: liElem,
|
||||
force: force
|
||||
});
|
||||
return this;
|
||||
};
|
||||
@ -82,7 +89,7 @@ layui.define('jquery', function(exports){
|
||||
Element.prototype.tab = function(options){
|
||||
options = options || {};
|
||||
dom.on('click', options.headerElem, function(e){
|
||||
var index = $(this).index();
|
||||
var index = $(options.headerElem).index($(this));
|
||||
call.tabClick.call(this, {
|
||||
index: index,
|
||||
options: options
|
||||
@ -134,21 +141,46 @@ layui.define('jquery', function(exports){
|
||||
var isJump = elemA.attr('href') !== 'javascript:;' && elemA.attr('target') === '_blank'; // 是否存在跳转
|
||||
var unselect = typeof othis.attr('lay-unselect') === 'string'; // 是否禁用选中
|
||||
var filter = parents.attr('lay-filter');
|
||||
var hasId = othis.attr('lay-id');
|
||||
|
||||
// 下标
|
||||
var index = 'index' in obj
|
||||
? obj.index
|
||||
: othis.parent().children('li').index(othis);
|
||||
|
||||
// 若非强制切换,则根据 tabBeforeChange 事件的返回结果决定是否切换
|
||||
if (!obj.force) {
|
||||
var liThis = othis.siblings('.' + THIS);
|
||||
var shouldChange = layui.event.call(this, MOD_NAME, 'tabBeforeChange('+ filter +')', {
|
||||
elem: parents,
|
||||
from: {
|
||||
index: othis.parent().children('li').index(liThis),
|
||||
id: liThis.attr('lay-id')
|
||||
},
|
||||
to: {
|
||||
index: index,
|
||||
id: hasId
|
||||
},
|
||||
});
|
||||
if(shouldChange === false) return;
|
||||
}
|
||||
|
||||
// 执行切换
|
||||
if(!(isJump || unselect)){
|
||||
othis.addClass(THIS).siblings().removeClass(THIS);
|
||||
item.eq(index).addClass(SHOW).siblings().removeClass(SHOW);
|
||||
if(hasId){
|
||||
var contentElem = item.filter('[lay-id="' + hasId + '"]');
|
||||
contentElem = contentElem.length ? contentElem : item.eq(index);
|
||||
contentElem.addClass(SHOW).siblings().removeClass(SHOW);
|
||||
}else{
|
||||
item.eq(index).addClass(SHOW).siblings().removeClass(SHOW);
|
||||
}
|
||||
}
|
||||
|
||||
layui.event.call(this, MOD_NAME, 'tab('+ filter +')', {
|
||||
elem: parents,
|
||||
index: index
|
||||
index: index,
|
||||
id: hasId
|
||||
});
|
||||
}
|
||||
|
||||
@ -159,6 +191,14 @@ layui.define('jquery', function(exports){
|
||||
var tabElem = li.closest('.layui-tab');
|
||||
var item = tabElem.children('.layui-tab-content').children('.layui-tab-item');
|
||||
var filter = tabElem.attr('lay-filter');
|
||||
var hasId = li.attr('lay-id');
|
||||
|
||||
var shouldClose = layui.event.call(li[0], MOD_NAME, 'tabBeforeDelete('+ filter +')', {
|
||||
elem: tabElem,
|
||||
index: index,
|
||||
id: hasId
|
||||
});
|
||||
if(shouldClose === false) return;
|
||||
|
||||
if(li.hasClass(THIS)){
|
||||
if (li.next()[0] && li.next().is('li')){
|
||||
@ -171,14 +211,21 @@ layui.define('jquery', function(exports){
|
||||
}
|
||||
|
||||
li.remove();
|
||||
item.eq(index).remove();
|
||||
if(hasId){
|
||||
var contentElem = item.filter('[lay-id="' + hasId + '"]');
|
||||
contentElem = contentElem.length ? contentElem : item.eq(index)
|
||||
contentElem.remove()
|
||||
}else{
|
||||
item.eq(index).remove();
|
||||
}
|
||||
setTimeout(function(){
|
||||
call.tabAuto();
|
||||
}, 50);
|
||||
|
||||
layui.event.call(this, MOD_NAME, 'tabDelete('+ filter +')', {
|
||||
elem: tabElem,
|
||||
index: index
|
||||
index: index,
|
||||
id: hasId
|
||||
});
|
||||
}
|
||||
|
||||
@ -202,10 +249,11 @@ layui.define('jquery', function(exports){
|
||||
}
|
||||
|
||||
// 开启关闭图标
|
||||
if(othis.attr('lay-allowclose')){
|
||||
var allowclose = othis.attr('lay-allowclose');
|
||||
if(allowclose && allowclose !== 'false'){
|
||||
title.find('li').each(function(){
|
||||
var li = $(this);
|
||||
if(!li.find('.'+CLOSE)[0]){
|
||||
if(!li.find('.'+CLOSE)[0] && li.attr('lay-allowclose') !== 'false'){
|
||||
var close = $('<i class="layui-icon layui-icon-close layui-unselect '+ CLOSE +'"></i>');
|
||||
close.on('click', call.tabDelete);
|
||||
li.append(close);
|
||||
@ -272,31 +320,63 @@ layui.define('jquery', function(exports){
|
||||
)
|
||||
*/
|
||||
|
||||
//点击菜单 - a标签触发
|
||||
,clickThis: function(){
|
||||
var othis = $(this)
|
||||
,parents = othis.parents(NAV_ELEM)
|
||||
,filter = parents.attr('lay-filter')
|
||||
,parent = othis.parent()
|
||||
,child = othis.siblings('.'+NAV_CHILD)
|
||||
,unselect = typeof parent.attr('lay-unselect') === 'string'; //是否禁用选中
|
||||
// 点击菜单 - a 标签触发
|
||||
,clickThis: function() {
|
||||
var othis = $(this);
|
||||
var parents = othis.closest(NAV_ELEM);
|
||||
var filter = parents.attr('lay-filter');
|
||||
var parent = othis.parent() ;
|
||||
var child = othis.siblings('.'+ NAV_CHILD);
|
||||
var unselect = typeof parent.attr('lay-unselect') === 'string'; // 是否禁用选中
|
||||
|
||||
if(!(othis.attr('href') !== 'javascript:;' && othis.attr('target') === '_blank') && !unselect){
|
||||
if(!child[0]){
|
||||
parents.find('.'+THIS).removeClass(THIS);
|
||||
// 满足点击选中的条件
|
||||
if (!(othis.attr('href') !== 'javascript:;' && othis.attr('target') === '_blank') && !unselect) {
|
||||
if (!child[0]) {
|
||||
parents.find('.'+ THIS).removeClass(THIS);
|
||||
parent.addClass(THIS);
|
||||
}
|
||||
}
|
||||
|
||||
//如果是垂直菜单
|
||||
if(parents.hasClass(NAV_TREE)){
|
||||
// 若为垂直菜单
|
||||
if (parents.hasClass(NAV_TREE)) {
|
||||
var NAV_ITEMED = NAV_ITEM + 'ed'; // 用于标注展开状态
|
||||
var needExpand = !parent.hasClass(NAV_ITEMED); // 是否执行展开
|
||||
var ANIM_MS = 200; // 动画过渡毫秒数
|
||||
|
||||
// 动画执行完成后的操作
|
||||
var complete = function() {
|
||||
$(this).css({
|
||||
"display": "" // 剔除动画生成的 style display,以适配外部样式的状态重置
|
||||
});
|
||||
// 避免导航滑块错位
|
||||
parents.children('.'+ NAV_BAR).css({
|
||||
opacity: 0
|
||||
})
|
||||
};
|
||||
|
||||
// 是否正处于动画中的状态
|
||||
if (child.is(':animated')) return;
|
||||
|
||||
// 剔除可能存在的 CSS3 动画类
|
||||
child.removeClass(NAV_ANIM);
|
||||
|
||||
//如果有子菜单,则展开
|
||||
if(child[0]){
|
||||
parent[child.css('display') === 'none' ? 'addClass': 'removeClass'](NAV_ITEM+'ed');
|
||||
if(parents.attr('lay-shrink') === 'all'){
|
||||
parent.siblings().removeClass(NAV_ITEM + 'ed');
|
||||
|
||||
// 若有子菜单,则对其执行展开或收缩
|
||||
if (child[0]) {
|
||||
if (needExpand) {
|
||||
// 先执行 slideDown 动画,再标注展开状态样式,避免元素 `block` 状态导致动画无效
|
||||
child.slideDown(ANIM_MS, complete);
|
||||
parent.addClass(NAV_ITEMED);
|
||||
} else {
|
||||
// 先取消展开状态样式,再将元素临时显示,避免 `none` 状态导致 slideUp 动画无效
|
||||
parent.removeClass(NAV_ITEMED);
|
||||
child.show().slideUp(ANIM_MS, complete);
|
||||
}
|
||||
|
||||
// 手风琴 --- 收缩兄弟展开项
|
||||
if (typeof parents.attr('lay-accordion') === 'string' || parents.attr('lay-shrink') === 'all') {
|
||||
var parentSibs = parent.siblings('.'+ NAV_ITEMED);
|
||||
parentSibs.removeClass(NAV_ITEMED);
|
||||
parentSibs.children('.'+ NAV_CHILD).show().stop().slideUp(ANIM_MS, complete);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -304,26 +384,16 @@ layui.define('jquery', function(exports){
|
||||
layui.event.call(this, MOD_NAME, 'nav('+ filter +')', othis);
|
||||
}
|
||||
|
||||
//点击子菜单选中
|
||||
/*
|
||||
,clickChild: function(){
|
||||
var othis = $(this), parents = othis.parents(NAV_ELEM)
|
||||
,filter = parents.attr('lay-filter');
|
||||
parents.find('.'+THIS).removeClass(THIS);
|
||||
othis.addClass(THIS);
|
||||
layui.event.call(this, MOD_NAME, 'nav('+ filter +')', othis);
|
||||
}
|
||||
*/
|
||||
|
||||
//折叠面板
|
||||
// 折叠面板
|
||||
,collapse: function(){
|
||||
var othis = $(this), icon = othis.find('.layui-colla-icon')
|
||||
,elemCont = othis.siblings('.layui-colla-content')
|
||||
,parents = othis.parents('.layui-collapse').eq(0)
|
||||
,filter = parents.attr('lay-filter')
|
||||
,isNone = elemCont.css('display') === 'none';
|
||||
var othis = $(this);
|
||||
var icon = othis.find('.layui-colla-icon');
|
||||
var elemCont = othis.siblings('.layui-colla-content');
|
||||
var parents = othis.parents('.layui-collapse').eq(0);
|
||||
var filter = parents.attr('lay-filter');
|
||||
var isNone = elemCont.css('display') === 'none';
|
||||
|
||||
//是否手风琴
|
||||
// 是否手风琴
|
||||
if(typeof parents.attr('lay-accordion') === 'string'){
|
||||
var show = parents.children('.layui-colla-item').children('.'+SHOW);
|
||||
show.siblings('.layui-colla-title').children('.layui-colla-icon').html('');
|
||||
@ -352,56 +422,65 @@ layui.define('jquery', function(exports){
|
||||
call.tabAuto.call({});
|
||||
}
|
||||
|
||||
//导航菜单
|
||||
// 导航菜单
|
||||
,nav: function(){
|
||||
var TIME = 200, timer = {}, timerMore = {}, timeEnd = {}, NAV_TITLE = 'layui-nav-title'
|
||||
var TIME = 200;
|
||||
var timer = {};
|
||||
var timerMore = {};
|
||||
var timeEnd = {};
|
||||
var NAV_TITLE = 'layui-nav-title';
|
||||
|
||||
//滑块跟随
|
||||
,follow = function(bar, nav, index){
|
||||
var othis = $(this), child = othis.find('.'+NAV_CHILD);
|
||||
if(nav.hasClass(NAV_TREE)){
|
||||
//无子菜单时跟随
|
||||
if(!child[0]){
|
||||
// 滑块跟随
|
||||
var follow = function(bar, nav, index) {
|
||||
var othis = $(this);
|
||||
var child = othis.find('.'+NAV_CHILD);
|
||||
|
||||
// 是否垂直导航菜单
|
||||
if (nav.hasClass(NAV_TREE)) {
|
||||
// 无子菜单时跟随
|
||||
if (!child[0]) {
|
||||
var thisA = othis.children('.'+ NAV_TITLE);
|
||||
bar.css({
|
||||
top: othis.offset().top - nav.offset().top
|
||||
,height: (thisA[0] ? thisA : othis).outerHeight()
|
||||
,opacity: 1
|
||||
top: othis.offset().top - nav.offset().top,
|
||||
height: (thisA[0] ? thisA : othis).outerHeight(),
|
||||
opacity: 1
|
||||
});
|
||||
}
|
||||
} else {
|
||||
child.addClass(NAV_ANIM);
|
||||
|
||||
//若居中对齐
|
||||
if(child.hasClass(NAV_CHILD_C)) child.css({
|
||||
left: -(child.outerWidth() - othis.width())/2
|
||||
});
|
||||
|
||||
//滑块定位
|
||||
if(child[0]){ //若有子菜单,则滑块消失
|
||||
bar.css({
|
||||
left: bar.position().left + bar.width()/2
|
||||
,width: 0
|
||||
,opacity: 0
|
||||
});
|
||||
} else { //bar 跟随
|
||||
bar.css({
|
||||
left: othis.position().left + parseFloat(othis.css('marginLeft'))
|
||||
,top: othis.position().top + othis.height() - bar.height()
|
||||
// 若居中对齐
|
||||
if (child.hasClass(NAV_CHILD_C)) {
|
||||
child.css({
|
||||
left: -(child.outerWidth() - othis.width()) / 2
|
||||
});
|
||||
}
|
||||
|
||||
//渐显滑块并适配宽度
|
||||
timer[index] = setTimeout(function(){
|
||||
// 滑块定位
|
||||
if (child[0]) { // 若有子菜单,则滑块消失
|
||||
bar.css({
|
||||
width: child[0] ? 0 : othis.width()
|
||||
,opacity: child[0] ? 0 : 1
|
||||
left: bar.position().left + bar.width() / 2,
|
||||
width: 0,
|
||||
opacity: 0
|
||||
});
|
||||
} else { // bar 跟随
|
||||
bar.css({
|
||||
left: othis.position().left + parseFloat(othis.css('marginLeft')),
|
||||
top: othis.position().top + othis.height() - bar.height()
|
||||
});
|
||||
}
|
||||
|
||||
// 渐显滑块并适配宽度
|
||||
timer[index] = setTimeout(function() {
|
||||
bar.css({
|
||||
width: child[0] ? 0 : othis.width(),
|
||||
opacity: child[0] ? 0 : 1
|
||||
});
|
||||
}, device.ie && device.ie < 10 ? 0 : TIME);
|
||||
|
||||
//显示子菜单
|
||||
// 显示子菜单
|
||||
clearTimeout(timeEnd[index]);
|
||||
if(child.css('display') === 'block'){
|
||||
if (child.css('display') === 'block') {
|
||||
clearTimeout(timerMore[index]);
|
||||
}
|
||||
timerMore[index] = setTimeout(function(){
|
||||
@ -411,61 +490,64 @@ layui.define('jquery', function(exports){
|
||||
}
|
||||
};
|
||||
|
||||
//遍历导航
|
||||
$(NAV_ELEM + elemFilter).each(function(index){
|
||||
var othis = $(this)
|
||||
,bar = $('<span class="'+ NAV_BAR +'"></span>')
|
||||
,itemElem = othis.find('.'+NAV_ITEM);
|
||||
// 遍历导航
|
||||
$(NAV_ELEM + elemFilter).each(function(index) {
|
||||
var othis = $(this);
|
||||
var bar = $('<span class="'+ NAV_BAR +'"></span>');
|
||||
var itemElem = othis.find('.'+NAV_ITEM);
|
||||
|
||||
//hover 滑动效果
|
||||
if(!othis.find('.'+NAV_BAR)[0]){
|
||||
// hover 滑动效果
|
||||
if (!othis.find('.'+NAV_BAR)[0]) {
|
||||
othis.append(bar);
|
||||
(othis.hasClass(NAV_TREE)
|
||||
( othis.hasClass(NAV_TREE)
|
||||
? itemElem.find('dd,>.'+ NAV_TITLE)
|
||||
: itemElem).on('mouseenter', function(){
|
||||
: itemElem
|
||||
).on('mouseenter', function() {
|
||||
follow.call(this, bar, othis, index);
|
||||
}).on('mouseleave', function(){ //鼠标移出
|
||||
//是否为垂直导航
|
||||
if(othis.hasClass(NAV_TREE)){
|
||||
}).on('mouseleave', function() { // 鼠标移出
|
||||
// 是否为垂直导航
|
||||
if (othis.hasClass(NAV_TREE)) {
|
||||
bar.css({
|
||||
height: 0
|
||||
,opacity: 0
|
||||
height: 0,
|
||||
opacity: 0
|
||||
});
|
||||
} else {
|
||||
//隐藏子菜单
|
||||
// 隐藏子菜单
|
||||
clearTimeout(timerMore[index]);
|
||||
timerMore[index] = setTimeout(function(){
|
||||
othis.find('.'+NAV_CHILD).removeClass(SHOW);
|
||||
othis.find('.'+NAV_MORE).removeClass(NAV_MORE+'d');
|
||||
othis.find('.'+ NAV_CHILD).removeClass(SHOW);
|
||||
othis.find('.'+ NAV_MORE).removeClass(NAV_MORE +'d');
|
||||
}, 300);
|
||||
}
|
||||
});
|
||||
othis.on('mouseleave', function(){
|
||||
|
||||
// 鼠标离开当前菜单时
|
||||
othis.on('mouseleave', function() {
|
||||
clearTimeout(timer[index])
|
||||
timeEnd[index] = setTimeout(function(){
|
||||
if(!othis.hasClass(NAV_TREE)){
|
||||
timeEnd[index] = setTimeout(function() {
|
||||
if (!othis.hasClass(NAV_TREE)) {
|
||||
bar.css({
|
||||
width: 0
|
||||
,left: bar.position().left + bar.width()/2
|
||||
,opacity: 0
|
||||
width: 0,
|
||||
left: bar.position().left + bar.width() / 2,
|
||||
opacity: 0
|
||||
});
|
||||
}
|
||||
}, TIME);
|
||||
});
|
||||
}
|
||||
|
||||
//展开子菜单
|
||||
itemElem.find('a').each(function(){
|
||||
var thisA = $(this)
|
||||
,parent = thisA.parent()
|
||||
,child = thisA.siblings('.'+NAV_CHILD);
|
||||
// 展开子菜单
|
||||
itemElem.find('a').each(function() {
|
||||
var thisA = $(this);
|
||||
var parent = thisA.parent();
|
||||
var child = thisA.siblings('.'+ NAV_CHILD);
|
||||
|
||||
//输出小箭头
|
||||
if(child[0] && !thisA.children('.'+NAV_MORE)[0]){
|
||||
// 输出小箭头
|
||||
if (child[0] && !thisA.children('.'+ NAV_MORE)[0]) {
|
||||
thisA.append('<i class="layui-icon '+ NAV_DOWN +' '+ NAV_MORE +'"></i>');
|
||||
}
|
||||
|
||||
thisA.off('click', call.clickThis).on('click', call.clickThis); //点击菜单
|
||||
thisA.off('click', call.clickThis).on('click', call.clickThis); // 点击菜单
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user