2.1.6
This commit is contained in:
@@ -66,6 +66,16 @@ layui.define('jquery', function(exports){
|
||||
return this;
|
||||
};
|
||||
|
||||
//自定义Tab选项卡
|
||||
Element.prototype.tab = function(options){
|
||||
options = options || {};
|
||||
dom.on('click', options.headerElem, function(e){
|
||||
var index = $(this).index();
|
||||
call.tabClick.call(this, e, index, null, options);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
//动态改变进度条
|
||||
Element.prototype.progress = function(filter, percent){
|
||||
var ELEM = 'layui-progress'
|
||||
@@ -84,11 +94,12 @@ layui.define('jquery', function(exports){
|
||||
//基础事件体
|
||||
,call = {
|
||||
//Tab点击
|
||||
tabClick: function(e, index, liElem){
|
||||
tabClick: function(e, index, liElem, options){
|
||||
options = options || {};
|
||||
var othis = liElem || $(this)
|
||||
,index = index || othis.parent().children('li').index(othis)
|
||||
,parents = othis.parents('.layui-tab').eq(0)
|
||||
,item = parents.children('.layui-tab-content').children('.layui-tab-item')
|
||||
,parents = options.headerElem ? othis.parent() : othis.parents('.layui-tab').eq(0)
|
||||
,item = $(options.bodyElem) || parents.children('.layui-tab-content').children('.layui-tab-item')
|
||||
,elemA = othis.find('a')
|
||||
,filter = parents.attr('lay-filter');
|
||||
|
||||
@@ -105,9 +116,10 @@ layui.define('jquery', function(exports){
|
||||
|
||||
//Tab删除
|
||||
,tabDelete: function(e, othis){
|
||||
var li = othis || $(this).parent(), index = li.index();
|
||||
var parents = li.parents('.layui-tab').eq(0);
|
||||
var item = parents.children('.layui-tab-content').children('.layui-tab-item')
|
||||
var li = othis || $(this).parent(), index = li.index()
|
||||
,parents = li.parents('.layui-tab').eq(0)
|
||||
,item = parents.children('.layui-tab-content').children('.layui-tab-item')
|
||||
,filter = parents.attr('lay-filter');
|
||||
|
||||
if(li.hasClass(THIS)){
|
||||
if(li.next()[0]){
|
||||
@@ -122,6 +134,11 @@ layui.define('jquery', function(exports){
|
||||
setTimeout(function(){
|
||||
call.tabAuto();
|
||||
}, 50);
|
||||
|
||||
layui.event.call(this, MOD_NAME, 'tabDelete('+ filter +')', {
|
||||
elem: parents
|
||||
,index: index
|
||||
});
|
||||
}
|
||||
|
||||
//Tab自适应
|
||||
@@ -180,11 +197,12 @@ layui.define('jquery', function(exports){
|
||||
,clickThis: function(){
|
||||
var othis = $(this), parents = othis.parents(NAV_ELEM)
|
||||
,filter = parents.attr('lay-filter')
|
||||
,elemA = othis.find('a');
|
||||
,elemA = othis.find('a')
|
||||
,unselect = typeof othis.attr('lay-unselect') === 'string';
|
||||
|
||||
if(othis.find('.'+NAV_CHILD)[0]) return;
|
||||
|
||||
if(!(elemA.attr('href') !== 'javascript:;' && elemA.attr('target') === '_blank')){
|
||||
if(!(elemA.attr('href') !== 'javascript:;' && elemA.attr('target') === '_blank') && !unselect){
|
||||
parents.find('.'+THIS).removeClass(THIS);
|
||||
othis.addClass(THIS);
|
||||
}
|
||||
@@ -234,8 +252,10 @@ layui.define('jquery', function(exports){
|
||||
};
|
||||
|
||||
//初始化元素操作
|
||||
Element.prototype.init = function(type){
|
||||
var that = this, items = {
|
||||
Element.prototype.init = function(type, filter){
|
||||
var that = this, elemFilter = function(){
|
||||
return filter ? ('[lay-filter="' + filter +'"]') : '';
|
||||
}(), items = {
|
||||
|
||||
//Tab选项卡
|
||||
tab: function(){
|
||||
@@ -278,7 +298,7 @@ layui.define('jquery', function(exports){
|
||||
}
|
||||
}
|
||||
|
||||
$(NAV_ELEM).each(function(index){
|
||||
$(NAV_ELEM + elemFilter).each(function(index){
|
||||
var othis = $(this)
|
||||
,bar = $('<span class="'+ NAV_BAR +'"></span>')
|
||||
,itemElem = othis.find('.'+NAV_ITEM);
|
||||
@@ -337,7 +357,7 @@ layui.define('jquery', function(exports){
|
||||
,breadcrumb: function(){
|
||||
var ELEM = '.layui-breadcrumb';
|
||||
|
||||
$(ELEM).each(function(){
|
||||
$(ELEM + elemFilter).each(function(){
|
||||
var othis = $(this)
|
||||
,separator = othis.attr('lay-separator') || '>'
|
||||
,aNode = othis.find('a');
|
||||
@@ -354,7 +374,7 @@ layui.define('jquery', function(exports){
|
||||
,progress: function(){
|
||||
var ELEM = 'layui-progress';
|
||||
|
||||
$('.'+ELEM).each(function(){
|
||||
$('.' + ELEM + elemFilter).each(function(){
|
||||
var othis = $(this)
|
||||
,elemBar = othis.find('.layui-progress-bar')
|
||||
,width = elemBar.attr('lay-percent');
|
||||
@@ -373,7 +393,7 @@ layui.define('jquery', function(exports){
|
||||
,collapse: function(){
|
||||
var ELEM = 'layui-collapse';
|
||||
|
||||
$('.'+ELEM).each(function(){
|
||||
$('.' + ELEM + elemFilter).each(function(){
|
||||
var elemItem = $(this).find('.layui-colla-item')
|
||||
elemItem.each(function(){
|
||||
var othis = $(this)
|
||||
@@ -393,13 +413,15 @@ layui.define('jquery', function(exports){
|
||||
}
|
||||
};
|
||||
|
||||
return layui.each(items, function(index, item){
|
||||
return items[type] ? items[type]() : layui.each(items, function(index, item){
|
||||
item();
|
||||
});
|
||||
};
|
||||
|
||||
Element.prototype.render = Element.prototype.init;
|
||||
|
||||
var element = new Element(), dom = $(document);
|
||||
element.init();
|
||||
element.render();
|
||||
|
||||
var TITLE = '.layui-tab-title li';
|
||||
dom.on('click', TITLE, call.tabClick); //Tab切换
|
||||
|
||||
@@ -51,15 +51,27 @@ layui.define(function(exports){
|
||||
var that = this, tplog = tpl;
|
||||
var jss = exp('^'+config.open+'#', ''), jsse = exp(config.close+'$', '');
|
||||
|
||||
tpl = tpl.replace(/\s+|\r|\t|\n/g, ' ').replace(exp(config.open+'#'), config.open+'# ')
|
||||
|
||||
tpl = tpl.replace(/\s+|\r|\t|\n/g, ' ')
|
||||
.replace(exp(config.open+'#'), config.open+'# ')
|
||||
.replace(exp(config.close+'}'), '} '+config.close).replace(/\\/g, '\\\\')
|
||||
|
||||
//不匹配指定区域的内容
|
||||
.replace(exp(config.open + '!(.+?)!' + config.close), function(str){
|
||||
str = str.replace(exp('^'+ config.open + '!'), '')
|
||||
.replace(exp('!'+ config.close), '')
|
||||
.replace(exp(config.open + '|' + config.close), function(tag){
|
||||
return tag.replace(/(.)/g, '\\$1')
|
||||
});
|
||||
return str
|
||||
})
|
||||
|
||||
//匹配JS规则内容
|
||||
.replace(/(?="|')/g, '\\').replace(tool.query(), function(str){
|
||||
str = str.replace(jss, '').replace(jsse, '');
|
||||
return '";' + str.replace(/\\/g, '') + ';view+="';
|
||||
})
|
||||
|
||||
//匹配普通字段
|
||||
.replace(tool.query(1), function(str){
|
||||
var start = '"+(';
|
||||
if(str.replace(/\s/g, '') === config.open+config.close){
|
||||
|
||||
@@ -95,13 +95,23 @@ layui.define('jquery', function(exports){
|
||||
|
||||
//某个时间在当前时间的多久前
|
||||
,timeAgo: function(time, onlyDate){
|
||||
var stamp = new Date().getTime() - new Date(time).getTime();
|
||||
var arr = [[], []]
|
||||
,stamp = new Date().getTime() - new Date(time).getTime();
|
||||
|
||||
//超过30天,返回具体日期
|
||||
if(stamp > 1000*60*60*24*30){
|
||||
stamp = new Date(time).toLocaleString();
|
||||
onlyDate && (stamp = stamp.replace(/\s[\S]+$/g, ''));
|
||||
return stamp;
|
||||
//返回具体日期
|
||||
if(stamp > 1000*60*60*24*8){
|
||||
stamp = new Date(time);
|
||||
arr[0][0] = stamp.getFullYear();
|
||||
arr[0][1] = stamp.getMonth() + 1;
|
||||
arr[0][2] = stamp.getDate();
|
||||
|
||||
//是否输出时间
|
||||
if(!onlyDate){
|
||||
arr[1][0] = stamp.getHours();
|
||||
arr[1][1] = stamp.getMinutes();
|
||||
arr[1][2] = stamp.getSeconds();
|
||||
}
|
||||
return arr[0].join('-') + ' ' + arr[1].join(':');
|
||||
}
|
||||
|
||||
//30天以内,返回“多久前”
|
||||
@@ -109,7 +119,7 @@ layui.define('jquery', function(exports){
|
||||
return ((stamp/1000/60/60/24)|0) + '天前';
|
||||
} else if(stamp >= 1000*60*60){
|
||||
return ((stamp/1000/60/60)|0) + '小时前';
|
||||
} else if(stamp >= 1000*60*3){ //3分钟以内为:刚刚
|
||||
} else if(stamp >= 1000*60*2){ //2分钟以内为:刚刚
|
||||
return ((stamp/1000/60)|0) + '分钟前';
|
||||
} else if(stamp < 0){
|
||||
return '未来';
|
||||
|
||||
Reference in New Issue
Block a user