This commit is contained in:
贤心 2021-05-31 08:57:00 +08:00
parent b5f6f89cfe
commit 7376bbe00d
20 changed files with 237 additions and 141 deletions

2
dist/css/layui.css vendored

File diff suppressed because one or more lines are too long

6
dist/layui.js vendored

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>基础方法 - layui</title>
<title>基础方法测试用例 - layui</title>
<link rel="stylesheet" href="../src/css/layui.css">
@ -26,25 +26,72 @@
<script src="../src/layui.js"></script>
<script>
layui.use('lay', function(){
var lay = layui.lay;
//sort
console.log(
'layui.sort: ',
layui.sort([{a: 3},{a: 0},{a: 0},{a: -1},{a: -5},{a: 6},{a: 9}], 'a')
'layui.sort: 数字',
layui.sort([{a: 3},{a: 0},{a: 0},{a: -1},{a: -5},{a: 6},{a: 9},{a: -333333}], 'a')
);
console.log(
'layui.sort: 中文',
layui.sort([{a: '男'},{a: '女'},{a: '男'},{a: '女'},{a: '男'}], 'a')
);
console.log(
'layui.sort: 英文',
layui.sort([{a: 'E'},{a: 'B'},{a: 'D'},{a: 'C'},{a: 'A'}], 'a')
);
console.log(
'layui.sort: 混合'
,layui.sort([
{a: 3}
,{a: '男'}
,{a: 0}
,{a: 66}
,{a: 99}
,{a: 'C'}
,{a: '女'}
,{a: 0}
,{a: -1}
,{a: 'B'}
,{a: '男'}
,{a: 'A'}
,{a: -5}
,{a: '男'}
,{a: 6}
,{a: 9}
], 'a')
);
console.log(
'layui._typeof: ',
layui._typeof(new RegExp()), layui._typeof(new Date()), layui._typeof([])
layui._typeof(new RegExp()),
layui._typeof(new Date()),
layui._typeof([])
);
console.log(
'layui._isArray ',
layui._isArray([1,6]), layui._isArray(lay('div')), layui._isArray(document.querySelectorAll('div')),
layui._isArray([1,6]),
layui._isArray(lay('div')),
layui._isArray(document.querySelectorAll('div')),
layui._isArray({key: 'value'})
);
console.log(
'lay.extend {}: ',
lay.extend(
{},
{a: 123, c: {ccc: 'ccc'}, arr: [1,3]},
{a: 111, b: 1, c: {bbb: 'bbb'}},
{a: 222222, arr: [5]}
)
);
console.log(
'lay.extend []: ',
lay.extend([], [1,3,5])
);
});
</script>
</body>

View File

@ -20,6 +20,7 @@ div[carousel-item]>*:nth-child(2n+1){background-color: #5FB878;}
</head>
<body>
<div class="layui-carousel" id="test1" lay-filter="test1">
<div carousel-item>
<div>条目1</div>

View File

@ -42,6 +42,7 @@ layui.use('dropdown', function(){
dropdown.render({
elem: '#demo1'
//,align: 'right'
,data: [{
title: 'menu item 1'
,templet: '<i class="layui-icon layui-icon-light"></i> {{d.title}} <span class="layui-badge-dot"></span>'
@ -183,6 +184,7 @@ layui.use('dropdown', function(){
elem: '#demo3'
,content: '自定义内容 123 '
,style: 'background:#666;color:#fff;padding:15px;'
,align: 'center'
,trigger: 'hover'
});

View File

@ -86,9 +86,11 @@
<div class="layui-input-block">
<select name="quiz" lay-verify="required" lay-verType="tips" lay-filter="quiz111">
<option value="">请选择问题</option>
<option value="0">你工作的第一个城市</option>
<option value="0">你工作的 第一个城市</option>
<option value="1" disabled>你的工号</option>
<option value="2">你最喜欢的老师</option>
<option value="2">
你最喜欢的老师
</option>
</select>
</div>
</div>
@ -249,11 +251,12 @@ layui.use(['form', 'layedit', 'laydate'], function(){
//初始赋值
var thisValue = form.val('first', {
'title': '测试'
'title': '测试测试测试'
,'phone': 11111111111
,'email': 'xu@sentsin.com'
,'date': '2021-05-30'
,'password': 123123
,'quiz': 2
//,'quiz': 2
,'interest': 3
,'like[write]': true
//,'open': false

View File

@ -138,6 +138,8 @@ layui.use('laydate', function(laydate){
}
});
//return;
//单控件
laydate.render({
elem: '#test2'

View File

@ -107,7 +107,7 @@ layui.use(['table', 'dropdown'], function(){
,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true, totalRowText: '合计:'}
,{field:'username', title:'用户名', width:120, edit: 'text', templet: '#usernameTpl'}
,{field:'email', title:'邮箱', hide: 0, width:150, edit: 'text', templet: function(d){
console.log(d);
console.log(d)
return '<em>'+ d.email +'</em>'
}}
,{field:'sex', title:'性别', width:80, edit: 'text', sort: true}

View File

@ -15,9 +15,7 @@
</head>
<body>
<div>
</div>
<script type="text/html" id="toolbarDemo">
<div class="layui-btn-container">
@ -245,16 +243,16 @@ layui.use(['table', 'dropdown'], function(){
,layEvent: 'LAYTABLE_TIPS'
,icon: 'layui-icon-tips'
}]
,escape: true
,cols: [[
{type: 'checkbox', fixed: 'left'}
,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true, totalRowText: '合计:'}
,{field:'username', title:'用户名', width:120, edit: 'text', templet: '#usernameTpl'}
,{field:'email', title:'邮箱', hide: 0, width:150, edit: 'text', templet: function(d){
console.log(d);
return '<em>'+ d.email +'</em>'
}}
,{field:'sex', title:'性别', width:80, edit: 'text', sort: true}
,{field:'city', title:'城市', width:120, templet: '#cityTpl1'}
,{field:'city', title:'城市', width:120}
,{field:'sign', title:'签名'}
,{field:'experience', title:'积分', width:80, sort: true, totalRow: '{{ d.TOTAL_NUMS }} 分', templet: '<div>{{ d.experience }} 分</div>'}
,{field:'ip', title:'IP', width:120}

View File

@ -1,7 +1,7 @@
{
"name": "layui",
"realname": "layui",
"version": "2.6.7",
"version": "2.6.8",
"description": "Classic modular Front-End UI library",
"main": "dist/layui.js",
"license": "MIT",

View File

@ -1,9 +1,8 @@
/**
@Name: layui
@Description: Classic modular front-end UI framework
@License: MIT
* Layui
* Classic modular Front-End UI library
* MIT Licensed
*/
@ -638,7 +637,7 @@ a cite{font-style: normal; *cursor:pointer;}
/* 流体 */.layui-btn-fluid{width: 100%;}
/** 表单 **/
.layui-input, .layui-textarea, .layui-select{height: 38px; line-height: 1.3; line-height: 38px\9; border-width: 1px; border-style: solid; background-color: #fff; border-radius: 2px;}
.layui-input, .layui-textarea, .layui-select{height: 38px; line-height: 1.3; line-height: 38px\9; border-width: 1px; border-style: solid; background-color: #fff; color: rgba(0,0,0,.85); border-radius: 2px;}
.layui-input::-webkit-input-placeholder,
.layui-textarea::-webkit-input-placeholder,
.layui-select::-webkit-input-placeholder{line-height: 1.3;}
@ -671,7 +670,7 @@ a cite{font-style: normal; *cursor:pointer;}
/* 下拉选择 */.layui-form-select{position: relative;}
.layui-form-select .layui-input{padding-right: 30px; cursor: pointer;}
.layui-form-select .layui-edge{position: absolute; right: 10px; top: 50%; margin-top: -3px; cursor: pointer; border-width: 6px; border-top-color: #c2c2c2; border-top-style: solid; transition: all .3s; -webkit-transition: all .3s;}
.layui-form-select dl{display: none; position: absolute; left: 0; top: 42px; padding: 5px 0; z-index: 899; min-width: 100%; border: 1px solid #d2d2d2; max-height: 300px; overflow-y: auto; background-color: #fff; border-radius: 2px; box-shadow: 0 2px 4px rgba(0,0,0,.12); box-sizing: border-box;}
.layui-form-select dl{display: none; position: absolute; left: 0; top: 42px; padding: 5px 0; z-index: 899; min-width: 100%; border: 1px solid #eee; max-height: 300px; overflow-y: auto; background-color: #fff; border-radius: 2px; box-shadow: 1px 1px 4px rgb(0 0 0 / 8%); box-sizing: border-box;}
.layui-form-select dl dt,
.layui-form-select dl dd{padding: 0 10px; line-height: 36px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;}
.layui-form-select dl dt{font-size: 12px; color: #999;}
@ -680,6 +679,7 @@ a cite{font-style: normal; *cursor:pointer;}
.layui-form-select .layui-select-group dd{padding-left: 20px;}
.layui-form-select dl dd.layui-select-tips{padding-left: 10px !important; color: #999;}
.layui-form-select dl dd.layui-this{background-color: #5FB878; color: #fff;}
/*.layui-form-select dl dd.layui-this{background-color: #F6F6F6; color: #5FB878; font-weight: 700;}*/
.layui-form-select dl dd.layui-disabled{background-color: #fff;}
.layui-form-selected dl{display: block;}
.layui-form-selected .layui-edge{margin-top: -9px; -webkit-transform:rotate(180deg); transform: rotate(180deg);}
@ -708,8 +708,8 @@ a cite{font-style: normal; *cursor:pointer;}
.layui-form-checkbox[lay-skin="primary"] i{right: auto; left: 0; width: 16px; height: 16px; line-height: 16px; border: 1px solid #d2d2d2; font-size: 12px; border-radius: 2px; background-color: #fff; -webkit-transition: .1s linear; transition: .1s linear;}
.layui-form-checkbox[lay-skin="primary"]:hover i{border-color: #5FB878; color: #fff;}
.layui-form-checked[lay-skin="primary"] i{border-color: #5FB878 !important; background-color: #5FB878; color: #fff;}
.layui-checkbox-disbaled[lay-skin="primary"] span{background: none!important; color: #c2c2c2!important;}
.layui-checkbox-disbaled[lay-skin="primary"]:hover i{border-color: #d2d2d2;}
.layui-checkbox-disabled[lay-skin="primary"] span{background: none!important; color: #c2c2c2!important;}
.layui-checkbox-disabled[lay-skin="primary"]:hover i{border-color: #d2d2d2;}
.layui-form-item .layui-form-checkbox[lay-skin="primary"]{margin-top: 10px;}
/* 复选框-开关风格 */.layui-form-switch{position: relative; display: inline-block; vertical-align: middle; height: 22px; line-height: 22px; min-width: 35px; padding: 0 5px; margin-top: 8px; border: 1px solid #d2d2d2; border-radius: 20px; cursor: pointer; background-color: #fff; -webkit-transition: .1s linear; transition: .1s linear;}
@ -719,11 +719,11 @@ a cite{font-style: normal; *cursor:pointer;}
.layui-form-onswitch i{left: 100%; margin-left: -21px; background-color: #fff;}
.layui-form-onswitch em{margin-left: 5px; margin-right: 21px; color: #fff!important;}
.layui-checkbox-disbaled{border-color: #eee !important;}
.layui-checkbox-disbaled span{background-color: #eee !important;}
.layui-checkbox-disbaled i{border-color: #eee !important;}
.layui-checkbox-disbaled em{color: #d2d2d2 !important;}
.layui-checkbox-disbaled:hover i{color: #fff !important;}
.layui-checkbox-disabled{border-color: #eee !important;}
.layui-checkbox-disabled span{background-color: #eee !important;}
.layui-checkbox-disabled i{border-color: #eee !important;}
.layui-checkbox-disabled em{color: #d2d2d2 !important;}
.layui-checkbox-disabled:hover i{color: #fff !important;}
/* 单选框 */
*[lay-radio]{display: none;}
@ -733,10 +733,10 @@ a cite{font-style: normal; *cursor:pointer;}
.layui-form-radioed,
.layui-form-radioed>i,
.layui-form-radio:hover *{color: #5FB878;}
.layui-radio-disbaled>i{color: #eee !important;}
.layui-radio-disbaled *{color: #c2c2c2!important;}
.layui-radio-disabled>i{color: #eee !important;}
.layui-radio-disabled *{color: #c2c2c2!important;}
/* 表单方框风格 */.layui-form-pane .layui-form-label{width: 110px; padding: 8px 15px; height: 38px; line-height: 20px; border-width: 1px; border-style: solid; border-radius: 2px 0 0 2px; text-align: center; background-color: #FBFBFB; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; box-sizing: border-box;}
/* 表单方框风格 */.layui-form-pane .layui-form-label{width: 110px; padding: 8px 15px; height: 38px; line-height: 20px; border-width: 1px; border-style: solid; border-radius: 2px 0 0 2px; text-align: center; background-color: #FAFAFA; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; box-sizing: border-box;}
.layui-form-pane .layui-input-inline{margin-left: -1px;}
.layui-form-pane .layui-input-block{margin-left: 110px; left: -1px;}
.layui-form-pane .layui-input{border-radius: 0 2px 2px 0;}
@ -941,12 +941,12 @@ a cite{font-style: normal; *cursor:pointer;}
.layui-table-body .layui-none{line-height: 26px; padding: 30px 15px; text-align: center; color: #999;}
.layui-table-fixed{position: absolute; left: 0; top: 0; z-index: 101;}
.layui-table-fixed .layui-table-body{overflow: hidden;}
.layui-table-fixed-l{box-shadow: 0 -1px 8px rgba(0,0,0,.08);}
.layui-table-fixed-l{box-shadow: 1px 0 8px rgba(0,0,0,.08);}
.layui-table-fixed-r{left: auto; right: -1px; border-width: 0; border-left-width: 1px; box-shadow: -1px 0 8px rgba(0,0,0,.08);}
.layui-table-fixed-r .layui-table-header{position: relative; overflow: visible;}
.layui-table-mend{position: absolute; right: -49px; top: 0; height: 100%; width: 50px;}
.layui-table-tool{position: relative; z-index: 890; width: 100%; min-height: 50px; line-height: 30px; padding: 10px 15px; border-width: 0; border-bottom-width: 1px;}
.layui-table-tool{position: relative; z-index: 890; width: 100%; min-height: 50px; line-height: 30px; padding: 10px 15px; border-width: 0; border-bottom-width: 1px; /*box-shadow: 0 1px 8px 0 rgb(0 0 0 / 8%);*/}
.layui-table-tool .layui-btn-container{margin-bottom: -10px;}
.layui-table-total{margin-bottom: -1px; border-width: 0; border-top-width: 1px; overflow: hidden;}
@ -1316,7 +1316,7 @@ body .layui-util-face .layui-layer-content{padding:0; background-color:#fff; co
.layui-colorpicker-trigger-i{display: inline-block; color: #FFF; font-size: 12px;}
.layui-colorpicker-trigger-i.layui-icon-close{color: #999;}
.layui-colorpicker-main{position: absolute; z-index: 66666666; width: 280px; padding: 7px; background: #FFF; border: 1px solid #d2d2d2; border-radius: 2px; box-shadow: 0 2px 4px rgba(0,0,0,.12);}
.layui-colorpicker-main{position: absolute; left: -999999px; top: -999999px; z-index: 66666666; width: 280px; margin: 5px 0; padding: 7px; background: #FFF; border: 1px solid #d2d2d2; border-radius: 2px; box-shadow: 0 2px 4px rgba(0,0,0,.12);}
.layui-colorpicker-main-wrapper{height: 180px; position: relative;}
.layui-colorpicker-basis{width: 260px; height: 100%; position: relative;}
.layui-colorpicker-basis-white{width: 100%; height: 100%; position: absolute; top: 0; left: 0; background: linear-gradient(90deg, #FFF, hsla(0,0%,100%,0));}
@ -1338,7 +1338,7 @@ body .layui-util-face .layui-layer-content{padding:0; background-color:#fff; co
.layui-colorpicker-main-input div.layui-inline{float: left; margin-right: 10px; font-size: 14px;}
.layui-colorpicker-main-input input.layui-input{width: 150px; height: 30px; color: #666;}
/** 滑块 By star1029 **/
/** 滑块 **/
.layui-slider{height: 4px; background: #eee; border-radius: 3px; position: relative; cursor: pointer;}
.layui-slider-bar{border-radius: 3px; position: absolute; height: 100%;}
.layui-slider-step{position: absolute; top: 0; width: 4px; height: 4px; border-radius: 50%; background: #FFF; -webkit-transform: translateX(-50%); transform: translateX(-50%);}

View File

@ -16,7 +16,7 @@
}
,Layui = function(){
this.v = '2.6.7'; //版本号
this.v = '2.6.8'; // layui 版本号
}
//识别预先可能定义的指定全局对象
@ -539,7 +539,6 @@
error: error
};
};
//typeof 类型细分 -> string/number/boolean/undefined/null、object/array/function/…
Layui.prototype._typeof = function(operand){
@ -608,16 +607,50 @@
//如果是数字,按大小排序;如果是非数字,则按字典序排序
clone.sort(function(o1, o2){
var isNum = /^-?\d+$/
,v1 = o1[key]
,v2 = o2[key];
if(isNum.test(v1)) v1 = parseFloat(v1);
if(isNum.test(v2)) v2 = parseFloat(v2);
var v1 = o1[key]
,v2 = o2[key]
,isNum = [
!isNaN(v1)
,!isNaN(v2)
];
return v1 - v2;
//若为数字比较
if(isNum[0] && isNum[1]){
if(v1 && (!v2 && v2 !== 0)){ //数字 vs 空
return 1;
} else if((!v1 && v1 !== 0) && v2){ //空 vs 数字
return -1;
} else { //数字 vs 数字
return v1 - v2;
}
};
/**
* 字典序排序
*/
//若为非数字比较
if(!isNum[0] && !isNum[1]){
//字典序比较
if(v1 > v2){
return 1;
} else if (v1 < v2) {
return -1;
} else {
return 0;
}
}
//若为混合比较
if(isNum[0] || !isNum[1]){ //数字 vs 非数字
return -1;
} else if(!isNum[0] || isNum[1]) { //非数字 vs 数字
return 1;
}
/*
//老版本
if(v1 && !v2){
return 1;
} else if(!v1 && v2){
@ -680,7 +713,7 @@
if(fn){
config.event[eventName] = config.event[eventName] || {};
//这里不再对多次事件监听做支持,避免更多麻烦
//这里不再对重复事件做支持
//config.event[eventName][filterName] ? config.event[eventName][filterName].push(fn) :
config.event[eventName][filterName] = [fn];
return this;

View File

@ -1,14 +1,16 @@
/**
@Title: colorpicker 颜色选择器组件
@LicenseMIT
/*!
* colorpicker
* 颜色选择组件
*/
layui.define('jquery', function(exports){
layui.define(['jquery', 'lay'], function(exports){
"use strict";
var $ = layui.jquery
,lay = layui.lay
,device = layui.device()
,clickOrMousedown = (device.mobile ? 'click' : 'mousedown')
//外部接口
,colorpicker = {
@ -217,7 +219,7 @@ layui.define('jquery', function(exports){
,elemColorBox = that.elemColorBox[0]
//颜色选择器对象
,elemPicker = that.elemPicker = $(['<div id="layui-colorpicker'+ that.index +'" data-index="'+ that.index +'" class="layui-anim layui-anim-upbit layui-colorpicker-main">'
,elemPicker = that.elemPicker = $(['<div id="layui-colorpicker'+ that.index +'" data-index="'+ that.index +'" class="layui-anim layui-anim-downbit layui-colorpicker-main">'
//颜色面板
,'<div class="layui-colorpicker-main-wrapper">'
,'<div class="layui-colorpicker-basis">'
@ -295,45 +297,12 @@ layui.define('jquery', function(exports){
//定位算法
Class.prototype.position = function(){
var that = this
,options = that.config
,elem = that.bindElem || that.elemColorBox[0]
,elemPicker = that.elemPicker[0]
,rect = elem.getBoundingClientRect() //绑定元素的坐标
,elemWidth = elemPicker.offsetWidth //控件的宽度
,elemHeight = elemPicker.offsetHeight //控件的高度
//滚动条高度
,scrollArea = function(type){
type = type ? 'scrollLeft' : 'scrollTop';
return document.body[type] | document.documentElement[type];
}
,winArea = function(type){
return document.documentElement[type ? 'clientWidth' : 'clientHeight']
}, margin = 5, left = rect.left, top = rect.bottom;
left = left - (elemWidth - elem.offsetWidth)/2;
top = top + margin
//如果右侧超出边界
if(left + elemWidth + margin > winArea('width')){
left = winArea('width') - elemWidth - margin;
} else if(left < margin){ //如果左侧超出边界
left = margin;
}
//如果底部超出边界
if(top + elemHeight + margin > winArea()){
top = rect.top > elemHeight //顶部是否有足够区域显示完全
? rect.top - elemHeight
: winArea() - elemHeight;
top = top - margin*2;
}
if(options.position){
elemPicker.style.position = options.position;
}
elemPicker.style.left = left + (options.position === 'fixed' ? 0 : scrollArea(1)) + 'px';
elemPicker.style.top = top + (options.position === 'fixed' ? 0 : scrollArea()) + 'px';
,options = that.config;
lay.position(that.bindElem || that.elemColorBox[0], that.elemPicker[0], {
position: options.position
,align: 'center'
});
return that;
};
//颜色选择器赋值
@ -435,7 +404,7 @@ layui.define('jquery', function(exports){
}
//拖拽元素
,elemMove = $(['<div class="layui-auxiliar-moving" id="LAY-colorpicker-moving"></div'].join(''))
,elemMove = $(['<div class="layui-auxiliar-moving" id="LAY-colorpicker-moving"></div>'].join(''))
,createMoveElem = function(call){
$('#LAY-colorpicker-moving')[0] || $('body').append(elemMove);
elemMove.on('mousemove', call);
@ -457,11 +426,12 @@ layui.define('jquery', function(exports){
if(top > maxh)top = maxh;
var h = top/180*360;
_h = h;
change(h, _s, _b, _a);
change(h, _s, _b, _a);
e.preventDefault();
};
createMoveElem(move);
//layui.stope(e);
e.preventDefault();
});
@ -514,6 +484,7 @@ layui.define('jquery', function(exports){
_b = b;
_s = s;
change(_h, s, b, _a);
layui.stope(e);
e.preventDefault();
choose.trigger(e, 'mousedown');
});
@ -675,7 +646,7 @@ layui.define('jquery', function(exports){
if(!options.elem[0] || that.elemColorBox[0].eventHandler) return;
//绑定关闭控件事件
$doc.on('click', function(e){
$doc.on(clickOrMousedown, function(e){
//如果点击的元素是颜色框
if($(e.target).hasClass(ELEM)
|| $(e.target).parents('.'+ELEM)[0]

View File

@ -304,6 +304,7 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
position: options.position
,e: that.e
,clickType: options.trigger === 'contextmenu' ? 'right' : null
,align: options.align || null
});
};

View File

@ -46,6 +46,7 @@ layui.define('layer', function(exports){
,'请输入正确的身份证号'
]
}
,autocomplete: null //全局 autocomplete 状态。null 表示不干预
};
};
@ -139,13 +140,21 @@ layui.define('layer', function(exports){
//表单控件渲染
Form.prototype.render = function(type, filter){
var that = this
,options = that.config
,elemForm = $(ELEM + function(){
return filter ? ('[lay-filter="' + filter +'"]') : '';
}())
,items = {
//输入框
input: function(){
var inputs = elemForm.find('input,textarea');
//初始化全局的 autocomplete
options.autocomplete && inputs.attr('autocomplete', options.autocomplete);
}
//下拉选择框
select: function(){
,select: function(){
var TIPS = '请选择', CLASS = 'layui-form-select', TITLE = 'layui-select-title'
,NONE = 'layui-select-none', initValue = '', thatInput
,selects = elemForm.find('select')
@ -441,8 +450,8 @@ layui.define('layer', function(exports){
var reElem = $(['<div class="'+ (isSearch ? '' : 'layui-unselect ') + CLASS
,(disabled ? ' layui-select-disabled' : '') +'">'
,'<div class="'+ TITLE +'">'
,('<input type="text" placeholder="'+ placeholder +'" '
+('value="'+ (value ? selected.html() : '') +'"') //默认值
,('<input type="text" placeholder="'+ $.trim(placeholder) +'" '
+('value="'+ $.trim(value ? selected.html() : '') +'"') //默认值
+((!disabled && isSearch) ? '' : ' readonly') //是否开启搜索
+' class="layui-input'
+(isSearch ? '' : ' layui-unselect')
@ -453,11 +462,11 @@ layui.define('layer', function(exports){
var arr = [];
layui.each(options, function(index, item){
if(index === 0 && !item.value){
arr.push('<dd lay-value="" class="layui-select-tips">'+ (item.innerHTML || TIPS) +'</dd>');
arr.push('<dd lay-value="" class="layui-select-tips">'+ $.trim(item.innerHTML || TIPS) +'</dd>');
} else if(item.tagName.toLowerCase() === 'optgroup'){
arr.push('<dt>'+ item.label +'</dt>');
} else {
arr.push('<dd lay-value="'+ item.value +'" class="'+ (value === item.value ? THIS : '') + (item.disabled ? (' '+DISABLED) : '') +'">'+ item.innerHTML +'</dd>');
arr.push('<dd lay-value="'+ item.value +'" class="'+ (value === item.value ? THIS : '') + (item.disabled ? (' '+DISABLED) : '') +'">'+ $.trim(item.innerHTML) +'</dd>');
}
});
arr.length === 0 && arr.push('<dd lay-value="" class="'+ DISABLED +'">没有选项</dd>');
@ -517,7 +526,7 @@ layui.define('layer', function(exports){
var hasRender = othis.next('.' + RE_CLASS[0])
,reElem = $(['<div class="layui-unselect '+ RE_CLASS[0]
,(check.checked ? (' '+ RE_CLASS[1]) : '') //选中状态
,(disabled ? ' layui-checkbox-disbaled '+ DISABLED : '') //禁用状态
,(disabled ? ' layui-checkbox-disabled '+ DISABLED : '') //禁用状态
,'"'
,(skin ? ' lay-skin="'+ skin +'"' : '') //风格
,'>'
@ -586,7 +595,7 @@ layui.define('layer', function(exports){
//替代元素
var reElem = $(['<div class="layui-unselect '+ CLASS
,(radio.checked ? (' '+CLASS+'ed') : '') //选中状态
,(disabled ? ' layui-radio-disbaled '+DISABLED : '') +'">' //禁用状态
,(disabled ? ' layui-radio-disabled '+DISABLED : '') +'">' //禁用状态
,'<i class="layui-anim layui-icon">'+ ICON[radio.checked ? 0 : 1] +'</i>'
,'<div>'+ function(){
var title = radio.title || '';
@ -604,7 +613,7 @@ layui.define('layer', function(exports){
}
};
type ? (
items[type] ? items[type]() : hint.error('不支持的'+ type + '表单渲染')
items[type] ? items[type]() : hint.error('不支持的 "'+ type + '" 表单渲染')
) : layui.each(items, function(index, item){
item();
});
@ -641,7 +650,10 @@ layui.define('layer', function(exports){
//匹配验证规则
if(verify[thisVer]){
var isTrue = isFn ? errorText = verify[thisVer](value, item) : !verify[thisVer][0].test(value);
var isTrue = isFn ? errorText = verify[thisVer](value, item) : !verify[thisVer][0].test(value)
//是否属于美化替换后的表单元素
,isForm2Elem = item.tagName.toLowerCase() === 'select' || /^checkbox|radio$/.test(item.type);
errorText = errorText || verify[thisVer][1];
if(thisVer === 'required'){
@ -654,7 +666,7 @@ layui.define('layer', function(exports){
if(verType === 'tips'){
layer.tips(errorText, function(){
if(typeof othis.attr('lay-ignore') !== 'string'){
if(item.tagName.toLowerCase() === 'select' || /^checkbox|radio$/.test(item.type)){
if(isForm2Elem){
return othis.next();
}
}
@ -669,10 +681,18 @@ layui.define('layer', function(exports){
}
//非移动设备自动定位焦点
if(!device.android && !device.ios){
if(!device.mobile){
setTimeout(function(){
item.focus();
(isForm2Elem ? othis.next().find('input') : item).focus();
}, 7);
} else { //移动设备定位
$dom.scrollTop(function(){
try {
return (isForm2Elem ? othis.next() : othis).offset().top - 15
} catch(e){
return 0;
}
}());
}
othis.addClass(DANGER);

View File

@ -35,10 +35,10 @@
lay.extend = function(){
var ai = 1, args = arguments
,clone = function(target, obj){
target = target || (obj.constructor === Array ? [] : {});
target = target || (layui._typeof(obj) === 'array' ? [] : {}); //目标对象
for(var i in obj){
//如果值为对象,则进入递归,继续深度合并
target[i] = (obj[i] && (obj[i].constructor === Object))
//如果值为普通对象,则进入递归,继续深度合并
target[i] = (obj[i] && obj[i].constructor === Object)
? clone(target[i], obj[i])
: obj[i];
}
@ -49,14 +49,14 @@
for(; ai < args.length; ai++){
if(typeof args[ai] === 'object'){
clone(args[0], args[ai])
clone(args[0], args[ai]);
}
}
return args[0];
};
//lay 模块版本
lay.v = '1.0.7';
lay.v = '1.0.8';
//ie版本
lay.ie = function(){
@ -75,7 +75,7 @@
* 获取 layui 常见方法以便用于组件单独版
*/
lay.layui = layui;
lay.layui = layui || {};
lay.getPath = layui.cache.dir; //获取当前 JS 所在目录
lay.stope = layui.stope; //中止冒泡
lay.each = function(){ //遍历
@ -145,11 +145,20 @@
,winArea = function(type){
return document.documentElement[type ? 'clientWidth' : 'clientHeight']
}, margin = 5, left = rect.left, top = rect.bottom;
//相对元素居中
if(obj.align === 'center'){
left = left - (elemWidth - elem.offsetWidth)/2;
} else if(obj.align === 'right'){
left = left - elemWidth + elem.offsetWidth;
}
//判断右侧是否超出边界
if(left + elemWidth + margin > winArea('width')){
left = winArea('width') - elemWidth - margin; //如果超出右侧,则将面板向右靠齐
}
//左侧是否超出边界
if(left < margin) left = margin;
//判断底部和顶部是否超出边界
if(top + elemHeight + margin > winArea()){

View File

@ -25,7 +25,7 @@
//外部调用
,laydate = {
v: '5.3.1'
v: '5.3.1' //layDate 版本号
,config: {} //全局配置项
,index: (window.laydate && window.laydate.v) ? 100000 : 0
,path: GLOBAL.laydate_dir || ready.getPath
@ -192,7 +192,7 @@
that.rangeStr = options.range ? (typeof options.range === 'string' ? options.range : '-') : '';
//若 range 参数为数组,则表示为开始日期和结束日期的 input 对象
if(options.range && options.range.constructor === Array){
if(layui._typeof(options.range) === 'array'){
that.rangeElem = [
lay(options.range[0]),
lay(options.range[1])
@ -304,7 +304,7 @@
//默认赋值
if(options.value && options.isInitValue){
if(options.value.constructor === Date){
if(layui._typeof(options.value) === 'date'){
that.setValue(that.parse(0, that.systemDate(options.value)));
} else {
that.setValue(options.value);
@ -696,7 +696,7 @@
) + lang.formatError[1]);
error = true;
}
} else if(value && value.constructor === Date){ //如果值为日期对象时
} else if(value && layui._typeof(value) === 'date'){ //如果值为日期对象时
options.dateTime = that.systemDate(value);
} else {
//重置开始日期
@ -1248,12 +1248,10 @@
//显示预览
elemPreview.html(value).css({
'color': '#5FB878'
,'font-size': '14px;'
});
setTimeout(function(){
elemPreview.css({
'color': '#666'
,'font-size': '12px;'
});
}, 300);
};
@ -1556,7 +1554,7 @@
//获取当前实例对象
thisModule.getThis = function(id){
var that = thisModule.that[id];
if(!that) hint.error(id ? (MOD_NAME +' instance with ID \''+ id +'\' not found') : 'ID argument required');
if(!that && isLayui) layui.hint().error(id ? (MOD_NAME +' instance with ID \''+ id +'\' not found') : 'ID argument required');
return that;
};

View File

@ -671,10 +671,10 @@ Class.pt.callback = function(){
if(config.success){
if(config.type == 2){
layero.find('iframe').on('load', function(){
config.success(layero, that.index);
config.success(layero, that.index, that);
});
} else {
config.success(layero, that.index);
config.success(layero, that.index, that);
}
}
layer.ie == 6 && that.IE6(layero);

View File

@ -72,6 +72,12 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
//解析自定义模板数据
,parseTempData = function(item3, content, tplData, text){ //表头数据、原始内容、表体数据、是否只返回文本
var options = this.config || {};
//是否防 xss
if(options.escape) content = util.escape(content);
//获取内容
var str = item3.templet ? function(){
return typeof item3.templet === 'function'
? item3.templet(tplData)
@ -738,7 +744,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
typeof options.error === 'function' && options.error(e, msg);
}
});
} else if(options.data && options.data.constructor === Array){ //已知数据
} else if(layui._typeof(options.data) === 'array'){ //已知数据
var res = {}
,startLimit = curr*options.limit - options.limit
@ -823,6 +829,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
}() +'">' + function(){
var tplData = $.extend(true, {
LAY_INDEX: numbers
,LAY_COL: item3
}, item1)
,checkName = table.config.checkName;
@ -854,7 +861,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
if(item3.toolbar){
return laytpl($(item3.toolbar).html()||'').render(tplData);
}
return parseTempData(item3, content, tplData);
return parseTempData.call(that, item3, content, tplData);
}()
,'</div></td>'].join('');
@ -978,7 +985,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
tplData[field] = thisTotalNum;
//获取自动计算的合并内容
getContent = item3.totalRow ? (parseTempData(item3, thisTotalNum, tplData) || text) : text;
getContent = item3.totalRow ? (parseTempData.call(that, item3, thisTotalNum, tplData) || text) : text;
//如果直接传入了合计行数据,则不输出自动计算的结果
return totalRowData ? (totalRowData[item3.field] || getContent) : getContent;
@ -1135,7 +1142,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
,options = that.config
,thisData = table.cache[that.key];
if(!thisData[index]) return;
if(thisData[index].constructor === Array) return;
if(layui._typeof(thisData[index]) === 'array') return;
thisData[index][options.checkName] = checked;
};
@ -1524,7 +1531,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
templet = item2.templet;
}
});
td.children(ELEM_CELL).html(parseTempData({
td.children(ELEM_CELL).html(parseTempData.call(that, {
templet: templet
}, value, data));
td.data('content', value);
@ -1637,7 +1644,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
}
});
othis.siblings(ELEM_CELL).html(function(value){
return parseTempData({
return parseTempData.call(that, {
templet: templet
}, value, data);
}(thisElem.value));
@ -1767,6 +1774,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
table.init = function(filter, settings){
settings = settings || {};
var that = this
,inst = null
,elemTable = filter ? $('table[lay-filter="'+ filter +'"]') : $(ELEM + '[lay-data]')
,errorTips = 'Table element property lay-data configuration item has a syntax error: ';
@ -1774,9 +1782,9 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
elemTable.each(function(){
var othis = $(this), tableData = othis.attr('lay-data');
try{
try {
tableData = new Function('return '+ tableData)();
} catch(e){
} catch(e) {
hint.error(errorTips + tableData, 'error')
}
@ -1832,6 +1840,8 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
});
options.data[i1] = row;
});
//执行渲染
table.render(options);
});
@ -1894,7 +1904,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
,data = table.cache[id] || [];
//计算全选个数
layui.each(data, function(i, item){
if(item.constructor === Array){
if(layui._typeof(item) === 'array'){
invalidNum++; //无效数据,或已删除的
return;
}
@ -1914,7 +1924,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
var arr = []
,data = table.cache[id] || [];
layui.each(data, function(i, item){
if(item.constructor === Array){
if(layui._typeof(item) === 'array'){
return;
};
arr.push(table.clearCacheKey(item));
@ -1929,7 +1939,8 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
data = data || table.clearCacheKey(table.cache[id]);
type = type || 'csv';
var config = thisTable.config[id] || {}
var thatTable = thisTable.that[id]
,config = thisTable.config[id] || {}
,textType = ({
csv: 'text/csv'
,xls: 'application/vnd.ms-excel'
@ -1958,7 +1969,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
if(content === undefined || content === null) content = '';
i1 == 0 && dataTitle.push(item3.title || '');
vals.push('"'+ parseTempData(item3, content, item1, 'text') + '"');
vals.push('"'+ parseTempData.call(thatTable, item3, content, item1, 'text') + '"');
}
});
}

View File

@ -101,7 +101,7 @@ layui.define('form', function(exports){
var that = this;
layui.each(options, function(key, item){
if(item.constructor === Array) delete that.config[key];
if(layui._typeof(item) === 'array') delete that.config[key];
});
that.config = $.extend(true, {}, that.config, options);