mirror of https://github.com/layui/layui
Merge branch 'layui:2.x' into 2.x
commit
c50b1197b6
File diff suppressed because one or more lines are too long
|
@ -12,21 +12,21 @@ toc: true
|
||||||
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code']}">
|
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code']}">
|
||||||
<textarea>
|
<textarea>
|
||||||
<div class="layui-btn-container">
|
<div class="layui-btn-container">
|
||||||
<button type="button" class="layui-btn layui-btn-primary">原始按钮</button>
|
|
||||||
<button type="button" class="layui-btn">默认按钮</button>
|
<button type="button" class="layui-btn">默认按钮</button>
|
||||||
<button type="button" class="layui-btn layui-btn-normal">百搭按钮</button>
|
<button type="button" class="layui-btn layui-bg-blue">蓝色按钮</button>
|
||||||
<button type="button" class="layui-btn layui-btn-warm">暖色按钮</button>
|
<button type="button" class="layui-btn layui-bg-orange">橙色按钮</button>
|
||||||
<button type="button" class="layui-btn layui-btn-danger">警告按钮</button>
|
<button type="button" class="layui-btn layui-bg-red">红色按钮</button>
|
||||||
|
<button type="button" class="layui-btn layui-bg-purple">紫色按钮</button>
|
||||||
<button type="button" class="layui-btn layui-btn-disabled">禁用按钮</button>
|
<button type="button" class="layui-btn layui-btn-disabled">禁用按钮</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="layui-btn-container">
|
<div class="layui-btn-container">
|
||||||
<button class="layui-btn layui-btn-primary layui-border">原始按钮</button>
|
|
||||||
<button class="layui-btn layui-btn-primary layui-border-green">主色按钮</button>
|
<button class="layui-btn layui-btn-primary layui-border-green">主色按钮</button>
|
||||||
<button class="layui-btn layui-btn-primary layui-border-blue">百搭按钮</button>
|
<button class="layui-btn layui-btn-primary layui-border-blue">蓝色按钮</button>
|
||||||
<button class="layui-btn layui-btn-primary layui-border-orange">暖色按钮</button>
|
<button class="layui-btn layui-btn-primary layui-border-orange">橙色按钮</button>
|
||||||
<button class="layui-btn layui-btn-primary layui-border-red">警告按钮</button>
|
<button class="layui-btn layui-btn-primary layui-border-red">红色按钮</button>
|
||||||
<button class="layui-btn layui-btn-primary layui-border-black">深色按钮</button>
|
<button class="layui-btn layui-btn-primary layui-border-purple">紫色按钮</button>
|
||||||
|
<button class="layui-btn layui-btn-primary layui-border">普通按钮</button>
|
||||||
</div>
|
</div>
|
||||||
</textarea>
|
</textarea>
|
||||||
</pre>
|
</pre>
|
||||||
|
|
|
@ -266,6 +266,7 @@ click: function(data, othis){
|
||||||
/*
|
/*
|
||||||
return false;
|
return false;
|
||||||
*/
|
*/
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
用法详见:[#示例](#examples)
|
用法详见:[#示例](#examples)
|
||||||
|
|
|
@ -61,8 +61,8 @@ toc: true
|
||||||
- 通过 `class="layui-form"` 定义一个表单域,通常设置在`<form>`标签上, 或普通`<div>` 标签亦可。
|
- 通过 `class="layui-form"` 定义一个表单域,通常设置在`<form>`标签上, 或普通`<div>` 标签亦可。
|
||||||
- 通过 `class="layui-form-item"` 定义一个块级元素的表单项容器
|
- 通过 `class="layui-form-item"` 定义一个块级元素的表单项容器
|
||||||
- 通过 `class="layui-form-label"` 定义标签
|
- 通过 `class="layui-form-label"` 定义标签
|
||||||
- 通过 `class="layui-form-block"` 定义表单项父容器为块级元素
|
- 通过 `class="layui-input-block"` 定义表单项父容器为块级元素
|
||||||
- 通过 `class="layui-form-inline"` 或 `class="layui-inline"` 定义表单项父容器为行内块元素
|
- 通过 `class="layui-input-inline"` 或 `class="layui-inline"` 定义表单项父容器为行内块元素
|
||||||
|
|
||||||
即必须按照规定的层级定义相应的 `class`。
|
即必须按照规定的层级定义相应的 `class`。
|
||||||
|
|
||||||
|
@ -408,7 +408,7 @@ form.on('select(test)', function(data){
|
||||||
| 属性名 | 描述 | 类型 | 默认值 |
|
| 属性名 | 描述 | 类型 | 默认值 |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| autocomplete | 设置 input 框的 `autocomplete` 属性初始值 | string | - |
|
| autocomplete | 设置 input 框的 `autocomplete` 属性初始值 | string | - |
|
||||||
| verIncludelRequired <sup>2.8.4+</sup> | 验证规则中是否同时包含必填。 form 组件在 `2.8.3` 版本中调整了内置校验规则,即:仅当非空时进行校验,避免强制携带必填的校验规则。如需保留之前的验证规则(即同时校验必填),可将该属性设置为 `true`。但一般还是建议将必填项放置在 `lay-verify` 属性上,如: `lay-verify="required\|number"` | boolean | `false` |
|
| verIncludeRequired <sup>2.8.4+</sup> | 验证规则中是否同时包含必填。 form 组件在 `2.8.3` 版本中调整了内置校验规则,即:仅当非空时进行校验,避免强制携带必填的校验规则。如需保留之前的验证规则(即同时校验必填),可将该属性设置为 `true`。但一般还是建议将必填项放置在 `lay-verify` 属性上,如: `lay-verify="required\|number"` | boolean | `false` |
|
||||||
|
|
||||||
该方法用于对 form 组件进行全局设置。
|
该方法用于对 form 组件进行全局设置。
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,7 @@ toc: true
|
||||||
数字输入框 <sup>2.8.9+</sup>
|
数字输入框 <sup>2.8.9+</sup>
|
||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
一般搭配 `<input type="number">` 使用,用于替代原生输入框,可继承 `step,min,max` 等原生属性。
|
一般搭配 `<input type="number">` 使用,用于替代原生数字输入框,可继承 `step,min,max` 等原生属性。
|
||||||
|
|
||||||
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], done: function(obj){
|
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], done: function(obj){
|
||||||
obj.render();
|
obj.render();
|
||||||
|
@ -130,9 +130,12 @@ toc: true
|
||||||
<div class="layui-col-xs6">
|
<div class="layui-col-xs6">
|
||||||
<input type="number" lay-affix="number" placeholder="设置 step,min,max" step="10" min="0" max="100" class="layui-input">
|
<input type="number" lay-affix="number" placeholder="设置 step,min,max" step="10" min="0" max="100" class="layui-input">
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-col-xs12">
|
<div class="layui-col-xs6">
|
||||||
<input type="number" lay-affix="number" disabled placeholder="禁用状态" value="0" class="layui-input">
|
<input type="number" lay-affix="number" readonly placeholder="不允许输入状态" class="layui-input">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="layui-col-xs6">
|
||||||
|
<input type="number" lay-affix="number" disabled placeholder="禁用状态" class="layui-input">
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ toc: true
|
||||||
- 通过 `<li></li>` 放置菜单列表项
|
- 通过 `<li></li>` 放置菜单列表项
|
||||||
- 属性:
|
- 属性:
|
||||||
- 追加 `className` 为 `layui-menu-item-group` 可设置当前菜单为菜单组,即子菜单为纵向层级。
|
- 追加 `className` 为 `layui-menu-item-group` 可设置当前菜单为菜单组,即子菜单为纵向层级。
|
||||||
- 或追加 `className` 为 `layui-menu-item-parent` 可这支当前菜单为父级菜单,即子菜单为横向层级。
|
- 或追加 `className` 为 `layui-menu-item-parent` 可设置当前菜单为父级菜单,即子菜单为横向层级。
|
||||||
- 追加 `className` 为 `layui-menu-item-divider` 可设置分隔线。
|
- 追加 `className` 为 `layui-menu-item-divider` 可设置分隔线。
|
||||||
- 追加 `className` 为 `layui-menu-item-up` 或 `layui-menu-item-down` 可设置子菜单默认收缩或展开。
|
- 追加 `className` 为 `layui-menu-item-up` 或 `layui-menu-item-down` 可设置子菜单默认收缩或展开。
|
||||||
- 追加 `className` 为 `layui-menu-item-checked` 可设置当前菜单为选中状态
|
- 追加 `className` 为 `layui-menu-item-checked` 可设置当前菜单为选中状态
|
||||||
|
|
|
@ -19,7 +19,7 @@ layui.use(function(){
|
||||||
var util = layui.util;
|
var util = layui.util;
|
||||||
|
|
||||||
// 模拟数据
|
// 模拟数据
|
||||||
var data = [{title:'一级1',id:1,field:'name1',checked:true,spread:true,children:[{title:'二级1-1 可允许跳转',id:3,field:'name11',href:'',children:[{title:'三级1-1-3',id:23,field:'',children:[{title:'四级1-1-3-1',id:24,field:'',children:[{title:'五级1-1-3-1-1',id:30,field:''},{title:'五级1-1-3-1-2',id:31,field:''}]}]},{title:'三级1-1-1',id:7,field:'',children:[{title:'四级1-1-1-1 可允许跳转',id:15,field:'',href:''}]},{title:'三级1-1-2',id:8,field:'',children:[{title:'四级1-1-2-1',id:32,field:''}]}]},{title:'二级1-2',id:4,spread:true,children:[{title:'三级1-2-1',id:9,field:'',disabled:true},{title:'三级1-2-2',id:10,field:''}]},{title:'二级1-3',id:20,field:'',children:[{title:'三级1-3-1',id:21,field:''},{title:'三级1-3-2',id:22,field:''}]}]},{title:'一级2',id:2,field:'',spread:true,children:[{title:'二级2-1',id:5,field:'',spread:true,children:[{title:'三级2-1-1',id:11,field:''},{title:'三级2-1-2',id:12,field:''}]},{title:'二级2-2',id:6,field:'',children:[{title:'三级2-2-1',id:13,field:''},{title:'三级2-2-2',id:14,field:'',disabled:true}]}]},{title:'一级3',id:16,field:'',children:[{title:'二级3-1',id:17,field:'',fixed:true,children:[{title:'三级3-1-1',id:18,field:''},{title:'三级3-1-2',id:19,field:''}]},{title:'二级3-2',id:27,field:'',children:[{title:'三级3-2-1',id:28,field:''},{title:'三级3-2-2',id:29,field:''}]}]}];
|
var data = [{title:'A-1',id:1,field:'name1',checked:true,spread:true,children:[{title:'B-1-1 可允许跳转',id:3,field:'name11',href:'',children:[{title:'C-1-1-3',id:23,field:'',children:[{title:'D-1-1-3-1',id:24,field:'',children:[{title:'E-1-1-3-1-1',id:30,field:''},{title:'E-1-1-3-1-2',id:31,field:''}]}]},{title:'C-1-1-1',id:7,field:'',children:[{title:'D-1-1-1-1 可允许跳转',id:15,field:'',href:''}]},{title:'C-1-1-2',id:8,field:'',children:[{title:'D-1-1-2-1',id:32,field:''}]}]},{title:'B-1-2',id:4,spread:true,children:[{title:'C-1-2-1',id:9,field:'',disabled:true},{title:'C-1-2-2',id:10,field:''}]},{title:'B-1-3',id:20,field:'',children:[{title:'C-1-3-1',id:21,field:''},{title:'C-1-3-2',id:22,field:''}]}]},{title:'A-2',id:2,field:'',spread:true,children:[{title:'B-2-1',id:5,field:'',spread:true,children:[{title:'C-2-1-1',id:11,field:''},{title:'C-2-1-2',id:12,field:''}]},{title:'B-2-2',id:6,field:'',children:[{title:'C-2-2-1',id:13,field:''},{title:'C-2-2-2',id:14,field:'',disabled:true}]}]},{title:'A-3',id:16,field:'',children:[{title:'B-3-1',id:17,field:'',fixed:true,children:[{title:'C-3-1-1',id:18,field:''},{title:'C-3-1-2',id:19,field:''}]},{title:'B-3-2',id:27,field:'',children:[{title:'C-3-2-1',id:28,field:''},{title:'C-3-2-2',id:29,field:''}]}]}];
|
||||||
|
|
||||||
// 渲染
|
// 渲染
|
||||||
tree.render({
|
tree.render({
|
||||||
|
|
|
@ -11,6 +11,28 @@ toc: true
|
||||||
|
|
||||||
> 导读:📑 [Layui 2.8 《升级指南》](/notes/2.8/upgrade-guide.html) · 📑 [Layui 新版文档站上线初衷](/notes/2.8/news.html)
|
> 导读:📑 [Layui 2.8 《升级指南》](/notes/2.8/upgrade-guide.html) · 📑 [Layui 新版文档站上线初衷](/notes/2.8/news.html)
|
||||||
|
|
||||||
|
|
||||||
|
<h2 id="2.8.11" class="ws-anchor">
|
||||||
|
2.8.11
|
||||||
|
<span class="layui-badge-rim">2023-07-13</span>
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
- #### form
|
||||||
|
- 修复 `radio` 标题模板中若存在图标,选中时该图标被强制更改的问题 # I7IERB
|
||||||
|
- 优化 `input` 数字输入框的精度问题 # I7I7J2
|
||||||
|
- 修正 `verIncludelRequired` 属性名为 `verIncludeRequired` # 1305
|
||||||
|
- #### table
|
||||||
|
- 修复 导出统计行中若存在逗号出现的内容分隔异常问题 # I7IDA3
|
||||||
|
- 修复 当点击筛选显示隐藏固定列时出现的未对齐的问题 # I7KQ0O
|
||||||
|
- #### menu
|
||||||
|
- 修复 `menu` 标题项自定义图标在展开收缩后被强制更改的问题 # 1303/I7JAPU
|
||||||
|
- #### tree
|
||||||
|
- 修复 点击复选框时未将对应的数据中的 `checked` 属性值进行同步的问题
|
||||||
|
|
||||||
|
### 下载: [layui-v2.8.11.zip](https://gitee.com/layui/layui/attach_files/1464525/download)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
<h2 id="2.8.10" class="ws-anchor">
|
<h2 id="2.8.10" class="ws-anchor">
|
||||||
2.8.10
|
2.8.10
|
||||||
<span class="layui-badge-rim">2023-07-03</span>
|
<span class="layui-badge-rim">2023-07-03</span>
|
||||||
|
|
|
@ -120,6 +120,9 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="layui-col-md3">
|
||||||
|
<input type="number" value="1.1" name="arr[]" required placeholder="数字输入框" lay-affix="number" autocomplete="off" class="layui-input">
|
||||||
|
</div>
|
||||||
<div class="layui-col-md3">
|
<div class="layui-col-md3">
|
||||||
<input type="number" step="0.01" min="0" max="10" name="arr[]" required placeholder="数字输入框" lay-affix="number" autocomplete="off" class="layui-input">
|
<input type="number" step="0.01" min="0" max="10" name="arr[]" required placeholder="数字输入框" lay-affix="number" autocomplete="off" class="layui-input">
|
||||||
</div>
|
</div>
|
||||||
|
@ -341,17 +344,13 @@
|
||||||
<div class="layui-form-item" pane>
|
<div class="layui-form-item" pane>
|
||||||
<label class="layui-form-label">单选框</label>
|
<label class="layui-form-label">单选框</label>
|
||||||
<div class="layui-input-block">
|
<div class="layui-input-block">
|
||||||
<input type="radio" name="sex" value="男" title="男">
|
<input type="radio" name="sex" value="1" title="男">
|
||||||
<input type="radio" name="sex" value="女" title="女" checked>
|
<input type="radio" name="sex" value="0" title="女" checked>
|
||||||
<input type="radio" name="sex" value="中型" title="中" disabled>
|
<input type="radio" name="sex" value="-1">
|
||||||
</div>
|
<div lay-radio>
|
||||||
</div>
|
保密 <i class="layui-icon layui-icon-user"></i>
|
||||||
<div class="layui-form-item" pane>
|
</div>
|
||||||
<label class="layui-form-label">单选框</label>
|
<input type="radio" name="sex" value="" title="禁用" disabled>
|
||||||
<div class="layui-input-block">
|
|
||||||
<input type="radio" name="sex.id" value="男" title="男">
|
|
||||||
<input type="radio" name="sex.id" value="女" title="女" checked>
|
|
||||||
<input type="radio" name="sex.id" value="中型" title="中">
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-form-item layui-form-text">
|
<div class="layui-form-item layui-form-text">
|
||||||
|
@ -436,7 +435,7 @@
|
||||||
,'interest': 3
|
,'interest': 3
|
||||||
,'like[write]': true
|
,'like[write]': true
|
||||||
//,'open': false
|
//,'open': false
|
||||||
,'sex': '男'
|
,'sex': '0'
|
||||||
,'desc': 'form 是我们非常看重的一块'
|
,'desc': 'form 是我们非常看重的一块'
|
||||||
,xxxxxxxxx: 123
|
,xxxxxxxxx: 123
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,18 +1,10 @@
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>树组件 - layui</title>
|
|
||||||
<meta name="renderer" content="webkit">
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||||
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
<title>树组件 - layui</title>
|
||||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
||||||
<meta name="format-detection" content="telephone=no">
|
|
||||||
|
|
||||||
<link rel="stylesheet" href="../src/css/layui.css" media="all">
|
<link rel="stylesheet" href="../src/css/layui.css" media="all">
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
body{padding: 100px;}
|
body{padding: 100px;}
|
||||||
#test1,#test2{margin-bottom: 100px; width: 400px;}
|
#test1,#test2{margin-bottom: 100px; width: 400px;}
|
||||||
|
@ -48,118 +40,118 @@
|
||||||
|
|
||||||
//数据源
|
//数据源
|
||||||
var data1 = [{
|
var data1 = [{
|
||||||
title: '一级1'
|
title: 'A-1'
|
||||||
,id: 1
|
,id: 1
|
||||||
,children: [{
|
,children: [{
|
||||||
title: '二级1-1'
|
title: 'B-1-1'
|
||||||
,id: 3
|
,id: 3
|
||||||
,href: 'https://www.layui.com/doc/'
|
,href: 'https://www.layui.com/doc/'
|
||||||
,children: [{
|
,children: [{
|
||||||
title: '三级1-1-3'
|
title: 'C-1-1-3'
|
||||||
,id: 23
|
,id: 23
|
||||||
,children: [{
|
,children: [{
|
||||||
title: '四级1-1-3-1'
|
title: 'D-1-1-3-1'
|
||||||
,id: 24
|
,id: 24
|
||||||
,children: [{
|
,children: [{
|
||||||
title: '五级1-1-3-1-1'
|
title: 'E-1-1-3-1-1'
|
||||||
,id: 30
|
,id: 30
|
||||||
},{
|
},{
|
||||||
title: '五级1-1-3-1-2'
|
title: 'E-1-1-3-1-2'
|
||||||
,id: 31
|
,id: 31
|
||||||
}]
|
}]
|
||||||
}]
|
}]
|
||||||
},{
|
},{
|
||||||
title: '三级1-1-1'
|
title: 'C-1-1-1'
|
||||||
,id: 7
|
,id: 7
|
||||||
,checked: true
|
,checked: true
|
||||||
,children: [{
|
,children: [{
|
||||||
title: '四级1-1-1-1'
|
title: 'D-1-1-1-1'
|
||||||
,id: 15
|
,id: 15
|
||||||
//,checked: true
|
//,checked: true
|
||||||
,href: 'https://www.layui.com/doc/base/infrastructure.html'
|
,href: 'https://www.layui.com/doc/base/infrastructure.html'
|
||||||
}]
|
}]
|
||||||
},{
|
},{
|
||||||
title: '三级1-1-2'
|
title: 'C-1-1-2'
|
||||||
,id: 8
|
,id: 8
|
||||||
,children: [{
|
,children: [{
|
||||||
title: '四级1-1-2-1'
|
title: 'D-1-1-2-1'
|
||||||
,id: 32
|
,id: 32
|
||||||
}]
|
}]
|
||||||
}]
|
}]
|
||||||
},{
|
},{
|
||||||
title: '二级1-2'
|
title: 'B-1-2'
|
||||||
,id: 4
|
,id: 4
|
||||||
,spread: true
|
,spread: true
|
||||||
,children: [{
|
,children: [{
|
||||||
title: '三级1-2-1'
|
title: 'C-1-2-1'
|
||||||
,id: 9
|
,id: 9
|
||||||
,checked: true
|
,checked: true
|
||||||
,disabled: true
|
,disabled: true
|
||||||
},{
|
},{
|
||||||
title: '三级1-2-2'
|
title: 'C-1-2-2'
|
||||||
,id: 10
|
,id: 10
|
||||||
}]
|
}]
|
||||||
},{
|
},{
|
||||||
title: '二级1-3'
|
title: 'B-1-3'
|
||||||
,id: 20
|
,id: 20
|
||||||
,children: [{
|
,children: [{
|
||||||
title: '三级1-3-1'
|
title: 'C-1-3-1'
|
||||||
,id: 21
|
,id: 21
|
||||||
},{
|
},{
|
||||||
title: '三级1-3-2'
|
title: 'C-1-3-2'
|
||||||
,id: 22
|
,id: 22
|
||||||
}]
|
}]
|
||||||
}]
|
}]
|
||||||
},{
|
},{
|
||||||
title: '一级2'
|
title: 'A-2'
|
||||||
,id: 2
|
,id: 2
|
||||||
,spread: true
|
,spread: true
|
||||||
,children: [{
|
,children: [{
|
||||||
title: '二级2-1'
|
title: 'B-2-1'
|
||||||
,id: 5
|
,id: 5
|
||||||
,spread: true
|
,spread: true
|
||||||
,children: [{
|
,children: [{
|
||||||
title: '三级2-1-1'
|
title: 'C-2-1-1'
|
||||||
,id: 11
|
,id: 11
|
||||||
},{
|
},{
|
||||||
title: '三级2-1-2'
|
title: 'C-2-1-2'
|
||||||
,id: 12
|
,id: 12
|
||||||
}]
|
}]
|
||||||
},{
|
},{
|
||||||
title: '二级2-2'
|
title: 'B-2-2'
|
||||||
,id: 6
|
,id: 6
|
||||||
,checked: true
|
,checked: true
|
||||||
,children: [{
|
,children: [{
|
||||||
title: '三级2-2-1'
|
title: 'C-2-2-1'
|
||||||
,id: 13
|
,id: 13
|
||||||
},{
|
},{
|
||||||
title: '三级2-2-2'
|
title: 'C-2-2-2'
|
||||||
,id: 14
|
,id: 14
|
||||||
,disabled: true
|
,disabled: true
|
||||||
}]
|
}]
|
||||||
}]
|
}]
|
||||||
},{
|
},{
|
||||||
title: '一级3'
|
title: 'A-3'
|
||||||
,id: 16
|
,id: 16
|
||||||
,children: [{
|
,children: [{
|
||||||
title: '二级3-1'
|
title: 'B-3-1'
|
||||||
,id: 17
|
,id: 17
|
||||||
,fixed: true
|
,fixed: true
|
||||||
,children: [{
|
,children: [{
|
||||||
title: '三级3-1-1'
|
title: 'C-3-1-1'
|
||||||
,id: 18
|
,id: 18
|
||||||
},{
|
},{
|
||||||
title: '三级3-1-2'
|
title: 'C-3-1-2'
|
||||||
,id: 19
|
,id: 19
|
||||||
}]
|
}]
|
||||||
},{
|
},{
|
||||||
title: '二级3-2'
|
title: 'B-3-2'
|
||||||
,id: 27
|
,id: 27
|
||||||
,children: [{
|
,children: [{
|
||||||
title: '三级3-2-1'
|
title: 'C-3-2-1'
|
||||||
,id: 28
|
,id: 28
|
||||||
},{
|
},{
|
||||||
title: '三级3-2-2'
|
title: 'C-3-2-2'
|
||||||
,id: 29
|
,id: 29
|
||||||
}]
|
}]
|
||||||
}]
|
}]
|
||||||
|
@ -222,7 +214,7 @@
|
||||||
console.log(checkedData);
|
console.log(checkedData);
|
||||||
}
|
}
|
||||||
,setChecked: function(){
|
,setChecked: function(){
|
||||||
tree.setChecked('demoId1', [1000, 1001, 1002]);
|
tree.setChecked('demoId1', [11,12]);
|
||||||
}
|
}
|
||||||
,reload: function(){
|
,reload: function(){
|
||||||
tree.reload('demoId1', {
|
tree.reload('demoId1', {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "layui",
|
"name": "layui",
|
||||||
"version": "2.8.10",
|
"version": "2.8.11",
|
||||||
"description": "Classic modular Front-End UI library",
|
"description": "Classic modular Front-End UI library",
|
||||||
"main": "dist/layui.js",
|
"main": "dist/layui.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
var Layui = function(){
|
var Layui = function(){
|
||||||
this.v = '2.8.10'; // Layui 版本号
|
this.v = '2.8.11'; // Layui 版本号
|
||||||
};
|
};
|
||||||
|
|
||||||
// 识别预先可能定义的指定全局对象
|
// 识别预先可能定义的指定全局对象
|
||||||
|
|
|
@ -6,86 +6,99 @@
|
||||||
layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var $ = layui.$
|
var $ = layui.$;
|
||||||
,laytpl = layui.laytpl
|
var laytpl = layui.laytpl;
|
||||||
,hint = layui.hint()
|
var hint = layui.hint();
|
||||||
,device = layui.device()
|
var device = layui.device();
|
||||||
,clickOrMousedown = (device.mobile ? 'touchstart' : 'mousedown')
|
var clickOrMousedown = (device.mobile ? 'touchstart' : 'mousedown');
|
||||||
|
|
||||||
//模块名
|
// 模块名
|
||||||
,MOD_NAME = 'dropdown'
|
var MOD_NAME = 'dropdown';
|
||||||
,MOD_INDEX = 'layui_'+ MOD_NAME +'_index' //模块索引名
|
var MOD_INDEX = 'layui_'+ MOD_NAME +'_index'; // 模块索引名
|
||||||
|
|
||||||
//外部接口
|
// 外部接口
|
||||||
,dropdown = {
|
var dropdown = {
|
||||||
config: {}
|
config: {},
|
||||||
,index: layui[MOD_NAME] ? (layui[MOD_NAME].index + 10000) : 0
|
index: layui[MOD_NAME] ? (layui[MOD_NAME].index + 10000) : 0,
|
||||||
|
|
||||||
//设置全局项
|
// 设置全局项
|
||||||
,set: function(options){
|
set: function(options){
|
||||||
var that = this;
|
var that = this;
|
||||||
that.config = $.extend({}, that.config, options);
|
that.config = $.extend({}, that.config, options);
|
||||||
return that;
|
return that;
|
||||||
}
|
},
|
||||||
|
|
||||||
//事件
|
// 事件
|
||||||
,on: function(events, callback){
|
on: function(events, callback){
|
||||||
return layui.onevent.call(this, MOD_NAME, events, callback);
|
return layui.onevent.call(this, MOD_NAME, events, callback);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
//操作当前实例
|
// 操作当前实例
|
||||||
,thisModule = function(){
|
var thisModule = function(){
|
||||||
var that = this;
|
var that = this;
|
||||||
var options = that.config;
|
var options = that.config;
|
||||||
var id = options.id;
|
var id = options.id;
|
||||||
|
|
||||||
thisModule.that[id] = that; //记录当前实例对象
|
thisModule.that[id] = that; // 记录当前实例对象
|
||||||
|
|
||||||
return {
|
return {
|
||||||
config: options
|
config: options,
|
||||||
//重置实例
|
// 重置实例
|
||||||
,reload: function(options){
|
reload: function(options){
|
||||||
that.reload.call(that, options);
|
that.reload.call(that, options);
|
||||||
}
|
},
|
||||||
,reloadData: function(options){
|
reloadData: function(options){
|
||||||
dropdown.reloadData(id, options);
|
dropdown.reloadData(id, options);
|
||||||
}
|
},
|
||||||
,close: function () {
|
close: function () {
|
||||||
that.remove()
|
that.remove()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
//字符常量
|
// 字符常量
|
||||||
,STR_ELEM = 'layui-dropdown', STR_HIDE = 'layui-hide', STR_DISABLED = 'layui-disabled', STR_NONE = 'layui-none'
|
var STR_ELEM = 'layui-dropdown';
|
||||||
,STR_ITEM_UP = 'layui-menu-item-up', STR_ITEM_DOWN = 'layui-menu-item-down', STR_MENU_TITLE = 'layui-menu-body-title', STR_ITEM_GROUP = 'layui-menu-item-group', STR_ITEM_PARENT = 'layui-menu-item-parent', STR_ITEM_DIV = 'layui-menu-item-divider', STR_ITEM_CHECKED = 'layui-menu-item-checked', STR_ITEM_CHECKED2 = 'layui-menu-item-checked2', STR_MENU_PANEL = 'layui-menu-body-panel', STR_MENU_PANEL_L = 'layui-menu-body-panel-left', STR_ELEM_SHADE = 'layui-dropdown-shade'
|
var STR_HIDE = 'layui-hide';
|
||||||
|
var STR_DISABLED = 'layui-disabled';
|
||||||
|
var STR_NONE = 'layui-none';
|
||||||
|
var STR_ITEM_UP = 'layui-menu-item-up';
|
||||||
|
var STR_ITEM_DOWN = 'layui-menu-item-down';
|
||||||
|
var STR_MENU_TITLE = 'layui-menu-body-title';
|
||||||
|
var STR_ITEM_GROUP = 'layui-menu-item-group';
|
||||||
|
var STR_ITEM_PARENT = 'layui-menu-item-parent';
|
||||||
|
var STR_ITEM_DIV = 'layui-menu-item-divider';
|
||||||
|
var STR_ITEM_CHECKED = 'layui-menu-item-checked';
|
||||||
|
var STR_ITEM_CHECKED2 = 'layui-menu-item-checked2';
|
||||||
|
var STR_MENU_PANEL = 'layui-menu-body-panel';
|
||||||
|
var STR_MENU_PANEL_L = 'layui-menu-body-panel-left';
|
||||||
|
var STR_ELEM_SHADE = 'layui-dropdown-shade';
|
||||||
|
|
||||||
,STR_GROUP_TITLE = '.'+ STR_ITEM_GROUP + '>.'+ STR_MENU_TITLE
|
var STR_GROUP_TITLE = '.'+ STR_ITEM_GROUP + '>.'+ STR_MENU_TITLE;
|
||||||
|
|
||||||
//构造器
|
// 构造器
|
||||||
,Class = function(options){
|
var Class = function(options){
|
||||||
var that = this;
|
var that = this;
|
||||||
that.index = ++dropdown.index;
|
that.index = ++dropdown.index;
|
||||||
that.config = $.extend({}, that.config, dropdown.config, options);
|
that.config = $.extend({}, that.config, dropdown.config, options);
|
||||||
that.init();
|
that.init();
|
||||||
};
|
};
|
||||||
|
|
||||||
//默认配置
|
// 默认配置
|
||||||
Class.prototype.config = {
|
Class.prototype.config = {
|
||||||
trigger: 'click' //事件类型
|
trigger: 'click', // 事件类型
|
||||||
,content: '' //自定义菜单内容
|
content: '', // 自定义菜单内容
|
||||||
,className: '' //自定义样式类名
|
className: '', // 自定义样式类名
|
||||||
,style: '' //设置面板 style 属性
|
style: '', // 设置面板 style 属性
|
||||||
,show: false //是否初始即显示菜单面板
|
show: false, // 是否初始即显示菜单面板
|
||||||
,isAllowSpread: true //是否允许菜单组展开收缩
|
isAllowSpread: true, // 是否允许菜单组展开收缩
|
||||||
,isSpreadItem: true //是否初始展开子菜单
|
isSpreadItem: true, // 是否初始展开子菜单
|
||||||
,data: [] //菜单数据结构
|
data: [], // 菜单数据结构
|
||||||
,delay: 300 //延迟关闭的毫秒数,若 trigger 为 hover 时才生效
|
delay: 300, // 延迟关闭的毫秒数,若 trigger 为 hover 时才生效
|
||||||
,shade: 0 // 遮罩
|
shade: 0 // 遮罩
|
||||||
};
|
};
|
||||||
|
|
||||||
//重载实例
|
// 重载实例
|
||||||
Class.prototype.reload = function(options, type){
|
Class.prototype.reload = function(options, type){
|
||||||
var that = this;
|
var that = this;
|
||||||
that.config = $.extend({}, that.config, options);
|
that.config = $.extend({}, that.config, options);
|
||||||
|
@ -240,19 +253,19 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
||||||
views.append(viewLi);
|
views.append(viewLi);
|
||||||
});
|
});
|
||||||
return views;
|
return views;
|
||||||
}
|
};
|
||||||
|
|
||||||
//主模板
|
// 主模板
|
||||||
,TPL_MAIN = ['<div class="layui-dropdown layui-border-box layui-panel layui-anim layui-anim-downbit" lay-id="' + options.id + '">'
|
var TPL_MAIN = ['<div class="layui-dropdown layui-border-box layui-panel layui-anim layui-anim-downbit" lay-id="' + options.id + '">'
|
||||||
,'</div>'].join('');
|
,'</div>'].join('');
|
||||||
|
|
||||||
//如果是右键事件,则每次触发事件时,将允许重新渲染
|
// 如果是右键事件,则每次触发事件时,将允许重新渲染
|
||||||
if(options.trigger === 'contextmenu' || lay.isTopElem(options.elem[0])) rerender = true;
|
if(options.trigger === 'contextmenu' || lay.isTopElem(options.elem[0])) rerender = true;
|
||||||
|
|
||||||
//判断是否已经打开了下拉菜单面板
|
// 判断是否已经打开了下拉菜单面板
|
||||||
if(!rerender && options.elem.data(MOD_INDEX +'_opened')) return;
|
if(!rerender && options.elem.data(MOD_INDEX +'_opened')) return;
|
||||||
|
|
||||||
//记录模板对象
|
// 记录模板对象
|
||||||
that.elemView = $('.' + STR_ELEM + '[lay-id="' + options.id + '"]');
|
that.elemView = $('.' + STR_ELEM + '[lay-id="' + options.id + '"]');
|
||||||
if (type === 'reloadData' && that.elemView.length) {
|
if (type === 'reloadData' && that.elemView.length) {
|
||||||
that.elemView.html(options.content || getDefaultView());
|
that.elemView.html(options.content || getDefaultView());
|
||||||
|
@ -260,23 +273,23 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
||||||
that.elemView = $(TPL_MAIN);
|
that.elemView = $(TPL_MAIN);
|
||||||
that.elemView.append(options.content || getDefaultView());
|
that.elemView.append(options.content || getDefaultView());
|
||||||
|
|
||||||
//初始化某些属性
|
// 初始化某些属性
|
||||||
if(options.className) that.elemView.addClass(options.className);
|
if(options.className) that.elemView.addClass(options.className);
|
||||||
if(options.style) that.elemView.attr('style', options.style);
|
if(options.style) that.elemView.attr('style', options.style);
|
||||||
|
|
||||||
//记录当前执行的实例索引
|
// 记录当前执行的实例索引
|
||||||
dropdown.thisId = options.id;
|
dropdown.thisId = options.id;
|
||||||
|
|
||||||
//插入视图
|
// 插入视图
|
||||||
that.remove(); //移除非当前绑定元素的面板
|
that.remove(); // 移除非当前绑定元素的面板
|
||||||
elemBody.append(that.elemView);
|
elemBody.append(that.elemView);
|
||||||
options.elem.data(MOD_INDEX +'_opened', true);
|
options.elem.data(MOD_INDEX +'_opened', true);
|
||||||
|
|
||||||
//遮罩
|
// 遮罩
|
||||||
var shade = options.shade ? ('<div class="'+ STR_ELEM_SHADE +'" style="'+ ('z-index:'+ (that.elemView.css('z-index')-1) +'; background-color: ' + (options.shade[1] || '#000') + '; opacity: ' + (options.shade[0] || options.shade)) +'"></div>') : '';
|
var shade = options.shade ? ('<div class="'+ STR_ELEM_SHADE +'" style="'+ ('z-index:'+ (that.elemView.css('z-index')-1) +'; background-color: ' + (options.shade[1] || '#000') + '; opacity: ' + (options.shade[0] || options.shade)) +'"></div>') : '';
|
||||||
that.elemView.before(shade);
|
that.elemView.before(shade);
|
||||||
|
|
||||||
//如果是鼠标移入事件,则鼠标移出时自动关闭
|
// 如果是鼠标移入事件,则鼠标移出时自动关闭
|
||||||
if(options.trigger === 'mouseenter'){
|
if(options.trigger === 'mouseenter'){
|
||||||
that.elemView.on('mouseenter', function(){
|
that.elemView.on('mouseenter', function(){
|
||||||
clearTimeout(thisModule.timer);
|
clearTimeout(thisModule.timer);
|
||||||
|
@ -286,17 +299,17 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//坐标定位
|
// 坐标定位
|
||||||
that.position();
|
that.position();
|
||||||
thisModule.prevElem = that.elemView; //记录当前打开的元素,以便在下次关闭
|
thisModule.prevElem = that.elemView; // 记录当前打开的元素,以便在下次关闭
|
||||||
thisModule.prevElem.data('prevElem', options.elem); //将当前绑定的元素,记录在打开元素的 data 对象中
|
thisModule.prevElem.data('prevElem', options.elem); // 将当前绑定的元素,记录在打开元素的 data 对象中
|
||||||
|
|
||||||
//阻止全局事件
|
// 阻止全局事件
|
||||||
that.elemView.find('.layui-menu').on(clickOrMousedown, function(e){
|
that.elemView.find('.layui-menu').on(clickOrMousedown, function(e){
|
||||||
layui.stope(e);
|
layui.stope(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
//触发菜单列表事件
|
// 触发菜单列表事件
|
||||||
that.elemView.find('.layui-menu li').on('click', function(e){
|
that.elemView.find('.layui-menu li').on('click', function(e){
|
||||||
var othis = $(this);
|
var othis = $(this);
|
||||||
var data = othis.data('item') || {};
|
var data = othis.data('item') || {};
|
||||||
|
@ -316,7 +329,7 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//触发菜单组展开收缩
|
// 触发菜单组展开收缩
|
||||||
that.elemView.find(STR_GROUP_TITLE).on('click', function(e){
|
that.elemView.find(STR_GROUP_TITLE).on('click', function(e){
|
||||||
var othis = $(this)
|
var othis = $(this)
|
||||||
,elemGroup = othis.parent()
|
,elemGroup = othis.parent()
|
||||||
|
@ -334,26 +347,26 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
//位置定位
|
// 位置定位
|
||||||
Class.prototype.position = function(obj){
|
Class.prototype.position = function(obj){
|
||||||
var that = this
|
var that = this;
|
||||||
,options = that.config;
|
var options = that.config;
|
||||||
|
|
||||||
lay.position(options.elem[0], that.elemView[0], {
|
lay.position(options.elem[0], that.elemView[0], {
|
||||||
position: options.position
|
position: options.position,
|
||||||
,e: that.e
|
e: that.e,
|
||||||
,clickType: options.trigger === 'contextmenu' ? 'right' : null
|
clickType: options.trigger === 'contextmenu' ? 'right' : null,
|
||||||
,align: options.align || null
|
align: options.align || null
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
//删除视图
|
// 删除视图
|
||||||
Class.prototype.remove = function(){
|
Class.prototype.remove = function(){
|
||||||
var that = this
|
var that = this;
|
||||||
,options = that.config
|
var options = that.config;
|
||||||
,elemPrev = thisModule.prevElem;
|
var elemPrev = thisModule.prevElem;
|
||||||
|
|
||||||
//若存在已打开的面板元素,则移除
|
// 若存在已打开的面板元素,则移除
|
||||||
if(elemPrev){
|
if(elemPrev){
|
||||||
elemPrev.data('prevElem') && (
|
elemPrev.data('prevElem') && (
|
||||||
elemPrev.data('prevElem').data(MOD_INDEX +'_opened', false)
|
elemPrev.data('prevElem').data(MOD_INDEX +'_opened', false)
|
||||||
|
@ -363,10 +376,10 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
||||||
lay('.' + STR_ELEM_SHADE).remove();
|
lay('.' + STR_ELEM_SHADE).remove();
|
||||||
};
|
};
|
||||||
|
|
||||||
//延迟删除视图
|
// 延迟删除视图
|
||||||
Class.prototype.delayRemove = function(){
|
Class.prototype.delayRemove = function(){
|
||||||
var that = this
|
var that = this;
|
||||||
,options = that.config;
|
var options = that.config;
|
||||||
clearTimeout(thisModule.timer);
|
clearTimeout(thisModule.timer);
|
||||||
|
|
||||||
thisModule.timer = setTimeout(function(){
|
thisModule.timer = setTimeout(function(){
|
||||||
|
@ -374,18 +387,18 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
||||||
}, options.delay);
|
}, options.delay);
|
||||||
};
|
};
|
||||||
|
|
||||||
//事件
|
// 事件
|
||||||
Class.prototype.events = function(){
|
Class.prototype.events = function(){
|
||||||
var that = this
|
var that = this;
|
||||||
,options = that.config;
|
var options = that.config;
|
||||||
|
|
||||||
//如果传入 hover,则解析为 mouseenter
|
// 若传入 hover,则解析为 mouseenter
|
||||||
if(options.trigger === 'hover') options.trigger = 'mouseenter';
|
if(options.trigger === 'hover') options.trigger = 'mouseenter';
|
||||||
|
|
||||||
//解除上一个事件
|
// 解除上一个事件
|
||||||
if(that.prevElem) that.prevElem.off(options.trigger, that.prevElemCallback);
|
if(that.prevElem) that.prevElem.off(options.trigger, that.prevElemCallback);
|
||||||
|
|
||||||
//记录被绑定的元素及回调
|
// 记录被绑定的元素及回调
|
||||||
that.prevElem = options.elem;
|
that.prevElem = options.elem;
|
||||||
that.prevElemCallback = function(e){
|
that.prevElemCallback = function(e){
|
||||||
clearTimeout(thisModule.timer);
|
clearTimeout(thisModule.timer);
|
||||||
|
@ -394,47 +407,48 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
};
|
};
|
||||||
|
|
||||||
//触发元素事件
|
// 触发元素事件
|
||||||
options.elem.on(options.trigger, that.prevElemCallback);
|
options.elem.on(options.trigger, that.prevElemCallback);
|
||||||
|
|
||||||
//如果是鼠标移入事件
|
// 如果是鼠标移入事件
|
||||||
if(options.trigger === 'mouseenter'){
|
if(options.trigger === 'mouseenter'){
|
||||||
//直行鼠标移出事件
|
// 直行鼠标移出事件
|
||||||
options.elem.on('mouseleave', function(){
|
options.elem.on('mouseleave', function(){
|
||||||
that.delayRemove();
|
that.delayRemove();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//记录所有实例
|
// 记录所有实例
|
||||||
thisModule.that = {}; //记录所有实例对象
|
thisModule.that = {}; // 记录所有实例对象
|
||||||
|
|
||||||
//获取当前实例对象
|
// 获取当前实例对象
|
||||||
thisModule.getThis = function(id){
|
thisModule.getThis = function(id){
|
||||||
var that = thisModule.that[id];
|
var that = thisModule.that[id];
|
||||||
if(!that) hint.error(id ? (MOD_NAME +' instance with ID \''+ id +'\' not found') : 'ID argument required');
|
if(!that) hint.error(id ? (MOD_NAME +' instance with ID \''+ id +'\' not found') : 'ID argument required');
|
||||||
return that;
|
return that;
|
||||||
};
|
};
|
||||||
|
|
||||||
//设置菜单组展开和收缩状态
|
// 设置菜单组展开和收缩状态
|
||||||
thisModule.spread = function(othis){
|
thisModule.spread = function(othis){
|
||||||
//菜单组展开和收缩
|
// 菜单组展开和收缩
|
||||||
var elemIcon = othis.children('.'+ STR_MENU_TITLE).find('.layui-icon');
|
var needSpread = othis.hasClass(STR_ITEM_UP);
|
||||||
if(othis.hasClass(STR_ITEM_UP)){
|
var elemIcon = othis.children('.'+ STR_MENU_TITLE).find('.layui-icon-' + (needSpread ? 'down' : 'up'));
|
||||||
|
if(needSpread){
|
||||||
othis.removeClass(STR_ITEM_UP).addClass(STR_ITEM_DOWN);
|
othis.removeClass(STR_ITEM_UP).addClass(STR_ITEM_DOWN);
|
||||||
elemIcon.removeClass('layui-icon-down').addClass('layui-icon-up');
|
elemIcon.removeClass('layui-icon-down').addClass('layui-icon-up');
|
||||||
} else {
|
} else {
|
||||||
othis.removeClass(STR_ITEM_DOWN).addClass(STR_ITEM_UP);
|
othis.removeClass(STR_ITEM_DOWN).addClass(STR_ITEM_UP);
|
||||||
elemIcon.removeClass('layui-icon-up').addClass('layui-icon-down')
|
elemIcon.removeClass('layui-icon-up').addClass('layui-icon-down');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//全局事件
|
// 全局事件
|
||||||
;!function(){
|
(function(){
|
||||||
var _WIN = $(window)
|
var _WIN = $(window);
|
||||||
,_DOC = $(document);
|
var _DOC = $(document);
|
||||||
|
|
||||||
//自适应定位
|
// 自适应定位
|
||||||
_WIN.on('resize', function(){
|
_WIN.on('resize', function(){
|
||||||
if(!dropdown.thisId) return;
|
if(!dropdown.thisId) return;
|
||||||
var that = thisModule.getThis(dropdown.thisId);
|
var that = thisModule.getThis(dropdown.thisId);
|
||||||
|
@ -455,7 +469,7 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//点击任意处关闭
|
// 点击任意处关闭
|
||||||
_DOC.on(clickOrMousedown, function(e){
|
_DOC.on(clickOrMousedown, function(e){
|
||||||
if(!dropdown.thisId) return;
|
if(!dropdown.thisId) return;
|
||||||
var that = thisModule.getThis(dropdown.thisId)
|
var that = thisModule.getThis(dropdown.thisId)
|
||||||
|
@ -463,8 +477,8 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
||||||
|
|
||||||
var options = that.config;
|
var options = that.config;
|
||||||
|
|
||||||
//如果触发的是绑定的元素,或者属于绑定元素的子元素,则不关闭
|
// 若触发的是绑定的元素,或者属于绑定元素的子元素,则不关闭
|
||||||
//满足条件:当前绑定的元素不是 body document,或者不是鼠标右键事件
|
// 满足条件:当前绑定的元素不是 body document,或者不是鼠标右键事件
|
||||||
if(!(lay.isTopElem(options.elem[0]) || options.trigger === 'contextmenu')){
|
if(!(lay.isTopElem(options.elem[0]) || options.trigger === 'contextmenu')){
|
||||||
if(
|
if(
|
||||||
e.target === options.elem[0] ||
|
e.target === options.elem[0] ||
|
||||||
|
@ -477,76 +491,76 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
||||||
that.remove();
|
that.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
//基础菜单的静态元素事件
|
// 基础菜单的静态元素事件
|
||||||
var ELEM_LI = '.layui-menu:not(.layui-dropdown-menu) li';
|
var ELEM_LI = '.layui-menu:not(.layui-dropdown-menu) li';
|
||||||
_DOC.on('click', ELEM_LI, function(e){
|
_DOC.on('click', ELEM_LI, function(e){
|
||||||
var othis = $(this)
|
var othis = $(this);
|
||||||
,parent = othis.parents('.layui-menu').eq(0)
|
var parent = othis.parents('.layui-menu').eq(0);
|
||||||
,isChild = othis.hasClass(STR_ITEM_GROUP) || othis.hasClass(STR_ITEM_PARENT)
|
var isChild = othis.hasClass(STR_ITEM_GROUP) || othis.hasClass(STR_ITEM_PARENT);
|
||||||
,filter = parent.attr('lay-filter') || parent.attr('id')
|
var filter = parent.attr('lay-filter') || parent.attr('id');
|
||||||
,options = lay.options(this);
|
var options = lay.options(this);
|
||||||
|
|
||||||
//非触发元素
|
// 非触发元素
|
||||||
if(othis.hasClass(STR_ITEM_DIV)) return;
|
if(othis.hasClass(STR_ITEM_DIV)) return;
|
||||||
|
|
||||||
//非菜单组
|
// 非菜单组
|
||||||
if(!isChild){
|
if(!isChild){
|
||||||
//选中
|
// 选中
|
||||||
parent.find('.'+ STR_ITEM_CHECKED).removeClass(STR_ITEM_CHECKED); //清除选中样式
|
parent.find('.'+ STR_ITEM_CHECKED).removeClass(STR_ITEM_CHECKED); // 清除选中样式
|
||||||
parent.find('.'+ STR_ITEM_CHECKED2).removeClass(STR_ITEM_CHECKED2); //清除父级菜单选中样式
|
parent.find('.'+ STR_ITEM_CHECKED2).removeClass(STR_ITEM_CHECKED2); // 清除父级菜单选中样式
|
||||||
othis.addClass(STR_ITEM_CHECKED); //添加选中样式
|
othis.addClass(STR_ITEM_CHECKED); //添加选中样式
|
||||||
othis.parents('.'+ STR_ITEM_PARENT).addClass(STR_ITEM_CHECKED2); //添加父级菜单选中样式
|
othis.parents('.'+ STR_ITEM_PARENT).addClass(STR_ITEM_CHECKED2); // 添加父级菜单选中样式
|
||||||
|
|
||||||
options.title = options.title || $.trim(othis.children('.'+ STR_MENU_TITLE).text());
|
options.title = options.title || $.trim(othis.children('.'+ STR_MENU_TITLE).text());
|
||||||
|
|
||||||
//触发事件
|
// 触发事件
|
||||||
layui.event.call(this, MOD_NAME, 'click('+ filter +')', options);
|
layui.event.call(this, MOD_NAME, 'click('+ filter +')', options);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//基础菜单的展开收缩事件
|
// 基础菜单的展开收缩事件
|
||||||
_DOC.on('click', (ELEM_LI + STR_GROUP_TITLE), function(e){
|
_DOC.on('click', (ELEM_LI + STR_GROUP_TITLE), function(e){
|
||||||
var othis = $(this)
|
var othis = $(this);
|
||||||
,elemGroup = othis.parents('.'+ STR_ITEM_GROUP +':eq(0)')
|
var elemGroup = othis.parents('.'+ STR_ITEM_GROUP +':eq(0)');
|
||||||
,options = lay.options(elemGroup[0]);
|
var options = lay.options(elemGroup[0]);
|
||||||
|
|
||||||
if(('isAllowSpread' in options) ? options.isAllowSpread : true){
|
if(('isAllowSpread' in options) ? options.isAllowSpread : true){
|
||||||
thisModule.spread(elemGroup);
|
thisModule.spread(elemGroup);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//判断子级菜单是否超出屏幕
|
// 判断子级菜单是否超出屏幕
|
||||||
var ELEM_LI_PAR = '.layui-menu .'+ STR_ITEM_PARENT
|
var ELEM_LI_PAR = '.layui-menu .'+ STR_ITEM_PARENT
|
||||||
_DOC.on('mouseenter', ELEM_LI_PAR, function(e){
|
_DOC.on('mouseenter', ELEM_LI_PAR, function(e){
|
||||||
var othis = $(this)
|
var othis = $(this);
|
||||||
,elemPanel = othis.find('.'+ STR_MENU_PANEL);
|
var elemPanel = othis.find('.'+ STR_MENU_PANEL);
|
||||||
|
|
||||||
if(!elemPanel[0]) return;
|
if(!elemPanel[0]) return;
|
||||||
var rect = elemPanel[0].getBoundingClientRect();
|
var rect = elemPanel[0].getBoundingClientRect();
|
||||||
|
|
||||||
//是否超出右侧屏幕
|
// 是否超出右侧屏幕
|
||||||
if(rect.right > _WIN.width()){
|
if(rect.right > _WIN.width()){
|
||||||
elemPanel.addClass(STR_MENU_PANEL_L);
|
elemPanel.addClass(STR_MENU_PANEL_L);
|
||||||
//不允许超出左侧屏幕
|
// 不允许超出左侧屏幕
|
||||||
rect = elemPanel[0].getBoundingClientRect();
|
rect = elemPanel[0].getBoundingClientRect();
|
||||||
if(rect.left < 0){
|
if(rect.left < 0){
|
||||||
elemPanel.removeClass(STR_MENU_PANEL_L);
|
elemPanel.removeClass(STR_MENU_PANEL_L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//是否超出底部屏幕
|
// 是否超出底部屏幕
|
||||||
if(rect.bottom > _WIN.height()){
|
if(rect.bottom > _WIN.height()){
|
||||||
elemPanel.eq(0).css('margin-top', -(rect.bottom - _WIN.height() + 5));
|
elemPanel.eq(0).css('margin-top', -(rect.bottom - _WIN.height() + 5));
|
||||||
}
|
}
|
||||||
}).on('mouseleave', ELEM_LI_PAR, function(e){
|
}).on('mouseleave', ELEM_LI_PAR, function(e){
|
||||||
var othis = $(this)
|
var othis = $(this)
|
||||||
,elemPanel = othis.children('.'+ STR_MENU_PANEL);
|
var elemPanel = othis.children('.'+ STR_MENU_PANEL);
|
||||||
|
|
||||||
elemPanel.removeClass(STR_MENU_PANEL_L);
|
elemPanel.removeClass(STR_MENU_PANEL_L);
|
||||||
elemPanel.css('margin-top', 0);
|
elemPanel.css('margin-top', 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
}();
|
})();
|
||||||
|
|
||||||
// 关闭面板
|
// 关闭面板
|
||||||
dropdown.close = function(id){
|
dropdown.close = function(id){
|
||||||
|
|
|
@ -46,7 +46,7 @@ layui.define(['lay', 'layer', 'util'], function(exports){
|
||||||
'请输入正确的身份证号'
|
'请输入正确的身份证号'
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
verIncludelRequired: false, // 验证规则是否包含必填 --- 为兼容旧版的验证机制
|
verIncludeRequired: false, // 验证规则是否包含必填 --- 为兼容旧版的验证机制
|
||||||
autocomplete: null // 全局 autocomplete 状态。 null 表示不干预
|
autocomplete: null // 全局 autocomplete 状态。 null 表示不干预
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -277,10 +277,11 @@ layui.define(['lay', 'layer', 'util'], function(exports){
|
||||||
value: ['up', 'down'],
|
value: ['up', 'down'],
|
||||||
split: true,
|
split: true,
|
||||||
className: 'layui-input-number',
|
className: 'layui-input-number',
|
||||||
disabled: disabled, // 跟随输入框禁用状态
|
disabled: othis.is('[disabled]'), // 跟随输入框禁用状态
|
||||||
click: function(elem){
|
click: function(elem){
|
||||||
var index = $(this).index();
|
var index = $(this).index();
|
||||||
var value = elem.val();
|
var value = elem.val();
|
||||||
|
var rawValue = value;
|
||||||
var step = Number(elem.attr('step')) || 1; // 加减的数字间隔
|
var step = Number(elem.attr('step')) || 1; // 加减的数字间隔
|
||||||
var min = Number(elem.attr('min'));
|
var min = Number(elem.attr('min'));
|
||||||
var max = Number(elem.attr('max'));
|
var max = Number(elem.attr('max'));
|
||||||
|
@ -294,11 +295,15 @@ layui.define(['lay', 'layer', 'util'], function(exports){
|
||||||
if(value < min) value = min;
|
if(value < min) value = min;
|
||||||
if(value > max) value = max;
|
if(value > max) value = max;
|
||||||
|
|
||||||
// 小数点后保留位数
|
// 获取小数点后位数
|
||||||
var fixed = function(step){
|
var decimals = function(step){
|
||||||
var decimals = (step.match(/\.(\d+$)/) || [])[1] || '';
|
var decimals = (step.toString().match(/\.(\d+$)/) || [])[1] || '';
|
||||||
return decimals.length;
|
return decimals.length;
|
||||||
}(step.toString());
|
};
|
||||||
|
|
||||||
|
// 位数比较
|
||||||
|
var fixed = Math.max(decimals(step), decimals(rawValue));
|
||||||
|
|
||||||
if(fixed) value = value.toFixed(fixed);
|
if(fixed) value = value.toFixed(fixed);
|
||||||
|
|
||||||
elem.val(value);
|
elem.val(value);
|
||||||
|
@ -386,7 +391,7 @@ layui.define(['lay', 'layer', 'util'], function(exports){
|
||||||
// 如果是第一项,且文本值等于 placeholder,则清空初始值
|
// 如果是第一项,且文本值等于 placeholder,则清空初始值
|
||||||
if(selectedIndex === 0 && initValue === input.attr('placeholder')){
|
if(selectedIndex === 0 && initValue === input.attr('placeholder')){
|
||||||
initValue = '';
|
initValue = '';
|
||||||
};
|
}
|
||||||
|
|
||||||
// 如果有选中值,则将输入框纠正为该值。否则清空输入框
|
// 如果有选中值,则将输入框纠正为该值。否则清空输入框
|
||||||
input.val(initValue || '');
|
input.val(initValue || '');
|
||||||
|
@ -576,7 +581,7 @@ layui.define(['lay', 'layer', 'util'], function(exports){
|
||||||
// 如果是第一项,且文本值等于 placeholder,则清空初始值
|
// 如果是第一项,且文本值等于 placeholder,则清空初始值
|
||||||
if(selectedIndex === 0 && initValue === input.attr('placeholder')){
|
if(selectedIndex === 0 && initValue === input.attr('placeholder')){
|
||||||
initValue = '';
|
initValue = '';
|
||||||
};
|
}
|
||||||
|
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
notOption(input.val(), function(none){
|
notOption(input.val(), function(none){
|
||||||
|
@ -807,12 +812,12 @@ layui.define(['lay', 'layer', 'util'], function(exports){
|
||||||
var next = $(this).next('.' + CLASS);
|
var next = $(this).next('.' + CLASS);
|
||||||
this.checked = false;
|
this.checked = false;
|
||||||
next.removeClass(CLASS + 'ed');
|
next.removeClass(CLASS + 'ed');
|
||||||
next.find('.layui-icon').removeClass(ANIM + ' ' + ICON[0]).addClass(ICON[1]);
|
next.children('.layui-icon').removeClass(ANIM + ' ' + ICON[0]).addClass(ICON[1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
radio[0].checked = true;
|
radio[0].checked = true;
|
||||||
reElem.addClass(CLASS + 'ed');
|
reElem.addClass(CLASS + 'ed');
|
||||||
reElem.find('.layui-icon').addClass(ANIM + ' ' + ICON[0]);
|
reElem.children('.layui-icon').addClass(ANIM + ' ' + ICON[0]);
|
||||||
|
|
||||||
layui.event.call(radio[0], MOD_NAME, 'radio('+ filter +')', {
|
layui.event.call(radio[0], MOD_NAME, 'radio('+ filter +')', {
|
||||||
elem: radio[0],
|
elem: radio[0],
|
||||||
|
@ -928,7 +933,7 @@ layui.define(['lay', 'layer', 'util'], function(exports){
|
||||||
|
|
||||||
// 匹配验证规则
|
// 匹配验证规则
|
||||||
if(rule){
|
if(rule){
|
||||||
var isTrue = typeof rule === 'function'
|
isTrue = typeof rule === 'function'
|
||||||
? errorText = rule(value, item)
|
? errorText = rule(value, item)
|
||||||
: !rule[0].test(value);
|
: !rule[0].test(value);
|
||||||
|
|
||||||
|
@ -946,7 +951,7 @@ layui.define(['lay', 'layer', 'util'], function(exports){
|
||||||
|
|
||||||
// 若为必填项或者非空命中校验,则阻止提交,弹出提示
|
// 若为必填项或者非空命中校验,则阻止提交,弹出提示
|
||||||
if(isTrue && (
|
if(isTrue && (
|
||||||
options.verIncludelRequired || (
|
options.verIncludeRequired || (
|
||||||
thisVer === 'required' || (
|
thisVer === 'required' || (
|
||||||
value && thisVer !== 'required'
|
value && thisVer !== 'required'
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,12 +6,15 @@
|
||||||
;!function(window, undefined){
|
;!function(window, undefined){
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var isLayui = window.layui && layui.define, $, win, ready = {
|
var isLayui = window.layui && layui.define;
|
||||||
|
var $;
|
||||||
|
var win;
|
||||||
|
var ready = {
|
||||||
getPath: function(){
|
getPath: function(){
|
||||||
var jsPath = document.currentScript ? document.currentScript.src : function(){
|
var jsPath = document.currentScript ? document.currentScript.src : function(){
|
||||||
var js = document.scripts
|
var js = document.scripts;
|
||||||
,last = js.length - 1
|
var last = js.length - 1;
|
||||||
,src;
|
var src;
|
||||||
for(var i = last; i > 0; i--){
|
for(var i = last; i > 0; i--){
|
||||||
if(js[i].readyState === 'interactive'){
|
if(js[i].readyState === 'interactive'){
|
||||||
src = js[i].src;
|
src = js[i].src;
|
||||||
|
@ -19,8 +22,8 @@ var isLayui = window.layui && layui.define, $, win, ready = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return src || js[last].src;
|
return src || js[last].src;
|
||||||
}()
|
}();
|
||||||
,GLOBAL = window.LAYUI_GLOBAL || {};
|
var GLOBAL = window.LAYUI_GLOBAL || {};
|
||||||
return GLOBAL.layer_dir || jsPath.substring(0, jsPath.lastIndexOf('/') + 1);
|
return GLOBAL.layer_dir || jsPath.substring(0, jsPath.lastIndexOf('/') + 1);
|
||||||
}(),
|
}(),
|
||||||
config: {
|
config: {
|
||||||
|
@ -32,29 +35,29 @@ var isLayui = window.layui && layui.define, $, win, ready = {
|
||||||
minStackArr: [],
|
minStackArr: [],
|
||||||
btn: ['确定', '取消'],
|
btn: ['确定', '取消'],
|
||||||
|
|
||||||
//五种原始层模式
|
// 五种原始层模式
|
||||||
type: ['dialog', 'page', 'iframe', 'loading', 'tips'],
|
type: ['dialog', 'page', 'iframe', 'loading', 'tips'],
|
||||||
|
|
||||||
//获取节点的style属性值
|
// 获取节点的 style 属性值
|
||||||
getStyle: function(node, name){
|
getStyle: function(node, name){
|
||||||
var style = node.currentStyle ? node.currentStyle : window.getComputedStyle(node, null);
|
var style = node.currentStyle ? node.currentStyle : window.getComputedStyle(node, null);
|
||||||
return style[style.getPropertyValue ? 'getPropertyValue' : 'getAttribute'](name);
|
return style[style.getPropertyValue ? 'getPropertyValue' : 'getAttribute'](name);
|
||||||
},
|
},
|
||||||
|
|
||||||
//载入 CSS 依赖
|
// 载入 CSS 依赖
|
||||||
link: function(href, fn, cssname){
|
link: function(href, fn, cssname){
|
||||||
//未设置路径,则不主动加载css
|
// 未设置路径,则不主动加载 css
|
||||||
if(!layer.path) return;
|
if(!layer.path) return;
|
||||||
|
|
||||||
var head = document.getElementsByTagName("head")[0]
|
var head = document.getElementsByTagName("head")[0];
|
||||||
,link = document.createElement('link');
|
var link = document.createElement('link');
|
||||||
|
|
||||||
if(typeof fn === 'string') cssname = fn;
|
if(typeof fn === 'string') cssname = fn;
|
||||||
|
|
||||||
var app = (cssname || href).replace(/\.|\//g, '');
|
var app = (cssname || href).replace(/\.|\//g, '');
|
||||||
var id = 'layuicss-'+ app
|
var id = 'layuicss-'+ app;
|
||||||
,STATUS_NAME = 'creating'
|
var STATUS_NAME = 'creating'
|
||||||
,timeout = 0;
|
var timeout = 0;
|
||||||
|
|
||||||
link.rel = 'stylesheet';
|
link.rel = 'stylesheet';
|
||||||
link.href = layer.path + href;
|
link.href = layer.path + href;
|
||||||
|
@ -66,21 +69,21 @@ var isLayui = window.layui && layui.define, $, win, ready = {
|
||||||
|
|
||||||
if(typeof fn !== 'function') return;
|
if(typeof fn !== 'function') return;
|
||||||
|
|
||||||
//轮询 css 是否加载完毕
|
// 轮询 css 是否加载完毕
|
||||||
(function poll(status) {
|
(function poll(status) {
|
||||||
var delay = 100
|
var delay = 100;
|
||||||
,getLinkElem = document.getElementById(id); //获取动态插入的 link 元素
|
var getLinkElem = document.getElementById(id); // 获取动态插入的 link 元素
|
||||||
|
|
||||||
//如果轮询超过指定秒数,则视为请求文件失败或 css 文件不符合规范
|
// 如果轮询超过指定秒数,则视为请求文件失败或 css 文件不符合规范
|
||||||
if(++timeout > 10 * 1000 / delay){
|
if(++timeout > 10 * 1000 / delay){
|
||||||
return window.console && console.error(app +'.css: Invalid');
|
return window.console && console.error(app +'.css: Invalid');
|
||||||
}
|
}
|
||||||
|
|
||||||
//css 加载就绪
|
// css 加载就绪
|
||||||
if(parseInt(ready.getStyle(getLinkElem, 'width')) === 1989){
|
if(parseInt(ready.getStyle(getLinkElem, 'width')) === 1989){
|
||||||
//如果参数来自于初始轮询(即未加载就绪时的),则移除 link 标签状态
|
// 如果参数来自于初始轮询(即未加载就绪时的),则移除 link 标签状态
|
||||||
if(status === STATUS_NAME) getLinkElem.removeAttribute('lay-status');
|
if(status === STATUS_NAME) getLinkElem.removeAttribute('lay-status');
|
||||||
//如果 link 标签的状态仍为「创建中」,则继续进入轮询,直到状态改变,则执行回调
|
// 如果 link 标签的状态仍为「创建中」,则继续进入轮询,直到状态改变,则执行回调
|
||||||
getLinkElem.getAttribute('lay-status') === STATUS_NAME ? setTimeout(poll, delay) : fn();
|
getLinkElem.getAttribute('lay-status') === STATUS_NAME ? setTimeout(poll, delay) : fn();
|
||||||
} else {
|
} else {
|
||||||
getLinkElem.setAttribute('lay-status', STATUS_NAME);
|
getLinkElem.setAttribute('lay-status', STATUS_NAME);
|
||||||
|
@ -89,19 +92,19 @@ var isLayui = window.layui && layui.define, $, win, ready = {
|
||||||
}, delay);
|
}, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
//parseInt(ready.getStyle(document.getElementById(id), 'width')) === 1989 ? fn() : setTimeout(poll, 1000);
|
// parseInt(ready.getStyle(document.getElementById(id), 'width')) === 1989 ? fn() : setTimeout(poll, 1000);
|
||||||
}());
|
}());
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//默认内置方法。
|
// 默认内置方法。
|
||||||
var layer = {
|
var layer = {
|
||||||
v: '3.6.0',
|
v: '3.7.0',
|
||||||
ie: function(){ //ie 版本
|
ie: function(){ // ie 版本
|
||||||
var agent = navigator.userAgent.toLowerCase();
|
var agent = navigator.userAgent.toLowerCase();
|
||||||
return (!!window.ActiveXObject || "ActiveXObject" in window) ? (
|
return (!!window.ActiveXObject || "ActiveXObject" in window) ? (
|
||||||
(agent.match(/msie\s(\d+)/) || [])[1] || '11' //由于 ie11 并没有 msie 的标识
|
(agent.match(/msie\s(\d+)/) || [])[1] || '11' // 由于 ie11 并没有 msie 的标识
|
||||||
) : false;
|
) : false;
|
||||||
}(),
|
}(),
|
||||||
index: (window.layer && window.layer.v) ? 100000 : 0,
|
index: (window.layer && window.layer.v) ? 100000 : 0,
|
||||||
|
@ -112,12 +115,12 @@ var layer = {
|
||||||
layer.path = ready.config.path || layer.path;
|
layer.path = ready.config.path || layer.path;
|
||||||
typeof options.extend === 'string' && (options.extend = [options.extend]);
|
typeof options.extend === 'string' && (options.extend = [options.extend]);
|
||||||
|
|
||||||
//如果设置了路径,则加载样式
|
// 如果设置了路径,则加载样式
|
||||||
if(ready.config.path) layer.ready();
|
if(ready.config.path) layer.ready();
|
||||||
|
|
||||||
if(!options.extend) return this;
|
if(!options.extend) return this;
|
||||||
|
|
||||||
//加载 css
|
// 加载 css
|
||||||
isLayui
|
isLayui
|
||||||
? layui.addcss('modules/layer/' + options.extend)
|
? layui.addcss('modules/layer/' + options.extend)
|
||||||
: ready.link('css/' + options.extend);
|
: ready.link('css/' + options.extend);
|
||||||
|
@ -140,7 +143,7 @@ var layer = {
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
//各种快捷引用
|
// 各种快捷引用
|
||||||
alert: function(content, options, yes){
|
alert: function(content, options, yes){
|
||||||
var type = typeof options === 'function';
|
var type = typeof options === 'function';
|
||||||
if(type) yes = options;
|
if(type) yes = options;
|
||||||
|
@ -164,7 +167,7 @@ var layer = {
|
||||||
}, type ? {} : options));
|
}, type ? {} : options));
|
||||||
},
|
},
|
||||||
|
|
||||||
msg: function(content, options, end){ //最常用提示层
|
msg: function(content, options, end){ // 最常用提示层
|
||||||
var type = typeof options === 'function', rskin = ready.config.skin;
|
var type = typeof options === 'function', rskin = ready.config.skin;
|
||||||
var skin = (rskin ? rskin + ' ' + rskin + '-msg' : '')||'layui-layer-msg';
|
var skin = (rskin ? rskin + ' ' + rskin + '-msg' : '')||'layui-layer-msg';
|
||||||
var anim = doms.anim.length - 1;
|
var anim = doms.anim.length - 1;
|
||||||
|
@ -222,7 +225,7 @@ var Class = function(setings){
|
||||||
that.creat();
|
that.creat();
|
||||||
};
|
};
|
||||||
that.index = ++layer.index;
|
that.index = ++layer.index;
|
||||||
that.config.maxWidth = $(win).width() - 15*2; //初始最大宽度:当前屏幕宽,左右留 15px 边距
|
that.config.maxWidth = $(win).width() - 15*2; // 初始最大宽度:当前屏幕宽,左右留 15px 边距
|
||||||
that.config = $.extend({}, that.config, ready.config, setings);
|
that.config = $.extend({}, that.config, ready.config, setings);
|
||||||
document.body ? creat() : setTimeout(function(){
|
document.body ? creat() : setTimeout(function(){
|
||||||
creat();
|
creat();
|
||||||
|
@ -231,7 +234,7 @@ var Class = function(setings){
|
||||||
|
|
||||||
Class.pt = Class.prototype;
|
Class.pt = Class.prototype;
|
||||||
|
|
||||||
//缓存常用字符
|
// 缓存常用字符
|
||||||
var doms = ['layui-layer', '.layui-layer-title', '.layui-layer-main', '.layui-layer-dialog', 'layui-layer-iframe', 'layui-layer-content', 'layui-layer-btn', 'layui-layer-close'];
|
var doms = ['layui-layer', '.layui-layer-title', '.layui-layer-main', '.layui-layer-dialog', 'layui-layer-iframe', 'layui-layer-content', 'layui-layer-btn', 'layui-layer-close'];
|
||||||
|
|
||||||
// 内置动画类
|
// 内置动画类
|
||||||
|
@ -278,7 +281,7 @@ Class.pt.config = {
|
||||||
tips: 2
|
tips: 2
|
||||||
};
|
};
|
||||||
|
|
||||||
//容器
|
// 容器
|
||||||
Class.pt.vessel = function(conType, callback){
|
Class.pt.vessel = function(conType, callback){
|
||||||
var that = this, times = that.index, config = that.config;
|
var that = this, times = that.index, config = that.config;
|
||||||
var zIndex = config.zIndex + times, titype = typeof config.title === 'object';
|
var zIndex = config.zIndex + times, titype = typeof config.title === 'object';
|
||||||
|
@ -454,7 +457,7 @@ Class.pt.creat = function(){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//建立容器
|
// 建立容器
|
||||||
that.vessel(conType, function(html, titleHTML, moveElem){
|
that.vessel(conType, function(html, titleHTML, moveElem){
|
||||||
body.append(html[0]);
|
body.append(html[0]);
|
||||||
conType ? function(){
|
conType ? function(){
|
||||||
|
@ -475,7 +478,7 @@ Class.pt.creat = function(){
|
||||||
config.scrollbar || doms.html.css('overflow', 'hidden').attr('layer-full', times);
|
config.scrollbar || doms.html.css('overflow', 'hidden').attr('layer-full', times);
|
||||||
}).auto(times);
|
}).auto(times);
|
||||||
|
|
||||||
//遮罩
|
// 遮罩
|
||||||
that.shadeo.css({
|
that.shadeo.css({
|
||||||
'background-color': config.shade[1] || '#000'
|
'background-color': config.shade[1] || '#000'
|
||||||
,'opacity': config.shade[0] || config.shade
|
,'opacity': config.shade[0] || config.shade
|
||||||
|
@ -483,10 +486,10 @@ Class.pt.creat = function(){
|
||||||
|
|
||||||
config.type == 2 && layer.ie == 6 && that.layero.find('iframe').attr('src', content[0]);
|
config.type == 2 && layer.ie == 6 && that.layero.find('iframe').attr('src', content[0]);
|
||||||
|
|
||||||
//坐标自适应浏览器窗口尺寸
|
// 坐标自适应浏览器窗口尺寸
|
||||||
config.type == 4 ? that.tips() : function(){
|
config.type == 4 ? that.tips() : function(){
|
||||||
that.offset()
|
that.offset()
|
||||||
//首次弹出时,若 css 尚未加载,则等待 css 加载完毕后,重新设定尺寸
|
// 首次弹出时,若 css 尚未加载,则等待 css 加载完毕后,重新设定尺寸
|
||||||
parseInt(ready.getStyle(document.getElementById(doms.MOVE), 'z-index')) || function(){
|
parseInt(ready.getStyle(document.getElementById(doms.MOVE), 'z-index')) || function(){
|
||||||
that.layero.css('visibility', 'hidden');
|
that.layero.css('visibility', 'hidden');
|
||||||
layer.ready(function(){
|
layer.ready(function(){
|
||||||
|
@ -534,22 +537,22 @@ Class.pt.resize = function(){
|
||||||
config.type == 4 && that.tips();
|
config.type == 4 && that.tips();
|
||||||
};
|
};
|
||||||
|
|
||||||
//自适应
|
// 自适应
|
||||||
Class.pt.auto = function(index){
|
Class.pt.auto = function(index){
|
||||||
var that = this, config = that.config, layero = $('#'+ doms[0] + index);
|
var that = this, config = that.config, layero = $('#'+ doms[0] + index);
|
||||||
|
|
||||||
if(config.area[0] === '' && config.maxWidth > 0){
|
if(config.area[0] === '' && config.maxWidth > 0){
|
||||||
//为了修复IE7下一个让人难以理解的bug
|
// 适配 ie7
|
||||||
if(layer.ie && layer.ie < 8 && config.btn){
|
if(layer.ie && layer.ie < 8 && config.btn){
|
||||||
layero.width(layero.innerWidth());
|
layero.width(layero.innerWidth());
|
||||||
}
|
}
|
||||||
layero.outerWidth() > config.maxWidth && layero.width(config.maxWidth);
|
layero.outerWidth() > config.maxWidth && layero.width(config.maxWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
var area = [layero.innerWidth(), layero.innerHeight()]
|
var area = [layero.innerWidth(), layero.innerHeight()];
|
||||||
,titHeight = layero.find(doms[1]).outerHeight() || 0
|
var titHeight = layero.find(doms[1]).outerHeight() || 0;
|
||||||
,btnHeight = layero.find('.'+doms[6]).outerHeight() || 0
|
var btnHeight = layero.find('.'+doms[6]).outerHeight() || 0;
|
||||||
,setHeight = function(elem){
|
var setHeight = function(elem){
|
||||||
elem = layero.find(elem);
|
elem = layero.find(elem);
|
||||||
elem.height(area[1] - titHeight - btnHeight - 2*(parseFloat(elem.css('padding-top'))|0));
|
elem.height(area[1] - titHeight - btnHeight - 2*(parseFloat(elem.css('padding-top'))|0));
|
||||||
};
|
};
|
||||||
|
@ -576,7 +579,7 @@ Class.pt.auto = function(index){
|
||||||
return that;
|
return that;
|
||||||
};
|
};
|
||||||
|
|
||||||
//计算坐标
|
// 计算坐标
|
||||||
Class.pt.offset = function(){
|
Class.pt.offset = function(){
|
||||||
var that = this, config = that.config, layero = that.layero;
|
var that = this, config = that.config, layero = that.layero;
|
||||||
var area = [layero.outerWidth(), layero.outerHeight()];
|
var area = [layero.outerWidth(), layero.outerHeight()];
|
||||||
|
@ -589,24 +592,24 @@ Class.pt.offset = function(){
|
||||||
that.offsetLeft = config.offset[1]||that.offsetLeft;
|
that.offsetLeft = config.offset[1]||that.offsetLeft;
|
||||||
} else if(config.offset !== 'auto'){
|
} else if(config.offset !== 'auto'){
|
||||||
|
|
||||||
if(config.offset === 't'){ //上
|
if(config.offset === 't'){ // 上
|
||||||
that.offsetTop = 0;
|
that.offsetTop = 0;
|
||||||
} else if(config.offset === 'r'){ //右
|
} else if(config.offset === 'r'){ // 右
|
||||||
that.offsetLeft = win.width() - area[0];
|
that.offsetLeft = win.width() - area[0];
|
||||||
} else if(config.offset === 'b'){ //下
|
} else if(config.offset === 'b'){ // 下
|
||||||
that.offsetTop = win.height() - area[1];
|
that.offsetTop = win.height() - area[1];
|
||||||
} else if(config.offset === 'l'){ //左
|
} else if(config.offset === 'l'){ // 左
|
||||||
that.offsetLeft = 0;
|
that.offsetLeft = 0;
|
||||||
} else if(config.offset === 'lt'){ //左上角
|
} else if(config.offset === 'lt'){ // 左上
|
||||||
that.offsetTop = 0;
|
that.offsetTop = 0;
|
||||||
that.offsetLeft = 0;
|
that.offsetLeft = 0;
|
||||||
} else if(config.offset === 'lb'){ //左下角
|
} else if(config.offset === 'lb'){ // 左下
|
||||||
that.offsetTop = win.height() - area[1];
|
that.offsetTop = win.height() - area[1];
|
||||||
that.offsetLeft = 0;
|
that.offsetLeft = 0;
|
||||||
} else if(config.offset === 'rt'){ //右上角
|
} else if(config.offset === 'rt'){ // 右上
|
||||||
that.offsetTop = 0;
|
that.offsetTop = 0;
|
||||||
that.offsetLeft = win.width() - area[0];
|
that.offsetLeft = win.width() - area[0];
|
||||||
} else if(config.offset === 'rb'){ //右下角
|
} else if(config.offset === 'rb'){ // 右下
|
||||||
that.offsetTop = win.height() - area[1];
|
that.offsetTop = win.height() - area[1];
|
||||||
that.offsetLeft = win.width() - area[0];
|
that.offsetLeft = win.width() - area[0];
|
||||||
} else {
|
} else {
|
||||||
|
@ -639,7 +642,7 @@ Class.pt.offset = function(){
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
//Tips
|
// Tips
|
||||||
Class.pt.tips = function(){
|
Class.pt.tips = function(){
|
||||||
var that = this, config = that.config, layero = that.layero;
|
var that = this, config = that.config, layero = that.layero;
|
||||||
var layArea = [layero.outerWidth(), layero.outerHeight()], follow = $(config.follow);
|
var layArea = [layero.outerWidth(), layero.outerHeight()], follow = $(config.follow);
|
||||||
|
@ -663,20 +666,20 @@ Class.pt.tips = function(){
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//辨别tips的方位
|
// 辨别 tips 的方位
|
||||||
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;
|
||||||
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();
|
||||||
goal.tipTop = goal.top + goal.height + 10;
|
goal.tipTop = goal.top + goal.height + 10;
|
||||||
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;
|
||||||
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]);
|
||||||
|
@ -704,31 +707,31 @@ Class.pt.tips = function(){
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//拖拽层
|
// 拖拽层
|
||||||
Class.pt.move = function(){
|
Class.pt.move = function(){
|
||||||
var that = this
|
var that = this;
|
||||||
,config = that.config
|
var config = that.config;
|
||||||
,_DOC = $(document)
|
var _DOC = $(document);
|
||||||
,layero = that.layero
|
var layero = that.layero;
|
||||||
,DATA_NAME = ['LAY_MOVE_DICT', 'LAY_RESIZE_DICT']
|
var DATA_NAME = ['LAY_MOVE_DICT', 'LAY_RESIZE_DICT'];
|
||||||
,moveElem = layero.find(config.move)
|
var moveElem = layero.find(config.move);
|
||||||
,resizeElem = layero.find('.layui-layer-resize');
|
var resizeElem = layero.find('.layui-layer-resize');
|
||||||
|
|
||||||
//给指定元素添加拖动光标
|
// 给指定元素添加拖动光标
|
||||||
if(config.move) moveElem.css('cursor', 'move');
|
if(config.move) moveElem.css('cursor', 'move');
|
||||||
|
|
||||||
//按下拖动元素
|
// 按下拖动元素
|
||||||
moveElem.on('mousedown', function(e){
|
moveElem.on('mousedown', function(e){
|
||||||
if (e.button) {return;} // 不是左键不处理
|
if (e.button) {return;} // 不是左键不处理
|
||||||
var othis = $(this)
|
var othis = $(this);
|
||||||
,dict = {};
|
var dict = {};
|
||||||
|
|
||||||
if(config.move){
|
if(config.move){
|
||||||
dict.layero = layero;
|
dict.layero = layero;
|
||||||
dict.config = config;
|
dict.config = config;
|
||||||
dict.offset = [
|
dict.offset = [
|
||||||
e.clientX - parseFloat(layero.css('left'))
|
e.clientX - parseFloat(layero.css('left')),
|
||||||
,e.clientY - parseFloat(layero.css('top'))
|
e.clientY - parseFloat(layero.css('top'))
|
||||||
];
|
];
|
||||||
|
|
||||||
othis.data(DATA_NAME[0], dict);
|
othis.data(DATA_NAME[0], dict);
|
||||||
|
@ -739,10 +742,10 @@ Class.pt.move = function(){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
//按下右下角拉伸
|
// 按下右下角拉伸
|
||||||
resizeElem.on('mousedown', function(e){
|
resizeElem.on('mousedown', function(e){
|
||||||
var othis = $(this)
|
var othis = $(this);
|
||||||
,dict = {};
|
var dict = {};
|
||||||
|
|
||||||
if(config.resize){
|
if(config.resize){
|
||||||
dict.layero = layero;
|
dict.layero = layero;
|
||||||
|
@ -762,52 +765,52 @@ Class.pt.move = function(){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
//拖动元素,避免多次调用实例造成事件叠加
|
// 拖动元素,避免多次调用实例造成事件叠加
|
||||||
if(ready.docEvent) return that;
|
if(ready.docEvent) return that;
|
||||||
_DOC.on('mousemove', function(e){
|
_DOC.on('mousemove', function(e){
|
||||||
//拖拽移动
|
// 拖拽移动
|
||||||
if(ready.eventMoveElem){
|
if(ready.eventMoveElem){
|
||||||
var dict = ready.eventMoveElem.data(DATA_NAME[0]) || {}
|
var dict = ready.eventMoveElem.data(DATA_NAME[0]) || {}
|
||||||
,layero = dict.layero
|
,layero = dict.layero
|
||||||
,config = dict.config;
|
,config = dict.config;
|
||||||
|
|
||||||
var X = e.clientX - dict.offset[0]
|
var X = e.clientX - dict.offset[0];
|
||||||
,Y = e.clientY - dict.offset[1]
|
var Y = e.clientY - dict.offset[1];
|
||||||
,fixed = layero.css('position') === 'fixed';
|
var fixed = layero.css('position') === 'fixed';
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
dict.stX = fixed ? 0 : win.scrollLeft();
|
dict.stX = fixed ? 0 : win.scrollLeft();
|
||||||
dict.stY = fixed ? 0 : win.scrollTop();
|
dict.stY = fixed ? 0 : win.scrollTop();
|
||||||
|
|
||||||
//控制元素不被拖出窗口外
|
// 控制元素不被拖出窗口外
|
||||||
if(!config.moveOut){
|
if(!config.moveOut){
|
||||||
var setRig = win.width() - layero.outerWidth() + dict.stX
|
var setRig = win.width() - layero.outerWidth() + dict.stX;
|
||||||
,setBot = win.height() - layero.outerHeight() + dict.stY;
|
var setBot = win.height() - layero.outerHeight() + dict.stY;
|
||||||
X < dict.stX && (X = dict.stX);
|
X < dict.stX && (X = dict.stX);
|
||||||
X > setRig && (X = setRig);
|
X > setRig && (X = setRig);
|
||||||
Y < dict.stY && (Y = dict.stY);
|
Y < dict.stY && (Y = dict.stY);
|
||||||
Y > setBot && (Y = setBot);
|
Y > setBot && (Y = setBot);
|
||||||
}
|
}
|
||||||
|
|
||||||
//拖动时跟随鼠标位置
|
// 拖动时跟随鼠标位置
|
||||||
layero.css({
|
layero.css({
|
||||||
left: X
|
left: X,
|
||||||
,top: Y
|
top: Y
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//Resize
|
// Resize
|
||||||
if(ready.eventResizeElem){
|
if(ready.eventResizeElem){
|
||||||
var dict = ready.eventResizeElem.data(DATA_NAME[1]) || {}
|
var dict = ready.eventResizeElem.data(DATA_NAME[1]) || {};
|
||||||
,config = dict.config;
|
var config = dict.config;
|
||||||
|
|
||||||
var X = e.clientX - dict.offset[0]
|
var X = e.clientX - dict.offset[0];
|
||||||
,Y = e.clientY - dict.offset[1];
|
var Y = e.clientY - dict.offset[1];
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
//拉伸宽高
|
// 拉伸宽高
|
||||||
layer.style(dict.index, {
|
layer.style(dict.index, {
|
||||||
width: dict.area[0] + X
|
width: dict.area[0] + X
|
||||||
,height: dict.area[1] + Y
|
,height: dict.area[1] + Y
|
||||||
|
@ -817,8 +820,8 @@ Class.pt.move = function(){
|
||||||
}
|
}
|
||||||
}).on('mouseup', function(e){
|
}).on('mouseup', function(e){
|
||||||
if(ready.eventMoveElem){
|
if(ready.eventMoveElem){
|
||||||
var dict = ready.eventMoveElem.data(DATA_NAME[0]) || {}
|
var dict = ready.eventMoveElem.data(DATA_NAME[0]) || {};
|
||||||
,config = dict.config;
|
var config = dict.config;
|
||||||
|
|
||||||
ready.eventMoveElem.removeData(DATA_NAME[0]);
|
ready.eventMoveElem.removeData(DATA_NAME[0]);
|
||||||
delete ready.eventMoveElem;
|
delete ready.eventMoveElem;
|
||||||
|
@ -832,7 +835,7 @@ Class.pt.move = function(){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ready.docEvent = true; //已给 document 执行全局事件
|
ready.docEvent = true; // 已给 document 执行全局事件
|
||||||
return that;
|
return that;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -850,7 +853,7 @@ Class.pt.callback = function(){
|
||||||
}
|
}
|
||||||
layer.ie == 6 && that.IE6(layero);
|
layer.ie == 6 && that.IE6(layero);
|
||||||
|
|
||||||
//按钮
|
// 按钮
|
||||||
layero.find('.'+ doms[6]).children('a').on('click', function(){
|
layero.find('.'+ doms[6]).children('a').on('click', function(){
|
||||||
var index = $(this).index();
|
var index = $(this).index();
|
||||||
if(index === 0){
|
if(index === 0){
|
||||||
|
@ -867,29 +870,29 @@ Class.pt.callback = function(){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//取消
|
// 取消
|
||||||
function cancel(){
|
function cancel(){
|
||||||
var close = config.cancel && config.cancel(that.index, layero, that);
|
var close = config.cancel && config.cancel(that.index, layero, that);
|
||||||
close === false || layer.close(that.index);
|
close === false || layer.close(that.index);
|
||||||
}
|
}
|
||||||
|
|
||||||
//右上角关闭回调
|
// 右上角关闭回调
|
||||||
layero.find('.'+ doms[7]).on('click', cancel);
|
layero.find('.'+ doms[7]).on('click', cancel);
|
||||||
|
|
||||||
//点遮罩关闭
|
// 点遮罩关闭
|
||||||
if(config.shadeClose){
|
if(config.shadeClose){
|
||||||
that.shadeo.on('click', function(){
|
that.shadeo.on('click', function(){
|
||||||
layer.close(that.index);
|
layer.close(that.index);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//最小化
|
// 最小化
|
||||||
layero.find('.layui-layer-min').on('click', function(){
|
layero.find('.layui-layer-min').on('click', function(){
|
||||||
var min = config.min && config.min(layero, that.index, that);
|
var min = config.min && config.min(layero, that.index, that);
|
||||||
min === false || layer.min(that.index, config);
|
min === false || layer.min(that.index, config);
|
||||||
});
|
});
|
||||||
|
|
||||||
//全屏/还原
|
// 全屏/还原
|
||||||
layero.find('.layui-layer-max').on('click', function(){
|
layero.find('.layui-layer-max').on('click', function(){
|
||||||
if($(this).hasClass('layui-layer-maxmin')){
|
if($(this).hasClass('layui-layer-maxmin')){
|
||||||
layer.restore(that.index);
|
layer.restore(that.index);
|
||||||
|
@ -905,7 +908,7 @@ Class.pt.callback = function(){
|
||||||
config.end && (ready.end[that.index] = config.end);
|
config.end && (ready.end[that.index] = config.end);
|
||||||
};
|
};
|
||||||
|
|
||||||
//for ie6 恢复select
|
// for ie6 恢复 select
|
||||||
ready.reselect = function(){
|
ready.reselect = function(){
|
||||||
$.each($('select'), function(index , value){
|
$.each($('select'), function(index , value){
|
||||||
var sthis = $(this);
|
var sthis = $(this);
|
||||||
|
@ -917,7 +920,7 @@ ready.reselect = function(){
|
||||||
};
|
};
|
||||||
|
|
||||||
Class.pt.IE6 = function(layero){
|
Class.pt.IE6 = function(layero){
|
||||||
//隐藏select
|
// 隐藏select
|
||||||
$('select').each(function(index , value){
|
$('select').each(function(index , value){
|
||||||
var sthis = $(this);
|
var sthis = $(this);
|
||||||
if(!sthis.parents('.'+doms[0])[0]){
|
if(!sthis.parents('.'+doms[0])[0]){
|
||||||
|
@ -927,11 +930,11 @@ Class.pt.IE6 = function(layero){
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
//需依赖原型的对外方法
|
// 需依赖原型的对外方法
|
||||||
Class.pt.openLayer = function(){
|
Class.pt.openLayer = function(){
|
||||||
var that = this;
|
var that = this;
|
||||||
|
|
||||||
//置顶当前窗口
|
// 置顶当前窗口
|
||||||
layer.zIndex = that.config.zIndex;
|
layer.zIndex = that.config.zIndex;
|
||||||
layer.setTop = function(layero){
|
layer.setTop = function(layero){
|
||||||
var setZindex = function(){
|
var setZindex = function(){
|
||||||
|
@ -972,18 +975,18 @@ ready.rescollbar = function(index){
|
||||||
|
|
||||||
window.layer = layer;
|
window.layer = layer;
|
||||||
|
|
||||||
//获取子iframe的DOM
|
// 获取子 iframe 的 DOM
|
||||||
layer.getChildFrame = function(selector, index){
|
layer.getChildFrame = function(selector, index){
|
||||||
index = index || $('.'+doms[4]).attr('times');
|
index = index || $('.'+doms[4]).attr('times');
|
||||||
return $('#'+ doms[0] + index).find('iframe').contents().find(selector);
|
return $('#'+ doms[0] + index).find('iframe').contents().find(selector);
|
||||||
};
|
};
|
||||||
|
|
||||||
//得到当前iframe层的索引,子iframe时使用
|
// 得到当前 iframe 层的索引,子 iframe 时使用
|
||||||
layer.getFrameIndex = function(name){
|
layer.getFrameIndex = function(name){
|
||||||
return $('#'+ name).parents('.'+doms[4]).attr('times');
|
return $('#'+ name).parents('.'+doms[4]).attr('times');
|
||||||
};
|
};
|
||||||
|
|
||||||
//iframe层自适应宽高
|
// iframe 层自适应宽高
|
||||||
layer.iframeAuto = function(index){
|
layer.iframeAuto = function(index){
|
||||||
if(!index) return;
|
if(!index) return;
|
||||||
var heg = layer.getChildFrame('html', index).outerHeight();
|
var heg = layer.getChildFrame('html', index).outerHeight();
|
||||||
|
@ -994,7 +997,7 @@ layer.iframeAuto = function(index){
|
||||||
layero.find('iframe').css({height: heg});
|
layero.find('iframe').css({height: heg});
|
||||||
};
|
};
|
||||||
|
|
||||||
//重置iframe url
|
// 重置 iframe url
|
||||||
layer.iframeSrc = function(index, url){
|
layer.iframeSrc = function(index, url){
|
||||||
$('#'+ doms[0] + index).find('iframe').attr('src', url);
|
$('#'+ doms[0] + index).find('iframe').attr('src', url);
|
||||||
};
|
};
|
||||||
|
@ -1156,13 +1159,13 @@ layer.full = function(index){
|
||||||
}, 100);
|
}, 100);
|
||||||
};
|
};
|
||||||
|
|
||||||
//改变title
|
// 改变 title
|
||||||
layer.title = function(name, index){
|
layer.title = function(name, index){
|
||||||
var title = $('#'+ doms[0] + (index || layer.index)).find(doms[1]);
|
var title = $('#'+ doms[0] + (index || layer.index)).find(doms[1]);
|
||||||
title.html(name);
|
title.html(name);
|
||||||
};
|
};
|
||||||
|
|
||||||
//关闭 layer 总方法
|
// 关闭 layer 总方法
|
||||||
layer.close = function(index, callback){
|
layer.close = function(index, callback){
|
||||||
var layero = function(){
|
var layero = function(){
|
||||||
var closest = $('.'+ doms[0]).find('#'+ index).closest('.'+ doms[0]);
|
var closest = $('.'+ doms[0]).find('#'+ index).closest('.'+ doms[0]);
|
||||||
|
@ -1257,7 +1260,7 @@ layer.close = function(index, callback){
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//关闭所有层
|
// 关闭所有层
|
||||||
layer.closeAll = function(type, callback){
|
layer.closeAll = function(type, callback){
|
||||||
if(typeof type === 'function'){
|
if(typeof type === 'function'){
|
||||||
callback = type;
|
callback = type;
|
||||||
|
@ -1279,17 +1282,18 @@ layer.closeLast = function(type){
|
||||||
layer.close($('.layui-layer-'+ type +':last').attr("times"));
|
layer.close($('.layui-layer-'+ type +':last').attr("times"));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
|
|
||||||
拓展模块,layui 开始合并在一起
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 拓展模块,layui 开始合并在一起
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var cache = layer.cache||{}, skin = function(type){
|
|
||||||
|
var cache = layer.cache || {};
|
||||||
|
var skin = function(type){
|
||||||
return (cache.skin ? (' ' + cache.skin + ' ' + cache.skin + '-'+type) : '');
|
return (cache.skin ? (' ' + cache.skin + ' ' + cache.skin + '-'+type) : '');
|
||||||
};
|
};
|
||||||
|
|
||||||
//仿系统prompt
|
// 仿系统 prompt
|
||||||
layer.prompt = function(options, yes){
|
layer.prompt = function(options, yes){
|
||||||
var style = '', placeholder = '';
|
var style = '', placeholder = '';
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
@ -1312,18 +1316,18 @@ layer.prompt = function(options, yes){
|
||||||
delete options.success;
|
delete options.success;
|
||||||
|
|
||||||
return layer.open($.extend({
|
return layer.open($.extend({
|
||||||
type: 1
|
type: 1,
|
||||||
,btn: ['确定','取消']
|
btn: ['确定','取消'],
|
||||||
,content: content
|
content: content,
|
||||||
,skin: 'layui-layer-prompt' + skin('prompt')
|
skin: 'layui-layer-prompt' + skin('prompt'),
|
||||||
,maxWidth: win.width()
|
maxWidth: win.width(),
|
||||||
,success: function(layero){
|
success: function(layero){
|
||||||
prompt = layero.find('.layui-layer-input');
|
prompt = layero.find('.layui-layer-input');
|
||||||
prompt.val(options.value || '').focus();
|
prompt.val(options.value || '').focus();
|
||||||
typeof success === 'function' && success(layero);
|
typeof success === 'function' && success(layero);
|
||||||
}
|
},
|
||||||
,resize: false
|
resize: false,
|
||||||
,yes: function(index){
|
yes: function(index){
|
||||||
var value = prompt.val();
|
var value = prompt.val();
|
||||||
if(value.length > (options.maxlength||500)) {
|
if(value.length > (options.maxlength||500)) {
|
||||||
layer.tips('最多输入'+ (options.maxlength || 500) +'个字数', prompt, {tips: 1});
|
layer.tips('最多输入'+ (options.maxlength || 500) +'个字数', prompt, {tips: 1});
|
||||||
|
@ -1334,7 +1338,7 @@ layer.prompt = function(options, yes){
|
||||||
}, options));
|
}, options));
|
||||||
};
|
};
|
||||||
|
|
||||||
//tab层
|
// tab 层
|
||||||
layer.tab = function(options){
|
layer.tab = function(options){
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
|
@ -1383,17 +1387,17 @@ layer.tab = function(options){
|
||||||
}, options));
|
}, options));
|
||||||
};
|
};
|
||||||
|
|
||||||
//相册层
|
// 相册层
|
||||||
layer.photos = function(options, loop, key){
|
layer.photos = function(options, loop, key){
|
||||||
var dict = {};
|
var dict = {};
|
||||||
options = options || {};
|
options = options || {};
|
||||||
if(!options.photos) return;
|
if(!options.photos) return;
|
||||||
|
|
||||||
//若 photos 并非选择器或 jQuery 对象,则为普通 object
|
// 若 photos 并非选择器或 jQuery 对象,则为普通 object
|
||||||
var isObject = !(typeof options.photos === 'string' || options.photos instanceof $)
|
var isObject = !(typeof options.photos === 'string' || options.photos instanceof $);
|
||||||
,photos = isObject ? options.photos : {}
|
var photos = isObject ? options.photos : {};
|
||||||
,data = photos.data || []
|
var data = photos.data || [];
|
||||||
,start = photos.start || 0;
|
var start = photos.start || 0;
|
||||||
|
|
||||||
dict.imgIndex = (start|0) + 1;
|
dict.imgIndex = (start|0) + 1;
|
||||||
options.img = options.img || 'img';
|
options.img = options.img || 'img';
|
||||||
|
@ -1401,8 +1405,8 @@ layer.photos = function(options, loop, key){
|
||||||
var success = options.success;
|
var success = options.success;
|
||||||
delete options.success;
|
delete options.success;
|
||||||
|
|
||||||
//如果 options.photos 不是一个对象
|
// 若 options.photos 不是一个对象
|
||||||
if(!isObject){ //页面直接获取
|
if(!isObject){ // 页面直接获取
|
||||||
var parent = $(options.photos), pushData = function(){
|
var parent = $(options.photos), pushData = function(){
|
||||||
data = [];
|
data = [];
|
||||||
parent.find(options.img).each(function(index){
|
parent.find(options.img).each(function(index){
|
||||||
|
@ -1434,14 +1438,14 @@ layer.photos = function(options, loop, key){
|
||||||
}), true);
|
}), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
//不直接弹出
|
// 不直接弹出
|
||||||
if(!loop) return;
|
if(!loop) return;
|
||||||
|
|
||||||
} else if (data.length === 0){
|
} else if (data.length === 0){
|
||||||
return layer.msg('没有图片');
|
return layer.msg('没有图片');
|
||||||
}
|
}
|
||||||
|
|
||||||
//上一张
|
// 上一张
|
||||||
dict.imgprev = function(key){
|
dict.imgprev = function(key){
|
||||||
dict.imgIndex--;
|
dict.imgIndex--;
|
||||||
if(dict.imgIndex < 1){
|
if(dict.imgIndex < 1){
|
||||||
|
@ -1450,7 +1454,7 @@ layer.photos = function(options, loop, key){
|
||||||
dict.tabimg(key);
|
dict.tabimg(key);
|
||||||
};
|
};
|
||||||
|
|
||||||
//下一张
|
// 下一张
|
||||||
dict.imgnext = function(key,errorMsg){
|
dict.imgnext = function(key,errorMsg){
|
||||||
dict.imgIndex++;
|
dict.imgIndex++;
|
||||||
if(dict.imgIndex > data.length){
|
if(dict.imgIndex > data.length){
|
||||||
|
@ -1460,7 +1464,7 @@ layer.photos = function(options, loop, key){
|
||||||
dict.tabimg(key)
|
dict.tabimg(key)
|
||||||
};
|
};
|
||||||
|
|
||||||
//方向键
|
// 方向键
|
||||||
dict.keyup = function(event){
|
dict.keyup = function(event){
|
||||||
if(!dict.end){
|
if(!dict.end){
|
||||||
var code = event.keyCode;
|
var code = event.keyCode;
|
||||||
|
@ -1475,7 +1479,7 @@ layer.photos = function(options, loop, key){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//切换
|
// 切换
|
||||||
dict.tabimg = function(key){
|
dict.tabimg = function(key){
|
||||||
if(data.length <= 1) return;
|
if(data.length <= 1) return;
|
||||||
photos.start = dict.imgIndex - 1;
|
photos.start = dict.imgIndex - 1;
|
||||||
|
@ -1483,7 +1487,7 @@ layer.photos = function(options, loop, key){
|
||||||
return layer.photos(options, true, key);
|
return layer.photos(options, true, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
//一些动作
|
// 一些动作
|
||||||
dict.event = function(){
|
dict.event = function(){
|
||||||
/*
|
/*
|
||||||
dict.bigimg.hover(function(){
|
dict.bigimg.hover(function(){
|
||||||
|
@ -1506,7 +1510,7 @@ layer.photos = function(options, loop, key){
|
||||||
$(document).on('keyup', dict.keyup);
|
$(document).on('keyup', dict.keyup);
|
||||||
};
|
};
|
||||||
|
|
||||||
//图片预加载
|
// 图片预加载
|
||||||
function loadImage(url, callback, error) {
|
function loadImage(url, callback, error) {
|
||||||
var img = new Image();
|
var img = new Image();
|
||||||
img.src = url;
|
img.src = url;
|
||||||
|
@ -1533,10 +1537,10 @@ layer.photos = function(options, loop, key){
|
||||||
|
|
||||||
var alt = data[start].alt || '';
|
var alt = data[start].alt || '';
|
||||||
|
|
||||||
//切换图片时不出现动画
|
// 切换图片时不出现动画
|
||||||
if(key) options.anim = -1;
|
if(key) options.anim = -1;
|
||||||
|
|
||||||
//弹出图片层
|
// 弹出图片层
|
||||||
dict.index = layer.open($.extend({
|
dict.index = layer.open($.extend({
|
||||||
type: 1,
|
type: 1,
|
||||||
id: 'layui-layer-photos',
|
id: 'layui-layer-photos',
|
||||||
|
@ -1544,10 +1548,10 @@ layer.photos = function(options, loop, key){
|
||||||
var imgarea = [img.width, img.height];
|
var imgarea = [img.width, img.height];
|
||||||
var winarea = [$(window).width() - 100, $(window).height() - 100];
|
var winarea = [$(window).width() - 100, $(window).height() - 100];
|
||||||
|
|
||||||
//如果 实际图片的宽或者高比 屏幕大(那么进行缩放)
|
// 若实际图片的宽或者高比 屏幕大(那么进行缩放)
|
||||||
if(!options.full && (imgarea[0]>winarea[0]||imgarea[1]>winarea[1])){
|
if(!options.full && (imgarea[0]>winarea[0]||imgarea[1]>winarea[1])){
|
||||||
var wh = [imgarea[0]/winarea[0],imgarea[1]/winarea[1]];//取宽度缩放比例、高度缩放比例
|
var wh = [imgarea[0]/winarea[0],imgarea[1]/winarea[1]];// 取宽度缩放比例、高度缩放比例
|
||||||
if(wh[0] > wh[1]){//取缩放比例最大的进行缩放
|
if(wh[0] > wh[1]){// 取缩放比例最大的进行缩放
|
||||||
imgarea[0] = imgarea[0]/wh[0];
|
imgarea[0] = imgarea[0]/wh[0];
|
||||||
imgarea[1] = imgarea[1]/wh[0];
|
imgarea[1] = imgarea[1]/wh[0];
|
||||||
} else if(wh[0] < wh[1]){
|
} else if(wh[0] < wh[1]){
|
||||||
|
@ -1620,7 +1624,7 @@ layer.photos = function(options, loop, key){
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
//主入口
|
// 主入口
|
||||||
ready.run = function(_$){
|
ready.run = function(_$){
|
||||||
$ = _$;
|
$ = _$;
|
||||||
win = $(window);
|
win = $(window);
|
||||||
|
@ -1631,22 +1635,22 @@ ready.run = function(_$){
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
//加载方式
|
// 加载方式
|
||||||
window.layui && layui.define ? (
|
window.layui && layui.define ? (
|
||||||
layer.ready()
|
layer.ready(),
|
||||||
,layui.define('jquery', function(exports){ //layui 加载
|
layui.define('jquery', function(exports){ // layui
|
||||||
layer.path = layui.cache.dir;
|
layer.path = layui.cache.dir;
|
||||||
ready.run(layui.$);
|
ready.run(layui.$);
|
||||||
|
|
||||||
//暴露模块
|
// export api
|
||||||
window.layer = layer;
|
window.layer = layer;
|
||||||
exports('layer', layer);
|
exports('layer', layer);
|
||||||
})
|
})
|
||||||
) : (
|
) : (
|
||||||
(typeof define === 'function' && define.amd) ? define(['jquery'], function(){ //requirejs 加载
|
(typeof define === 'function' && define.amd) ? define(['jquery'], function(){ // requirejs
|
||||||
ready.run(window.jQuery);
|
ready.run(window.jQuery);
|
||||||
return layer;
|
return layer;
|
||||||
}) : function(){ //普通 script 标签加载
|
}) : function(){ // 普通 script 标签引入
|
||||||
layer.ready();
|
layer.ready();
|
||||||
ready.run(window.jQuery);
|
ready.run(window.jQuery);
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -552,18 +552,18 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//初始工具栏
|
// 初始工具栏
|
||||||
Class.prototype.renderToolbar = function(){
|
Class.prototype.renderToolbar = function(){
|
||||||
var that = this
|
var that = this
|
||||||
,options = that.config
|
var options = that.config
|
||||||
|
|
||||||
//添加工具栏左侧模板
|
// 添加工具栏左侧模板
|
||||||
var leftDefaultTemp = [
|
var leftDefaultTemp = [
|
||||||
'<div class="layui-inline" lay-event="add"><i class="layui-icon layui-icon-add-1"></i></div>'
|
'<div class="layui-inline" lay-event="add"><i class="layui-icon layui-icon-add-1"></i></div>',
|
||||||
,'<div class="layui-inline" lay-event="update"><i class="layui-icon layui-icon-edit"></i></div>'
|
'<div class="layui-inline" lay-event="update"><i class="layui-icon layui-icon-edit"></i></div>',
|
||||||
,'<div class="layui-inline" lay-event="delete"><i class="layui-icon layui-icon-delete"></i></div>'
|
'<div class="layui-inline" lay-event="delete"><i class="layui-icon layui-icon-delete"></i></div>'
|
||||||
].join('')
|
].join('');
|
||||||
,elemToolTemp = that.layTool.find('.layui-table-tool-temp');
|
var elemToolTemp = that.layTool.find('.layui-table-tool-temp');
|
||||||
|
|
||||||
if(options.toolbar === 'default'){
|
if(options.toolbar === 'default'){
|
||||||
elemToolTemp.html(leftDefaultTemp);
|
elemToolTemp.html(leftDefaultTemp);
|
||||||
|
@ -574,22 +574,22 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//添加工具栏右侧面板
|
// 添加工具栏右侧面板
|
||||||
var layout = {
|
var layout = {
|
||||||
filter: {
|
filter: {
|
||||||
title: '筛选列'
|
title: '筛选列',
|
||||||
,layEvent: 'LAYTABLE_COLS'
|
layEvent: 'LAYTABLE_COLS',
|
||||||
,icon: 'layui-icon-cols'
|
icon: 'layui-icon-cols'
|
||||||
}
|
},
|
||||||
,exports: {
|
exports: {
|
||||||
title: '导出'
|
title: '导出',
|
||||||
,layEvent: 'LAYTABLE_EXPORT'
|
layEvent: 'LAYTABLE_EXPORT',
|
||||||
,icon: 'layui-icon-export'
|
icon: 'layui-icon-export'
|
||||||
}
|
},
|
||||||
,print: {
|
print: {
|
||||||
title: '打印'
|
title: '打印',
|
||||||
,layEvent: 'LAYTABLE_PRINT'
|
layEvent: 'LAYTABLE_PRINT',
|
||||||
,icon: 'layui-icon-print'
|
icon: 'layui-icon-print'
|
||||||
}
|
}
|
||||||
}, iconElem = [];
|
}, iconElem = [];
|
||||||
|
|
||||||
|
@ -608,12 +608,12 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
||||||
|
|
||||||
// 分页栏
|
// 分页栏
|
||||||
Class.prototype.renderPagebar = function(){
|
Class.prototype.renderPagebar = function(){
|
||||||
var that = this
|
var that = this;
|
||||||
,options = that.config
|
var options = that.config;
|
||||||
|
|
||||||
,layPagebar = that.layPagebar = $('<div class="layui-inline layui-table-pagebar"></div>')
|
var layPagebar = that.layPagebar = $('<div class="layui-inline layui-table-pagebar"></div>');
|
||||||
|
|
||||||
//开启分页栏自定义模板
|
// 开启分页栏自定义模板
|
||||||
if(options.pagebar){
|
if(options.pagebar){
|
||||||
var pagebarHtml = $(options.pagebar).html() || '';
|
var pagebarHtml = $(options.pagebar).html() || '';
|
||||||
pagebarHtml && layPagebar.append(laytpl(pagebarHtml).render(options));
|
pagebarHtml && layPagebar.append(laytpl(pagebarHtml).render(options));
|
||||||
|
@ -621,17 +621,17 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//同步表头父列的相关值
|
// 同步表头父列的相关值
|
||||||
Class.prototype.setParentCol = function(hide, parentKey){
|
Class.prototype.setParentCol = function(hide, parentKey){
|
||||||
var that = this
|
var that = this;
|
||||||
,options = that.config
|
var options = that.config;
|
||||||
|
|
||||||
,parentTh = that.layHeader.find('th[data-key="'+ parentKey +'"]') //获取父列元素
|
var parentTh = that.layHeader.find('th[data-key="'+ parentKey +'"]'); // 获取父列元素
|
||||||
,parentColspan = parseInt(parentTh.attr('colspan')) || 0;
|
var parentColspan = parseInt(parentTh.attr('colspan')) || 0;
|
||||||
|
|
||||||
if(parentTh[0]){
|
if(parentTh[0]){
|
||||||
var arrParentKey = parentKey.split('-')
|
var arrParentKey = parentKey.split('-');
|
||||||
,getThisCol = options.cols[arrParentKey[1]][arrParentKey[2]];
|
var getThisCol = options.cols[arrParentKey[1]][arrParentKey[2]];
|
||||||
|
|
||||||
hide ? parentColspan-- : parentColspan++;
|
hide ? parentColspan-- : parentColspan++;
|
||||||
|
|
||||||
|
@ -641,7 +641,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
||||||
getThisCol.colspan2 = parentColspan; // 更新实际的 colspan 数
|
getThisCol.colspan2 = parentColspan; // 更新实际的 colspan 数
|
||||||
getThisCol.hide = parentColspan < 1; // 同步 hide 参数
|
getThisCol.hide = parentColspan < 1; // 同步 hide 参数
|
||||||
|
|
||||||
//递归,继续往上查询是否有父列
|
// 递归,继续往上查询是否有父列
|
||||||
var nextParentKey = parentTh.data('parentkey');
|
var nextParentKey = parentTh.data('parentkey');
|
||||||
nextParentKey && that.setParentCol(hide, nextParentKey);
|
nextParentKey && that.setParentCol(hide, nextParentKey);
|
||||||
}
|
}
|
||||||
|
@ -855,9 +855,9 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
||||||
// 重置表格尺寸/结构
|
// 重置表格尺寸/结构
|
||||||
Class.prototype.resize = function(){
|
Class.prototype.resize = function(){
|
||||||
var that = this;
|
var that = this;
|
||||||
that.fullSize(); //让表格铺满
|
that.fullSize(); // 让表格铺满
|
||||||
that.setColsWidth(); //自适应列宽
|
that.setColsWidth(); // 自适应列宽
|
||||||
that.scrollPatch(); //滚动条补丁
|
that.scrollPatch(); // 滚动条补丁
|
||||||
};
|
};
|
||||||
|
|
||||||
// 表格重载
|
// 表格重载
|
||||||
|
@ -1749,7 +1749,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
||||||
return width;
|
return width;
|
||||||
};
|
};
|
||||||
|
|
||||||
//滚动条补丁
|
// 滚动条补丁
|
||||||
Class.prototype.scrollPatch = function(){
|
Class.prototype.scrollPatch = function(){
|
||||||
var that = this;
|
var that = this;
|
||||||
var layMainTable = that.layMain.children('table');
|
var layMainTable = that.layMain.children('table');
|
||||||
|
@ -1784,7 +1784,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
||||||
that.layFixed.find(ELEM_BODY).css(
|
that.layFixed.find(ELEM_BODY).css(
|
||||||
'height',
|
'height',
|
||||||
layMainTable.height() >= fixHeight ? fixHeight : 'auto'
|
layMainTable.height() >= fixHeight ? fixHeight : 'auto'
|
||||||
);
|
).scrollTop(that.layMain.scrollTop()); // 固定列滚动条高度
|
||||||
|
|
||||||
// 表格宽度小于容器宽度时,隐藏固定列
|
// 表格宽度小于容器宽度时,隐藏固定列
|
||||||
that.layFixRight[
|
that.layFixRight[
|
||||||
|
@ -2482,11 +2482,11 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
||||||
layui.stope(e);
|
layui.stope(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
//同步滚动条
|
// 同步滚动条
|
||||||
that.layMain.on('scroll', function(){
|
that.layMain.on('scroll', function(){
|
||||||
var othis = $(this)
|
var othis = $(this);
|
||||||
,scrollLeft = othis.scrollLeft()
|
var scrollLeft = othis.scrollLeft();
|
||||||
,scrollTop = othis.scrollTop();
|
var scrollTop = othis.scrollTop();
|
||||||
|
|
||||||
that.layHeader.scrollLeft(scrollLeft);
|
that.layHeader.scrollLeft(scrollLeft);
|
||||||
that.layTotal.scrollLeft(scrollLeft);
|
that.layTotal.scrollLeft(scrollLeft);
|
||||||
|
@ -2495,7 +2495,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
||||||
layer.close(that.tipsIndex);
|
layer.close(that.tipsIndex);
|
||||||
});
|
});
|
||||||
|
|
||||||
//自适应
|
// 适应
|
||||||
_WIN.on('resize', function(){
|
_WIN.on('resize', function(){
|
||||||
that.resize();
|
that.resize();
|
||||||
});
|
});
|
||||||
|
@ -2796,7 +2796,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
||||||
|
|
||||||
// 表合计
|
// 表合计
|
||||||
thatTable && layui.each(thatTable.dataTotal, function(i, o){
|
thatTable && layui.each(thatTable.dataTotal, function(i, o){
|
||||||
fieldsIsHide[o.field] || dataTotal.push(o.total);
|
fieldsIsHide[o.field] || dataTotal.push('"' + (o.total || '') + '"');
|
||||||
});
|
});
|
||||||
|
|
||||||
return dataTitle.join(',') + '\r\n' + dataMain.join('\r\n') + '\r\n' + dataTotal.join(',');
|
return dataTitle.join(',') + '\r\n' + dataMain.join('\r\n') + '\r\n' + dataTotal.join(',');
|
||||||
|
|
|
@ -5,95 +5,108 @@
|
||||||
layui.define('form', function(exports){
|
layui.define('form', function(exports){
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var $ = layui.$
|
var $ = layui.$;
|
||||||
,form = layui.form
|
var form = layui.form;
|
||||||
,layer = layui.layer
|
var layer = layui.layer;
|
||||||
|
|
||||||
//模块名
|
// 模块名
|
||||||
,MOD_NAME = 'tree'
|
var MOD_NAME = 'tree';
|
||||||
|
|
||||||
//外部接口
|
// 外部接口
|
||||||
,tree = {
|
var tree = {
|
||||||
config: {}
|
config: {},
|
||||||
,index: layui[MOD_NAME] ? (layui[MOD_NAME].index + 10000) : 0
|
index: layui[MOD_NAME] ? (layui[MOD_NAME].index + 10000) : 0,
|
||||||
|
|
||||||
//设置全局项
|
// 设置全局项
|
||||||
,set: function(options){
|
set: function(options){
|
||||||
var that = this;
|
var that = this;
|
||||||
that.config = $.extend({}, that.config, options);
|
that.config = $.extend({}, that.config, options);
|
||||||
return that;
|
return that;
|
||||||
}
|
},
|
||||||
|
|
||||||
//事件
|
// 事件
|
||||||
,on: function(events, callback){
|
on: function(events, callback){
|
||||||
return layui.onevent.call(this, MOD_NAME, events, callback);
|
return layui.onevent.call(this, MOD_NAME, events, callback);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
//操作当前实例
|
// 操作当前实例
|
||||||
,thisModule = function(){
|
var thisModule = function(){
|
||||||
var that = this
|
var that = this;
|
||||||
,options = that.config
|
var options = that.config;
|
||||||
,id = options.id || that.index;
|
var id = options.id || that.index;
|
||||||
|
|
||||||
thisModule.that[id] = that; //记录当前实例对象
|
thisModule.that[id] = that; // 记录当前实例对象
|
||||||
thisModule.config[id] = options; //记录当前实例配置项
|
thisModule.config[id] = options; // 记录当前实例配置项
|
||||||
|
|
||||||
return {
|
return {
|
||||||
config: options
|
config: options,
|
||||||
//重置实例
|
// 重置实例
|
||||||
,reload: function(options){
|
reload: function(options){
|
||||||
that.reload.call(that, options);
|
that.reload.call(that, options);
|
||||||
}
|
},
|
||||||
,getChecked: function(){
|
getChecked: function(){
|
||||||
return that.getChecked.call(that);
|
return that.getChecked.call(that);
|
||||||
}
|
},
|
||||||
,setChecked: function(id){//设置值
|
setChecked: function(id){// 设置值
|
||||||
return that.setChecked.call(that, id);
|
return that.setChecked.call(that, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
//获取当前实例配置项
|
// 获取当前实例配置项
|
||||||
,getThisModuleConfig = function(id){
|
var getThisModuleConfig = function(id){
|
||||||
var config = thisModule.config[id];
|
var config = thisModule.config[id];
|
||||||
if(!config) hint.error('The ID option was not found in the '+ MOD_NAME +' instance');
|
if(!config) hint.error('The ID option was not found in the '+ MOD_NAME +' instance');
|
||||||
return config || null;
|
return config || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//字符常量
|
// 字符常量
|
||||||
,SHOW = 'layui-show', HIDE = 'layui-hide', NONE = 'layui-none', DISABLED = 'layui-disabled'
|
var SHOW = 'layui-show';
|
||||||
|
var HIDE = 'layui-hide';
|
||||||
|
var NONE = 'layui-none';
|
||||||
|
var DISABLED = 'layui-disabled';
|
||||||
|
|
||||||
,ELEM_VIEW = 'layui-tree', ELEM_SET = 'layui-tree-set', ICON_CLICK = 'layui-tree-iconClick'
|
var ELEM_VIEW = 'layui-tree';
|
||||||
,ICON_ADD = 'layui-icon-addition', ICON_SUB = 'layui-icon-subtraction', ELEM_ENTRY = 'layui-tree-entry', ELEM_MAIN = 'layui-tree-main', ELEM_TEXT = 'layui-tree-txt', ELEM_PACK = 'layui-tree-pack', ELEM_SPREAD = 'layui-tree-spread'
|
var ELEM_SET = 'layui-tree-set';
|
||||||
,ELEM_LINE_SHORT = 'layui-tree-setLineShort', ELEM_SHOW = 'layui-tree-showLine', ELEM_EXTEND = 'layui-tree-lineExtend'
|
var ICON_CLICK = 'layui-tree-iconClick';
|
||||||
|
var ICON_ADD = 'layui-icon-addition';
|
||||||
|
var ICON_SUB = 'layui-icon-subtraction';
|
||||||
|
var ELEM_ENTRY = 'layui-tree-entry';
|
||||||
|
var ELEM_MAIN = 'layui-tree-main';
|
||||||
|
var ELEM_TEXT = 'layui-tree-txt';
|
||||||
|
var ELEM_PACK = 'layui-tree-pack';
|
||||||
|
var ELEM_SPREAD = 'layui-tree-spread';
|
||||||
|
var ELEM_LINE_SHORT = 'layui-tree-setLineShort';
|
||||||
|
var ELEM_SHOW = 'layui-tree-showLine';
|
||||||
|
var ELEM_EXTEND = 'layui-tree-lineExtend';
|
||||||
|
|
||||||
//构造器
|
// 构造器
|
||||||
,Class = function(options){
|
var Class = function(options){
|
||||||
var that = this;
|
var that = this;
|
||||||
that.index = ++tree.index;
|
that.index = ++tree.index;
|
||||||
that.config = $.extend({}, that.config, tree.config, options);
|
that.config = $.extend({}, that.config, tree.config, options);
|
||||||
that.render();
|
that.render();
|
||||||
};
|
};
|
||||||
|
|
||||||
//默认配置
|
// 默认配置
|
||||||
Class.prototype.config = {
|
Class.prototype.config = {
|
||||||
data: [] //数据
|
data: [], // 数据
|
||||||
|
|
||||||
,showCheckbox: false //是否显示复选框
|
showCheckbox: false, // 是否显示复选框
|
||||||
,showLine: true //是否开启连接线
|
showLine: true, // 是否开启连接线
|
||||||
,accordion: false //是否开启手风琴模式
|
accordion: false, // 是否开启手风琴模式
|
||||||
,onlyIconControl: false //是否仅允许节点左侧图标控制展开收缩
|
onlyIconControl: false, // 是否仅允许节点左侧图标控制展开收缩
|
||||||
,isJump: false //是否允许点击节点时弹出新窗口跳转
|
isJump: false, // 是否允许点击节点时弹出新窗口跳转
|
||||||
,edit: false //是否开启节点的操作图标
|
edit: false, // 是否开启节点的操作图标
|
||||||
|
|
||||||
,text: {
|
text: {
|
||||||
defaultNodeName: '未命名' //节点默认名称
|
defaultNodeName: '未命名', // 节点默认名称
|
||||||
,none: '无数据' //数据为空时的文本提示
|
none: '无数据' // 数据为空时的文本提示
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//重载实例
|
// 重载实例
|
||||||
Class.prototype.reload = function(options){
|
Class.prototype.reload = function(options){
|
||||||
var that = this;
|
var that = this;
|
||||||
|
|
||||||
|
@ -105,10 +118,10 @@ layui.define('form', function(exports){
|
||||||
that.render();
|
that.render();
|
||||||
};
|
};
|
||||||
|
|
||||||
//主体渲染
|
// 主体渲染
|
||||||
Class.prototype.render = function(){
|
Class.prototype.render = function(){
|
||||||
var that = this
|
var that = this;
|
||||||
,options = that.config;
|
var options = that.config;
|
||||||
|
|
||||||
that.checkids = [];
|
that.checkids = [];
|
||||||
|
|
||||||
|
@ -118,10 +131,10 @@ layui.define('form', function(exports){
|
||||||
var othis = options.elem = $(options.elem);
|
var othis = options.elem = $(options.elem);
|
||||||
if(!othis[0]) return;
|
if(!othis[0]) return;
|
||||||
|
|
||||||
//索引
|
// 索引
|
||||||
that.key = options.id || that.index;
|
that.key = options.id || that.index;
|
||||||
|
|
||||||
//插入组件结构
|
// 插入组件结构
|
||||||
that.elem = temp;
|
that.elem = temp;
|
||||||
that.elemNone = $('<div class="layui-tree-emptyText">'+ options.text.none +'</div>');
|
that.elemNone = $('<div class="layui-tree-emptyText">'+ options.text.none +'</div>');
|
||||||
othis.html(that.elem);
|
othis.html(that.elem);
|
||||||
|
@ -130,24 +143,24 @@ layui.define('form', function(exports){
|
||||||
return that.elem.append(that.elemNone);
|
return that.elem.append(that.elemNone);
|
||||||
};
|
};
|
||||||
|
|
||||||
//复选框渲染
|
// 复选框渲染
|
||||||
if(options.showCheckbox){
|
if(options.showCheckbox){
|
||||||
that.renderForm('checkbox');
|
that.renderForm('checkbox');
|
||||||
};
|
};
|
||||||
|
|
||||||
that.elem.find('.layui-tree-set').each(function(){
|
that.elem.find('.layui-tree-set').each(function(){
|
||||||
var othis = $(this);
|
var othis = $(this);
|
||||||
//最外层
|
// 最外层
|
||||||
if(!othis.parent('.layui-tree-pack')[0]){
|
if(!othis.parent('.layui-tree-pack')[0]){
|
||||||
othis.addClass('layui-tree-setHide');
|
othis.addClass('layui-tree-setHide');
|
||||||
};
|
};
|
||||||
|
|
||||||
//没有下一个节点 上一层父级有延伸线
|
// 没有下一个节点 上一层父级有延伸线
|
||||||
if(!othis.next()[0] && othis.parents('.layui-tree-pack').eq(1).hasClass('layui-tree-lineExtend')){
|
if(!othis.next()[0] && othis.parents('.layui-tree-pack').eq(1).hasClass('layui-tree-lineExtend')){
|
||||||
othis.addClass(ELEM_LINE_SHORT);
|
othis.addClass(ELEM_LINE_SHORT);
|
||||||
};
|
};
|
||||||
|
|
||||||
//没有下一个节点 外层最后一个
|
// 没有下一个节点 外层最后一个
|
||||||
if(!othis.next()[0] && !othis.parents('.layui-tree-set').eq(0).next()[0]){
|
if(!othis.next()[0] && !othis.parents('.layui-tree-set').eq(0).next()[0]){
|
||||||
othis.addClass(ELEM_LINE_SHORT);
|
othis.addClass(ELEM_LINE_SHORT);
|
||||||
};
|
};
|
||||||
|
@ -156,25 +169,25 @@ layui.define('form', function(exports){
|
||||||
that.events();
|
that.events();
|
||||||
};
|
};
|
||||||
|
|
||||||
//渲染表单
|
// 渲染表单
|
||||||
Class.prototype.renderForm = function(type){
|
Class.prototype.renderForm = function(type){
|
||||||
form.render(type, 'LAY-tree-'+ this.index);
|
form.render(type, 'LAY-tree-'+ this.index);
|
||||||
};
|
};
|
||||||
|
|
||||||
//节点解析
|
// 节点解析
|
||||||
Class.prototype.tree = function(elem, children){
|
Class.prototype.tree = function(elem, children){
|
||||||
var that = this
|
var that = this;
|
||||||
,options = that.config
|
var options = that.config;
|
||||||
,data = children || options.data;
|
var data = children || options.data;
|
||||||
|
|
||||||
//遍历数据
|
// 遍历数据
|
||||||
layui.each(data, function(index, item){
|
layui.each(data, function(index, item){
|
||||||
var hasChild = item.children && item.children.length > 0
|
var hasChild = item.children && item.children.length > 0;
|
||||||
,packDiv = $('<div class="layui-tree-pack" '+ (item.spread ? 'style="display: block;"' : '') +'></div>')
|
var packDiv = $('<div class="layui-tree-pack" '+ (item.spread ? 'style="display: block;"' : '') +'></div>');
|
||||||
,entryDiv = $(['<div data-id="'+ item.id +'" class="layui-tree-set'+ (item.spread ? " layui-tree-spread" : "") + (item.checked ? " layui-tree-checkedFirst" : "") +'">'
|
var entryDiv = $(['<div data-id="'+ item.id +'" class="layui-tree-set'+ (item.spread ? " layui-tree-spread" : "") + (item.checked ? " layui-tree-checkedFirst" : "") +'">'
|
||||||
,'<div class="layui-tree-entry">'
|
,'<div class="layui-tree-entry">'
|
||||||
,'<div class="layui-tree-main">'
|
,'<div class="layui-tree-main">'
|
||||||
//箭头
|
// 箭头
|
||||||
,function(){
|
,function(){
|
||||||
if(options.showLine){
|
if(options.showLine){
|
||||||
if(hasChild){
|
if(hasChild){
|
||||||
|
@ -187,12 +200,12 @@ layui.define('form', function(exports){
|
||||||
};
|
};
|
||||||
}()
|
}()
|
||||||
|
|
||||||
//复选框
|
// 复选框
|
||||||
,function(){
|
,function(){
|
||||||
return options.showCheckbox ? '<input type="checkbox" name="'+ (item.field || ('layuiTreeCheck_'+ item.id)) +'" same="layuiTreeCheck" lay-skin="primary" '+ (item.disabled ? "disabled" : "") +' value="'+ item.id +'">' : '';
|
return options.showCheckbox ? '<input type="checkbox" name="'+ (item.field || ('layuiTreeCheck_'+ item.id)) +'" same="layuiTreeCheck" lay-skin="primary" '+ (item.disabled ? "disabled" : "") +' value="'+ item.id +'">' : '';
|
||||||
}()
|
}()
|
||||||
|
|
||||||
//节点
|
// 节点
|
||||||
,function(){
|
,function(){
|
||||||
if(options.isJump && item.href){
|
if(options.isJump && item.href){
|
||||||
return '<a href="'+ item.href +'" target="_blank" class="'+ ELEM_TEXT +'">'+ (item.title || item.label || options.text.defaultNodeName) +'</a>';
|
return '<a href="'+ item.href +'" target="_blank" class="'+ ELEM_TEXT +'">'+ (item.title || item.label || options.text.defaultNodeName) +'</a>';
|
||||||
|
@ -202,7 +215,7 @@ layui.define('form', function(exports){
|
||||||
}()
|
}()
|
||||||
,'</div>'
|
,'</div>'
|
||||||
|
|
||||||
//节点操作图标
|
// 节点操作图标
|
||||||
,function(){
|
,function(){
|
||||||
if(!options.edit) return '';
|
if(!options.edit) return '';
|
||||||
|
|
||||||
|
@ -225,7 +238,7 @@ layui.define('form', function(exports){
|
||||||
}()
|
}()
|
||||||
,'</div></div>'].join(''));
|
,'</div></div>'].join(''));
|
||||||
|
|
||||||
//如果有子节点,则递归继续生成树
|
// 如果有子节点,则递归继续生成树
|
||||||
if(hasChild){
|
if(hasChild){
|
||||||
entryDiv.append(packDiv);
|
entryDiv.append(packDiv);
|
||||||
that.tree(packDiv, item.children);
|
that.tree(packDiv, item.children);
|
||||||
|
@ -233,48 +246,49 @@ layui.define('form', function(exports){
|
||||||
|
|
||||||
elem.append(entryDiv);
|
elem.append(entryDiv);
|
||||||
|
|
||||||
//若有前置节点,前置节点加连接线
|
// 若有前置节点,前置节点加连接线
|
||||||
if(entryDiv.prev('.'+ELEM_SET)[0]){
|
if(entryDiv.prev('.'+ELEM_SET)[0]){
|
||||||
entryDiv.prev().children('.layui-tree-pack').addClass('layui-tree-showLine');
|
entryDiv.prev().children('.layui-tree-pack').addClass('layui-tree-showLine');
|
||||||
};
|
};
|
||||||
|
|
||||||
//若无子节点,则父节点加延伸线
|
// 若无子节点,则父节点加延伸线
|
||||||
if(!hasChild){
|
if(!hasChild){
|
||||||
entryDiv.parent('.layui-tree-pack').addClass('layui-tree-lineExtend');
|
entryDiv.parent('.layui-tree-pack').addClass('layui-tree-lineExtend');
|
||||||
};
|
};
|
||||||
|
|
||||||
//展开节点操作
|
// 展开节点操作
|
||||||
that.spread(entryDiv, item);
|
that.spread(entryDiv, item);
|
||||||
|
|
||||||
//选择框
|
// 选择框
|
||||||
if(options.showCheckbox){
|
if(options.showCheckbox){
|
||||||
item.checked && that.checkids.push(item.id);
|
item.checked && that.checkids.push(item.id);
|
||||||
that.checkClick(entryDiv, item);
|
that.checkClick(entryDiv, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
//操作节点
|
// 操作节点
|
||||||
options.edit && that.operate(entryDiv, item);
|
options.edit && that.operate(entryDiv, item);
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
//展开节点
|
// 展开节点
|
||||||
Class.prototype.spread = function(elem, item){
|
Class.prototype.spread = function(elem, item){
|
||||||
var that = this
|
var that = this;
|
||||||
,options = that.config
|
var options = that.config;
|
||||||
,entry = elem.children('.'+ELEM_ENTRY)
|
var entry = elem.children('.'+ELEM_ENTRY);
|
||||||
,elemMain = entry.children('.'+ ELEM_MAIN)
|
var elemMain = entry.children('.'+ ELEM_MAIN);
|
||||||
,elemIcon = entry.find('.'+ ICON_CLICK)
|
var elemCheckbox = elemMain.find('input[same="layuiTreeCheck"]');
|
||||||
,elemText = entry.find('.'+ ELEM_TEXT)
|
var elemIcon = entry.find('.'+ ICON_CLICK);
|
||||||
,touchOpen = options.onlyIconControl ? elemIcon : elemMain //判断展开通过节点还是箭头图标
|
var elemText = entry.find('.'+ ELEM_TEXT);
|
||||||
,state = '';
|
var touchOpen = options.onlyIconControl ? elemIcon : elemMain; // 判断展开通过节点还是箭头图标
|
||||||
|
var state = '';
|
||||||
|
|
||||||
//展开收缩
|
// 展开收缩
|
||||||
touchOpen.on('click', function(e){
|
touchOpen.on('click', function(e){
|
||||||
var packCont = elem.children('.'+ELEM_PACK)
|
var packCont = elem.children('.'+ELEM_PACK)
|
||||||
,iconClick = touchOpen.children('.layui-icon')[0] ? touchOpen.children('.layui-icon') : touchOpen.find('.layui-tree-icon').children('.layui-icon');
|
,iconClick = touchOpen.children('.layui-icon')[0] ? touchOpen.children('.layui-icon') : touchOpen.find('.layui-tree-icon').children('.layui-icon');
|
||||||
|
|
||||||
//若没有子节点
|
// 若没有子节点
|
||||||
if(!packCont[0]){
|
if(!packCont[0]){
|
||||||
state = 'normal';
|
state = 'normal';
|
||||||
}else{
|
}else{
|
||||||
|
@ -287,7 +301,7 @@ layui.define('form', function(exports){
|
||||||
packCont.slideDown(200);
|
packCont.slideDown(200);
|
||||||
iconClick.addClass(ICON_SUB).removeClass(ICON_ADD);
|
iconClick.addClass(ICON_SUB).removeClass(ICON_ADD);
|
||||||
|
|
||||||
//是否手风琴
|
// 是否手风琴
|
||||||
if(options.accordion){
|
if(options.accordion){
|
||||||
var sibls = elem.siblings('.'+ELEM_SET);
|
var sibls = elem.siblings('.'+ELEM_SET);
|
||||||
sibls.removeClass(ELEM_SPREAD);
|
sibls.removeClass(ELEM_SPREAD);
|
||||||
|
@ -298,71 +312,77 @@ layui.define('form', function(exports){
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
//点击回调
|
// 点击回调
|
||||||
elemText.on('click', function(){
|
elemText.on('click', function(){
|
||||||
var othis = $(this);
|
var othis = $(this);
|
||||||
|
|
||||||
//判断是否禁用状态
|
// 判断是否禁用状态
|
||||||
if(othis.hasClass(DISABLED)) return;
|
if(othis.hasClass(DISABLED)) return;
|
||||||
|
|
||||||
//判断展开收缩状态
|
// 判断展开收缩状态
|
||||||
if(elem.hasClass(ELEM_SPREAD)){
|
if(elem.hasClass(ELEM_SPREAD)){
|
||||||
state = options.onlyIconControl ? 'open' : 'close';
|
state = options.onlyIconControl ? 'open' : 'close';
|
||||||
} else {
|
} else {
|
||||||
state = options.onlyIconControl ? 'close' : 'open';
|
state = options.onlyIconControl ? 'close' : 'open';
|
||||||
}
|
}
|
||||||
|
|
||||||
//点击产生的回调
|
// 获取选中状态
|
||||||
|
if(elemCheckbox[0]){
|
||||||
|
item['checked'] = elemCheckbox.prop('checked');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 点击产生的回调
|
||||||
options.click && options.click({
|
options.click && options.click({
|
||||||
elem: elem
|
elem: elem,
|
||||||
,state: state
|
state: state,
|
||||||
,data: item
|
data: item
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
//计算复选框选中状态
|
// 计算复选框选中状态
|
||||||
Class.prototype.setCheckbox = function(elem, item, elemCheckbox){
|
Class.prototype.setCheckbox = function(elem, item, elemCheckbox){
|
||||||
var that = this
|
var that = this;
|
||||||
,options = that.config
|
var options = that.config;
|
||||||
,checked = elemCheckbox.prop('checked');
|
var checked = elemCheckbox.prop('checked');
|
||||||
|
|
||||||
if(elemCheckbox.prop('disabled')) return;
|
if(elemCheckbox.prop('disabled')) return;
|
||||||
|
|
||||||
//同步子节点选中状态
|
// 同步子节点选中状态
|
||||||
if(typeof item.children === 'object' || elem.find('.'+ELEM_PACK)[0]){
|
if(typeof item.children === 'object' || elem.find('.'+ELEM_PACK)[0]){
|
||||||
var childs = elem.find('.'+ ELEM_PACK).find('input[same="layuiTreeCheck"]');
|
var elemCheckboxs = elem.find('.'+ ELEM_PACK).find('input[same="layuiTreeCheck"]');
|
||||||
childs.each(function(){
|
elemCheckboxs.each(function(index){
|
||||||
if(this.disabled) return; //不可点击则跳过
|
if(this.disabled) return; // 不可点击则跳过
|
||||||
|
if(item.children[index]) item.children[index]['checked'] = checked;
|
||||||
this.checked = checked;
|
this.checked = checked;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
//同步父节点选中状态
|
// 同步父节点选中状态
|
||||||
var setParentsChecked = function(thisNodeElem){
|
var setParentsChecked = function(thisNodeElem){
|
||||||
//若无父节点,则终止递归
|
// 若无父节点,则终止递归
|
||||||
if(!thisNodeElem.parents('.'+ ELEM_SET)[0]) return;
|
if(!thisNodeElem.parents('.'+ ELEM_SET)[0]) return;
|
||||||
|
|
||||||
var state
|
var state;
|
||||||
,parentPack = thisNodeElem.parent('.'+ ELEM_PACK)
|
var parentPack = thisNodeElem.parent('.'+ ELEM_PACK);
|
||||||
,parentNodeElem = parentPack.parent()
|
var parentNodeElem = parentPack.parent();
|
||||||
,parentCheckbox = parentPack.prev().find('input[same="layuiTreeCheck"]');
|
var parentCheckbox = parentPack.prev().find('input[same="layuiTreeCheck"]');
|
||||||
|
|
||||||
//如果子节点有任意一条选中,则父节点为选中状态
|
// 如果子节点有任意一条选中,则父节点为选中状态
|
||||||
if(checked){
|
if(checked){
|
||||||
parentCheckbox.prop('checked', checked);
|
parentCheckbox.prop('checked', checked);
|
||||||
} else { //如果当前节点取消选中,则根据计算“兄弟和子孙”节点选中状态,来同步父节点选中状态
|
} else { // 如果当前节点取消选中,则根据计算“兄弟和子孙”节点选中状态,来同步父节点选中状态
|
||||||
parentPack.find('input[same="layuiTreeCheck"]').each(function(){
|
parentPack.find('input[same="layuiTreeCheck"]').each(function(){
|
||||||
if(this.checked){
|
if(this.checked){
|
||||||
state = true;
|
state = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//如果兄弟子孙节点全部未选中,则父节点也应为非选中状态
|
// 如果兄弟子孙节点全部未选中,则父节点也应为非选中状态
|
||||||
state || parentCheckbox.prop('checked', false);
|
state || parentCheckbox.prop('checked', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
//向父节点递归
|
// 向父节点递归
|
||||||
setParentsChecked(parentNodeElem);
|
setParentsChecked(parentNodeElem);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -371,157 +391,161 @@ layui.define('form', function(exports){
|
||||||
that.renderForm('checkbox');
|
that.renderForm('checkbox');
|
||||||
};
|
};
|
||||||
|
|
||||||
//复选框选择
|
// 复选框选择
|
||||||
Class.prototype.checkClick = function(elem, item){
|
Class.prototype.checkClick = function(elem, item){
|
||||||
var that = this
|
var that = this;
|
||||||
,options = that.config
|
var options = that.config;
|
||||||
,entry = elem.children('.'+ ELEM_ENTRY)
|
var entry = elem.children('.'+ ELEM_ENTRY);
|
||||||
,elemMain = entry.children('.'+ ELEM_MAIN);
|
var elemMain = entry.children('.'+ ELEM_MAIN);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//点击复选框
|
// 点击复选框
|
||||||
elemMain.on('click', 'input[same="layuiTreeCheck"]+', function(e){
|
elemMain.on('click', 'input[same="layuiTreeCheck"]+', function(e){
|
||||||
layui.stope(e); //阻止点击节点事件
|
layui.stope(e); // 阻止点击节点事件
|
||||||
|
|
||||||
var elemCheckbox = $(this).prev()
|
var elemCheckbox = $(this).prev();
|
||||||
,checked = elemCheckbox.prop('checked');
|
var checked = elemCheckbox.prop('checked');
|
||||||
|
|
||||||
if(elemCheckbox.prop('disabled')) return;
|
if(elemCheckbox.prop('disabled')) return;
|
||||||
|
|
||||||
that.setCheckbox(elem, item, elemCheckbox);
|
that.setCheckbox(elem, item, elemCheckbox);
|
||||||
|
item.checked = checked;
|
||||||
|
|
||||||
//复选框点击产生的回调
|
// 复选框点击产生的回调
|
||||||
options.oncheck && options.oncheck({
|
options.oncheck && options.oncheck({
|
||||||
elem: elem
|
elem: elem,
|
||||||
,checked: checked
|
checked: checked,
|
||||||
,data: item
|
data: item
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
//节点操作
|
// 节点操作
|
||||||
Class.prototype.operate = function(elem, item){
|
Class.prototype.operate = function(elem, item){
|
||||||
var that = this
|
var that = this;
|
||||||
,options = that.config
|
var options = that.config;
|
||||||
,entry = elem.children('.'+ ELEM_ENTRY)
|
var entry = elem.children('.'+ ELEM_ENTRY);
|
||||||
,elemMain = entry.children('.'+ ELEM_MAIN);
|
var elemMain = entry.children('.'+ ELEM_MAIN);
|
||||||
|
|
||||||
entry.children('.layui-tree-btnGroup').on('click', '.layui-icon', function(e){
|
entry.children('.layui-tree-btnGroup').on('click', '.layui-icon', function(e){
|
||||||
layui.stope(e); //阻止节点操作
|
layui.stope(e); // 阻止节点操作
|
||||||
|
|
||||||
var type = $(this).data("type")
|
var type = $(this).data("type");
|
||||||
,packCont = elem.children('.'+ELEM_PACK)
|
var packCont = elem.children('.'+ELEM_PACK);
|
||||||
,returnObj = {
|
var returnObj = {
|
||||||
data: item
|
data: item,
|
||||||
,type: type
|
type: type,
|
||||||
,elem:elem
|
elem:elem
|
||||||
};
|
};
|
||||||
//增加
|
// 增加
|
||||||
if(type == 'add'){
|
if(type == 'add'){
|
||||||
//若节点本身无子节点
|
// 若节点本身无子节点
|
||||||
if(!packCont[0]){
|
if(!packCont[0]){
|
||||||
//若开启连接线,更改图标样式
|
// 若开启连接线,更改图标样式
|
||||||
if(options.showLine){
|
if(options.showLine){
|
||||||
elemMain.find('.'+ICON_CLICK).addClass('layui-tree-icon');
|
elemMain.find('.'+ICON_CLICK).addClass('layui-tree-icon');
|
||||||
elemMain.find('.'+ICON_CLICK).children('.layui-icon').addClass(ICON_ADD).removeClass('layui-icon-file');
|
elemMain.find('.'+ICON_CLICK).children('.layui-icon').addClass(ICON_ADD).removeClass('layui-icon-file');
|
||||||
//若未开启连接线,显示箭头
|
// 若未开启连接线,显示箭头
|
||||||
}else{
|
} else {
|
||||||
elemMain.find('.layui-tree-iconArrow').removeClass(HIDE);
|
elemMain.find('.layui-tree-iconArrow').removeClass(HIDE);
|
||||||
};
|
};
|
||||||
//节点添加子节点容器
|
// 节点添加子节点容器
|
||||||
elem.append('<div class="layui-tree-pack"></div>');
|
elem.append('<div class="layui-tree-pack"></div>');
|
||||||
};
|
};
|
||||||
|
|
||||||
//新增节点
|
// 新增节点
|
||||||
var key = options.operate && options.operate(returnObj)
|
var key = options.operate && options.operate(returnObj);
|
||||||
,obj = {};
|
var obj = {};
|
||||||
|
|
||||||
obj.title = options.text.defaultNodeName;
|
obj.title = options.text.defaultNodeName;
|
||||||
obj.id = key;
|
obj.id = key;
|
||||||
that.tree(elem.children('.'+ELEM_PACK), [obj]);
|
that.tree(elem.children('.'+ELEM_PACK), [obj]);
|
||||||
|
|
||||||
//放在新增后面,因为要对元素进行操作
|
// 放在新增后面,因为要对元素进行操作
|
||||||
if(options.showLine){
|
if(options.showLine){
|
||||||
//节点本身无子节点
|
// 节点本身无子节点
|
||||||
if(!packCont[0]){
|
if(!packCont[0]){
|
||||||
//遍历兄弟节点,判断兄弟节点是否有子节点
|
// 遍历兄弟节点,判断兄弟节点是否有子节点
|
||||||
var siblings = elem.siblings('.'+ELEM_SET), num = 1
|
var siblings = elem.siblings('.'+ELEM_SET)
|
||||||
,parentPack = elem.parent('.'+ELEM_PACK);
|
var num = 1;
|
||||||
|
var parentPack = elem.parent('.'+ELEM_PACK);
|
||||||
|
|
||||||
layui.each(siblings, function(index, i){
|
layui.each(siblings, function(index, i){
|
||||||
if(!$(i).children('.'+ELEM_PACK)[0]){
|
if(!$(i).children('.'+ELEM_PACK)[0]){
|
||||||
num = 0;
|
num = 0;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
//若兄弟节点都有子节点
|
// 若兄弟节点都有子节点
|
||||||
if(num == 1){
|
if(num == 1){
|
||||||
//兄弟节点添加连接线
|
// 兄弟节点添加连接线
|
||||||
siblings.children('.'+ELEM_PACK).addClass(ELEM_SHOW);
|
siblings.children('.'+ELEM_PACK).addClass(ELEM_SHOW);
|
||||||
siblings.children('.'+ELEM_PACK).children('.'+ELEM_SET).removeClass(ELEM_LINE_SHORT);
|
siblings.children('.'+ELEM_PACK).children('.'+ELEM_SET).removeClass(ELEM_LINE_SHORT);
|
||||||
elem.children('.'+ELEM_PACK).addClass(ELEM_SHOW);
|
elem.children('.'+ELEM_PACK).addClass(ELEM_SHOW);
|
||||||
//父级移除延伸线
|
// 父级移除延伸线
|
||||||
parentPack.removeClass(ELEM_EXTEND);
|
parentPack.removeClass(ELEM_EXTEND);
|
||||||
//同层节点最后一个更改线的状态
|
// 同层节点最后一个更改线的状态
|
||||||
parentPack.children('.'+ELEM_SET).last().children('.'+ELEM_PACK).children('.'+ELEM_SET).last().addClass(ELEM_LINE_SHORT);
|
parentPack.children('.'+ELEM_SET).last().children('.'+ELEM_PACK).children('.'+ELEM_SET).last().addClass(ELEM_LINE_SHORT);
|
||||||
}else{
|
} else {
|
||||||
elem.children('.'+ELEM_PACK).children('.'+ELEM_SET).addClass(ELEM_LINE_SHORT);
|
elem.children('.'+ELEM_PACK).children('.'+ELEM_SET).addClass(ELEM_LINE_SHORT);
|
||||||
};
|
};
|
||||||
}else{
|
} else {
|
||||||
//添加延伸线
|
// 添加延伸线
|
||||||
if(!packCont.hasClass(ELEM_EXTEND)){
|
if(!packCont.hasClass(ELEM_EXTEND)){
|
||||||
packCont.addClass(ELEM_EXTEND);
|
packCont.addClass(ELEM_EXTEND);
|
||||||
};
|
};
|
||||||
//子节点添加延伸线
|
// 子节点添加延伸线
|
||||||
elem.find('.'+ELEM_PACK).each(function(){
|
elem.find('.'+ELEM_PACK).each(function(){
|
||||||
$(this).children('.'+ELEM_SET).last().addClass(ELEM_LINE_SHORT);
|
$(this).children('.'+ELEM_SET).last().addClass(ELEM_LINE_SHORT);
|
||||||
});
|
});
|
||||||
//如果前一个节点有延伸线
|
// 如果前一个节点有延伸线
|
||||||
if(packCont.children('.'+ELEM_SET).last().prev().hasClass(ELEM_LINE_SHORT)){
|
if(packCont.children('.'+ELEM_SET).last().prev().hasClass(ELEM_LINE_SHORT)){
|
||||||
packCont.children('.'+ELEM_SET).last().prev().removeClass(ELEM_LINE_SHORT);
|
packCont.children('.'+ELEM_SET).last().prev().removeClass(ELEM_LINE_SHORT);
|
||||||
}else{
|
}else{
|
||||||
//若之前的没有,说明处于连接状态
|
// 若之前的没有,说明处于连接状态
|
||||||
packCont.children('.'+ELEM_SET).last().removeClass(ELEM_LINE_SHORT);
|
packCont.children('.'+ELEM_SET).last().removeClass(ELEM_LINE_SHORT);
|
||||||
};
|
};
|
||||||
//若是最外层,要始终保持相连的状态
|
// 若是最外层,要始终保持相连的状态
|
||||||
if(!elem.parent('.'+ELEM_PACK)[0] && elem.next()[0]){
|
if(!elem.parent('.'+ELEM_PACK)[0] && elem.next()[0]){
|
||||||
packCont.children('.'+ELEM_SET).last().removeClass(ELEM_LINE_SHORT);
|
packCont.children('.'+ELEM_SET).last().removeClass(ELEM_LINE_SHORT);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
if(!options.showCheckbox) return;
|
if(!options.showCheckbox) return;
|
||||||
//若开启复选框,同步新增节点状态
|
// 若开启复选框,同步新增节点状态
|
||||||
if(elemMain.find('input[same="layuiTreeCheck"]')[0].checked){
|
if(elemMain.find('input[same="layuiTreeCheck"]')[0].checked){
|
||||||
var packLast = elem.children('.'+ELEM_PACK).children('.'+ELEM_SET).last();
|
var packLast = elem.children('.'+ELEM_PACK).children('.'+ELEM_SET).last();
|
||||||
packLast.find('input[same="layuiTreeCheck"]')[0].checked = true;
|
packLast.find('input[same="layuiTreeCheck"]')[0].checked = true;
|
||||||
};
|
};
|
||||||
that.renderForm('checkbox');
|
that.renderForm('checkbox');
|
||||||
|
|
||||||
//修改
|
// 修改
|
||||||
}else if(type == 'update'){
|
} else if(type == 'update') {
|
||||||
var text = elemMain.children('.'+ ELEM_TEXT).html();
|
var text = elemMain.children('.'+ ELEM_TEXT).html();
|
||||||
elemMain.children('.'+ ELEM_TEXT).html('');
|
elemMain.children('.'+ ELEM_TEXT).html('');
|
||||||
//添加输入框,覆盖在文字上方
|
// 添加输入框,覆盖在文字上方
|
||||||
elemMain.append('<input type="text" class="layui-tree-editInput">');
|
elemMain.append('<input type="text" class="layui-tree-editInput">');
|
||||||
//获取焦点
|
// 获取焦点
|
||||||
elemMain.children('.layui-tree-editInput').val(text).focus();
|
elemMain.children('.layui-tree-editInput').val(text).focus();
|
||||||
//嵌入文字移除输入框
|
// 嵌入文字移除输入框
|
||||||
var getVal = function(input){
|
var getVal = function(input){
|
||||||
var textNew = input.val().trim();
|
var textNew = input.val().trim();
|
||||||
textNew = textNew ? textNew : options.text.defaultNodeName;
|
textNew = textNew ? textNew : options.text.defaultNodeName;
|
||||||
input.remove();
|
input.remove();
|
||||||
elemMain.children('.'+ ELEM_TEXT).html(textNew);
|
elemMain.children('.'+ ELEM_TEXT).html(textNew);
|
||||||
|
|
||||||
//同步数据
|
// 同步数据
|
||||||
returnObj.data.title = textNew;
|
returnObj.data.title = textNew;
|
||||||
|
|
||||||
//节点修改的回调
|
// 节点修改的回调
|
||||||
options.operate && options.operate(returnObj);
|
options.operate && options.operate(returnObj);
|
||||||
};
|
};
|
||||||
//失去焦点
|
// 失去焦点
|
||||||
elemMain.children('.layui-tree-editInput').blur(function(){
|
elemMain.children('.layui-tree-editInput').blur(function(){
|
||||||
getVal($(this));
|
getVal($(this));
|
||||||
});
|
});
|
||||||
//回车
|
// 回车
|
||||||
elemMain.children('.layui-tree-editInput').on('keydown', function(e){
|
elemMain.children('.layui-tree-editInput').on('keydown', function(e){
|
||||||
if(e.keyCode === 13){
|
if(e.keyCode === 13){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -529,116 +553,120 @@ layui.define('form', function(exports){
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
//删除
|
// 删除
|
||||||
} else {
|
} else {
|
||||||
layer.confirm('确认删除该节点 "<span style="color: #999;">'+ (item.title || '') +'</span>" 吗?', function(index){
|
layer.confirm('确认删除该节点 "<span style="color: #999;">'+ (item.title || '') +'</span>" 吗?', function(index){
|
||||||
options.operate && options.operate(returnObj); //节点删除的回调
|
options.operate && options.operate(returnObj); // 节点删除的回调
|
||||||
returnObj.status = 'remove'; //标注节点删除
|
returnObj.status = 'remove'; // 标注节点删除
|
||||||
|
|
||||||
layer.close(index);
|
layer.close(index);
|
||||||
|
|
||||||
//若删除最后一个,显示空数据提示
|
// 若删除最后一个,显示空数据提示
|
||||||
if(!elem.prev('.'+ELEM_SET)[0] && !elem.next('.'+ELEM_SET)[0] && !elem.parent('.'+ELEM_PACK)[0]){
|
if(!elem.prev('.'+ELEM_SET)[0] && !elem.next('.'+ELEM_SET)[0] && !elem.parent('.'+ELEM_PACK)[0]){
|
||||||
elem.remove();
|
elem.remove();
|
||||||
that.elem.append(that.elemNone);
|
that.elem.append(that.elemNone);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
//若有兄弟节点
|
// 若有兄弟节点
|
||||||
if(elem.siblings('.'+ELEM_SET).children('.'+ELEM_ENTRY)[0]){
|
if(elem.siblings('.'+ELEM_SET).children('.'+ELEM_ENTRY)[0]){
|
||||||
//若开启复选框
|
// 若开启复选框
|
||||||
if(options.showCheckbox){
|
if(options.showCheckbox){
|
||||||
//若开启复选框,进行下步操作
|
// 若开启复选框,进行下步操作
|
||||||
var elemDel = function(elem){
|
var elemDel = function(elem){
|
||||||
//若无父结点,则不执行
|
// 若无父结点,则不执行
|
||||||
if(!elem.parents('.'+ELEM_SET)[0]) return;
|
if(!elem.parents('.'+ELEM_SET)[0]) return;
|
||||||
var siblingTree = elem.siblings('.'+ELEM_SET).children('.'+ELEM_ENTRY)
|
var siblingTree = elem.siblings('.'+ELEM_SET).children('.'+ELEM_ENTRY);
|
||||||
,parentTree = elem.parent('.'+ELEM_PACK).prev()
|
var parentTree = elem.parent('.'+ELEM_PACK).prev();
|
||||||
,checkState = parentTree.find('input[same="layuiTreeCheck"]')[0]
|
var checkState = parentTree.find('input[same="layuiTreeCheck"]')[0];
|
||||||
,state = 1, num = 0;
|
var state = 1;
|
||||||
//若父节点未勾选
|
var num = 0;
|
||||||
|
|
||||||
|
// 若父节点未勾选
|
||||||
if(checkState.checked == false){
|
if(checkState.checked == false){
|
||||||
//遍历兄弟节点
|
// 遍历兄弟节点
|
||||||
siblingTree.each(function(i, item1){
|
siblingTree.each(function(i, item1){
|
||||||
var input = $(item1).find('input[same="layuiTreeCheck"]')[0]
|
var input = $(item1).find('input[same="layuiTreeCheck"]')[0]
|
||||||
if(input.checked == false && !input.disabled){
|
if(input.checked == false && !input.disabled){
|
||||||
state = 0;
|
state = 0;
|
||||||
};
|
};
|
||||||
//判断是否全为不可勾选框
|
// 判断是否全为不可勾选框
|
||||||
if(!input.disabled){
|
if(!input.disabled){
|
||||||
num = 1;
|
num = 1;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
//若有可勾选选择框并且已勾选
|
// 若有可勾选选择框并且已勾选
|
||||||
if(state == 1 && num == 1){
|
if(state == 1 && num == 1){
|
||||||
//勾选父节点
|
// 勾选父节点
|
||||||
checkState.checked = true;
|
checkState.checked = true;
|
||||||
that.renderForm('checkbox');
|
that.renderForm('checkbox');
|
||||||
//向上遍历祖先节点
|
// 向上遍历祖先节点
|
||||||
elemDel(parentTree.parent('.'+ELEM_SET));
|
elemDel(parentTree.parent('.'+ELEM_SET));
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
elemDel(elem);
|
elemDel(elem);
|
||||||
};
|
};
|
||||||
//若开启连接线
|
// 若开启连接线
|
||||||
if(options.showLine){
|
if(options.showLine){
|
||||||
//遍历兄弟节点,判断兄弟节点是否有子节点
|
// 遍历兄弟节点,判断兄弟节点是否有子节点
|
||||||
var siblings = elem.siblings('.'+ELEM_SET), num = 1
|
var siblings = elem.siblings('.'+ELEM_SET);
|
||||||
,parentPack = elem.parent('.'+ELEM_PACK);
|
var num = 1;
|
||||||
|
var parentPack = elem.parent('.'+ELEM_PACK);
|
||||||
|
|
||||||
layui.each(siblings, function(index, i){
|
layui.each(siblings, function(index, i){
|
||||||
if(!$(i).children('.'+ELEM_PACK)[0]){
|
if(!$(i).children('.'+ELEM_PACK)[0]){
|
||||||
num = 0;
|
num = 0;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
//若兄弟节点都有子节点
|
// 若兄弟节点都有子节点
|
||||||
if(num == 1){
|
if(num == 1){
|
||||||
//若节点本身无子节点
|
// 若节点本身无子节点
|
||||||
if(!packCont[0]){
|
if(!packCont[0]){
|
||||||
//父级去除延伸线,因为此时子节点里没有空节点
|
// 父级去除延伸线,因为此时子节点里没有空节点
|
||||||
parentPack.removeClass(ELEM_EXTEND);
|
parentPack.removeClass(ELEM_EXTEND);
|
||||||
siblings.children('.'+ELEM_PACK).addClass(ELEM_SHOW);
|
siblings.children('.'+ELEM_PACK).addClass(ELEM_SHOW);
|
||||||
siblings.children('.'+ELEM_PACK).children('.'+ELEM_SET).removeClass(ELEM_LINE_SHORT);
|
siblings.children('.'+ELEM_PACK).children('.'+ELEM_SET).removeClass(ELEM_LINE_SHORT);
|
||||||
};
|
};
|
||||||
//若为最后一个节点
|
// 若为最后一个节点
|
||||||
if(!elem.next()[0]){
|
if(!elem.next()[0]){
|
||||||
elem.prev().children('.'+ELEM_PACK).children('.'+ELEM_SET).last().addClass(ELEM_LINE_SHORT);
|
elem.prev().children('.'+ELEM_PACK).children('.'+ELEM_SET).last().addClass(ELEM_LINE_SHORT);
|
||||||
}else{
|
}else{
|
||||||
parentPack.children('.'+ELEM_SET).last().children('.'+ELEM_PACK).children('.'+ELEM_SET).last().addClass(ELEM_LINE_SHORT);
|
parentPack.children('.'+ELEM_SET).last().children('.'+ELEM_PACK).children('.'+ELEM_SET).last().addClass(ELEM_LINE_SHORT);
|
||||||
};
|
};
|
||||||
//若为最外层最后一个节点,去除前一个结点的连接线
|
// 若为最外层最后一个节点,去除前一个结点的连接线
|
||||||
if(!elem.next()[0] && !elem.parents('.'+ELEM_SET)[1] && !elem.parents('.'+ELEM_SET).eq(0).next()[0]){
|
if(!elem.next()[0] && !elem.parents('.'+ELEM_SET)[1] && !elem.parents('.'+ELEM_SET).eq(0).next()[0]){
|
||||||
elem.prev('.'+ELEM_SET).addClass(ELEM_LINE_SHORT);
|
elem.prev('.'+ELEM_SET).addClass(ELEM_LINE_SHORT);
|
||||||
};
|
};
|
||||||
}else{
|
}else{
|
||||||
//若为最后一个节点且有延伸线
|
// 若为最后一个节点且有延伸线
|
||||||
if(!elem.next()[0] && elem.hasClass(ELEM_LINE_SHORT)){
|
if(!elem.next()[0] && elem.hasClass(ELEM_LINE_SHORT)){
|
||||||
elem.prev().addClass(ELEM_LINE_SHORT);
|
elem.prev().addClass(ELEM_LINE_SHORT);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
}else{
|
} else {
|
||||||
//若无兄弟节点
|
// 若无兄弟节点
|
||||||
var prevDiv = elem.parent('.'+ELEM_PACK).prev();
|
var prevDiv = elem.parent('.'+ELEM_PACK).prev();
|
||||||
//若开启了连接线
|
// 若开启了连接线
|
||||||
if(options.showLine){
|
if(options.showLine){
|
||||||
prevDiv.find('.'+ICON_CLICK).removeClass('layui-tree-icon');
|
prevDiv.find('.'+ICON_CLICK).removeClass('layui-tree-icon');
|
||||||
prevDiv.find('.'+ICON_CLICK).children('.layui-icon').removeClass(ICON_SUB).addClass('layui-icon-file');
|
prevDiv.find('.'+ICON_CLICK).children('.layui-icon').removeClass(ICON_SUB).addClass('layui-icon-file');
|
||||||
//父节点所在层添加延伸线
|
// 父节点所在层添加延伸线
|
||||||
var pare = prevDiv.parents('.'+ELEM_PACK).eq(0);
|
var pare = prevDiv.parents('.'+ELEM_PACK).eq(0);
|
||||||
pare.addClass(ELEM_EXTEND);
|
pare.addClass(ELEM_EXTEND);
|
||||||
|
|
||||||
//兄弟节点最后子节点添加延伸线
|
// 兄弟节点最后子节点添加延伸线
|
||||||
pare.children('.'+ELEM_SET).each(function(){
|
pare.children('.'+ELEM_SET).each(function(){
|
||||||
$(this).children('.'+ELEM_PACK).children('.'+ELEM_SET).last().addClass(ELEM_LINE_SHORT);
|
$(this).children('.'+ELEM_PACK).children('.'+ELEM_SET).last().addClass(ELEM_LINE_SHORT);
|
||||||
});
|
});
|
||||||
}else{
|
}else{
|
||||||
//父节点隐藏箭头
|
// 父节点隐藏箭头
|
||||||
prevDiv.find('.layui-tree-iconArrow').addClass(HIDE);
|
prevDiv.find('.layui-tree-iconArrow').addClass(HIDE);
|
||||||
};
|
};
|
||||||
//移除展开属性
|
// 移除展开属性
|
||||||
elem.parents('.'+ELEM_SET).eq(0).removeClass(ELEM_SPREAD);
|
elem.parents('.'+ELEM_SET).eq(0).removeClass(ELEM_SPREAD);
|
||||||
//移除节点容器
|
// 移除节点容器
|
||||||
elem.parent('.'+ELEM_PACK).remove();
|
elem.parent('.'+ELEM_PACK).remove();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -649,32 +677,32 @@ layui.define('form', function(exports){
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
//部分事件
|
// 部分事件
|
||||||
Class.prototype.events = function(){
|
Class.prototype.events = function(){
|
||||||
var that = this
|
var that = this;
|
||||||
,options = that.config
|
var options = that.config;
|
||||||
,checkWarp = that.elem.find('.layui-tree-checkedFirst');
|
var checkWarp = that.elem.find('.layui-tree-checkedFirst');
|
||||||
|
|
||||||
//初始选中
|
// 初始选中
|
||||||
that.setChecked(that.checkids);
|
that.setChecked(that.checkids);
|
||||||
|
|
||||||
//搜索
|
// 搜索
|
||||||
that.elem.find('.layui-tree-search').on('keyup', function(){
|
that.elem.find('.layui-tree-search').on('keyup', function(){
|
||||||
var input = $(this)
|
var input = $(this);
|
||||||
,val = input.val()
|
var val = input.val();
|
||||||
,pack = input.nextAll()
|
var pack = input.nextAll();
|
||||||
,arr = [];
|
var arr = [];
|
||||||
|
|
||||||
//遍历所有的值
|
// 遍历所有的值
|
||||||
pack.find('.'+ ELEM_TEXT).each(function(){
|
pack.find('.'+ ELEM_TEXT).each(function(){
|
||||||
var entry = $(this).parents('.'+ELEM_ENTRY);
|
var entry = $(this).parents('.'+ELEM_ENTRY);
|
||||||
//若值匹配,加一个类以作标识
|
// 若值匹配,加一个类以作标识
|
||||||
if($(this).html().indexOf(val) != -1){
|
if($(this).html().indexOf(val) != -1){
|
||||||
arr.push($(this).parent());
|
arr.push($(this).parent());
|
||||||
|
|
||||||
var select = function(div){
|
var select = function(div){
|
||||||
div.addClass('layui-tree-searchShow');
|
div.addClass('layui-tree-searchShow');
|
||||||
//向上父节点渲染
|
// 向上父节点渲染
|
||||||
if(div.parent('.'+ELEM_PACK)[0]){
|
if(div.parent('.'+ELEM_PACK)[0]){
|
||||||
select(div.parent('.'+ELEM_PACK).parent('.'+ELEM_SET));
|
select(div.parent('.'+ELEM_PACK).parent('.'+ELEM_SET));
|
||||||
};
|
};
|
||||||
|
@ -683,7 +711,7 @@ layui.define('form', function(exports){
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
//根据标志剔除
|
// 根据标志剔除
|
||||||
pack.find('.'+ELEM_ENTRY).each(function(){
|
pack.find('.'+ELEM_ENTRY).each(function(){
|
||||||
var parent = $(this).parent('.'+ELEM_SET);
|
var parent = $(this).parent('.'+ELEM_SET);
|
||||||
if(!parent.hasClass('layui-tree-searchShow')){
|
if(!parent.hasClass('layui-tree-searchShow')){
|
||||||
|
@ -694,13 +722,13 @@ layui.define('form', function(exports){
|
||||||
that.elem.append(that.elemNone);
|
that.elem.append(that.elemNone);
|
||||||
};
|
};
|
||||||
|
|
||||||
//节点过滤的回调
|
// 节点过滤的回调
|
||||||
options.onsearch && options.onsearch({
|
options.onsearch && options.onsearch({
|
||||||
elem: arr
|
elem: arr
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
//还原搜索初始状态
|
// 还原搜索初始状态
|
||||||
that.elem.find('.layui-tree-search').on('keydown', function(){
|
that.elem.find('.layui-tree-search').on('keydown', function(){
|
||||||
$(this).nextAll().find('.'+ELEM_ENTRY).each(function(){
|
$(this).nextAll().find('.'+ELEM_ENTRY).each(function(){
|
||||||
var parent = $(this).parent('.'+ELEM_SET);
|
var parent = $(this).parent('.'+ELEM_SET);
|
||||||
|
@ -710,23 +738,24 @@ layui.define('form', function(exports){
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
//得到选中节点
|
// 得到选中节点
|
||||||
Class.prototype.getChecked = function(){
|
Class.prototype.getChecked = function(){
|
||||||
var that = this
|
var that = this;
|
||||||
,options = that.config
|
var options = that.config;
|
||||||
,checkId = []
|
var checkId = [];
|
||||||
,checkData = [];
|
var checkData = [];
|
||||||
|
|
||||||
//遍历节点找到选中索引
|
// 遍历节点找到选中索引
|
||||||
that.elem.find('.layui-form-checked').each(function(){
|
that.elem.find('.layui-form-checked').each(function(){
|
||||||
checkId.push($(this).prev()[0].value);
|
checkId.push($(this).prev()[0].value);
|
||||||
});
|
});
|
||||||
|
|
||||||
//遍历节点
|
// 遍历节点
|
||||||
var eachNodes = function(data, checkNode){
|
var eachNodes = function(data, checkNode){
|
||||||
layui.each(data, function(index, item){
|
layui.each(data, function(index, item){
|
||||||
layui.each(checkId, function(index2, item2){
|
layui.each(checkId, function(index2, item2){
|
||||||
if(item.id == item2){
|
if(item.id == item2){
|
||||||
|
item['checked'] = true;
|
||||||
var cloneItem = $.extend({}, item);
|
var cloneItem = $.extend({}, item);
|
||||||
delete cloneItem.children;
|
delete cloneItem.children;
|
||||||
|
|
||||||
|
@ -747,18 +776,18 @@ layui.define('form', function(exports){
|
||||||
return checkData;
|
return checkData;
|
||||||
};
|
};
|
||||||
|
|
||||||
//设置选中节点
|
// 设置选中节点
|
||||||
Class.prototype.setChecked = function(checkedId){
|
Class.prototype.setChecked = function(checkedId){
|
||||||
var that = this
|
var that = this;
|
||||||
,options = that.config;
|
var options = that.config;
|
||||||
|
|
||||||
//初始选中
|
// 初始选中
|
||||||
that.elem.find('.'+ELEM_SET).each(function(i, item){
|
that.elem.find('.'+ELEM_SET).each(function(i, item){
|
||||||
var thisId = $(this).data('id')
|
var thisId = $(this).data('id');
|
||||||
,input = $(item).children('.'+ELEM_ENTRY).find('input[same="layuiTreeCheck"]')
|
var input = $(item).children('.'+ELEM_ENTRY).find('input[same="layuiTreeCheck"]');
|
||||||
,reInput = input.next();
|
var reInput = input.next();
|
||||||
|
|
||||||
//若返回数字
|
// 若返回数字
|
||||||
if(typeof checkedId === 'number'){
|
if(typeof checkedId === 'number'){
|
||||||
if(thisId.toString() == checkedId.toString()){
|
if(thisId.toString() == checkedId.toString()){
|
||||||
if(!input[0].checked){
|
if(!input[0].checked){
|
||||||
|
@ -767,7 +796,7 @@ layui.define('form', function(exports){
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
//若返回数组
|
// 若返回数组
|
||||||
else if(typeof checkedId === 'object'){
|
else if(typeof checkedId === 'object'){
|
||||||
layui.each(checkedId, function(index, value){
|
layui.each(checkedId, function(index, value){
|
||||||
if(value.toString() == thisId.toString() && !input[0].checked){
|
if(value.toString() == thisId.toString() && !input[0].checked){
|
||||||
|
@ -779,11 +808,11 @@ layui.define('form', function(exports){
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
//记录所有实例
|
// 记录所有实例
|
||||||
thisModule.that = {}; //记录所有实例对象
|
thisModule.that = {}; // 记录所有实例对象
|
||||||
thisModule.config = {}; //记录所有实例配置项
|
thisModule.config = {}; // 记录所有实例配置项
|
||||||
|
|
||||||
//重载实例
|
// 重载实例
|
||||||
tree.reload = function(id, options){
|
tree.reload = function(id, options){
|
||||||
var that = thisModule.that[id];
|
var that = thisModule.that[id];
|
||||||
that.reload(options);
|
that.reload(options);
|
||||||
|
@ -791,19 +820,19 @@ layui.define('form', function(exports){
|
||||||
return thisModule.call(that);
|
return thisModule.call(that);
|
||||||
};
|
};
|
||||||
|
|
||||||
//获得选中的节点数据
|
// 获得选中的节点数据
|
||||||
tree.getChecked = function(id){
|
tree.getChecked = function(id){
|
||||||
var that = thisModule.that[id];
|
var that = thisModule.that[id];
|
||||||
return that.getChecked();
|
return that.getChecked();
|
||||||
};
|
};
|
||||||
|
|
||||||
//设置选中节点
|
// 设置选中节点
|
||||||
tree.setChecked = function(id, checkedId){
|
tree.setChecked = function(id, checkedId){
|
||||||
var that = thisModule.that[id];
|
var that = thisModule.that[id];
|
||||||
return that.setChecked(checkedId);
|
return that.setChecked(checkedId);
|
||||||
};
|
};
|
||||||
|
|
||||||
//核心入口
|
// 核心入口
|
||||||
tree.render = function(options){
|
tree.render = function(options){
|
||||||
var inst = new Class(options);
|
var inst = new Class(options);
|
||||||
return thisModule.call(inst);
|
return thisModule.call(inst);
|
||||||
|
|
|
@ -1007,7 +1007,7 @@ layui.define(['table'], function (exports) {
|
||||||
layui.stope(event);
|
layui.stope(event);
|
||||||
// 处理数据
|
// 处理数据
|
||||||
// var trElem = item.closest('tr');
|
// var trElem = item.closest('tr');
|
||||||
expandNode({trElem}, null, null, null, true);
|
expandNode({trElem: trElem}, null, null, null, true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue