|
|
|
@ -19,7 +19,7 @@ layui.define('jquery', function(exports){
|
|
|
|
|
options = $.extend(true, {
|
|
|
|
|
target: 'body', // fixbar 的插入目标选择器
|
|
|
|
|
bars: [], // bar 信息
|
|
|
|
|
default: true, // 是否显示默认 bar
|
|
|
|
|
"default": true, // 是否显示默认 bar
|
|
|
|
|
margin: 160, // 出现 top bar 的滚动条高度临界值
|
|
|
|
|
duration: 320 // top bar 等动画时长(毫秒)
|
|
|
|
|
}, options);
|
|
|
|
@ -33,7 +33,7 @@ layui.define('jquery', function(exports){
|
|
|
|
|
: $(options.target === 'body' ? $doc : $target)
|
|
|
|
|
|
|
|
|
|
// 是否提供默认图标
|
|
|
|
|
if(options.default){
|
|
|
|
|
if(options['default']){
|
|
|
|
|
// 兼容旧版本的一些属性
|
|
|
|
|
if(options.bar1){
|
|
|
|
|
options.bars.push({
|
|
|
|
@ -254,35 +254,71 @@ layui.define('jquery', function(exports){
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 转化为日期格式字符
|
|
|
|
|
toDateString: function(time, format){
|
|
|
|
|
//若 null 或空字符,则返回空字符
|
|
|
|
|
toDateString: function(time, format, options){
|
|
|
|
|
// 若 null 或空字符,则返回空字符
|
|
|
|
|
if(time === null || time === '') return '';
|
|
|
|
|
|
|
|
|
|
var that = this
|
|
|
|
|
,date = new Date(function(){
|
|
|
|
|
|
|
|
|
|
// 引用自 dayjs
|
|
|
|
|
// https://github.com/iamkun/dayjs/blob/v1.11.9/src/constant.js#L30
|
|
|
|
|
var REGEX_FORMAT = /\[([^\]]+)]|y{1,4}|M{1,2}|d{1,2}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|SSS/g;
|
|
|
|
|
var that = this;
|
|
|
|
|
var date = new Date(function(){
|
|
|
|
|
if(!time) return;
|
|
|
|
|
return isNaN(time) ? time : (typeof time === 'string' ? parseInt(time) : time)
|
|
|
|
|
}() || new Date())
|
|
|
|
|
,ymd = [
|
|
|
|
|
that.digit(date.getFullYear(), 4)
|
|
|
|
|
,that.digit(date.getMonth() + 1)
|
|
|
|
|
,that.digit(date.getDate())
|
|
|
|
|
]
|
|
|
|
|
,hms = [
|
|
|
|
|
that.digit(date.getHours())
|
|
|
|
|
,that.digit(date.getMinutes())
|
|
|
|
|
,that.digit(date.getSeconds())
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!date.getDate()) return hint.error('Invalid Msec for "util.toDateString(Msec)"'), '';
|
|
|
|
|
|
|
|
|
|
var years = date.getFullYear();
|
|
|
|
|
var month = date.getMonth();
|
|
|
|
|
var days = date.getDate();
|
|
|
|
|
var hours = date.getHours();
|
|
|
|
|
var minutes = date.getMinutes();
|
|
|
|
|
var seconds = date.getSeconds();
|
|
|
|
|
var milliseconds = date.getMilliseconds();
|
|
|
|
|
|
|
|
|
|
var defaultMeridiem = function(hours, minutes){
|
|
|
|
|
var hm = hours * 100 + minutes;
|
|
|
|
|
if (hm < 600) {
|
|
|
|
|
return '凌晨';
|
|
|
|
|
} else if (hm < 900) {
|
|
|
|
|
return '早上';
|
|
|
|
|
} else if (hm < 1100) {
|
|
|
|
|
return '上午';
|
|
|
|
|
} else if (hm < 1300) {
|
|
|
|
|
return '中午';
|
|
|
|
|
} else if (hm < 1800) {
|
|
|
|
|
return '下午';
|
|
|
|
|
}
|
|
|
|
|
return '晚上';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var meridiem = (options && options.customMeridiem) || defaultMeridiem;
|
|
|
|
|
|
|
|
|
|
var matches = {
|
|
|
|
|
yy: function(){return String(years).slice(-2);},
|
|
|
|
|
yyyy: function(){return that.digit(years, 4);},
|
|
|
|
|
M: function(){return String(month + 1);},
|
|
|
|
|
MM: function(){return that.digit(month + 1);},
|
|
|
|
|
d: function(){return String(days);},
|
|
|
|
|
dd: function(){return that.digit(days);},
|
|
|
|
|
H: function(){return String(hours);},
|
|
|
|
|
HH: function(){return that.digit(hours);},
|
|
|
|
|
h: function(){return String(hours % 12 || 12);},
|
|
|
|
|
hh: function(){return that.digit(hours % 12 || 12);},
|
|
|
|
|
A: function(){return meridiem(hours, minutes);},
|
|
|
|
|
m: function(){return String(minutes);},
|
|
|
|
|
mm: function(){return that.digit(minutes);},
|
|
|
|
|
s: function(){return String(seconds);},
|
|
|
|
|
ss: function(){return that.digit(seconds);},
|
|
|
|
|
SSS: function(){return that.digit(milliseconds, 3);}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
format = format || 'yyyy-MM-dd HH:mm:ss';
|
|
|
|
|
return format.replace(/yyyy/g, ymd[0])
|
|
|
|
|
.replace(/MM/g, ymd[1])
|
|
|
|
|
.replace(/dd/g, ymd[2])
|
|
|
|
|
.replace(/HH/g, hms[0])
|
|
|
|
|
.replace(/mm/g, hms[1])
|
|
|
|
|
.replace(/ss/g, hms[2]);
|
|
|
|
|
|
|
|
|
|
return format.replace(REGEX_FORMAT, function(match, $1) {
|
|
|
|
|
return $1 || (matches[match] && matches[match]()) || match;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 转义 html
|
|
|
|
@ -322,51 +358,51 @@ layui.define('jquery', function(exports){
|
|
|
|
|
// 让指定的元素保持在可视区域
|
|
|
|
|
toVisibleArea: function(options){
|
|
|
|
|
options = $.extend({
|
|
|
|
|
margin: 160 //触发动作的边界值
|
|
|
|
|
,duration: 200 //动画持续毫秒数
|
|
|
|
|
,type: 'y' //触发方向,x 水平、y 垂直
|
|
|
|
|
margin: 160, // 触发动作的边界值
|
|
|
|
|
duration: 200, // 动画持续毫秒数
|
|
|
|
|
type: 'y' // 触发方向,x 水平、y 垂直
|
|
|
|
|
}, options);
|
|
|
|
|
|
|
|
|
|
if(!options.scrollElem[0] || !options.thisElem[0]) return;
|
|
|
|
|
|
|
|
|
|
var scrollElem = options.scrollElem //滚动元素
|
|
|
|
|
,thisElem = options.thisElem //目标元素
|
|
|
|
|
,vertical = options.type === 'y' //是否垂直方向
|
|
|
|
|
,SCROLL_NAME = vertical ? 'scrollTop' : 'scrollLeft' //滚动方法
|
|
|
|
|
,OFFSET_NAME = vertical ? 'top' : 'left' //坐标方式
|
|
|
|
|
,scrollValue = scrollElem[SCROLL_NAME]() //当前滚动距离
|
|
|
|
|
,size = scrollElem[vertical ? 'height' : 'width']() //滚动元素的尺寸
|
|
|
|
|
,scrollOffet = scrollElem.offset()[OFFSET_NAME] //滚动元素所处位置
|
|
|
|
|
,thisOffset = thisElem.offset()[OFFSET_NAME] - scrollOffet //目标元素当前的所在位置
|
|
|
|
|
,obj = {};
|
|
|
|
|
var scrollElem = options.scrollElem // 滚动元素
|
|
|
|
|
var thisElem = options.thisElem // 目标元素
|
|
|
|
|
var vertical = options.type === 'y' // 是否垂直方向
|
|
|
|
|
var SCROLL_NAME = vertical ? 'scrollTop' : 'scrollLeft' // 滚动方法
|
|
|
|
|
var OFFSET_NAME = vertical ? 'top' : 'left' // 坐标方式
|
|
|
|
|
var scrollValue = scrollElem[SCROLL_NAME]() // 当前滚动距离
|
|
|
|
|
var size = scrollElem[vertical ? 'height' : 'width']() // 滚动元素的尺寸
|
|
|
|
|
var scrollOffet = scrollElem.offset()[OFFSET_NAME] // 滚动元素所处位置
|
|
|
|
|
var thisOffset = thisElem.offset()[OFFSET_NAME] - scrollOffet // 目标元素当前的所在位置
|
|
|
|
|
var obj = {};
|
|
|
|
|
|
|
|
|
|
//边界满足条件
|
|
|
|
|
// 边界满足条件
|
|
|
|
|
if(thisOffset > size - options.margin || thisOffset < options.margin){
|
|
|
|
|
obj[SCROLL_NAME] = thisOffset - size/2 + scrollValue
|
|
|
|
|
scrollElem.animate(obj, options.duration);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
//批量事件
|
|
|
|
|
// 批量事件
|
|
|
|
|
event: function(attr, obj, eventType){
|
|
|
|
|
var _body = $('body');
|
|
|
|
|
eventType = eventType || 'click';
|
|
|
|
|
|
|
|
|
|
//记录事件回调集合
|
|
|
|
|
// 记录事件回调集合
|
|
|
|
|
obj = util.event[attr] = $.extend(true, util.event[attr], obj) || {};
|
|
|
|
|
|
|
|
|
|
//清除委托事件
|
|
|
|
|
// 清除委托事件
|
|
|
|
|
util.event.UTIL_EVENT_CALLBACK = util.event.UTIL_EVENT_CALLBACK || {};
|
|
|
|
|
_body.off(eventType, '*['+ attr +']', util.event.UTIL_EVENT_CALLBACK[attr])
|
|
|
|
|
|
|
|
|
|
//绑定委托事件
|
|
|
|
|
// 绑定委托事件
|
|
|
|
|
util.event.UTIL_EVENT_CALLBACK[attr] = function(){
|
|
|
|
|
var othis = $(this)
|
|
|
|
|
,key = othis.attr(attr);
|
|
|
|
|
var othis = $(this);
|
|
|
|
|
var key = othis.attr(attr);
|
|
|
|
|
(typeof obj[key] === 'function') && obj[key].call(this, othis);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//清除旧事件,绑定新事件
|
|
|
|
|
// 清除旧事件,绑定新事件
|
|
|
|
|
_body.on(eventType, '*['+ attr +']', util.event.UTIL_EVENT_CALLBACK[attr]);
|
|
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
@ -375,11 +411,6 @@ layui.define('jquery', function(exports){
|
|
|
|
|
|
|
|
|
|
util.on = util.event;
|
|
|
|
|
|
|
|
|
|
// DOM 尺寸变化,该创意来自:http://benalman.com/projects/jquery-resize-plugin/
|
|
|
|
|
/*
|
|
|
|
|
!function(a,b,c){"$:nomunge";function l(){f=b[g](function(){d.each(function(){var b=a(this),c=b.width(),d=b.height(),e=a.data(this,i);(c!==e.w||d!==e.h)&&b.trigger(h,[e.w=c,e.h=d])}),l()},e[j])}var f,d=a([]),e=a.resize=a.extend(a.resize,{}),g="setTimeout",h="resize",i=h+"-special-event",j="delay",k="throttleWindow";e[j]=250,e[k]=!0,a.event.special[h]={setup:function(){if(!e[k]&&this[g])return!1;var b=a(this);d=d.add(b),a.data(this,i,{w:b.width(),h:b.height()}),1===d.length&&l()},teardown:function(){if(!e[k]&&this[g])return!1;var b=a(this);d=d.not(b),b.removeData(i),d.length||clearTimeout(f)},add:function(b){function f(b,e,f){var g=a(this),h=a.data(this,i)||{};h.w=e!==c?e:g.width(),h.h=f!==c?f:g.height(),d.apply(this,arguments)}if(!e[k]&&this[g])return!1;var d;return a.isFunction(b)?(d=b,f):(d=b.handler,b.handler=f,void 0)}}}($,window);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// 输出接口
|
|
|
|
|
exports('util', util);
|
|
|
|
|
});
|