1.0.9
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
@Name:layui.code 代码修饰器
|
||||
@Author:贤心
|
||||
@License:LGPL
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
@Name:layui.element 常用元素操作
|
||||
@Author:贤心
|
||||
@License:LGPL
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
@@ -33,27 +33,34 @@ layui.define('jquery', function(exports){
|
||||
|
||||
//外部Tab新增
|
||||
Element.prototype.tabAdd = function(filter, options){
|
||||
var tabElem = $('.layui-tab[lay-filter='+ filter +']')
|
||||
,titElem = tabElem.children('.layui-tab-title')
|
||||
var TITLE = '.layui-tab-title'
|
||||
,tabElem = $('.layui-tab[lay-filter='+ filter +']')
|
||||
,titElem = tabElem.children(TITLE)
|
||||
,contElem = tabElem.children('.layui-tab-content');
|
||||
titElem.append('<li>'+ (options.title||'unnaming') +'</li>');
|
||||
titElem.append('<li lay-id="'+ (options.id||'') +'">'+ (options.title||'unnaming') +'</li>');
|
||||
contElem.append('<div class="layui-tab-item">'+ (options.content||'') +'</div>');
|
||||
return call.tabAuto(), this;
|
||||
call.hideTabMore(true);
|
||||
call.tabAuto();
|
||||
return this;
|
||||
};
|
||||
|
||||
//外部Tab删除
|
||||
Element.prototype.tabDelete = function(filter, index){
|
||||
var tabElem = $('.layui-tab[lay-filter='+ filter +']')
|
||||
,liElem = tabElem.children('.layui-tab-title').find('>li').eq(index);
|
||||
Element.prototype.tabDelete = function(filter, layid){
|
||||
var TITLE = '.layui-tab-title'
|
||||
,tabElem = $('.layui-tab[lay-filter='+ filter +']')
|
||||
,titElem = tabElem.children(TITLE)
|
||||
,liElem = titElem.find('>li[lay-id="'+ layid +'"]');
|
||||
call.tabDelete(null, liElem);
|
||||
return this;
|
||||
};
|
||||
|
||||
//外部Tab切换
|
||||
Element.prototype.tabChange = function(filter, index){
|
||||
var tabElem = $('.layui-tab[lay-filter='+ filter +']')
|
||||
,liElem = tabElem.children('.layui-tab-title').find('>li').eq(index);
|
||||
call.tabClick(null, index, liElem);
|
||||
Element.prototype.tabChange = function(filter, layid){
|
||||
var TITLE = '.layui-tab-title'
|
||||
,tabElem = $('.layui-tab[lay-filter='+ filter +']')
|
||||
,titElem = tabElem.children(TITLE)
|
||||
,liElem = titElem.find('>li[lay-id="'+ layid +'"]');
|
||||
call.tabClick(null, null, liElem);
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -78,7 +85,7 @@ layui.define('jquery', function(exports){
|
||||
tabClick: function(e, index, liElem){
|
||||
var othis = liElem || $(this)
|
||||
,index = index || othis.index()
|
||||
,parents = othis.parents('.layui-tab')
|
||||
,parents = othis.parents('.layui-tab').eq(0)
|
||||
,item = parents.children('.layui-tab-content').children('.layui-tab-item')
|
||||
,filter = parents.attr('lay-filter');
|
||||
|
||||
@@ -94,7 +101,7 @@ layui.define('jquery', function(exports){
|
||||
//Tab删除
|
||||
,tabDelete: function(e, othis){
|
||||
var li = othis || $(this).parent(), index = li.index();
|
||||
var parents = li.parents('.layui-tab');
|
||||
var parents = li.parents('.layui-tab').eq(0);
|
||||
var item = parents.children('.layui-tab-content').children('.layui-tab-item')
|
||||
|
||||
if(li.hasClass(THIS)){
|
||||
@@ -107,12 +114,15 @@ layui.define('jquery', function(exports){
|
||||
|
||||
li.remove();
|
||||
item.eq(index).remove();
|
||||
setTimeout(function(){
|
||||
call.tabAuto();
|
||||
}, 50);
|
||||
}
|
||||
|
||||
//Tab自适应
|
||||
,tabAuto: function(){
|
||||
var SCROLL = 'layui-tab-scroll', MORE = 'layui-tab-more', BAR = 'layui-tab-bar'
|
||||
, CLOSE = 'layui-tab-close', that = this;
|
||||
,CLOSE = 'layui-tab-close', that = this;
|
||||
|
||||
$('.layui-tab').each(function(){
|
||||
var othis = $(this)
|
||||
@@ -125,6 +135,10 @@ layui.define('jquery', function(exports){
|
||||
call.hideTabMore(true)
|
||||
}
|
||||
|
||||
if(!title[0]){
|
||||
title = othis.children('.'+OVER).children('.layui-tab-title');
|
||||
}
|
||||
|
||||
//允许关闭
|
||||
if(othis.attr('lay-allowClose')){
|
||||
title.find('li').each(function(){
|
||||
@@ -141,12 +155,14 @@ layui.define('jquery', function(exports){
|
||||
if(title.prop('scrollWidth') > title.outerWidth()+1){
|
||||
if(title.find('.'+BAR)[0]) return;
|
||||
title.append(span);
|
||||
othis.attr('overflow', '');
|
||||
span.on('click', function(e){
|
||||
title[this.title ? 'removeClass' : 'addClass'](MORE);
|
||||
this.title = this.title ? '' : '收缩';
|
||||
});
|
||||
} else {
|
||||
title.find('.'+BAR).remove();
|
||||
othis.removeAttr('overflow');
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -158,6 +174,7 @@ layui.define('jquery', function(exports){
|
||||
tsbTitle.find('.layui-tab-bar').attr('title','');
|
||||
}
|
||||
}
|
||||
|
||||
//点击选中
|
||||
,clickThis: function(){
|
||||
var othis = $(this), parents = othis.parents(NAV_ELEM)
|
||||
@@ -185,6 +202,29 @@ layui.define('jquery', function(exports){
|
||||
parent[child.css('display') === 'none' ? 'addClass': 'removeClass'](NAV_ITEM+'ed');
|
||||
}
|
||||
}
|
||||
|
||||
//折叠面板
|
||||
,collapse: function(){
|
||||
var othis = $(this), icon = othis.find('.layui-colla-icon')
|
||||
,elemCont = othis.siblings('.layui-colla-content')
|
||||
,parents = othis.parents('.layui-collapse').eq(0)
|
||||
,filter = parents.attr('lay-filter')
|
||||
,display = elemCont.css('display') === 'none';
|
||||
//是否手风琴
|
||||
if(typeof parents.attr('lay-accordion') === 'string'){
|
||||
var show = parents.children('.layui-colla-item').children('.'+SHOW);
|
||||
show.siblings('.layui-colla-title').children('.layui-colla-icon').html('');
|
||||
show.removeClass(SHOW);
|
||||
}
|
||||
elemCont[display ? 'addClass' : 'removeClass'](SHOW);
|
||||
icon.html(display ? '' : '');
|
||||
|
||||
layui.event.call(this, MOD_NAME, 'collapse('+ filter +')', {
|
||||
title: othis
|
||||
,content: elemCont
|
||||
,show: display
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
//初始化元素操作
|
||||
@@ -320,6 +360,28 @@ layui.define('jquery', function(exports){
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//折叠面板
|
||||
,collapse: function(){
|
||||
var ELEM = 'layui-collapse';
|
||||
|
||||
$('.'+ELEM).each(function(){
|
||||
var elemItem = $(this).find('.layui-colla-item')
|
||||
elemItem.each(function(){
|
||||
var othis = $(this)
|
||||
,elemTitle = othis.find('.layui-colla-title')
|
||||
,elemCont = othis.find('.layui-colla-content');
|
||||
|
||||
//初始状态
|
||||
elemTitle.find('.layui-colla-icon').remove();
|
||||
elemTitle.append('<i class="layui-icon layui-colla-icon">'+ (elemCont.css('display') === 'none' ? '' : '') +'</i>');
|
||||
|
||||
//点击标题
|
||||
elemTitle.off('click', call.collapse).on('click', call.collapse);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return layui.each(items, function(index, item){
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
@Name:layui.flow 流加载
|
||||
@Author:贤心
|
||||
@License:LGPL
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ layui.define('layer', function(exports){
|
||||
,hint = layui.hint()
|
||||
,device = layui.device()
|
||||
|
||||
,MOD_NAME = 'form', ELEM = '.layui-form', THIS = 'layui-this', SHOW = 'layui-show', DISABLED = 'layui-disabled'
|
||||
,MOD_NAME = 'form', ELEM = '.layui-form', THIS = 'layui-this', SHOW = 'layui-show', HIDE = 'layui-hide', DISABLED = 'layui-disabled'
|
||||
|
||||
,Form = function(){
|
||||
this.config = {
|
||||
@@ -73,9 +73,11 @@ layui.define('layer', function(exports){
|
||||
//表单控件渲染
|
||||
Form.prototype.render = function(type){
|
||||
var that = this, items = {
|
||||
|
||||
//下拉选择框
|
||||
select: function(){
|
||||
var TIPS = '请选择', CLASS = 'layui-form-select', TITLE = 'layui-select-title'
|
||||
,NONE = 'layui-select-none', initValue = ''
|
||||
|
||||
,selects = $(ELEM).find('select'), hide = function(e, clear){
|
||||
if(!$(e.target).parent().hasClass(TITLE) || clear){
|
||||
@@ -83,31 +85,99 @@ layui.define('layer', function(exports){
|
||||
}
|
||||
}
|
||||
|
||||
,events = function(reElem, disabled){
|
||||
var select = $(this), title = reElem.find('.' + TITLE);
|
||||
,events = function(reElem, disabled, isSearch){
|
||||
var select = $(this)
|
||||
,title = reElem.find('.' + TITLE)
|
||||
,input = title.find('input')
|
||||
,dl = reElem.find('dl')
|
||||
,dds = dl.children('dd')
|
||||
|
||||
|
||||
if(disabled) return;
|
||||
|
||||
//展开下拉
|
||||
var showDown = function(){
|
||||
reElem.addClass(CLASS+'ed');
|
||||
initValue = input.val();
|
||||
dds.removeClass(HIDE);
|
||||
}, hideDown = function(){
|
||||
reElem.removeClass(CLASS+'ed');
|
||||
input.blur();
|
||||
};
|
||||
|
||||
//点击标题区域
|
||||
title.on('click', function(e){
|
||||
reElem.hasClass(CLASS+'ed') ? reElem.removeClass(CLASS+'ed') : (
|
||||
reElem.hasClass(CLASS+'ed') ? (
|
||||
hideDown()
|
||||
) : (
|
||||
hide(e, true),
|
||||
reElem.addClass(CLASS+'ed')
|
||||
showDown()
|
||||
);
|
||||
dl.find('.'+NONE).remove();
|
||||
});
|
||||
|
||||
//点击箭头获取焦点
|
||||
title.find('.layui-edge').on('click', function(){
|
||||
input.focus();
|
||||
});
|
||||
|
||||
//键盘事件
|
||||
input.on('keyup', function(e){
|
||||
var keyCode = e.keyCode;
|
||||
//Tab键
|
||||
if(keyCode === 9){
|
||||
showDown();
|
||||
}
|
||||
}).on('keydown', function(e){
|
||||
var keyCode = e.keyCode;
|
||||
//Tab键
|
||||
if(keyCode === 9){
|
||||
hideDown();
|
||||
} else if(keyCode === 13){ //回车键
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
//搜索匹配
|
||||
if(isSearch){
|
||||
var search = function(e){
|
||||
var value = this.value, num = 0, keyCode = e.keyCode;
|
||||
|
||||
if(keyCode === 9 || keyCode === 13 || keyCode === 37 || keyCode === 38 || keyCode === 39 || keyCode === 40){
|
||||
return false;
|
||||
}
|
||||
|
||||
layui.each(dds, function(){
|
||||
var othis = $(this), not = othis.text().indexOf(value) === -1;
|
||||
if(not) num++;
|
||||
othis[not ? 'addClass' : 'removeClass'](HIDE);
|
||||
});
|
||||
|
||||
if(num === dds.length){
|
||||
dl.find('.'+NONE)[0] || dl.append('<p class="'+ NONE +'">无匹配项</p>');
|
||||
} else {
|
||||
dl.find('.'+NONE).remove();
|
||||
}
|
||||
};
|
||||
input.on('keyup', search).on('blur', function(){
|
||||
input.val(initValue);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//选择
|
||||
reElem.find('dl>dd').on('click', function(){
|
||||
dds.on('click', function(){
|
||||
var othis = $(this), value = othis.attr('lay-value');
|
||||
var filter = select.attr('lay-filter'); //获取过滤器
|
||||
|
||||
if(othis.hasClass(DISABLED)) return false;
|
||||
|
||||
select.val(value).removeClass('layui-form-danger'), title.find('input').val(othis.text());
|
||||
select.val(value).removeClass('layui-form-danger'), input.val(othis.text());
|
||||
othis.addClass(THIS).siblings().removeClass(THIS);
|
||||
layui.event(MOD_NAME, 'select('+ filter +')', {
|
||||
layui.event.call(this, MOD_NAME, 'select('+ filter +')', {
|
||||
elem: select[0]
|
||||
,value: value
|
||||
,othis: reElem
|
||||
});
|
||||
});
|
||||
|
||||
@@ -116,16 +186,20 @@ layui.define('layer', function(exports){
|
||||
});
|
||||
|
||||
//关闭下拉
|
||||
$(document).off('click', hide).on('click', hide)
|
||||
$(document).off('click', hide).on('click', hide);
|
||||
}
|
||||
|
||||
selects.each(function(index, select){
|
||||
var othis = $(this), hasRender = othis.next('.'+CLASS), disabled = this.disabled;
|
||||
var value = select.value, selected = $(select.options[select.selectedIndex]); //获取当前选中项
|
||||
|
||||
if(typeof othis.attr('lay-ignore') === 'string') return othis.show();
|
||||
|
||||
var isSearch = typeof othis.attr('lay-search') === 'string';
|
||||
|
||||
//替代元素
|
||||
var reElem = $(['<div class="layui-unselect '+ CLASS + (disabled ? ' layui-select-disabled' : '') +'">'
|
||||
,'<div class="'+ TITLE +'"><input type="text" placeholder="'+ (select.options[0].innerHTML ? select.options[0].innerHTML : TIPS) +'" value="'+ (value ? selected.html() : '') +'" readonly class="layui-input layui-unselect'+ (disabled ? (' '+DISABLED) : '') +'">'
|
||||
,'<div class="'+ TITLE +'"><input type="text" placeholder="'+ (select.options[0].innerHTML ? select.options[0].innerHTML : TIPS) +'" value="'+ (value ? selected.html() : '') +'" '+ (isSearch ? '' : 'readonly') +' class="layui-input layui-unselect'+ (disabled ? (' '+DISABLED) : '') +'">'
|
||||
,'<i class="layui-edge"></i></div>'
|
||||
,'<dl class="layui-anim layui-anim-upbit'+ (othis.find('optgroup')[0] ? ' layui-select-group' : '') +'">'+ function(options){
|
||||
var arr = [];
|
||||
@@ -143,7 +217,7 @@ layui.define('layer', function(exports){
|
||||
|
||||
hasRender[0] && hasRender.remove(); //如果已经渲染,则Rerender
|
||||
othis.after(reElem);
|
||||
events.call(this, reElem, disabled);
|
||||
events.call(this, reElem, disabled, isSearch);
|
||||
});
|
||||
}
|
||||
//复选框/开关
|
||||
@@ -159,36 +233,42 @@ layui.define('layer', function(exports){
|
||||
|
||||
//勾选
|
||||
reElem.on('click', function(){
|
||||
var filter = check.attr('lay-filter'); //获取过滤器
|
||||
var filter = check.attr('lay-filter') //获取过滤器
|
||||
,text = (check.attr('lay-text')||'').split('|');
|
||||
|
||||
if(check[0].disabled) return;
|
||||
|
||||
check[0].checked ? (
|
||||
check[0].checked = false
|
||||
,reElem.removeClass(RE_CLASS[1])
|
||||
,reElem.removeClass(RE_CLASS[1]).find('em').text(text[1])
|
||||
) : (
|
||||
check[0].checked = true
|
||||
,reElem.addClass(RE_CLASS[1])
|
||||
,reElem.addClass(RE_CLASS[1]).find('em').text(text[0])
|
||||
);
|
||||
layui.event(MOD_NAME, RE_CLASS[2]+'('+ filter +')', {
|
||||
|
||||
layui.event.call(check[0], MOD_NAME, RE_CLASS[2]+'('+ filter +')', {
|
||||
elem: check[0]
|
||||
,value: check[0].value
|
||||
,othis: reElem
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
checks.each(function(index, check){
|
||||
var othis = $(this), skin = othis.attr('lay-skin'), disabled = this.disabled;
|
||||
var othis = $(this), skin = othis.attr('lay-skin')
|
||||
,text = (othis.attr('lay-text')||'').split('|'), disabled = this.disabled;
|
||||
if(skin === 'switch') skin = '_'+skin;
|
||||
var RE_CLASS = CLASS[skin] || CLASS.checkbox;
|
||||
|
||||
if(typeof othis.attr('lay-ignore') === 'string') return othis.show();
|
||||
|
||||
//替代元素
|
||||
var hasRender = othis.next('.' + RE_CLASS[0]);
|
||||
var reElem = $(['<div class="layui-unselect '+ RE_CLASS[0] + (
|
||||
check.checked ? (' '+RE_CLASS[1]) : '') + (disabled ? ' layui-checkbox-disbaled '+DISABLED : '') +'">'
|
||||
check.checked ? (' '+RE_CLASS[1]) : '') + (disabled ? ' layui-checkbox-disbaled '+DISABLED : '') +'" lay-skin="'+ (skin||'') +'">'
|
||||
,{
|
||||
_switch: '<i></i>'
|
||||
}[skin] || ('<span>'+ (check.title || '勾选') +'</span><i class="layui-icon"></i>')
|
||||
_switch: '<em>'+ ((check.checked ? text[0] : text[1])||'') +'</em><i></i>'
|
||||
}[skin] || ('<span>'+ (check.title || '勾选') +'</span><i class="layui-icon">'+ (skin ? '' : '') +'</i>')
|
||||
,'</div>'].join(''));
|
||||
|
||||
hasRender[0] && hasRender.remove(); //如果已经渲染,则Rerender
|
||||
@@ -222,9 +302,10 @@ layui.define('layer', function(exports){
|
||||
reElem.addClass(CLASS+'ed');
|
||||
reElem.find('.layui-icon').addClass(ANIM).html(ICON[0]);
|
||||
|
||||
layui.event(MOD_NAME, 'radio('+ filter +')', {
|
||||
layui.event.call(radio[0], MOD_NAME, 'radio('+ filter +')', {
|
||||
elem: radio[0]
|
||||
,value: radio[0].value
|
||||
,othis: reElem
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -232,6 +313,8 @@ layui.define('layer', function(exports){
|
||||
radios.each(function(index, radio){
|
||||
var othis = $(this), hasRender = othis.next('.' + CLASS), disabled = this.disabled;
|
||||
|
||||
if(typeof othis.attr('lay-ignore') === 'string') return othis.show();
|
||||
|
||||
//替代元素
|
||||
var reElem = $(['<div class="layui-unselect '+ CLASS + (radio.checked ? (' '+CLASS+'ed') : '') + (disabled ? ' layui-radio-disbaled '+DISABLED : '') +'">'
|
||||
,'<i class="layui-anim layui-icon">'+ ICON[radio.checked ? 0 : 1] +'</i>'
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
@Name:layui.layedit 富文本编辑器
|
||||
@Author:贤心
|
||||
@License:LGPL
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
@Name : layui.laypage 分页组件
|
||||
@Author:贤心
|
||||
@License:LGPL
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
@Name : layui.laytpl 模板引擎
|
||||
@Author:贤心
|
||||
@License:LGPL
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
@Name:layer mobile v2.0 弹层组件移动版
|
||||
@Author:贤心
|
||||
@Site:http://layer.layui.com/mobie/
|
||||
@License:LGPL
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
@Title: layui.upload 单文件上传 - 全浏览器兼容版
|
||||
@Author: 贤心
|
||||
@License:LGPL
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
@Name:layui.tree 树组件
|
||||
@Author:贤心
|
||||
@License:LGPL
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
@Title: layui.upload 单文件上传 - 全浏览器兼容版
|
||||
@Author: 贤心
|
||||
@License:LGPL
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
@Name:layui.util 工具集
|
||||
@Author:贤心
|
||||
@License:LGPL
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user