mirror of https://github.com/layui/layui
Merge branch '2.x' into feat/touch
commit
f0a0c7f5e6
|
@ -222,13 +222,22 @@ layui.use(['table', 'dropdown'], function(){
|
||||||
},{
|
},{
|
||||||
id: 'unchecked',
|
id: 'unchecked',
|
||||||
title: '取消选中某行'
|
title: '取消选中某行'
|
||||||
|
},{
|
||||||
|
id: 'mult-checked',
|
||||||
|
title: '同时选中多个'
|
||||||
},{
|
},{
|
||||||
id: 'reset-checked',
|
id: 'reset-checked',
|
||||||
title: '给选中行取消选中状态'
|
title: '给选中行取消选中状态'
|
||||||
}],
|
}],
|
||||||
// 菜单被点击的事件
|
// 菜单被点击的事件
|
||||||
click: function(obj){
|
click: function(obj) {
|
||||||
if(obj.id === 'reset-checked'){
|
if (obj.id === 'mult-checked') {
|
||||||
|
// 同时选中多个
|
||||||
|
table.setRowChecked(id, {
|
||||||
|
index: [3, 4, 5], // 2.9.1+
|
||||||
|
checked: true
|
||||||
|
});
|
||||||
|
} else if(obj.id === 'reset-checked') {
|
||||||
// 给选中行取消选中状态
|
// 给选中行取消选中状态
|
||||||
table.setRowChecked(id, {
|
table.setRowChecked(id, {
|
||||||
index: 'all',
|
index: 'all',
|
||||||
|
|
|
@ -16,7 +16,8 @@ body{padding: 50px;}
|
||||||
<button class="layui-btn" lay-on="e1">事件1</button>
|
<button class="layui-btn" lay-on="e1">事件1</button>
|
||||||
<button class="layui-btn" lay-on="e2">事件2</button>
|
<button class="layui-btn" lay-on="e2">事件2</button>
|
||||||
<button class="layui-btn" lay-on="e3">事件3</button>
|
<button class="layui-btn" lay-on="e3">事件3</button>
|
||||||
<button class="layui-btn" lay-active="e4">事件4</button>
|
<button class="layui-btn" lay-active="e4">hover: active - 事件4</button>
|
||||||
|
<button class="layui-btn" lay-active1="e4">hover: active1 - 事件4</button>
|
||||||
|
|
||||||
<br><br>
|
<br><br>
|
||||||
|
|
||||||
|
@ -108,7 +109,7 @@ layui.use(['lay', 'util', 'layer'], function(){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 事件集的替换和增加
|
// Test: 事件集的替换和增加
|
||||||
util.on({
|
util.on({
|
||||||
e1: function(othis){ // 重置事件 e1
|
e1: function(othis){ // 重置事件 e1
|
||||||
alert(othis.html() + ' - replace')
|
alert(othis.html() + ' - replace')
|
||||||
|
@ -121,8 +122,19 @@ layui.use(['lay', 'util', 'layer'], function(){
|
||||||
// 自定义触发事件的元素属性名、自定义触发事件的方式
|
// 自定义触发事件的元素属性名、自定义触发事件的方式
|
||||||
util.on('lay-active', {
|
util.on('lay-active', {
|
||||||
e4: layui.throttle(function(othis) {
|
e4: layui.throttle(function(othis) {
|
||||||
layer.tips(othis.html(), this);
|
layer.tips(othis.html(), this, { tips: 3 });
|
||||||
}, 3000) // 3s 内不重复执行
|
}, 3000), // 3s 内不重复执行
|
||||||
|
e5: function() {
|
||||||
|
console.log(111);
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
trigger: 'mouseenter'
|
||||||
|
});
|
||||||
|
// Test: 不同属性、相同值
|
||||||
|
util.on('lay-active1', {
|
||||||
|
e4: function(othis) {
|
||||||
|
this.innerHTML = 'hover: '+ (Math.random()*100000 | 0);
|
||||||
|
}
|
||||||
}, {
|
}, {
|
||||||
trigger: 'mouseenter'
|
trigger: 'mouseenter'
|
||||||
});
|
});
|
||||||
|
|
|
@ -1319,7 +1319,7 @@ body .layui-table-tips .layui-layer-content{background: none; padding: 0; box-sh
|
||||||
.layui-nav-itemed>a{color: #fff !important;}
|
.layui-nav-itemed>a{color: #fff !important;}
|
||||||
.layui-nav-tree .layui-nav-bar{background-color: #16baaa;}
|
.layui-nav-tree .layui-nav-bar{background-color: #16baaa;}
|
||||||
|
|
||||||
.layui-nav-tree .layui-nav-child{position: relative; z-index: 0; top: 0; border: none; background-color: rgba(0,0,0,.3); box-shadow: none;}
|
.layui-nav-tree .layui-nav-child{position: relative; z-index: 0; top: 0; border: none; background: none; background-color: rgba(0,0,0,.3); box-shadow: none;}
|
||||||
.layui-nav-tree .layui-nav-child dd{margin: 0;}
|
.layui-nav-tree .layui-nav-child dd{margin: 0;}
|
||||||
.layui-nav-tree .layui-nav-child a{color: #fff; color: rgba(255,255,255,.7);}
|
.layui-nav-tree .layui-nav-child a{color: #fff; color: rgba(255,255,255,.7);}
|
||||||
.layui-nav-tree .layui-nav-child a:hover{background: none; color: #fff;}
|
.layui-nav-tree .layui-nav-child a:hover{background: none; color: #fff;}
|
||||||
|
|
|
@ -260,7 +260,6 @@ html #layuicss-layer{display: none; position: absolute; width: 1989px;}
|
||||||
.layui-layer-photos-footer a:hover{text-decoration: underline;}
|
.layui-layer-photos-footer a:hover{text-decoration: underline;}
|
||||||
.layui-layer-photos-footer em{font-style: normal;}
|
.layui-layer-photos-footer em{font-style: normal;}
|
||||||
|
|
||||||
|
|
||||||
/* 关闭动画 */
|
/* 关闭动画 */
|
||||||
@-webkit-keyframes layer-bounceOut {
|
@-webkit-keyframes layer-bounceOut {
|
||||||
100% {opacity: 0; -webkit-transform: scale(.7); transform: scale(.7)}
|
100% {opacity: 0; -webkit-transform: scale(.7); transform: scale(.7)}
|
||||||
|
@ -273,9 +272,3 @@ html #layuicss-layer{display: none; position: absolute; width: 1989px;}
|
||||||
0% {-webkit-transform: scale(1); -ms-transform: scale(1);transform: scale(1);}
|
0% {-webkit-transform: scale(1); -ms-transform: scale(1);transform: scale(1);}
|
||||||
}
|
}
|
||||||
.layer-anim-close{-webkit-animation-name: layer-bounceOut; animation-name: layer-bounceOut; -webkit-animation-fill-mode: both; animation-fill-mode: both; -webkit-animation-duration:.2s; animation-duration:.2s;}
|
.layer-anim-close{-webkit-animation-name: layer-bounceOut; animation-name: layer-bounceOut; -webkit-animation-fill-mode: both; animation-fill-mode: both; -webkit-animation-duration:.2s; animation-duration:.2s;}
|
||||||
|
|
||||||
@media screen and (max-width: 1100px) {
|
|
||||||
.layui-layer-iframe{overflow-y: auto; -webkit-overflow-scrolling: touch;}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -671,13 +671,15 @@ Class.pt.tips = function(){
|
||||||
};
|
};
|
||||||
|
|
||||||
// 辨别 tips 的方位
|
// 辨别 tips 的方位
|
||||||
|
// 21 为箭头大小 8*2 + 箭头相对父元素的top偏移 5
|
||||||
goal.where = [function(){ // 上
|
goal.where = [function(){ // 上
|
||||||
goal.autoLeft();
|
goal.autoLeft();
|
||||||
goal.tipTop = goal.top - layArea[1] - 10;
|
goal.tipTop = goal.top - layArea[1] - 10;
|
||||||
tipsG.removeClass('layui-layer-TipsB').addClass('layui-layer-TipsT').css('border-right-color', config.tips[1]);
|
tipsG.removeClass('layui-layer-TipsB').addClass('layui-layer-TipsT').css('border-right-color', config.tips[1]);
|
||||||
}, function(){ // 右
|
}, function(){ // 右
|
||||||
goal.tipLeft = goal.left + goal.width + 10;
|
goal.tipLeft = goal.left + goal.width + 10;
|
||||||
goal.tipTop = goal.top;
|
goal.tipTop = goal.top - (goal.height * 0.75 < 21 ? 21 - goal.height * 0.5 : 0);
|
||||||
|
goal.tipTop = Math.max(goal.tipTop, 0);
|
||||||
tipsG.removeClass('layui-layer-TipsL').addClass('layui-layer-TipsR').css('border-bottom-color', config.tips[1]);
|
tipsG.removeClass('layui-layer-TipsL').addClass('layui-layer-TipsR').css('border-bottom-color', config.tips[1]);
|
||||||
}, function(){ // 下
|
}, function(){ // 下
|
||||||
goal.autoLeft();
|
goal.autoLeft();
|
||||||
|
@ -685,7 +687,8 @@ Class.pt.tips = function(){
|
||||||
tipsG.removeClass('layui-layer-TipsT').addClass('layui-layer-TipsB').css('border-right-color', config.tips[1]);
|
tipsG.removeClass('layui-layer-TipsT').addClass('layui-layer-TipsB').css('border-right-color', config.tips[1]);
|
||||||
}, function(){ // 左
|
}, function(){ // 左
|
||||||
goal.tipLeft = goal.left - layArea[0] - 10;
|
goal.tipLeft = goal.left - layArea[0] - 10;
|
||||||
goal.tipTop = goal.top;
|
goal.tipTop = goal.top - (goal.height * 0.75 < 21 ? 21 - goal.height * 0.5 : 0);
|
||||||
|
goal.tipTop = Math.max(goal.tipTop, 0);
|
||||||
tipsG.removeClass('layui-layer-TipsR').addClass('layui-layer-TipsL').css('border-bottom-color', config.tips[1]);
|
tipsG.removeClass('layui-layer-TipsR').addClass('layui-layer-TipsL').css('border-bottom-color', config.tips[1]);
|
||||||
}];
|
}];
|
||||||
goal.where[guide-1]();
|
goal.where[guide-1]();
|
||||||
|
|
|
@ -1560,10 +1560,16 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
||||||
Class.prototype.setRowChecked = function(opts){
|
Class.prototype.setRowChecked = function(opts){
|
||||||
var that = this;
|
var that = this;
|
||||||
var options = that.config;
|
var options = that.config;
|
||||||
var isCheckAll = opts.index === 'all';
|
var isCheckAll = opts.index === 'all'; // 是否操作全部
|
||||||
var tr = that.layBody.find('tr'+ (
|
var isCheckMult = layui.type(opts.index) === 'array'; // 是否操作多个
|
||||||
isCheckAll ? '' : '[data-index="'+ opts.index +'"]'
|
|
||||||
));
|
// 匹配行元素
|
||||||
|
var tr = function(tr) {
|
||||||
|
return isCheckAll ? tr : tr.filter(isCheckMult ? function() {
|
||||||
|
var dataIndex = $(this).data('index');
|
||||||
|
return opts.index.indexOf(dataIndex) !== -1;
|
||||||
|
} : '[data-index="'+ opts.index +'"]');
|
||||||
|
}(that.layBody.find('tr'));
|
||||||
|
|
||||||
// 默认属性
|
// 默认属性
|
||||||
opts = $.extend({
|
opts = $.extend({
|
||||||
|
@ -1573,18 +1579,31 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
||||||
// 同步数据选中属性值
|
// 同步数据选中属性值
|
||||||
var thisData = table.cache[that.key];
|
var thisData = table.cache[that.key];
|
||||||
var existChecked = 'checked' in opts;
|
var existChecked = 'checked' in opts;
|
||||||
|
|
||||||
|
// 若为单选框,则单向选中;若为复选框,则切换选中。
|
||||||
var getChecked = function(value){
|
var getChecked = function(value){
|
||||||
// 若为单选框,则单向选中;若为复选框,则切换选中。
|
|
||||||
return opts.type === 'radio' ? true : (existChecked ? opts.checked : !value)
|
return opts.type === 'radio' ? true : (existChecked ? opts.checked : !value)
|
||||||
};
|
};
|
||||||
|
|
||||||
// 设置数据选中属性
|
// 设置选中状态
|
||||||
layui.each(thisData, function(i, item){
|
layui.each(thisData, function(i, item){
|
||||||
if(layui.type(item) === 'array' || item[options.disabledName]) return; // 空项
|
// 绕过空项和禁用项
|
||||||
if(Number(opts.index) === i || isCheckAll){
|
if(layui.type(item) === 'array' || item[options.disabledName]) return;
|
||||||
|
|
||||||
|
// 匹配条件
|
||||||
|
var matched = isCheckAll || (
|
||||||
|
isCheckMult ? opts.index.indexOf(i) !== -1 : Number(opts.index) === i
|
||||||
|
);
|
||||||
|
|
||||||
|
// 设置匹配项的选中值
|
||||||
|
if(matched){
|
||||||
|
// 标记数据选中状态
|
||||||
var checked = item[options.checkName] = getChecked(item[options.checkName]);
|
var checked = item[options.checkName] = getChecked(item[options.checkName]);
|
||||||
var currTr = isCheckAll ? tr.filter('[data-index="'+ i +'"]') : tr;
|
|
||||||
currTr[checked ? 'addClass' : 'removeClass'](ELEM_CHECKED); // 标记当前选中行背景色
|
// 标记当前行背景色
|
||||||
|
var currTr = tr.filter('[data-index="'+ i +'"]');
|
||||||
|
currTr[checked ? 'addClass' : 'removeClass'](ELEM_CHECKED);
|
||||||
|
|
||||||
// 若为 radio 类型,则取消其他行选中背景色
|
// 若为 radio 类型,则取消其他行选中背景色
|
||||||
if(opts.type === 'radio'){
|
if(opts.type === 'radio'){
|
||||||
currTr.siblings().removeClass(ELEM_CHECKED);
|
currTr.siblings().removeClass(ELEM_CHECKED);
|
||||||
|
|
|
@ -93,7 +93,7 @@ layui.define(['table'], function (exports) {
|
||||||
var updateCache = function (id, childrenKey, data) {
|
var updateCache = function (id, childrenKey, data) {
|
||||||
var tableCache = table.cache[id];
|
var tableCache = table.cache[id];
|
||||||
layui.each(data || tableCache, function (index, item) {
|
layui.each(data || tableCache, function (index, item) {
|
||||||
var itemDataIndex = item[LAY_DATA_INDEX];
|
var itemDataIndex = item[LAY_DATA_INDEX] || '';
|
||||||
if (itemDataIndex.indexOf('-') !== -1) {
|
if (itemDataIndex.indexOf('-') !== -1) {
|
||||||
tableCache[itemDataIndex] = item
|
tableCache[itemDataIndex] = item
|
||||||
}
|
}
|
||||||
|
|
|
@ -427,7 +427,7 @@ layui.define('jquery', function(exports){
|
||||||
var callbacks = dataCache.callbacks;
|
var callbacks = dataCache.callbacks;
|
||||||
|
|
||||||
// 根据 attr 记录事件集合
|
// 根据 attr 记录事件集合
|
||||||
events = $.extend(true, dataCache.events, events) || {};
|
events = dataCache.events[attr] = $.extend(true, dataCache.events[attr], events);
|
||||||
|
|
||||||
// 清除事件委托,避免重复绑定
|
// 清除事件委托,避免重复绑定
|
||||||
elem.off(options.trigger, attrSelector, callbacks[attr]);
|
elem.off(options.trigger, attrSelector, callbacks[attr]);
|
||||||
|
|
Loading…
Reference in New Issue