mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-20 02:29:24 +08:00
update layui to 2.1.5
This commit is contained in:
@@ -1,304 +1,2 @@
|
||||
/**
|
||||
|
||||
@Name : layui.laypage 分页组件
|
||||
@Author:贤心
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define(function(exports){
|
||||
"use strict";
|
||||
|
||||
var doc = document
|
||||
,id = 'getElementById'
|
||||
,tag = 'getElementsByTagName'
|
||||
|
||||
//字符常量
|
||||
,MOD_NAME = 'laypage', DISABLED = 'layui-disabled'
|
||||
|
||||
//构造器
|
||||
,Class = function(options){
|
||||
var that = this;
|
||||
that.config = options || {};
|
||||
that.config.index = ++laypage.index;
|
||||
that.render(true);
|
||||
};
|
||||
|
||||
//判断传入的容器类型
|
||||
Class.prototype.type = function(){
|
||||
var config = this.config;
|
||||
if(typeof config.elem === 'object'){
|
||||
return config.elem.length === undefined ? 2 : 3;
|
||||
}
|
||||
};
|
||||
|
||||
//分页视图
|
||||
Class.prototype.view = function(){
|
||||
var that = this
|
||||
,config = that.config
|
||||
,groups = config.groups = 'groups' in config ? (config.groups|0) : 5; //连续页码个数
|
||||
|
||||
//排版
|
||||
config.layout = typeof config.layout === 'object'
|
||||
? config.layout
|
||||
: ['prev', 'page', 'next'];
|
||||
|
||||
config.count = config.count|0; //数据总数
|
||||
config.curr = (config.curr|0) || 1; //当前页
|
||||
|
||||
//每页条数的选择项
|
||||
config.limits = typeof config.limits === 'object'
|
||||
? config.limits
|
||||
: [10, 20, 30, 40, 50];
|
||||
config.limit = (config.limit|0) || 10; //默认条数
|
||||
|
||||
//总页数
|
||||
config.pages = Math.ceil(config.count/config.limit) || 1;
|
||||
|
||||
//当前页不能超过总页数
|
||||
if(config.curr > config.pages){
|
||||
config.curr = config.pages;
|
||||
}
|
||||
|
||||
//连续分页个数不能低于0且不能大于总页数
|
||||
if(groups < 0){
|
||||
groups = 1;
|
||||
} else if (groups > config.pages){
|
||||
groups = config.pages;
|
||||
}
|
||||
|
||||
config.prev = 'prev' in config ? config.prev : '上一页'; //上一页文本
|
||||
config.next = 'next' in config ? config.next : '下一页'; //下一页文本
|
||||
|
||||
//计算当前组
|
||||
var index = config.pages > groups
|
||||
? Math.ceil( (config.curr + (groups > 1 ? 1 : 0)) / (groups > 0 ? groups : 1) )
|
||||
: 1
|
||||
|
||||
//试图片段
|
||||
,views = {
|
||||
//上一页
|
||||
prev: function(){
|
||||
return config.prev
|
||||
? '<a href="javascript:;" class="layui-laypage-prev'+ (config.curr == 1 ? (' ' + DISABLED) : '') +'" data-page="'+ (config.curr - 1) +'">'+ config.prev +'</a>'
|
||||
: '';
|
||||
}()
|
||||
|
||||
//页码
|
||||
,page: function(){
|
||||
var pager = [];
|
||||
|
||||
//数据量为0时,不输出页码
|
||||
if(config.count < 1){
|
||||
return '';
|
||||
}
|
||||
|
||||
//首页
|
||||
if(index > 1 && config.first !== false && groups !== 0){
|
||||
pager.push('<a href="javascript:;" class="layui-laypage-first" data-page="1" title="首页">'+ (config.first || 1) +'</a>');
|
||||
}
|
||||
|
||||
//计算当前页码组的起始页
|
||||
var halve = Math.floor((groups-1)/2) //页码数等分
|
||||
,start = index > 1 ? config.curr - halve : 1
|
||||
,end = index > 1 ? (function(){
|
||||
var max = config.curr + (groups - halve - 1);
|
||||
return max > config.pages ? config.pages : max;
|
||||
}()) : groups;
|
||||
|
||||
//防止最后一组出现“不规定”的连续页码数
|
||||
if(end - start < groups - 1){
|
||||
start = end - groups + 1;
|
||||
}
|
||||
|
||||
//输出左分割符
|
||||
if(config.first !== false && start > 2){
|
||||
pager.push('<span class="layui-laypage-spr">…</span>')
|
||||
}
|
||||
|
||||
//输出连续页码
|
||||
for(; start <= end; start++){
|
||||
if(start === config.curr){
|
||||
//当前页
|
||||
pager.push('<span class="layui-laypage-curr"><em class="layui-laypage-em" '+ (/^#/.test(config.theme) ? 'style="background-color:'+ config.theme +';"' : '') +'></em><em>'+ start +'</em></span>');
|
||||
} else {
|
||||
pager.push('<a href="javascript:;" data-page="'+ start +'">'+ start +'</a>');
|
||||
}
|
||||
}
|
||||
|
||||
//输出输出右分隔符 & 末页
|
||||
if(config.pages > groups && config.pages > end && config.last !== false){
|
||||
if(end + 1 < config.pages){
|
||||
pager.push('<span class="layui-laypage-spr">…</span>');
|
||||
}
|
||||
if(groups !== 0){
|
||||
pager.push('<a href="javascript:;" class="layui-laypage-last" title="尾页" data-page="'+ config.pages +'">'+ (config.last || config.pages) +'</a>');
|
||||
}
|
||||
}
|
||||
|
||||
return pager.join('');
|
||||
}()
|
||||
|
||||
//下一页
|
||||
,next: function(){
|
||||
return config.next
|
||||
? '<a href="javascript:;" class="layui-laypage-next'+ (config.curr == config.pages ? (' ' + DISABLED) : '') +'" data-page="'+ (config.curr + 1) +'">'+ config.next +'</a>'
|
||||
: '';
|
||||
}()
|
||||
|
||||
//数据总数
|
||||
,count: '<span class="layui-laypage-count">共 '+ config.count +' 条</span>'
|
||||
|
||||
//每页条数
|
||||
,limit: function(){
|
||||
var options = ['<span class="layui-laypage-limits"><select lay-ignore>'];
|
||||
layui.each(config.limits, function(index, item){
|
||||
options.push(
|
||||
'<option value="'+ item +'"'
|
||||
+(item === config.limit ? 'selected' : '')
|
||||
+'>'+ item +' 条/页</option>'
|
||||
);
|
||||
});
|
||||
return options.join('') +'</select></span>';
|
||||
}()
|
||||
|
||||
//跳页区域
|
||||
,skip: function(){
|
||||
return ['<span class="layui-laypage-skip">到第'
|
||||
,'<input type="text" min="1" value="'+ config.curr +'" class="layui-input">'
|
||||
,'页<button type="button" class="layui-laypage-btn">确定</button>'
|
||||
,'</span>'].join('');
|
||||
}()
|
||||
};
|
||||
|
||||
return ['<div class="layui-box layui-laypage layui-laypage-'+ (config.theme ? (
|
||||
/^#/.test(config.theme) ? 'molv' : config.theme
|
||||
) : 'default') +'" id="layui-laypage-'+ config.index +'">'
|
||||
,function(){
|
||||
var plate = [];
|
||||
layui.each(config.layout, function(index, item){
|
||||
if(views[item]){
|
||||
plate.push(views[item])
|
||||
}
|
||||
});
|
||||
return plate.join('');
|
||||
}()
|
||||
,'</div>'].join('');
|
||||
};
|
||||
|
||||
//跳页的回调
|
||||
Class.prototype.jump = function(elem, isskip){
|
||||
if(!elem) return;
|
||||
var that = this
|
||||
,config = that.config
|
||||
,childs = elem.children
|
||||
,btn = elem[tag]('button')[0]
|
||||
,input = elem[tag]('input')[0]
|
||||
,select = elem[tag]('select')[0]
|
||||
,skip = function(){
|
||||
var curr = input.value.replace(/\s|\D/g, '')|0;
|
||||
if(curr){
|
||||
config.curr = curr;
|
||||
that.render();
|
||||
}
|
||||
};
|
||||
|
||||
if(isskip) return skip();
|
||||
|
||||
//页码
|
||||
for(var i = 0, len = childs.length; i < len; i++){
|
||||
if(childs[i].nodeName.toLowerCase() === 'a'){
|
||||
laypage.on(childs[i], 'click', function(){
|
||||
var curr = this.getAttribute('data-page')|0;
|
||||
if(curr < 1 || curr > config.pages) return;
|
||||
config.curr = curr;
|
||||
that.render();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//条数
|
||||
if(select){
|
||||
laypage.on(select, 'change', function(){
|
||||
var value = this.value;
|
||||
if(config.curr*value > config.count){
|
||||
config.curr = Math.ceil(config.count/value);
|
||||
}
|
||||
config.limit = value;
|
||||
that.render();
|
||||
});
|
||||
}
|
||||
|
||||
//确定
|
||||
if(btn){
|
||||
laypage.on(btn, 'click', function(){
|
||||
skip();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
//输入页数字控制
|
||||
Class.prototype.skip = function(elem){
|
||||
if(!elem) return;
|
||||
var that = this, input = elem[tag]('input')[0];
|
||||
if(!input) return;
|
||||
laypage.on(input, 'keyup', function(e){
|
||||
var value = this.value
|
||||
,keyCode = e.keyCode;
|
||||
if(/^(37|38|39|40)$/.test(keyCode)) return;
|
||||
if(/\D/.test(value)){
|
||||
this.value = value.replace(/\D/, '');
|
||||
}
|
||||
if(keyCode === 13){
|
||||
that.jump(elem, true)
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
//渲染分页
|
||||
Class.prototype.render = function(load){
|
||||
var that = this
|
||||
,config = that.config
|
||||
,type = that.type()
|
||||
,view = that.view();
|
||||
|
||||
if(type === 2){
|
||||
config.elem && (config.elem.innerHTML = view);
|
||||
} else if(type === 3){
|
||||
config.elem.html(view);
|
||||
} else {
|
||||
if(doc[id](config.elem)){
|
||||
doc[id](config.elem).innerHTML = view;
|
||||
}
|
||||
}
|
||||
|
||||
config.jump && config.jump(config, load);
|
||||
|
||||
var elem = doc[id]('layui-laypage-' + config.index);
|
||||
that.jump(elem);
|
||||
|
||||
if(config.hash && !load){
|
||||
location.hash = '!'+ config.hash +'='+ config.curr;
|
||||
}
|
||||
|
||||
that.skip(elem);
|
||||
};
|
||||
|
||||
//外部接口
|
||||
var laypage = {
|
||||
//分页渲染
|
||||
render: function(options){
|
||||
var o = new Class(options);
|
||||
return o.index;
|
||||
}
|
||||
,index: layui.laypage ? (layui.laypage.index + 10000) : 0
|
||||
,on: function(elem, even, fn){
|
||||
elem.attachEvent ? elem.attachEvent('on'+ even, function(e){
|
||||
fn.call(elem, e); //for ie
|
||||
}) : elem.addEventListener(even, fn, false);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
exports(MOD_NAME, laypage);
|
||||
});
|
||||
/** layui-v2.1.5 MIT License By http://www.layui.com */
|
||||
;layui.define(function(e){"use strict";var a=document,t="getElementById",n="getElementsByTagName",i="laypage",r="layui-disabled",u=function(e){var a=this;a.config=e||{},a.config.index=++s.index,a.render(!0)};u.prototype.type=function(){var e=this.config;if("object"==typeof e.elem)return void 0===e.elem.length?2:3},u.prototype.view=function(){var e=this,a=e.config,t=a.groups="groups"in a?0|a.groups:5;a.layout="object"==typeof a.layout?a.layout:["prev","page","next"],a.count=0|a.count,a.curr=0|a.curr||1,a.limits="object"==typeof a.limits?a.limits:[10,20,30,40,50],a.limit=0|a.limit||10,a.pages=Math.ceil(a.count/a.limit)||1,a.curr>a.pages&&(a.curr=a.pages),t<0?t=1:t>a.pages&&(t=a.pages),a.prev="prev"in a?a.prev:"上一页",a.next="next"in a?a.next:"下一页";var n=a.pages>t?Math.ceil((a.curr+(t>1?1:0))/(t>0?t:1)):1,i={prev:function(){return a.prev?'<a href="javascript:;" class="layui-laypage-prev'+(1==a.curr?" "+r:"")+'" data-page="'+(a.curr-1)+'">'+a.prev+"</a>":""}(),page:function(){var e=[];if(a.count<1)return"";n>1&&a.first!==!1&&0!==t&&e.push('<a href="javascript:;" class="layui-laypage-first" data-page="1" title="首页">'+(a.first||1)+"</a>");var i=Math.floor((t-1)/2),r=n>1?a.curr-i:1,u=n>1?function(){var e=a.curr+(t-i-1);return e>a.pages?a.pages:e}():t;for(u-r<t-1&&(r=u-t+1),a.first!==!1&&r>2&&e.push('<span class="layui-laypage-spr">…</span>');r<=u;r++)r===a.curr?e.push('<span class="layui-laypage-curr"><em class="layui-laypage-em" '+(/^#/.test(a.theme)?'style="background-color:'+a.theme+';"':"")+"></em><em>"+r+"</em></span>"):e.push('<a href="javascript:;" data-page="'+r+'">'+r+"</a>");return a.pages>t&&a.pages>u&&a.last!==!1&&(u+1<a.pages&&e.push('<span class="layui-laypage-spr">…</span>'),0!==t&&e.push('<a href="javascript:;" class="layui-laypage-last" title="尾页" data-page="'+a.pages+'">'+(a.last||a.pages)+"</a>")),e.join("")}(),next:function(){return a.next?'<a href="javascript:;" class="layui-laypage-next'+(a.curr==a.pages?" "+r:"")+'" data-page="'+(a.curr+1)+'">'+a.next+"</a>":""}(),count:'<span class="layui-laypage-count">共 '+a.count+" 条</span>",limit:function(){var e=['<span class="layui-laypage-limits"><select lay-ignore>'];return layui.each(a.limits,function(t,n){e.push('<option value="'+n+'"'+(n===a.limit?"selected":"")+">"+n+" 条/页</option>")}),e.join("")+"</select></span>"}(),skip:function(){return['<span class="layui-laypage-skip">到第','<input type="text" min="1" value="'+a.curr+'" class="layui-input">','页<button type="button" class="layui-laypage-btn">确定</button>',"</span>"].join("")}()};return['<div class="layui-box layui-laypage layui-laypage-'+(a.theme?/^#/.test(a.theme)?"molv":a.theme:"default")+'" id="layui-laypage-'+a.index+'">',function(){var e=[];return layui.each(a.layout,function(a,t){i[t]&&e.push(i[t])}),e.join("")}(),"</div>"].join("")},u.prototype.jump=function(e,a){if(e){var t=this,i=t.config,r=e.children,u=e[n]("button")[0],l=e[n]("input")[0],p=e[n]("select")[0],c=function(){var e=0|l.value.replace(/\s|\D/g,"");e&&(i.curr=e,t.render())};if(a)return c();for(var o=0,y=r.length;o<y;o++)"a"===r[o].nodeName.toLowerCase()&&s.on(r[o],"click",function(){var e=0|this.getAttribute("data-page");e<1||e>i.pages||(i.curr=e,t.render())});p&&s.on(p,"change",function(){var e=this.value;i.curr*e>i.count&&(i.curr=Math.ceil(i.count/e)),i.limit=e,t.render()}),u&&s.on(u,"click",function(){c()})}},u.prototype.skip=function(e){if(e){var a=this,t=e[n]("input")[0];t&&s.on(t,"keyup",function(t){var n=this.value,i=t.keyCode;/^(37|38|39|40)$/.test(i)||(/\D/.test(n)&&(this.value=n.replace(/\D/,"")),13===i&&a.jump(e,!0))})}},u.prototype.render=function(e){var n=this,i=n.config,r=n.type(),u=n.view();2===r?i.elem&&(i.elem.innerHTML=u):3===r?i.elem.html(u):a[t](i.elem)&&(a[t](i.elem).innerHTML=u),i.jump&&i.jump(i,e);var s=a[t]("layui-laypage-"+i.index);n.jump(s),i.hash&&!e&&(location.hash="!"+i.hash+"="+i.curr),n.skip(s)};var s={render:function(e){var a=new u(e);return a.index},index:layui.laypage?layui.laypage.index+1e4:0,on:function(e,a,t){return e.attachEvent?e.attachEvent("on"+a,function(a){t.call(e,a)}):e.addEventListener(a,t,!1),this}};e(i,s)});
|
Reference in New Issue
Block a user