Merge branch '2.x' of github.com:layui/layui into 2.x

pull/1381/head
贤心 2023-09-20 15:34:53 +08:00
commit 3d42e6724a
4 changed files with 85 additions and 31 deletions

View File

@ -24,6 +24,7 @@
<button class="layui-btn" lay-on="test7">Prompt</button>
<button class="layui-btn" lay-on="test8">Tab</button>
<button class="layui-btn" lay-on="test9">Photo</button>
<button class="layui-btn" lay-on="test10">Drawer</button>
<button class="layui-btn" lay-on="testTime">自动关闭</button>
<a href="https://layui.dev/docs/2.8/layer/" target="_blank" class="layui-btn">更多例子</a>
</div>
@ -215,6 +216,19 @@ layui.use(['layer', 'util'], function(layer, util){
}
});
}
,test10: function(){
layer.open({
title:'drawer',
type: 1,
offset: 'b',
anim: 'slideUp', // 从下往上
area: ['100%', '160px'],
shade: 0.1,
shadeClose: true,
content: $('#test11111'),
maxmin: true,
});
}
});
// 相册层

View File

@ -299,12 +299,12 @@ layui.define(['jquery', 'lay'], function(exports){
}, 50);
}
// 移除过
// 移除过
setTimeout(function(){
elemItem.removeClass(THIS + ' ' + ELEM_PREV + ' ' + ELEM_NEXT + ' ' + ELEM_LEFT + ' ' + ELEM_RIGHT);
elemItem.eq(options.index).addClass(THIS);
that.haveSlide = false; // 解锁
}, 300);
}, 350);
// 指示器焦点
that.elemInd.find('li').eq(options.index).addClass(THIS)

View File

@ -174,6 +174,48 @@ layui.define(['lay', 'layer', 'util'], function(exports){
// 初始化全局的 autocomplete
options.autocomplete && inputs.attr('autocomplete', options.autocomplete);
var handleInputNumberEvents = function(elem, eventType){
var that = this;
var rawValue = elem.val();
var value = Number(rawValue);
var step = Number(elem.attr('step')) || 1; // 加减的数字间隔
var min = Number(elem.attr('min'));
var max = Number(elem.attr('max'));
var precision = Number(elem.attr('lay-precision'));
var noAction = eventType === 'blur' && rawValue === '' // 失焦时空值不作处理
if(isNaN(value)) return; // 若非数字,则不作处理
if(eventType === 'click'){
var isDecrement = !!$(that).index() // 0: icon-up, 1: icon-down
value = isDecrement ? value - step : value + step;
}
// 获取小数点后位数
var decimals = function(step){
var decimals = (step.toString().match(/\.(\d+$)/) || [])[1] || '';
return decimals.length;
};
precision = precision >= 0 ? precision : Math.max(decimals(step), decimals(rawValue));
if(!noAction){
if(value <= min) value = min;
if(value >= max) value = max;
if(precision) value = value.toFixed(precision);
elem.val(value)
}
// 更新按钮状态
var controlBtn = {
increment: elem.next().find('.layui-icon-up'),
decrement: elem.next().find('.layui-icon-down')
}
controlBtn.increment[(value >= max && !noAction) ? 'addClass' : 'removeClass'](DISABLED)
controlBtn.decrement[(value <= min && !noAction) ? 'addClass' : 'removeClass'](DISABLED)
}
// 初始化输入框动态点缀
elemForm.find('input[lay-affix],textarea[lay-affix]').each(function(){
var othis = $(this);
@ -248,6 +290,11 @@ layui.define(['lay', 'layer', 'util'], function(exports){
var value = this.value;
opts.show === 'auto' && showAffix(elemAffix, value);
});
// 失去焦点事件
othis.on('blur', function(){
typeof opts.blur === 'function' && opts.blur.call(this, othis, opts);
});
// 点击动态后缀事件
elemIcon.on('click', function(){
@ -295,35 +342,11 @@ layui.define(['lay', 'layer', 'util'], function(exports){
className: 'layui-input-number',
disabled: othis.is('[disabled]'), // 跟随输入框禁用状态
click: function(elem){
var index = $(this).index();
var value = elem.val();
var rawValue = value;
var step = Number(elem.attr('step')) || 1; // 加减的数字间隔
var min = Number(elem.attr('min'));
var max = Number(elem.attr('max'));
if(isNaN(value)) return; // 若非数字,则不作处理
value = Number(value);
value = index ? value - step : value + step;
// min max
if(value < min) value = min;
if(value > max) value = max;
// 获取小数点后位数
var decimals = function(step){
var decimals = (step.toString().match(/\.(\d+$)/) || [])[1] || '';
return decimals.length;
};
// 位数比较
var fixed = Math.max(decimals(step), decimals(rawValue));
if(fixed) value = value.toFixed(fixed);
elem.val(value);
}
handleInputNumberEvents.call(this, elem, 'click')
},
blur: function(elem){
handleInputNumberEvents.call(this, elem, 'blur')
},
}
};

View File

@ -1719,6 +1719,23 @@ layer.photos = function(options, loop, key){
ready.run = function(_$){
$ = _$;
win = $(window);
// 移动端兼容性处理
// https://gitee.com/layui/layui/issues/I81WGC
// https://github.com/jquery/jquery/issues/1729
var agent = navigator.userAgent.toLowerCase();
var isMobile = /android|iphone|ipod|ipad|ios/.test(agent)
var _win = $(window);
if(isMobile){
$.each({Height: "height", Width: "width"}, function(propSuffix, funcName){
var propName = 'inner' + propSuffix;
win[funcName] = function(){
return propName in window
? window[propName]
: _win[funcName]()
}
})
}
doms.html = $('html');
layer.open = function(deliver){
var o = new Class(deliver);