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/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) 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') + }, } }; 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);