From 6aa349b6402daa5d16c0cd72563721b1f6223ea7 Mon Sep 17 00:00:00 2001
From: morning-star <1453017105@qq.com>
Date: Tue, 19 Sep 2023 00:59:22 +0800
Subject: [PATCH 1/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=20layer=20=E7=A7=BB?=
=?UTF-8?q?=E5=8A=A8=E7=AB=AF=E5=AE=9A=E4=BD=8D=20(#1376)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* 优化 layer 移动端定位
* update code
---
examples/layer.html | 14 ++++++++++++++
src/modules/layer.js | 17 +++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/examples/layer.html b/examples/layer.html
index ab878860..20a3e144 100644
--- a/examples/layer.html
+++ b/examples/layer.html
@@ -24,6 +24,7 @@
+
更多例子
@@ -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,
+ });
+ }
});
// 相册层
diff --git a/src/modules/layer.js b/src/modules/layer.js
index fe2aab1f..322192b1 100644
--- a/src/modules/layer.js
+++ b/src/modules/layer.js
@@ -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);
From b1628e77a3e0ed9b534ee0ff48bce0fc85744efd Mon Sep 17 00:00:00 2001
From: sight <1453017105@qq.com>
Date: Wed, 20 Sep 2023 11:57:52 +0800
Subject: [PATCH 2/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=BD=AE=E6=92=AD?=
=?UTF-8?q?=E7=BB=84=E4=BB=B6=E5=8A=A8=E7=94=BB=E6=95=88=E6=9E=9C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/modules/carousel.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/modules/carousel.js b/src/modules/carousel.js
index e58637f7..4bfbf840 100644
--- a/src/modules/carousel.js
+++ b/src/modules/carousel.js
@@ -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)
From 4ab2a80f92effdd2fe0d36047d0bbf1dd6603073 Mon Sep 17 00:00:00 2001
From: morning-star <1453017105@qq.com>
Date: Wed, 20 Sep 2023 13:16:11 +0800
Subject: [PATCH 3/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20`input-number`=20=20?=
=?UTF-8?q?=E7=BB=84=E4=BB=B6=20`lay-precision`=20attributes=EF=BC=8C?=
=?UTF-8?q?=E4=BC=98=E5=8C=96=E7=A6=81=E7=94=A8=E8=A7=86=E8=A7=89=E6=95=88?=
=?UTF-8?q?=E6=9E=9C=20(#1375)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* 新增 `input-number` 组件 `lay-precision` attributes,优化禁用视觉效果
* update code
* refactor
---
src/modules/form.js | 81 +++++++++++++++++++++++++++++----------------
1 file changed, 52 insertions(+), 29 deletions(-)
diff --git a/src/modules/form.js b/src/modules/form.js
index dfb10324..d7705c2f 100644
--- a/src/modules/form.js
+++ b/src/modules/form.js
@@ -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')
+ },
}
};