mirror of
https://github.com/201206030/novel-plus.git
synced 2025-07-06 01:06:39 +00:00
上传后台管理系统代码
This commit is contained in:
11
novel-admin/src/main/resources/static/js/lay/all-mobile.js
Normal file
11
novel-admin/src/main/resources/static/js/lay/all-mobile.js
Normal file
@ -0,0 +1,11 @@
|
||||
/**
|
||||
|
||||
@Name:用于打包移动完整版
|
||||
@Author:贤心
|
||||
@License:LGPL
|
||||
|
||||
*/
|
||||
|
||||
layui.define(function(exports){
|
||||
exports('layui.mobile', layui.v);
|
||||
});
|
15
novel-admin/src/main/resources/static/js/lay/all.js
Normal file
15
novel-admin/src/main/resources/static/js/lay/all.js
Normal file
@ -0,0 +1,15 @@
|
||||
/**
|
||||
|
||||
@Name:用于打包PC完整版,即包含layui.js和所有模块的完整合并(该文件不会存在于构建后的目录)
|
||||
@Author:贤心
|
||||
@License:LGPL
|
||||
|
||||
*/
|
||||
|
||||
layui.define(function(exports){
|
||||
var cache = layui.cache;
|
||||
layui.config({
|
||||
dir: cache.dir.replace(/lay\/dest\/$/, '')
|
||||
});
|
||||
exports('layui.all', layui.v);
|
||||
});
|
314
novel-admin/src/main/resources/static/js/lay/modules/carousel.js
Normal file
314
novel-admin/src/main/resources/static/js/lay/modules/carousel.js
Normal file
@ -0,0 +1,314 @@
|
||||
/**
|
||||
|
||||
@Name:layui.carousel 轮播模块
|
||||
@Author:贤心
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define('jquery', function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.$
|
||||
,hint = layui.hint()
|
||||
,device = layui.device()
|
||||
|
||||
//外部接口
|
||||
,carousel = {
|
||||
config: {} //全局配置项
|
||||
|
||||
//设置全局项
|
||||
,set: function(options){
|
||||
var that = this;
|
||||
that.config = $.extend({}, that.config, options);
|
||||
return that;
|
||||
}
|
||||
|
||||
//事件监听
|
||||
,on: function(events, callback){
|
||||
return layui.onevent.call(this, MOD_NAME, events, callback);
|
||||
}
|
||||
}
|
||||
|
||||
//字符常量
|
||||
,MOD_NAME = 'carousel', ELEM = '.layui-carousel', THIS = 'layui-this', SHOW = 'layui-show', HIDE = 'layui-hide', DISABLED = 'layui-disabled'
|
||||
|
||||
,ELEM_ITEM = '>*[carousel-item]>*', ELEM_LEFT = 'layui-carousel-left', ELEM_RIGHT = 'layui-carousel-right', ELEM_PREV = 'layui-carousel-prev', ELEM_NEXT = 'layui-carousel-next', ELEM_ARROW = 'layui-carousel-arrow', ELEM_IND = 'layui-carousel-ind'
|
||||
|
||||
//构造器
|
||||
,Class = function(options){
|
||||
var that = this;
|
||||
that.config = $.extend({}, that.config, carousel.config, options);
|
||||
that.render();
|
||||
};
|
||||
|
||||
//默认配置
|
||||
Class.prototype.config = {
|
||||
width: '600px'
|
||||
,height: '280px'
|
||||
,full: false //是否全屏
|
||||
,arrow: 'hover' //切换箭头默认显示状态:hover/always/none
|
||||
,indicator: 'inside' //指示器位置:inside/outside/none
|
||||
,autoplay: true //是否自动切换
|
||||
,interval: 3000 //自动切换的时间间隔,不能低于800ms
|
||||
,anim: '' //动画类型:default/updown/fade
|
||||
,trigger: 'click' //指示器的触发方式:click/hover
|
||||
,index: 0 //初始开始的索引
|
||||
};
|
||||
|
||||
//轮播渲染
|
||||
Class.prototype.render = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
options.elem = $(options.elem);
|
||||
if(!options.elem[0]) return;
|
||||
that.elemItem = options.elem.find(ELEM_ITEM);
|
||||
|
||||
if(options.index < 0) options.index = 0;
|
||||
if(options.index >= that.elemItem.length) options.index = that.elemItem.length - 1;
|
||||
if(options.interval < 800) options.interval = 800;
|
||||
|
||||
//是否全屏模式
|
||||
if(options.full){
|
||||
options.elem.css({
|
||||
position: 'fixed'
|
||||
,width: '100%'
|
||||
,height: '100%'
|
||||
,zIndex: 9999
|
||||
});
|
||||
} else {
|
||||
options.elem.css({
|
||||
width: options.width
|
||||
,height: options.height
|
||||
});
|
||||
}
|
||||
|
||||
options.elem.attr('lay-anim', options.anim);
|
||||
|
||||
//初始焦点状态
|
||||
that.elemItem.eq(options.index).addClass(THIS);
|
||||
|
||||
//指示器等动作
|
||||
that.indicator();
|
||||
if(that.elemItem.length <= 1) return;
|
||||
that.arrow();
|
||||
that.autoplay();
|
||||
that.events();
|
||||
};
|
||||
|
||||
//重置轮播
|
||||
Class.prototype.reload = function(options){
|
||||
var that = this;
|
||||
clearInterval(that.timer);
|
||||
that.config = $.extend({}, that.config, options);
|
||||
that.render();
|
||||
};
|
||||
|
||||
//获取上一个等待条目的索引
|
||||
Class.prototype.prevIndex = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
var prevIndex = options.index - 1;
|
||||
if(prevIndex < 0){
|
||||
prevIndex = that.elemItem.length - 1;
|
||||
}
|
||||
return prevIndex;
|
||||
};
|
||||
|
||||
//获取下一个等待条目的索引
|
||||
Class.prototype.nextIndex = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
var nextIndex = options.index + 1;
|
||||
if(nextIndex >= that.elemItem.length){
|
||||
nextIndex = 0;
|
||||
}
|
||||
return nextIndex;
|
||||
};
|
||||
|
||||
//索引递增
|
||||
Class.prototype.addIndex = function(num){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
num = num || 1;
|
||||
options.index = options.index + num;
|
||||
|
||||
//index不能超过轮播总数量
|
||||
if(options.index >= that.elemItem.length){
|
||||
options.index = 0;
|
||||
}
|
||||
};
|
||||
|
||||
//索引递减
|
||||
Class.prototype.subIndex = function(num){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
num = num || 1;
|
||||
options.index = options.index - num;
|
||||
|
||||
//index不能超过轮播总数量
|
||||
if(options.index < 0){
|
||||
options.index = that.elemItem.length - 1;
|
||||
}
|
||||
};
|
||||
|
||||
//自动轮播
|
||||
Class.prototype.autoplay = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
if(!options.autoplay) return;
|
||||
|
||||
that.timer = setInterval(function(){
|
||||
that.slide();
|
||||
}, options.interval);
|
||||
};
|
||||
|
||||
//箭头
|
||||
Class.prototype.arrow = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
//模板
|
||||
var tplArrow = $([
|
||||
'<button class="layui-icon '+ ELEM_ARROW +'" lay-type="sub">'+ (options.anim === 'updown' ? '' : '') +'</button>'
|
||||
,'<button class="layui-icon '+ ELEM_ARROW +'" lay-type="add">'+ (options.anim === 'updown' ? '' : '') +'</button>'
|
||||
].join(''));
|
||||
|
||||
//预设基础属性
|
||||
options.elem.attr('lay-arrow', options.arrow);
|
||||
|
||||
//避免重复插入
|
||||
if(options.elem.find('.'+ELEM_ARROW)[0]){
|
||||
options.elem.find('.'+ELEM_ARROW).remove();
|
||||
};
|
||||
options.elem.append(tplArrow);
|
||||
|
||||
//事件
|
||||
tplArrow.on('click', function(){
|
||||
var othis = $(this)
|
||||
,type = othis.attr('lay-type')
|
||||
that.slide(type);
|
||||
});
|
||||
};
|
||||
|
||||
//指示器
|
||||
Class.prototype.indicator = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
//模板
|
||||
var tplInd = that.elemInd = $(['<div class="'+ ELEM_IND +'"><ul>'
|
||||
,function(){
|
||||
var li = [];
|
||||
layui.each(that.elemItem, function(index){
|
||||
li.push('<li'+ (options.index === index ? ' class="layui-this"' : '') +'></li>');
|
||||
});
|
||||
return li.join('');
|
||||
}()
|
||||
,'</ul></div>'].join(''));
|
||||
|
||||
//预设基础属性
|
||||
options.elem.attr('lay-indicator', options.indicator);
|
||||
|
||||
//避免重复插入
|
||||
if(options.elem.find('.'+ELEM_IND)[0]){
|
||||
options.elem.find('.'+ELEM_IND).remove();
|
||||
};
|
||||
options.elem.append(tplInd);
|
||||
|
||||
if(options.anim === 'updown'){
|
||||
tplInd.css('margin-top', -(tplInd.height()/2));
|
||||
}
|
||||
|
||||
//事件
|
||||
tplInd.find('li').on(options.trigger === 'hover' ? 'mouseover' : options.trigger, function(){
|
||||
var othis = $(this)
|
||||
,index = othis.index();
|
||||
if(index > options.index){
|
||||
that.slide('add', index - options.index);
|
||||
} else if(index < options.index){
|
||||
that.slide('sub', options.index - index);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
//滑动切换
|
||||
Class.prototype.slide = function(type, num){
|
||||
var that = this
|
||||
,elemItem = that.elemItem
|
||||
,options = that.config
|
||||
,thisIndex = options.index
|
||||
,filter = options.elem.attr('lay-filter');
|
||||
|
||||
if(that.haveSlide) return;
|
||||
|
||||
//滑动方向
|
||||
if(type === 'sub'){
|
||||
that.subIndex(num);
|
||||
elemItem.eq(options.index).addClass(ELEM_PREV);
|
||||
setTimeout(function(){
|
||||
elemItem.eq(thisIndex).addClass(ELEM_RIGHT);
|
||||
elemItem.eq(options.index).addClass(ELEM_RIGHT);
|
||||
}, 50);
|
||||
} else { //默认递增滑
|
||||
that.addIndex(num);
|
||||
elemItem.eq(options.index).addClass(ELEM_NEXT);
|
||||
setTimeout(function(){
|
||||
elemItem.eq(thisIndex).addClass(ELEM_LEFT);
|
||||
elemItem.eq(options.index).addClass(ELEM_LEFT);
|
||||
}, 50);
|
||||
};
|
||||
|
||||
//移除过度类
|
||||
setTimeout(function(){
|
||||
elemItem.removeClass(THIS + ' ' + ELEM_PREV + ' ' + ELEM_NEXT + ' ' + ELEM_LEFT + ' ' + ELEM_RIGHT);
|
||||
elemItem.eq(options.index).addClass(THIS);
|
||||
that.haveSlide = false; //解锁
|
||||
}, 300);
|
||||
|
||||
//指示器焦点
|
||||
that.elemInd.find('li').eq(options.index).addClass(THIS)
|
||||
.siblings().removeClass(THIS);
|
||||
|
||||
that.haveSlide = true;
|
||||
|
||||
layui.event.call(this, MOD_NAME, 'change('+ filter +')', {
|
||||
index: options.index
|
||||
,prevIndex: thisIndex
|
||||
,item: elemItem.eq(options.index)
|
||||
});
|
||||
};
|
||||
|
||||
//事件处理
|
||||
Class.prototype.events = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
if(options.elem.data('haveEvents')) return;
|
||||
|
||||
//移入移出容器
|
||||
options.elem.on('mouseenter', function(){
|
||||
clearInterval(that.timer);
|
||||
}).on('mouseleave', function(){
|
||||
that.autoplay();
|
||||
});
|
||||
|
||||
options.elem.data('haveEvents', true);
|
||||
};
|
||||
|
||||
//核心入口
|
||||
carousel.render = function(options){
|
||||
var inst = new Class(options);
|
||||
return inst;
|
||||
};
|
||||
|
||||
exports(MOD_NAME, carousel);
|
||||
});
|
||||
|
||||
|
61
novel-admin/src/main/resources/static/js/lay/modules/code.js
Normal file
61
novel-admin/src/main/resources/static/js/lay/modules/code.js
Normal file
@ -0,0 +1,61 @@
|
||||
/**
|
||||
|
||||
@Name:layui.code 代码修饰器
|
||||
@Author:贤心
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define('jquery', function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.$;
|
||||
var about = 'http://www.layui.com/doc/modules/code.html'; //关于信息
|
||||
|
||||
exports('code', function(options){
|
||||
var elems = [];
|
||||
options = options || {};
|
||||
options.elem = $(options.elem||'.layui-code');
|
||||
options.about = 'about' in options ? options.about : true;
|
||||
|
||||
options.elem.each(function(){
|
||||
elems.push(this);
|
||||
});
|
||||
|
||||
layui.each(elems.reverse(), function(index, item){
|
||||
var othis = $(item), html = othis.html();
|
||||
|
||||
//转义HTML标签
|
||||
if(othis.attr('lay-encode') || options.encode){
|
||||
html = html.replace(/&(?!#?[a-zA-Z0-9]+;)/g, '&')
|
||||
.replace(/</g, '<').replace(/>/g, '>').replace(/'/g, ''').replace(/"/g, '"')
|
||||
}
|
||||
|
||||
othis.html('<ol class="layui-code-ol"><li>' + html.replace(/[\r\t\n]+/g, '</li><li>') + '</li></ol>')
|
||||
|
||||
if(!othis.find('>.layui-code-h3')[0]){
|
||||
othis.prepend('<h3 class="layui-code-h3">'+ (othis.attr('lay-title')||options.title||'code') + (options.about ? '<a href="'+ about +'" target="_blank">layui.code</a>' : '') + '</h3>');
|
||||
}
|
||||
|
||||
var ol = othis.find('>.layui-code-ol');
|
||||
othis.addClass('layui-box layui-code-view');
|
||||
|
||||
//识别皮肤
|
||||
if(othis.attr('lay-skin') || options.skin){
|
||||
othis.addClass('layui-code-' +(othis.attr('lay-skin') || options.skin));
|
||||
}
|
||||
|
||||
//按行数适配左边距
|
||||
if((ol.find('li').length/100|0) > 0){
|
||||
ol.css('margin-left', (ol.find('li').length/100|0) + 'px');
|
||||
}
|
||||
|
||||
//设置最大高度
|
||||
if(othis.attr('lay-height') || options.height){
|
||||
ol.css('max-height', othis.attr('lay-height') || options.height);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
}).addcss('modules/code.css', 'skincodecss');
|
411
novel-admin/src/main/resources/static/js/lay/modules/element.js
Normal file
411
novel-admin/src/main/resources/static/js/lay/modules/element.js
Normal file
@ -0,0 +1,411 @@
|
||||
/**
|
||||
|
||||
@Name:layui.element 常用元素操作
|
||||
@Author:贤心
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define('jquery', function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.$
|
||||
,hint = layui.hint()
|
||||
,device = layui.device()
|
||||
|
||||
,MOD_NAME = 'element', THIS = 'layui-this', SHOW = 'layui-show'
|
||||
|
||||
,Element = function(){
|
||||
this.config = {};
|
||||
};
|
||||
|
||||
//全局设置
|
||||
Element.prototype.set = function(options){
|
||||
var that = this;
|
||||
$.extend(true, that.config, options);
|
||||
return that;
|
||||
};
|
||||
|
||||
//表单事件监听
|
||||
Element.prototype.on = function(events, callback){
|
||||
return layui.onevent.call(this, MOD_NAME, events, callback);
|
||||
};
|
||||
|
||||
//外部Tab新增
|
||||
Element.prototype.tabAdd = function(filter, options){
|
||||
var TITLE = '.layui-tab-title'
|
||||
,tabElem = $('.layui-tab[lay-filter='+ filter +']')
|
||||
,titElem = tabElem.children(TITLE)
|
||||
,barElem = titElem.children('.layui-tab-bar')
|
||||
,contElem = tabElem.children('.layui-tab-content')
|
||||
,li = '<li lay-id="'+ (options.id||'') +'">'+ (options.title||'unnaming') +'</li>';
|
||||
barElem[0] ? barElem.before(li) : titElem.append(li);
|
||||
contElem.append('<div class="layui-tab-item">'+ (options.content||'') +'</div>');
|
||||
call.hideTabMore(true);
|
||||
call.tabAuto();
|
||||
return this;
|
||||
};
|
||||
|
||||
//外部Tab删除
|
||||
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, 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;
|
||||
};
|
||||
|
||||
//动态改变进度条
|
||||
Element.prototype.progress = function(filter, percent){
|
||||
var ELEM = 'layui-progress'
|
||||
,elem = $('.'+ ELEM +'[lay-filter='+ filter +']')
|
||||
,elemBar = elem.find('.'+ ELEM +'-bar')
|
||||
,text = elemBar.find('.'+ ELEM +'-text');
|
||||
elemBar.css('width', percent);
|
||||
text.text(percent);
|
||||
return this;
|
||||
};
|
||||
|
||||
var NAV_ELEM = '.layui-nav', NAV_ITEM = 'layui-nav-item', NAV_BAR = 'layui-nav-bar'
|
||||
,NAV_TREE = 'layui-nav-tree', NAV_CHILD = 'layui-nav-child', NAV_MORE = 'layui-nav-more'
|
||||
,NAV_ANIM = 'layui-anim layui-anim-upbit'
|
||||
|
||||
//基础事件体
|
||||
,call = {
|
||||
//Tab点击
|
||||
tabClick: function(e, index, liElem){
|
||||
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')
|
||||
,elemA = othis.find('a')
|
||||
,filter = parents.attr('lay-filter');
|
||||
|
||||
if(!(elemA.attr('href') !== 'javascript:;' && elemA.attr('target') === '_blank')){
|
||||
othis.addClass(THIS).siblings().removeClass(THIS);
|
||||
item.eq(index).addClass(SHOW).siblings().removeClass(SHOW);
|
||||
}
|
||||
|
||||
layui.event.call(this, MOD_NAME, 'tab('+ filter +')', {
|
||||
elem: parents
|
||||
,index: index
|
||||
});
|
||||
}
|
||||
|
||||
//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')
|
||||
|
||||
if(li.hasClass(THIS)){
|
||||
if(li.next()[0]){
|
||||
call.tabClick.call(li.next()[0], null, index + 1);
|
||||
} else if(li.prev()[0]){
|
||||
call.tabClick.call(li.prev()[0], null, index - 1);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
$('.layui-tab').each(function(){
|
||||
var othis = $(this)
|
||||
,title = othis.children('.layui-tab-title')
|
||||
,item = othis.children('.layui-tab-content').children('.layui-tab-item')
|
||||
,STOPE = 'lay-stope="tabmore"'
|
||||
,span = $('<span class="layui-unselect layui-tab-bar" '+ STOPE +'><i '+ STOPE +' class="layui-icon"></i></span>');
|
||||
|
||||
if(that === window && device.ie != 8){
|
||||
call.hideTabMore(true)
|
||||
}
|
||||
|
||||
//允许关闭
|
||||
if(othis.attr('lay-allowClose')){
|
||||
title.find('li').each(function(){
|
||||
var li = $(this);
|
||||
if(!li.find('.'+CLOSE)[0]){
|
||||
var close = $('<i class="layui-icon layui-unselect '+ CLOSE +'">ဆ</i>');
|
||||
close.on('click', call.tabDelete);
|
||||
li.append(close);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//响应式
|
||||
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');
|
||||
}
|
||||
});
|
||||
}
|
||||
//隐藏更多Tab
|
||||
,hideTabMore: function(e){
|
||||
var tsbTitle = $('.layui-tab-title');
|
||||
if(e === true || $(e.target).attr('lay-stope') !== 'tabmore'){
|
||||
tsbTitle.removeClass('layui-tab-more');
|
||||
tsbTitle.find('.layui-tab-bar').attr('title','');
|
||||
}
|
||||
}
|
||||
|
||||
//点击选中
|
||||
,clickThis: function(){
|
||||
var othis = $(this), parents = othis.parents(NAV_ELEM)
|
||||
,filter = parents.attr('lay-filter')
|
||||
,elemA = othis.find('a');
|
||||
|
||||
if(othis.find('.'+NAV_CHILD)[0]) return;
|
||||
|
||||
if(!(elemA.attr('href') !== 'javascript:;' && elemA.attr('target') === '_blank')){
|
||||
parents.find('.'+THIS).removeClass(THIS);
|
||||
othis.addClass(THIS);
|
||||
}
|
||||
|
||||
layui.event.call(this, MOD_NAME, 'nav('+ filter +')', othis);
|
||||
}
|
||||
//点击子菜单选中
|
||||
,clickChild: function(){
|
||||
var othis = $(this), parents = othis.parents(NAV_ELEM)
|
||||
,filter = parents.attr('lay-filter');
|
||||
parents.find('.'+THIS).removeClass(THIS);
|
||||
othis.addClass(THIS);
|
||||
layui.event.call(this, MOD_NAME, 'nav('+ filter +')', othis);
|
||||
}
|
||||
//展开二级菜单
|
||||
,showChild: function(){
|
||||
var othis = $(this), parents = othis.parents(NAV_ELEM);
|
||||
var parent = othis.parent(), child = othis.siblings('.'+NAV_CHILD);
|
||||
if(parents.hasClass(NAV_TREE)){
|
||||
child.removeClass(NAV_ANIM);
|
||||
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')
|
||||
,isNone = 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[isNone ? 'addClass' : 'removeClass'](SHOW);
|
||||
icon.html(isNone ? '' : '');
|
||||
|
||||
layui.event.call(this, MOD_NAME, 'collapse('+ filter +')', {
|
||||
title: othis
|
||||
,content: elemCont
|
||||
,show: isNone
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
//初始化元素操作
|
||||
Element.prototype.init = function(type){
|
||||
var that = this, items = {
|
||||
|
||||
//Tab选项卡
|
||||
tab: function(){
|
||||
call.tabAuto.call({});
|
||||
}
|
||||
|
||||
//导航菜单
|
||||
,nav: function(){
|
||||
var TIME = 200, timer = {}, timerMore = {}, timeEnd = {}, follow = function(bar, nav, index){
|
||||
var othis = $(this), child = othis.find('.'+NAV_CHILD);
|
||||
|
||||
if(nav.hasClass(NAV_TREE)){
|
||||
bar.css({
|
||||
top: othis.position().top
|
||||
,height: othis.children('a').height()
|
||||
,opacity: 1
|
||||
});
|
||||
} else {
|
||||
child.addClass(NAV_ANIM);
|
||||
bar.css({
|
||||
left: othis.position().left + parseFloat(othis.css('marginLeft'))
|
||||
,top: othis.position().top + othis.height() - 5
|
||||
});
|
||||
|
||||
timer[index] = setTimeout(function(){
|
||||
bar.css({
|
||||
width: othis.width()
|
||||
,opacity: 1
|
||||
});
|
||||
}, device.ie && device.ie < 10 ? 0 : TIME);
|
||||
|
||||
clearTimeout(timeEnd[index]);
|
||||
if(child.css('display') === 'block'){
|
||||
clearTimeout(timerMore[index]);
|
||||
}
|
||||
timerMore[index] = setTimeout(function(){
|
||||
child.addClass(SHOW)
|
||||
othis.find('.'+NAV_MORE).addClass(NAV_MORE+'d');
|
||||
}, 300);
|
||||
}
|
||||
}
|
||||
|
||||
$(NAV_ELEM).each(function(index){
|
||||
var othis = $(this)
|
||||
,bar = $('<span class="'+ NAV_BAR +'"></span>')
|
||||
,itemElem = othis.find('.'+NAV_ITEM);
|
||||
|
||||
//Hover滑动效果
|
||||
if(!othis.find('.'+NAV_BAR)[0]){
|
||||
othis.append(bar);
|
||||
itemElem.on('mouseenter', function(){
|
||||
follow.call(this, bar, othis, index);
|
||||
}).on('mouseleave', function(){
|
||||
if(!othis.hasClass(NAV_TREE)){
|
||||
clearTimeout(timerMore[index]);
|
||||
timerMore[index] = setTimeout(function(){
|
||||
othis.find('.'+NAV_CHILD).removeClass(SHOW);
|
||||
othis.find('.'+NAV_MORE).removeClass(NAV_MORE+'d');
|
||||
}, 300);
|
||||
}
|
||||
});
|
||||
othis.on('mouseleave', function(){
|
||||
clearTimeout(timer[index])
|
||||
timeEnd[index] = setTimeout(function(){
|
||||
if(othis.hasClass(NAV_TREE)){
|
||||
bar.css({
|
||||
height: 0
|
||||
,top: bar.position().top + bar.height()/2
|
||||
,opacity: 0
|
||||
});
|
||||
} else {
|
||||
bar.css({
|
||||
width: 0
|
||||
,left: bar.position().left + bar.width()/2
|
||||
,opacity: 0
|
||||
});
|
||||
}
|
||||
}, TIME);
|
||||
});
|
||||
}
|
||||
|
||||
itemElem.each(function(){
|
||||
var oitem = $(this), child = oitem.find('.'+NAV_CHILD);
|
||||
|
||||
//二级菜单
|
||||
if(child[0] && !oitem.find('.'+NAV_MORE)[0]){
|
||||
var one = oitem.children('a');
|
||||
one.append('<span class="'+ NAV_MORE +'"></span>');
|
||||
}
|
||||
|
||||
oitem.off('click', call.clickThis).on('click', call.clickThis); //点击选中
|
||||
oitem.children('a').off('click', call.showChild).on('click', call.showChild); //展开二级菜单
|
||||
child.children('dd').off('click', call.clickChild).on('click', call.clickChild); //点击子菜单选中
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//面包屑
|
||||
,breadcrumb: function(){
|
||||
var ELEM = '.layui-breadcrumb';
|
||||
|
||||
$(ELEM).each(function(){
|
||||
var othis = $(this)
|
||||
,separator = othis.attr('lay-separator') || '>'
|
||||
,aNode = othis.find('a');
|
||||
if(aNode.find('.layui-box')[0]) return;
|
||||
aNode.each(function(index){
|
||||
if(index === aNode.length - 1) return;
|
||||
$(this).append('<span class="layui-box">'+ separator +'</span>');
|
||||
});
|
||||
othis.css('visibility', 'visible');
|
||||
});
|
||||
}
|
||||
|
||||
//进度条
|
||||
,progress: function(){
|
||||
var ELEM = 'layui-progress';
|
||||
|
||||
$('.'+ELEM).each(function(){
|
||||
var othis = $(this)
|
||||
,elemBar = othis.find('.layui-progress-bar')
|
||||
,width = elemBar.attr('lay-percent');
|
||||
elemBar.css('width', width);
|
||||
if(othis.attr('lay-showPercent')){
|
||||
setTimeout(function(){
|
||||
var percent = Math.round(elemBar.width()/othis.width()*100);
|
||||
if(percent > 100) percent = 100;
|
||||
elemBar.html('<span class="'+ ELEM +'-text">'+ percent +'%</span>');
|
||||
},350);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//折叠面板
|
||||
,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')
|
||||
,isNone = elemCont.css('display') === 'none';
|
||||
|
||||
//初始状态
|
||||
elemTitle.find('.layui-colla-icon').remove();
|
||||
elemTitle.append('<i class="layui-icon layui-colla-icon">'+ (isNone ? '' : '') +'</i>');
|
||||
|
||||
//点击标题
|
||||
elemTitle.off('click', call.collapse).on('click', call.collapse);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return layui.each(items, function(index, item){
|
||||
item();
|
||||
});
|
||||
};
|
||||
|
||||
var element = new Element(), dom = $(document);
|
||||
element.init();
|
||||
|
||||
var TITLE = '.layui-tab-title li';
|
||||
dom.on('click', TITLE, call.tabClick); //Tab切换
|
||||
dom.on('click', call.hideTabMore); //隐藏展开的Tab
|
||||
$(window).on('resize', call.tabAuto); //自适应
|
||||
|
||||
exports(MOD_NAME, element);
|
||||
});
|
||||
|
176
novel-admin/src/main/resources/static/js/lay/modules/flow.js
Normal file
176
novel-admin/src/main/resources/static/js/lay/modules/flow.js
Normal file
@ -0,0 +1,176 @@
|
||||
/**
|
||||
|
||||
@Name:layui.flow 流加载
|
||||
@Author:贤心
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
|
||||
layui.define('jquery', function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.$, Flow = function(options){}
|
||||
,ELEM_MORE = 'layui-flow-more'
|
||||
,ELEM_LOAD = '<i class="layui-anim layui-anim-rotate layui-anim-loop layui-icon "></i>';
|
||||
|
||||
//主方法
|
||||
Flow.prototype.load = function(options){
|
||||
var that = this, page = 0, lock, isOver, lazyimg, timer;
|
||||
options = options || {};
|
||||
|
||||
var elem = $(options.elem); if(!elem[0]) return;
|
||||
var scrollElem = $(options.scrollElem || document); //滚动条所在元素
|
||||
var mb = options.mb || 50; //与底部的临界距离
|
||||
var isAuto = 'isAuto' in options ? options.isAuto : true; //是否自动滚动加载
|
||||
var end = options.end || '没有更多了'; //“末页”显示文案
|
||||
|
||||
//滚动条所在元素是否为document
|
||||
var notDocment = options.scrollElem && options.scrollElem !== document;
|
||||
|
||||
//加载更多
|
||||
var ELEM_TEXT = '<cite>加载更多</cite>'
|
||||
,more = $('<div class="layui-flow-more"><a href="javascript:;">'+ ELEM_TEXT +'</a></div>');
|
||||
|
||||
if(!elem.find('.layui-flow-more')[0]){
|
||||
elem.append(more);
|
||||
}
|
||||
|
||||
//加载下一个元素
|
||||
var next = function(html, over){
|
||||
html = $(html);
|
||||
more.before(html);
|
||||
over = over == 0 ? true : null;
|
||||
over ? more.html(end) : more.find('a').html(ELEM_TEXT);
|
||||
isOver = over;
|
||||
lock = null;
|
||||
lazyimg && lazyimg();
|
||||
};
|
||||
|
||||
//触发请求
|
||||
var done = function(){
|
||||
lock = true;
|
||||
more.find('a').html(ELEM_LOAD);
|
||||
typeof options.done === 'function' && options.done(++page, next);
|
||||
};
|
||||
|
||||
done();
|
||||
|
||||
//不自动滚动加载
|
||||
more.find('a').on('click', function(){
|
||||
var othis = $(this);
|
||||
if(isOver) return;
|
||||
lock || done();
|
||||
});
|
||||
|
||||
//如果允许图片懒加载
|
||||
if(options.isLazyimg){
|
||||
var lazyimg = that.lazyimg({
|
||||
elem: options.elem + ' img'
|
||||
,scrollElem: options.scrollElem
|
||||
});
|
||||
}
|
||||
|
||||
if(!isAuto) return that;
|
||||
|
||||
scrollElem.on('scroll', function(){
|
||||
var othis = $(this), top = othis.scrollTop();
|
||||
|
||||
if(timer) clearTimeout(timer);
|
||||
if(isOver) return;
|
||||
|
||||
timer = setTimeout(function(){
|
||||
//计算滚动所在容器的可视高度
|
||||
var height = notDocment ? othis.height() : $(window).height();
|
||||
|
||||
//计算滚动所在容器的实际高度
|
||||
var scrollHeight = notDocment
|
||||
? othis.prop('scrollHeight')
|
||||
: document.documentElement.scrollHeight;
|
||||
|
||||
//临界点
|
||||
if(scrollHeight - top - height <= mb){
|
||||
lock || done();
|
||||
}
|
||||
}, 100);
|
||||
});
|
||||
return that;
|
||||
};
|
||||
|
||||
//图片懒加载
|
||||
Flow.prototype.lazyimg = function(options){
|
||||
var that = this, index = 0, haveScroll;
|
||||
options = options || {};
|
||||
|
||||
var scrollElem = $(options.scrollElem || document); //滚动条所在元素
|
||||
var elem = options.elem || 'img';
|
||||
|
||||
//滚动条所在元素是否为document
|
||||
var notDocment = options.scrollElem && options.scrollElem !== document;
|
||||
|
||||
//显示图片
|
||||
var show = function(item, height){
|
||||
var start = scrollElem.scrollTop(), end = start + height;
|
||||
var elemTop = notDocment ? function(){
|
||||
return item.offset().top - scrollElem.offset().top + start;
|
||||
}() : item.offset().top;
|
||||
|
||||
/* 始终只加载在当前屏范围内的图片 */
|
||||
if(elemTop >= start && elemTop <= end){
|
||||
if(!item.attr('src')){
|
||||
var src = item.attr('lay-src');
|
||||
layui.img(src, function(){
|
||||
var next = that.lazyimg.elem.eq(index);
|
||||
item.attr('src', src).removeAttr('lay-src');
|
||||
|
||||
/* 当前图片加载就绪后,检测下一个图片是否在当前屏 */
|
||||
next[0] && render(next);
|
||||
index++;
|
||||
});
|
||||
}
|
||||
}
|
||||
}, render = function(othis, scroll){
|
||||
|
||||
//计算滚动所在容器的可视高度
|
||||
var height = notDocment ? (scroll||scrollElem).height() : $(window).height();
|
||||
var start = scrollElem.scrollTop(), end = start + height;
|
||||
|
||||
that.lazyimg.elem = $(elem);
|
||||
|
||||
if(othis){
|
||||
show(othis, height);
|
||||
} else {
|
||||
//计算未加载过的图片
|
||||
for(var i = 0; i < that.lazyimg.elem.length; i++){
|
||||
var item = that.lazyimg.elem.eq(i), elemTop = notDocment ? function(){
|
||||
return item.offset().top - scrollElem.offset().top + start;
|
||||
}() : item.offset().top;
|
||||
|
||||
show(item, height);
|
||||
index = i;
|
||||
|
||||
//如果图片的top坐标,超出了当前屏,则终止后续图片的遍历
|
||||
if(elemTop > end) break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
render();
|
||||
|
||||
if(!haveScroll){
|
||||
var timer;
|
||||
scrollElem.on('scroll', function(){
|
||||
var othis = $(this);
|
||||
if(timer) clearTimeout(timer)
|
||||
timer = setTimeout(function(){
|
||||
render(null, othis);
|
||||
}, 50);
|
||||
});
|
||||
haveScroll = true;
|
||||
}
|
||||
return render;
|
||||
};
|
||||
|
||||
//暴露接口
|
||||
exports('flow', new Flow());
|
||||
});
|
471
novel-admin/src/main/resources/static/js/lay/modules/form.js
Normal file
471
novel-admin/src/main/resources/static/js/lay/modules/form.js
Normal file
@ -0,0 +1,471 @@
|
||||
/**
|
||||
|
||||
@Name:layui.form 表单组件
|
||||
@Author:贤心
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define('layer', function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.$
|
||||
,layer = layui.layer
|
||||
,hint = layui.hint()
|
||||
,device = layui.device()
|
||||
|
||||
,MOD_NAME = 'form', ELEM = '.layui-form', THIS = 'layui-this', SHOW = 'layui-show', HIDE = 'layui-hide', DISABLED = 'layui-disabled'
|
||||
|
||||
,Form = function(){
|
||||
this.config = {
|
||||
verify: {
|
||||
required: [
|
||||
/[\S]+/
|
||||
,'必填项不能为空'
|
||||
]
|
||||
,phone: [
|
||||
/^1\d{10}$/
|
||||
,'请输入正确的手机号'
|
||||
]
|
||||
,email: [
|
||||
/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/
|
||||
,'邮箱格式不正确'
|
||||
]
|
||||
,url: [
|
||||
/(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/
|
||||
,'链接格式不正确'
|
||||
]
|
||||
,number: function(value){
|
||||
if(!value || isNaN(value)) return '只能填写数字'
|
||||
}
|
||||
,date: [
|
||||
/^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/
|
||||
,'日期格式不正确'
|
||||
]
|
||||
,identity: [
|
||||
/(^\d{15}$)|(^\d{17}(x|X|\d)$)/
|
||||
,'请输入正确的身份证号'
|
||||
]
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
//全局设置
|
||||
Form.prototype.set = function(options){
|
||||
var that = this;
|
||||
$.extend(true, that.config, options);
|
||||
return that;
|
||||
};
|
||||
|
||||
//验证规则设定
|
||||
Form.prototype.verify = function(settings){
|
||||
var that = this;
|
||||
$.extend(true, that.config.verify, settings);
|
||||
return that;
|
||||
};
|
||||
|
||||
//表单事件监听
|
||||
Form.prototype.on = function(events, callback){
|
||||
return layui.onevent.call(this, MOD_NAME, events, callback);
|
||||
};
|
||||
|
||||
//表单控件渲染
|
||||
Form.prototype.render = function(type, filter){
|
||||
var that = this
|
||||
,elemForm = $(ELEM + function(){
|
||||
return filter ? ('[lay-filter="' + filter +'"]') : '';
|
||||
}())
|
||||
,items = {
|
||||
|
||||
//下拉选择框
|
||||
select: function(){
|
||||
var TIPS = '请选择', CLASS = 'layui-form-select', TITLE = 'layui-select-title'
|
||||
,NONE = 'layui-select-none', initValue = '', thatInput
|
||||
|
||||
,selects = elemForm.find('select'), hide = function(e, clear){
|
||||
if(!$(e.target).parent().hasClass(TITLE) || clear){
|
||||
$('.'+CLASS).removeClass(CLASS+'ed ' + CLASS+'up');
|
||||
thatInput && initValue && thatInput.val(initValue);
|
||||
}
|
||||
thatInput = null;
|
||||
}
|
||||
|
||||
,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(){
|
||||
var top = reElem.offset().top + reElem.outerHeight() + 5 - win.scrollTop()
|
||||
,dlHeight = dl.outerHeight();
|
||||
reElem.addClass(CLASS+'ed');
|
||||
dds.removeClass(HIDE);
|
||||
|
||||
//上下定位识别
|
||||
if(top + dlHeight > win.height() && top >= dlHeight){
|
||||
reElem.addClass(CLASS + 'up');
|
||||
}
|
||||
}, hideDown = function(choose){
|
||||
reElem.removeClass(CLASS+'ed ' + CLASS+'up');
|
||||
input.blur();
|
||||
|
||||
if(choose) return;
|
||||
|
||||
notOption(input.val(), function(none){
|
||||
if(none){
|
||||
initValue = dl.find('.'+THIS).html();
|
||||
input && input.val(initValue);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
//点击标题区域
|
||||
title.on('click', function(e){
|
||||
reElem.hasClass(CLASS+'ed') ? (
|
||||
hideDown()
|
||||
) : (
|
||||
hide(e, true),
|
||||
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();
|
||||
}
|
||||
});
|
||||
|
||||
//检测值是否不属于select项
|
||||
var notOption = function(value, callback, origin){
|
||||
var num = 0;
|
||||
layui.each(dds, function(){
|
||||
var othis = $(this)
|
||||
,text = othis.text()
|
||||
,not = text.indexOf(value) === -1;
|
||||
if(value === '' || (origin === 'blur') ? value !== text : not) num++;
|
||||
origin === 'keyup' && othis[not ? 'addClass' : 'removeClass'](HIDE);
|
||||
});
|
||||
var none = num === dds.length;
|
||||
return callback(none), none;
|
||||
};
|
||||
|
||||
//搜索匹配
|
||||
var search = function(e){
|
||||
var value = this.value, keyCode = e.keyCode;
|
||||
|
||||
if(keyCode === 9 || keyCode === 13
|
||||
|| keyCode === 37 || keyCode === 38
|
||||
|| keyCode === 39 || keyCode === 40
|
||||
){
|
||||
return false;
|
||||
}
|
||||
|
||||
notOption(value, function(none){
|
||||
if(none){
|
||||
dl.find('.'+NONE)[0] || dl.append('<p class="'+ NONE +'">无匹配项</p>');
|
||||
} else {
|
||||
dl.find('.'+NONE).remove();
|
||||
}
|
||||
}, 'keyup');
|
||||
|
||||
if(value === ''){
|
||||
dl.find('.'+NONE).remove();
|
||||
}
|
||||
};
|
||||
if(isSearch){
|
||||
input.on('keyup', search).on('blur', function(e){
|
||||
thatInput = input;
|
||||
initValue = dl.find('.'+THIS).html();
|
||||
setTimeout(function(){
|
||||
notOption(input.val(), function(none){
|
||||
if(none && !initValue){
|
||||
input.val('');
|
||||
}
|
||||
}, 'blur');
|
||||
}, 200);
|
||||
});
|
||||
}
|
||||
|
||||
//选择
|
||||
dds.on('click', function(){
|
||||
var othis = $(this), value = othis.attr('lay-value');
|
||||
var filter = select.attr('lay-filter'); //获取过滤器
|
||||
|
||||
if(othis.hasClass(DISABLED)) return false;
|
||||
|
||||
if(othis.hasClass('layui-select-tips')){
|
||||
input.val('');
|
||||
} else {
|
||||
input.val(othis.text());
|
||||
othis.addClass(THIS);
|
||||
}
|
||||
|
||||
othis.siblings().removeClass(THIS);
|
||||
select.val(value).removeClass('layui-form-danger')
|
||||
layui.event.call(this, MOD_NAME, 'select('+ filter +')', {
|
||||
elem: select[0]
|
||||
,value: value
|
||||
,othis: reElem
|
||||
});
|
||||
|
||||
hideDown(true);
|
||||
return false;
|
||||
});
|
||||
|
||||
reElem.find('dl>dt').on('click', function(e){
|
||||
return false;
|
||||
});
|
||||
|
||||
//关闭下拉
|
||||
$(document).off('click', hide).on('click', hide);
|
||||
}
|
||||
|
||||
selects.each(function(index, select){
|
||||
var othis = $(this)
|
||||
,hasRender = othis.next('.'+CLASS)
|
||||
,disabled = this.disabled
|
||||
,value = select.value
|
||||
,selected = $(select.options[select.selectedIndex]) //获取当前选中项
|
||||
,optionsFirst = select.options[0];
|
||||
|
||||
if(typeof othis.attr('lay-ignore') === 'string') return othis.show();
|
||||
|
||||
var isSearch = typeof othis.attr('lay-search') === 'string'
|
||||
,placeholder = optionsFirst ? (
|
||||
optionsFirst.value ? TIPS : (optionsFirst.innerHTML || TIPS)
|
||||
) : TIPS;
|
||||
|
||||
//替代元素
|
||||
var reElem = $(['<div class="'+ (isSearch ? '' : 'layui-unselect ') + CLASS + (disabled ? ' layui-select-disabled' : '') +'">'
|
||||
,'<div class="'+ TITLE +'"><input type="text" placeholder="'+ placeholder +'" value="'+ (value ? selected.html() : '') +'" '+ (isSearch ? '' : 'readonly') +' class="layui-input'+ (isSearch ? '' : ' 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 = [];
|
||||
layui.each(options, function(index, item){
|
||||
if(index === 0 && !item.value){
|
||||
arr.push('<dd lay-value="" class="layui-select-tips">'+ (item.innerHTML || TIPS) +'</dd>');
|
||||
} else if(item.tagName.toLowerCase() === 'optgroup'){
|
||||
arr.push('<dt>'+ item.label +'</dt>');
|
||||
} else {
|
||||
arr.push('<dd lay-value="'+ item.value +'" class="'+ (value === item.value ? THIS : '') + (item.disabled ? (' '+DISABLED) : '') +'">'+ item.innerHTML +'</dd>');
|
||||
}
|
||||
});
|
||||
arr.length === 0 && arr.push('<dd lay-value="" class="'+ DISABLED +'">没有选项</dd>');
|
||||
return arr.join('');
|
||||
}(othis.find('*')) +'</dl>'
|
||||
,'</div>'].join(''));
|
||||
|
||||
hasRender[0] && hasRender.remove(); //如果已经渲染,则Rerender
|
||||
othis.after(reElem);
|
||||
events.call(this, reElem, disabled, isSearch);
|
||||
});
|
||||
}
|
||||
//复选框/开关
|
||||
,checkbox: function(){
|
||||
var CLASS = {
|
||||
checkbox: ['layui-form-checkbox', 'layui-form-checked', 'checkbox']
|
||||
,_switch: ['layui-form-switch', 'layui-form-onswitch', 'switch']
|
||||
}
|
||||
,checks = elemForm.find('input[type=checkbox]')
|
||||
|
||||
,events = function(reElem, RE_CLASS){
|
||||
var check = $(this);
|
||||
|
||||
//勾选
|
||||
reElem.on('click', function(){
|
||||
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]).find('em').text(text[1])
|
||||
) : (
|
||||
check[0].checked = true
|
||||
,reElem.addClass(RE_CLASS[1]).find('em').text(text[0])
|
||||
);
|
||||
|
||||
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')
|
||||
,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 : '') +'" lay-skin="'+ (skin||'') +'">'
|
||||
,{
|
||||
_switch: '<em>'+ ((check.checked ? text[0] : text[1])||'') +'</em><i></i>'
|
||||
}[skin] || ((check.title.replace(/\s/g, '') ? ('<span>'+ check.title +'</span>') : '') +'<i class="layui-icon">'+ (skin ? '' : '') +'</i>')
|
||||
,'</div>'].join(''));
|
||||
|
||||
hasRender[0] && hasRender.remove(); //如果已经渲染,则Rerender
|
||||
othis.after(reElem);
|
||||
events.call(this, reElem, RE_CLASS);
|
||||
});
|
||||
}
|
||||
//单选框
|
||||
,radio: function(){
|
||||
var CLASS = 'layui-form-radio', ICON = ['', '']
|
||||
,radios = elemForm.find('input[type=radio]')
|
||||
|
||||
,events = function(reElem){
|
||||
var radio = $(this), ANIM = 'layui-anim-scaleSpring';
|
||||
|
||||
reElem.on('click', function(){
|
||||
var name = radio[0].name, forms = radio.parents(ELEM);
|
||||
var filter = radio.attr('lay-filter'); //获取过滤器
|
||||
var sameRadio = forms.find('input[name='+ name.replace(/(\.|#|\[|\])/g, '\\$1') +']'); //找到相同name的兄弟
|
||||
|
||||
if(radio[0].disabled) return;
|
||||
|
||||
layui.each(sameRadio, function(){
|
||||
var next = $(this).next('.'+CLASS);
|
||||
this.checked = false;
|
||||
next.removeClass(CLASS+'ed');
|
||||
next.find('.layui-icon').removeClass(ANIM).html(ICON[1]);
|
||||
});
|
||||
|
||||
radio[0].checked = true;
|
||||
reElem.addClass(CLASS+'ed');
|
||||
reElem.find('.layui-icon').addClass(ANIM).html(ICON[0]);
|
||||
|
||||
layui.event.call(radio[0], MOD_NAME, 'radio('+ filter +')', {
|
||||
elem: radio[0]
|
||||
,value: radio[0].value
|
||||
,othis: reElem
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
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>'
|
||||
,'<span>'+ (radio.title||'未命名') +'</span>'
|
||||
,'</div>'].join(''));
|
||||
|
||||
hasRender[0] && hasRender.remove(); //如果已经渲染,则Rerender
|
||||
othis.after(reElem);
|
||||
events.call(this, reElem);
|
||||
});
|
||||
}
|
||||
};
|
||||
type ? (
|
||||
items[type] ? items[type]() : hint.error('不支持的'+ type + '表单渲染')
|
||||
) : layui.each(items, function(index, item){
|
||||
item();
|
||||
});
|
||||
return that;
|
||||
};
|
||||
|
||||
//表单提交校验
|
||||
var submit = function(){
|
||||
var button = $(this), verify = form.config.verify, stop = null
|
||||
,DANGER = 'layui-form-danger', field = {} ,elem = button.parents(ELEM)
|
||||
|
||||
,verifyElem = elem.find('*[lay-verify]') //获取需要校验的元素
|
||||
,formElem = button.parents('form')[0] //获取当前所在的form元素,如果存在的话
|
||||
,fieldElem = elem.find('input,select,textarea') //获取所有表单域
|
||||
,filter = button.attr('lay-filter'); //获取过滤器
|
||||
|
||||
//开始校验
|
||||
layui.each(verifyElem, function(_, item){
|
||||
var othis = $(this), ver = othis.attr('lay-verify').split('|');
|
||||
var tips = '', value = othis.val();
|
||||
othis.removeClass(DANGER);
|
||||
layui.each(ver, function(_, thisVer){
|
||||
var isFn = typeof verify[thisVer] === 'function';
|
||||
if(verify[thisVer] && (isFn ? tips = verify[thisVer](value, item) : !verify[thisVer][0].test(value)) ){
|
||||
layer.msg(tips || verify[thisVer][1], {
|
||||
icon: 5
|
||||
,shift: 6
|
||||
});
|
||||
//非移动设备自动定位焦点
|
||||
if(!device.android && !device.ios){
|
||||
item.focus();
|
||||
}
|
||||
othis.addClass(DANGER);
|
||||
return stop = true;
|
||||
}
|
||||
});
|
||||
if(stop) return stop;
|
||||
});
|
||||
|
||||
if(stop) return false;
|
||||
|
||||
layui.each(fieldElem, function(_, item){
|
||||
if(!item.name) return;
|
||||
if(/^checkbox|radio$/.test(item.type) && !item.checked) return;
|
||||
field[item.name] = item.value;
|
||||
});
|
||||
|
||||
//获取字段
|
||||
return layui.event.call(this, MOD_NAME, 'submit('+ filter +')', {
|
||||
elem: this
|
||||
,form: formElem
|
||||
,field: field
|
||||
});
|
||||
};
|
||||
|
||||
//自动完成渲染
|
||||
var form = new Form()
|
||||
,dom = $(document), win = $(window);
|
||||
|
||||
form.render();
|
||||
|
||||
//表单reset重置渲染
|
||||
dom.on('reset', ELEM, function(){
|
||||
var filter = $(this).attr('lay-filter');
|
||||
setTimeout(function(){
|
||||
form.render(null, filter);
|
||||
}, 50);
|
||||
});
|
||||
|
||||
//表单提交事件
|
||||
dom.on('submit', ELEM, submit)
|
||||
.on('click', '*[lay-submit]', submit);
|
||||
|
||||
exports(MOD_NAME, form);
|
||||
});
|
||||
|
||||
|
10987
novel-admin/src/main/resources/static/js/lay/modules/jquery.js
vendored
Normal file
10987
novel-admin/src/main/resources/static/js/lay/modules/jquery.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1855
novel-admin/src/main/resources/static/js/lay/modules/laydate.js
Normal file
1855
novel-admin/src/main/resources/static/js/lay/modules/laydate.js
Normal file
File diff suppressed because it is too large
Load Diff
649
novel-admin/src/main/resources/static/js/lay/modules/layedit.js
Normal file
649
novel-admin/src/main/resources/static/js/lay/modules/layedit.js
Normal file
@ -0,0 +1,649 @@
|
||||
/**
|
||||
|
||||
@Name:layui.layedit 富文本编辑器
|
||||
@Author:贤心
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define(['layer', 'form'], function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.$
|
||||
,layer = layui.layer
|
||||
,form = layui.form
|
||||
,hint = layui.hint()
|
||||
,device = layui.device()
|
||||
|
||||
,MOD_NAME = 'layedit', THIS = 'layui-this', SHOW = 'layui-show', ABLED = 'layui-disabled'
|
||||
|
||||
,Edit = function(){
|
||||
var that = this;
|
||||
that.index = 0;
|
||||
|
||||
//全局配置
|
||||
that.config = {
|
||||
//默认工具bar
|
||||
tool: [
|
||||
'strong', 'italic', 'underline', 'del'
|
||||
,'|'
|
||||
,'left', 'center', 'right'
|
||||
,'|'
|
||||
,'link', 'unlink', 'face', 'image'
|
||||
]
|
||||
,hideTool: []
|
||||
,height: 280 //默认高
|
||||
};
|
||||
};
|
||||
|
||||
//全局设置
|
||||
Edit.prototype.set = function(options){
|
||||
var that = this;
|
||||
$.extend(true, that.config, options);
|
||||
return that;
|
||||
};
|
||||
|
||||
//事件监听
|
||||
Edit.prototype.on = function(events, callback){
|
||||
return layui.onevent(MOD_NAME, events, callback);
|
||||
};
|
||||
|
||||
//建立编辑器
|
||||
Edit.prototype.build = function(id, settings){
|
||||
settings = settings || {};
|
||||
|
||||
var that = this
|
||||
,config = that.config
|
||||
,ELEM = 'layui-layedit', textArea = $('#'+id)
|
||||
,name = 'LAY_layedit_'+ (++that.index)
|
||||
,haveBuild = textArea.next('.'+ELEM)
|
||||
|
||||
,set = $.extend({}, config, settings)
|
||||
|
||||
,tool = function(){
|
||||
var node = [], hideTools = {};
|
||||
layui.each(set.hideTool, function(_, item){
|
||||
hideTools[item] = true;
|
||||
});
|
||||
layui.each(set.tool, function(_, item){
|
||||
if(tools[item] && !hideTools[item]){
|
||||
node.push(tools[item]);
|
||||
}
|
||||
});
|
||||
return node.join('');
|
||||
}()
|
||||
|
||||
|
||||
,editor = $(['<div class="'+ ELEM +'">'
|
||||
,'<div class="layui-unselect layui-layedit-tool">'+ tool +'</div>'
|
||||
,'<div class="layui-layedit-iframe">'
|
||||
,'<iframe id="'+ name +'" name="'+ name +'" textarea="'+ id +'" frameborder="0"></iframe>'
|
||||
,'</div>'
|
||||
,'</div>'].join(''))
|
||||
|
||||
//编辑器不兼容ie8以下
|
||||
if(device.ie && device.ie < 8){
|
||||
return textArea.removeClass('layui-hide').addClass(SHOW);
|
||||
}
|
||||
|
||||
haveBuild[0] && (haveBuild.remove());
|
||||
|
||||
setIframe.call(that, editor, textArea[0], set)
|
||||
textArea.addClass('layui-hide').after(editor);
|
||||
|
||||
return that.index;
|
||||
};
|
||||
|
||||
//获得编辑器中内容
|
||||
Edit.prototype.getContent = function(index){
|
||||
var iframeWin = getWin(index);
|
||||
if(!iframeWin[0]) return;
|
||||
return toLower(iframeWin[0].document.body.innerHTML);
|
||||
};
|
||||
|
||||
//获得编辑器中纯文本内容
|
||||
Edit.prototype.getText = function(index){
|
||||
var iframeWin = getWin(index);
|
||||
if(!iframeWin[0]) return;
|
||||
return $(iframeWin[0].document.body).text();
|
||||
};
|
||||
/**
|
||||
* 设置编辑器内容
|
||||
* @param {[type]} index 编辑器索引
|
||||
* @param {[type]} content 要设置的内容
|
||||
* @param {[type]} flag 是否追加模式
|
||||
*/
|
||||
Edit.prototype.setContent = function(index, content, flag){
|
||||
var iframeWin = getWin(index);
|
||||
if(!iframeWin[0]) return;
|
||||
if(flag){
|
||||
$(iframeWin[0].document.body).append(content)
|
||||
}else{
|
||||
$(iframeWin[0].document.body).html(content)
|
||||
};
|
||||
layedit.sync(index)
|
||||
};
|
||||
//将编辑器内容同步到textarea(一般用于异步提交时)
|
||||
Edit.prototype.sync = function(index){
|
||||
var iframeWin = getWin(index);
|
||||
if(!iframeWin[0]) return;
|
||||
var textarea = $('#'+iframeWin[1].attr('textarea'));
|
||||
textarea.val(toLower(iframeWin[0].document.body.innerHTML));
|
||||
};
|
||||
|
||||
//获取编辑器选中内容
|
||||
Edit.prototype.getSelection = function(index){
|
||||
var iframeWin = getWin(index);
|
||||
if(!iframeWin[0]) return;
|
||||
var range = Range(iframeWin[0].document);
|
||||
return document.selection ? range.text : range.toString();
|
||||
};
|
||||
|
||||
//iframe初始化
|
||||
var setIframe = function(editor, textArea, set){
|
||||
var that = this, iframe = editor.find('iframe');
|
||||
|
||||
iframe.css({
|
||||
height: set.height
|
||||
}).on('load', function(){
|
||||
var conts = iframe.contents()
|
||||
,iframeWin = iframe.prop('contentWindow')
|
||||
,head = conts.find('head')
|
||||
,style = $(['<style>'
|
||||
,'*{margin: 0; padding: 0;}'
|
||||
,'body{padding: 10px; line-height: 20px; overflow-x: hidden; word-wrap: break-word; font: 14px Helvetica Neue,Helvetica,PingFang SC,Microsoft YaHei,Tahoma,Arial,sans-serif; -webkit-box-sizing: border-box !important; -moz-box-sizing: border-box !important; box-sizing: border-box !important;}'
|
||||
,'a{color:#01AAED; text-decoration:none;}a:hover{color:#c00}'
|
||||
,'p{margin-bottom: 10px;}'
|
||||
,'img{display: inline-block; border: none; vertical-align: middle;}'
|
||||
,'pre{margin: 10px 0; padding: 10px; line-height: 20px; border: 1px solid #ddd; border-left-width: 6px; background-color: #F2F2F2; color: #333; font-family: Courier New; font-size: 12px;}'
|
||||
,'</style>'].join(''))
|
||||
,body = conts.find('body');
|
||||
|
||||
head.append(style);
|
||||
body.attr('contenteditable', 'true').css({
|
||||
'min-height': set.height
|
||||
}).html(textArea.value||'');
|
||||
|
||||
hotkey.apply(that, [iframeWin, iframe, textArea, set]); //快捷键处理
|
||||
toolActive.call(that, iframeWin, editor, set); //触发工具
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
//获得iframe窗口对象
|
||||
,getWin = function(index){
|
||||
var iframe = $('#LAY_layedit_'+ index)
|
||||
,iframeWin = iframe.prop('contentWindow');
|
||||
return [iframeWin, iframe];
|
||||
}
|
||||
|
||||
//IE8下将标签处理成小写
|
||||
,toLower = function(html){
|
||||
if(device.ie == 8){
|
||||
html = html.replace(/<.+>/g, function(str){
|
||||
return str.toLowerCase();
|
||||
});
|
||||
}
|
||||
return html;
|
||||
}
|
||||
|
||||
//快捷键处理
|
||||
,hotkey = function(iframeWin, iframe, textArea, set){
|
||||
var iframeDOM = iframeWin.document, body = $(iframeDOM.body);
|
||||
body.on('keydown', function(e){
|
||||
var keycode = e.keyCode;
|
||||
//处理回车
|
||||
if(keycode === 13){
|
||||
var range = Range(iframeDOM);
|
||||
var container = getContainer(range)
|
||||
,parentNode = container.parentNode;
|
||||
|
||||
if(parentNode.tagName.toLowerCase() === 'pre'){
|
||||
if(e.shiftKey) return
|
||||
layer.msg('请暂时用shift+enter');
|
||||
return false;
|
||||
}
|
||||
iframeDOM.execCommand('formatBlock', false, '<p>');
|
||||
}
|
||||
});
|
||||
|
||||
//给textarea同步内容
|
||||
$(textArea).parents('form').on('submit', function(){
|
||||
var html = body.html();
|
||||
//IE8下将标签处理成小写
|
||||
if(device.ie == 8){
|
||||
html = html.replace(/<.+>/g, function(str){
|
||||
return str.toLowerCase();
|
||||
});
|
||||
}
|
||||
textArea.value = html;
|
||||
});
|
||||
|
||||
//处理粘贴
|
||||
body.on('paste', function(e){
|
||||
iframeDOM.execCommand('formatBlock', false, '<p>');
|
||||
setTimeout(function(){
|
||||
filter.call(iframeWin, body);
|
||||
textArea.value = body.html();
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
|
||||
//标签过滤
|
||||
,filter = function(body){
|
||||
var iframeWin = this
|
||||
,iframeDOM = iframeWin.document;
|
||||
|
||||
//清除影响版面的css属性
|
||||
body.find('*[style]').each(function(){
|
||||
var textAlign = this.style.textAlign;
|
||||
this.removeAttribute('style');
|
||||
$(this).css({
|
||||
'text-align': textAlign || ''
|
||||
})
|
||||
});
|
||||
|
||||
//修饰表格
|
||||
body.find('table').addClass('layui-table');
|
||||
|
||||
//移除不安全的标签
|
||||
body.find('script,link').remove();
|
||||
}
|
||||
|
||||
//Range对象兼容性处理
|
||||
,Range = function(iframeDOM){
|
||||
return iframeDOM.selection
|
||||
? iframeDOM.selection.createRange()
|
||||
: iframeDOM.getSelection().getRangeAt(0);
|
||||
}
|
||||
|
||||
//当前Range对象的endContainer兼容性处理
|
||||
,getContainer = function(range){
|
||||
return range.endContainer || range.parentElement().childNodes[0]
|
||||
}
|
||||
|
||||
//在选区插入内联元素
|
||||
,insertInline = function(tagName, attr, range){
|
||||
var iframeDOM = this.document
|
||||
,elem = document.createElement(tagName)
|
||||
for(var key in attr){
|
||||
elem.setAttribute(key, attr[key]);
|
||||
}
|
||||
elem.removeAttribute('text');
|
||||
|
||||
if(iframeDOM.selection){ //IE
|
||||
var text = range.text || attr.text;
|
||||
if(tagName === 'a' && !text) return;
|
||||
if(text){
|
||||
elem.innerHTML = text;
|
||||
}
|
||||
range.pasteHTML($(elem).prop('outerHTML'));
|
||||
range.select();
|
||||
} else { //非IE
|
||||
var text = range.toString() || attr.text;
|
||||
if(tagName === 'a' && !text) return;
|
||||
if(text){
|
||||
elem.innerHTML = text;
|
||||
}
|
||||
range.deleteContents();
|
||||
range.insertNode(elem);
|
||||
}
|
||||
}
|
||||
|
||||
//工具选中
|
||||
,toolCheck = function(tools, othis){
|
||||
var iframeDOM = this.document
|
||||
,CHECK = 'layedit-tool-active'
|
||||
,container = getContainer(Range(iframeDOM))
|
||||
,item = function(type){
|
||||
return tools.find('.layedit-tool-'+type)
|
||||
}
|
||||
|
||||
if(othis){
|
||||
othis[othis.hasClass(CHECK) ? 'removeClass' : 'addClass'](CHECK);
|
||||
}
|
||||
|
||||
tools.find('>i').removeClass(CHECK);
|
||||
item('unlink').addClass(ABLED);
|
||||
|
||||
$(container).parents().each(function(){
|
||||
var tagName = this.tagName.toLowerCase()
|
||||
,textAlign = this.style.textAlign;
|
||||
|
||||
//文字
|
||||
if(tagName === 'b' || tagName === 'strong'){
|
||||
item('b').addClass(CHECK)
|
||||
}
|
||||
if(tagName === 'i' || tagName === 'em'){
|
||||
item('i').addClass(CHECK)
|
||||
}
|
||||
if(tagName === 'u'){
|
||||
item('u').addClass(CHECK)
|
||||
}
|
||||
if(tagName === 'strike'){
|
||||
item('d').addClass(CHECK)
|
||||
}
|
||||
|
||||
//对齐
|
||||
if(tagName === 'p'){
|
||||
if(textAlign === 'center'){
|
||||
item('center').addClass(CHECK);
|
||||
} else if(textAlign === 'right'){
|
||||
item('right').addClass(CHECK);
|
||||
} else {
|
||||
item('left').addClass(CHECK);
|
||||
}
|
||||
}
|
||||
|
||||
//超链接
|
||||
if(tagName === 'a'){
|
||||
item('link').addClass(CHECK);
|
||||
item('unlink').removeClass(ABLED);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//触发工具
|
||||
,toolActive = function(iframeWin, editor, set){
|
||||
var iframeDOM = iframeWin.document
|
||||
,body = $(iframeDOM.body)
|
||||
,toolEvent = {
|
||||
//超链接
|
||||
link: function(range){
|
||||
var container = getContainer(range)
|
||||
,parentNode = $(container).parent();
|
||||
|
||||
link.call(body, {
|
||||
href: parentNode.attr('href')
|
||||
,target: parentNode.attr('target')
|
||||
}, function(field){
|
||||
var parent = parentNode[0];
|
||||
if(parent.tagName === 'A'){
|
||||
parent.href = field.url;
|
||||
} else {
|
||||
insertInline.call(iframeWin, 'a', {
|
||||
target: field.target
|
||||
,href: field.url
|
||||
,text: field.url
|
||||
}, range);
|
||||
}
|
||||
});
|
||||
}
|
||||
//清除超链接
|
||||
,unlink: function(range){
|
||||
iframeDOM.execCommand('unlink');
|
||||
}
|
||||
//表情
|
||||
,face: function(range){
|
||||
face.call(this, function(img){
|
||||
insertInline.call(iframeWin, 'img', {
|
||||
src: img.src
|
||||
,alt: img.alt
|
||||
}, range);
|
||||
});
|
||||
}
|
||||
//图片
|
||||
,image: function(range){
|
||||
var that = this;
|
||||
layui.use('upload', function(upload){
|
||||
var uploadImage = set.uploadImage || {};
|
||||
upload.render({
|
||||
url: uploadImage.url
|
||||
,method: uploadImage.type
|
||||
,elem: $(that).find('input')[0]
|
||||
,done: function(res){
|
||||
if(res.code == 0){
|
||||
res.data = res.data || {};
|
||||
insertInline.call(iframeWin, 'img', {
|
||||
src: res.data.src
|
||||
,alt: res.data.title
|
||||
}, range);
|
||||
} else {
|
||||
layer.msg(res.msg||'上传失败');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
//插入代码
|
||||
,code: function(range){
|
||||
code.call(body, function(pre){
|
||||
insertInline.call(iframeWin, 'pre', {
|
||||
text: pre.code
|
||||
,'lay-lang': pre.lang
|
||||
}, range);
|
||||
});
|
||||
}
|
||||
//帮助
|
||||
,help: function(){
|
||||
layer.open({
|
||||
type: 2
|
||||
,title: '帮助'
|
||||
,area: ['600px', '380px']
|
||||
,shadeClose: true
|
||||
,shade: 0.1
|
||||
,skin: 'layui-layer-msg'
|
||||
,content: ['http://www.layui.com/about/layedit/help.html', 'no']
|
||||
});
|
||||
}
|
||||
}
|
||||
,tools = editor.find('.layui-layedit-tool')
|
||||
|
||||
,click = function(){
|
||||
var othis = $(this)
|
||||
,events = othis.attr('layedit-event')
|
||||
,command = othis.attr('lay-command');
|
||||
|
||||
if(othis.hasClass(ABLED)) return;
|
||||
|
||||
body.focus();
|
||||
|
||||
var range = Range(iframeDOM)
|
||||
,container = range.commonAncestorContainer
|
||||
|
||||
if(command){
|
||||
iframeDOM.execCommand(command);
|
||||
if(/justifyLeft|justifyCenter|justifyRight/.test(command)){
|
||||
iframeDOM.execCommand('formatBlock', false, '<p>');
|
||||
}
|
||||
setTimeout(function(){
|
||||
body.focus();
|
||||
}, 10);
|
||||
} else {
|
||||
toolEvent[events] && toolEvent[events].call(this, range);
|
||||
}
|
||||
toolCheck.call(iframeWin, tools, othis);
|
||||
}
|
||||
|
||||
,isClick = /image/
|
||||
|
||||
tools.find('>i').on('mousedown', function(){
|
||||
var othis = $(this)
|
||||
,events = othis.attr('layedit-event');
|
||||
if(isClick.test(events)) return;
|
||||
click.call(this)
|
||||
}).on('click', function(){
|
||||
var othis = $(this)
|
||||
,events = othis.attr('layedit-event');
|
||||
if(!isClick.test(events)) return;
|
||||
click.call(this)
|
||||
});
|
||||
|
||||
//触发内容区域
|
||||
body.on('click', function(){
|
||||
toolCheck.call(iframeWin, tools);
|
||||
layer.close(face.index);
|
||||
});
|
||||
}
|
||||
|
||||
//超链接面板
|
||||
,link = function(options, callback){
|
||||
var body = this, index = layer.open({
|
||||
type: 1
|
||||
,id: 'LAY_layedit_link'
|
||||
,area: '350px'
|
||||
,shade: 0.05
|
||||
,shadeClose: true
|
||||
,moveType: 1
|
||||
,title: '超链接'
|
||||
,skin: 'layui-layer-msg'
|
||||
,content: ['<ul class="layui-form" style="margin: 15px;">'
|
||||
,'<li class="layui-form-item">'
|
||||
,'<label class="layui-form-label" style="width: 60px;">URL</label>'
|
||||
,'<div class="layui-input-block" style="margin-left: 90px">'
|
||||
,'<input name="url" lay-verify="url" value="'+ (options.href||'') +'" autofocus="true" autocomplete="off" class="layui-input">'
|
||||
,'</div>'
|
||||
,'</li>'
|
||||
,'<li class="layui-form-item">'
|
||||
,'<label class="layui-form-label" style="width: 60px;">打开方式</label>'
|
||||
,'<div class="layui-input-block" style="margin-left: 90px">'
|
||||
,'<input type="radio" name="target" value="_self" class="layui-input" title="当前窗口"'
|
||||
+ ((options.target==='_self' || !options.target) ? 'checked' : '') +'>'
|
||||
,'<input type="radio" name="target" value="_blank" class="layui-input" title="新窗口" '
|
||||
+ (options.target==='_blank' ? 'checked' : '') +'>'
|
||||
,'</div>'
|
||||
,'</li>'
|
||||
,'<li class="layui-form-item" style="text-align: center;">'
|
||||
,'<button type="button" lay-submit lay-filter="layedit-link-yes" class="layui-btn"> 确定 </button>'
|
||||
,'<button style="margin-left: 20px;" type="button" class="layui-btn layui-btn-primary"> 取消 </button>'
|
||||
,'</li>'
|
||||
,'</ul>'].join('')
|
||||
,success: function(layero, index){
|
||||
var eventFilter = 'submit(layedit-link-yes)';
|
||||
form.render('radio');
|
||||
layero.find('.layui-btn-primary').on('click', function(){
|
||||
layer.close(index);
|
||||
body.focus();
|
||||
});
|
||||
form.on(eventFilter, function(data){
|
||||
layer.close(link.index);
|
||||
callback && callback(data.field);
|
||||
});
|
||||
}
|
||||
});
|
||||
link.index = index;
|
||||
}
|
||||
|
||||
//表情面板
|
||||
,face = function(callback){
|
||||
//表情库
|
||||
var faces = function(){
|
||||
var alt = ["[微笑]", "[嘻嘻]", "[哈哈]", "[可爱]", "[可怜]", "[挖鼻]", "[吃惊]", "[害羞]", "[挤眼]", "[闭嘴]", "[鄙视]", "[爱你]", "[泪]", "[偷笑]", "[亲亲]", "[生病]", "[太开心]", "[白眼]", "[右哼哼]", "[左哼哼]", "[嘘]", "[衰]", "[委屈]", "[吐]", "[哈欠]", "[抱抱]", "[怒]", "[疑问]", "[馋嘴]", "[拜拜]", "[思考]", "[汗]", "[困]", "[睡]", "[钱]", "[失望]", "[酷]", "[色]", "[哼]", "[鼓掌]", "[晕]", "[悲伤]", "[抓狂]", "[黑线]", "[阴险]", "[怒骂]", "[互粉]", "[心]", "[伤心]", "[猪头]", "[熊猫]", "[兔子]", "[ok]", "[耶]", "[good]", "[NO]", "[赞]", "[来]", "[弱]", "[草泥马]", "[神马]", "[囧]", "[浮云]", "[给力]", "[围观]", "[威武]", "[奥特曼]", "[礼物]", "[钟]", "[话筒]", "[蜡烛]", "[蛋糕]"], arr = {};
|
||||
layui.each(alt, function(index, item){
|
||||
arr[item] = layui.cache.dir + 'images/face/'+ index + '.gif';
|
||||
});
|
||||
return arr;
|
||||
}();
|
||||
face.hide = face.hide || function(e){
|
||||
if($(e.target).attr('layedit-event') !== 'face'){
|
||||
layer.close(face.index);
|
||||
}
|
||||
}
|
||||
return face.index = layer.tips(function(){
|
||||
var content = [];
|
||||
layui.each(faces, function(key, item){
|
||||
content.push('<li title="'+ key +'"><img src="'+ item +'" alt="'+ key +'"></li>');
|
||||
});
|
||||
return '<ul class="layui-clear">' + content.join('') + '</ul>';
|
||||
}(), this, {
|
||||
tips: 1
|
||||
,time: 0
|
||||
,skin: 'layui-box layui-util-face'
|
||||
,maxWidth: 500
|
||||
,success: function(layero, index){
|
||||
layero.css({
|
||||
marginTop: -4
|
||||
,marginLeft: -10
|
||||
}).find('.layui-clear>li').on('click', function(){
|
||||
callback && callback({
|
||||
src: faces[this.title]
|
||||
,alt: this.title
|
||||
});
|
||||
layer.close(index);
|
||||
});
|
||||
$(document).off('click', face.hide).on('click', face.hide);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//插入代码面板
|
||||
,code = function(callback){
|
||||
var body = this, index = layer.open({
|
||||
type: 1
|
||||
,id: 'LAY_layedit_code'
|
||||
,area: '550px'
|
||||
,shade: 0.05
|
||||
,shadeClose: true
|
||||
,moveType: 1
|
||||
,title: '插入代码'
|
||||
,skin: 'layui-layer-msg'
|
||||
,content: ['<ul class="layui-form layui-form-pane" style="margin: 15px;">'
|
||||
,'<li class="layui-form-item">'
|
||||
,'<label class="layui-form-label">请选择语言</label>'
|
||||
,'<div class="layui-input-block">'
|
||||
,'<select name="lang">'
|
||||
,'<option value="JavaScript">JavaScript</option>'
|
||||
,'<option value="HTML">HTML</option>'
|
||||
,'<option value="CSS">CSS</option>'
|
||||
,'<option value="Java">Java</option>'
|
||||
,'<option value="PHP">PHP</option>'
|
||||
,'<option value="C#">C#</option>'
|
||||
,'<option value="Python">Python</option>'
|
||||
,'<option value="Ruby">Ruby</option>'
|
||||
,'<option value="Go">Go</option>'
|
||||
,'</select>'
|
||||
,'</div>'
|
||||
,'</li>'
|
||||
,'<li class="layui-form-item layui-form-text">'
|
||||
,'<label class="layui-form-label">代码</label>'
|
||||
,'<div class="layui-input-block">'
|
||||
,'<textarea name="code" lay-verify="required" autofocus="true" class="layui-textarea" style="height: 200px;"></textarea>'
|
||||
,'</div>'
|
||||
,'</li>'
|
||||
,'<li class="layui-form-item" style="text-align: center;">'
|
||||
,'<button type="button" lay-submit lay-filter="layedit-code-yes" class="layui-btn"> 确定 </button>'
|
||||
,'<button style="margin-left: 20px;" type="button" class="layui-btn layui-btn-primary"> 取消 </button>'
|
||||
,'</li>'
|
||||
,'</ul>'].join('')
|
||||
,success: function(layero, index){
|
||||
var eventFilter = 'submit(layedit-code-yes)';
|
||||
form.render('select');
|
||||
layero.find('.layui-btn-primary').on('click', function(){
|
||||
layer.close(index);
|
||||
body.focus();
|
||||
});
|
||||
form.on(eventFilter, function(data){
|
||||
layer.close(code.index);
|
||||
callback && callback(data.field);
|
||||
});
|
||||
}
|
||||
});
|
||||
code.index = index;
|
||||
}
|
||||
|
||||
//全部工具
|
||||
,tools = {
|
||||
html: '<i class="layui-icon layedit-tool-html" title="HTML源代码" lay-command="html" layedit-event="html""></i><span class="layedit-tool-mid"></span>'
|
||||
,strong: '<i class="layui-icon layedit-tool-b" title="加粗" lay-command="Bold" layedit-event="b""></i>'
|
||||
,italic: '<i class="layui-icon layedit-tool-i" title="斜体" lay-command="italic" layedit-event="i""></i>'
|
||||
,underline: '<i class="layui-icon layedit-tool-u" title="下划线" lay-command="underline" layedit-event="u""></i>'
|
||||
,del: '<i class="layui-icon layedit-tool-d" title="删除线" lay-command="strikeThrough" layedit-event="d""></i>'
|
||||
|
||||
,'|': '<span class="layedit-tool-mid"></span>'
|
||||
|
||||
,left: '<i class="layui-icon layedit-tool-left" title="左对齐" lay-command="justifyLeft" layedit-event="left""></i>'
|
||||
,center: '<i class="layui-icon layedit-tool-center" title="居中对齐" lay-command="justifyCenter" layedit-event="center""></i>'
|
||||
,right: '<i class="layui-icon layedit-tool-right" title="右对齐" lay-command="justifyRight" layedit-event="right""></i>'
|
||||
,link: '<i class="layui-icon layedit-tool-link" title="插入链接" layedit-event="link""></i>'
|
||||
,unlink: '<i class="layui-icon layedit-tool-unlink layui-disabled" title="清除链接" lay-command="unlink" layedit-event="unlink""></i>'
|
||||
,face: '<i class="layui-icon layedit-tool-face" title="表情" layedit-event="face""></i>'
|
||||
,image: '<i class="layui-icon layedit-tool-image" title="图片" layedit-event="image"><input type="file" name="file"></i>'
|
||||
,code: '<i class="layui-icon layedit-tool-code" title="插入代码" layedit-event="code"></i>'
|
||||
|
||||
,help: '<i class="layui-icon layedit-tool-help" title="帮助" layedit-event="help"></i>'
|
||||
}
|
||||
|
||||
,edit = new Edit();
|
||||
|
||||
exports(MOD_NAME, edit);
|
||||
});
|
1294
novel-admin/src/main/resources/static/js/lay/modules/layer.js
Normal file
1294
novel-admin/src/main/resources/static/js/lay/modules/layer.js
Normal file
File diff suppressed because it is too large
Load Diff
304
novel-admin/src/main/resources/static/js/lay/modules/laypage.js
Normal file
304
novel-admin/src/main/resources/static/js/lay/modules/laypage.js
Normal file
@ -0,0 +1,304 @@
|
||||
/**
|
||||
|
||||
@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);
|
||||
});
|
111
novel-admin/src/main/resources/static/js/lay/modules/laytpl.js
Normal file
111
novel-admin/src/main/resources/static/js/lay/modules/laytpl.js
Normal file
@ -0,0 +1,111 @@
|
||||
/**
|
||||
|
||||
@Name : layui.laytpl 模板引擎
|
||||
@Author:贤心
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define(function(exports){
|
||||
|
||||
"use strict";
|
||||
|
||||
var config = {
|
||||
open: '{{',
|
||||
close: '}}'
|
||||
};
|
||||
|
||||
var tool = {
|
||||
exp: function(str){
|
||||
return new RegExp(str, 'g');
|
||||
},
|
||||
//匹配满足规则内容
|
||||
query: function(type, _, __){
|
||||
var types = [
|
||||
'#([\\s\\S])+?', //js语句
|
||||
'([^{#}])*?' //普通字段
|
||||
][type || 0];
|
||||
return exp((_||'') + config.open + types + config.close + (__||''));
|
||||
},
|
||||
escape: function(html){
|
||||
return String(html||'').replace(/&(?!#?[a-zA-Z0-9]+;)/g, '&')
|
||||
.replace(/</g, '<').replace(/>/g, '>').replace(/'/g, ''').replace(/"/g, '"');
|
||||
},
|
||||
error: function(e, tplog){
|
||||
var error = 'Laytpl Error:';
|
||||
typeof console === 'object' && console.error(error + e + '\n'+ (tplog || ''));
|
||||
return error + e;
|
||||
}
|
||||
};
|
||||
|
||||
var exp = tool.exp, Tpl = function(tpl){
|
||||
this.tpl = tpl;
|
||||
};
|
||||
|
||||
Tpl.pt = Tpl.prototype;
|
||||
|
||||
window.errors = 0;
|
||||
|
||||
//编译模版
|
||||
Tpl.pt.parse = function(tpl, data){
|
||||
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+'# ')
|
||||
|
||||
.replace(exp(config.close+'}'), '} '+config.close).replace(/\\/g, '\\\\')
|
||||
|
||||
.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){
|
||||
return '';
|
||||
}
|
||||
str = str.replace(exp(config.open+'|'+config.close), '');
|
||||
if(/^=/.test(str)){
|
||||
str = str.replace(/^=/, '');
|
||||
start = '"+_escape_(';
|
||||
}
|
||||
return start + str.replace(/\\/g, '') + ')+"';
|
||||
});
|
||||
|
||||
tpl = '"use strict";var view = "' + tpl + '";return view;';
|
||||
|
||||
try{
|
||||
that.cache = tpl = new Function('d, _escape_', tpl);
|
||||
return tpl(data, tool.escape);
|
||||
} catch(e){
|
||||
delete that.cache;
|
||||
return tool.error(e, tplog);
|
||||
}
|
||||
};
|
||||
|
||||
Tpl.pt.render = function(data, callback){
|
||||
var that = this, tpl;
|
||||
if(!data) return tool.error('no data');
|
||||
tpl = that.cache ? that.cache(data, tool.escape) : that.parse(that.tpl, data);
|
||||
if(!callback) return tpl;
|
||||
callback(tpl);
|
||||
};
|
||||
|
||||
var laytpl = function(tpl){
|
||||
if(typeof tpl !== 'string') return tool.error('Template not found');
|
||||
return new Tpl(tpl);
|
||||
};
|
||||
|
||||
laytpl.config = function(options){
|
||||
options = options || {};
|
||||
for(var i in options){
|
||||
config[i] = options[i];
|
||||
}
|
||||
};
|
||||
|
||||
laytpl.v = '1.2.0';
|
||||
|
||||
exports('laytpl', laytpl);
|
||||
|
||||
});
|
@ -0,0 +1,30 @@
|
||||
/**
|
||||
|
||||
@Name:layui 移动模块入口 | 构建后则为移动模块集合
|
||||
@Author:贤心
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
|
||||
if(!layui['layui.mobile']){
|
||||
layui.config({
|
||||
base: layui.cache.dir + 'lay/modules/mobile/'
|
||||
}).extend({
|
||||
'layer-mobile': 'layer-mobile'
|
||||
,'zepto': 'zepto'
|
||||
,'upload-mobile': 'upload-mobile'
|
||||
,'layim-mobile': 'layim-mobile'
|
||||
});
|
||||
}
|
||||
|
||||
layui.define([
|
||||
'layer-mobile'
|
||||
,'zepto'
|
||||
,'layim-mobile'
|
||||
], function(exports){
|
||||
exports('mobile', {
|
||||
layer: layui['layer-mobile'] //弹层
|
||||
,layim: layui['layim-mobile'] //WebIM
|
||||
});
|
||||
});
|
@ -0,0 +1,189 @@
|
||||
/*!
|
||||
|
||||
@Name:layer mobile v2.0.0 弹层组件移动版
|
||||
@Author:贤心
|
||||
@Site:http://layer.layui.com/mobie/
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define(function(exports){
|
||||
|
||||
"use strict";
|
||||
|
||||
var win = window, doc = document, query = 'querySelectorAll', claname = 'getElementsByClassName', S = function(s){
|
||||
return doc[query](s);
|
||||
};
|
||||
|
||||
//默认配置
|
||||
var config = {
|
||||
type: 0
|
||||
,shade: true
|
||||
,shadeClose: true
|
||||
,fixed: true
|
||||
,anim: 'scale' //默认动画类型
|
||||
};
|
||||
|
||||
var ready = {
|
||||
extend: function(obj){
|
||||
var newobj = JSON.parse(JSON.stringify(config));
|
||||
for(var i in obj){
|
||||
newobj[i] = obj[i];
|
||||
}
|
||||
return newobj;
|
||||
},
|
||||
timer: {}, end: {}
|
||||
};
|
||||
|
||||
//点触事件
|
||||
ready.touch = function(elem, fn){
|
||||
elem.addEventListener('click', function(e){
|
||||
fn.call(this, e);
|
||||
}, false);
|
||||
};
|
||||
|
||||
var index = 0, classs = ['layui-m-layer'], Layer = function(options){
|
||||
var that = this;
|
||||
that.config = ready.extend(options);
|
||||
that.view();
|
||||
};
|
||||
|
||||
Layer.prototype.view = function(){
|
||||
var that = this, config = that.config, layerbox = doc.createElement('div');
|
||||
|
||||
that.id = layerbox.id = classs[0] + index;
|
||||
layerbox.setAttribute('class', classs[0] + ' ' + classs[0]+(config.type || 0));
|
||||
layerbox.setAttribute('index', index);
|
||||
|
||||
//标题区域
|
||||
var title = (function(){
|
||||
var titype = typeof config.title === 'object';
|
||||
return config.title
|
||||
? '<h3 style="'+ (titype ? config.title[1] : '') +'">'+ (titype ? config.title[0] : config.title) +'</h3>'
|
||||
: '';
|
||||
}());
|
||||
|
||||
//按钮区域
|
||||
var button = (function(){
|
||||
typeof config.btn === 'string' && (config.btn = [config.btn]);
|
||||
var btns = (config.btn || []).length, btndom;
|
||||
if(btns === 0 || !config.btn){
|
||||
return '';
|
||||
}
|
||||
btndom = '<span yes type="1">'+ config.btn[0] +'</span>'
|
||||
if(btns === 2){
|
||||
btndom = '<span no type="0">'+ config.btn[1] +'</span>' + btndom;
|
||||
}
|
||||
return '<div class="layui-m-layerbtn">'+ btndom + '</div>';
|
||||
}());
|
||||
|
||||
if(!config.fixed){
|
||||
config.top = config.hasOwnProperty('top') ? config.top : 100;
|
||||
config.style = config.style || '';
|
||||
config.style += ' top:'+ ( doc.body.scrollTop + config.top) + 'px';
|
||||
}
|
||||
|
||||
if(config.type === 2){
|
||||
config.content = '<i></i><i class="layui-m-layerload"></i><i></i><p>'+ (config.content||'') +'</p>';
|
||||
}
|
||||
|
||||
if(config.skin) config.anim = 'up';
|
||||
if(config.skin === 'msg') config.shade = false;
|
||||
|
||||
layerbox.innerHTML = (config.shade ? '<div '+ (typeof config.shade === 'string' ? 'style="'+ config.shade +'"' : '') +' class="layui-m-layershade"></div>' : '')
|
||||
+'<div class="layui-m-layermain" '+ (!config.fixed ? 'style="position:static;"' : '') +'>'
|
||||
+'<div class="layui-m-layersection">'
|
||||
+'<div class="layui-m-layerchild '+ (config.skin ? 'layui-m-layer-' + config.skin + ' ' : '') + (config.className ? config.className : '') + ' ' + (config.anim ? 'layui-m-anim-' + config.anim : '') +'" ' + ( config.style ? 'style="'+config.style+'"' : '' ) +'>'
|
||||
+ title
|
||||
+'<div class="layui-m-layercont">'+ config.content +'</div>'
|
||||
+ button
|
||||
+'</div>'
|
||||
+'</div>'
|
||||
+'</div>';
|
||||
|
||||
if(!config.type || config.type === 2){
|
||||
var dialogs = doc[claname](classs[0] + config.type), dialen = dialogs.length;
|
||||
if(dialen >= 1){
|
||||
layer.close(dialogs[0].getAttribute('index'))
|
||||
}
|
||||
}
|
||||
|
||||
document.body.appendChild(layerbox);
|
||||
var elem = that.elem = S('#'+that.id)[0];
|
||||
config.success && config.success(elem);
|
||||
|
||||
that.index = index++;
|
||||
that.action(config, elem);
|
||||
};
|
||||
|
||||
Layer.prototype.action = function(config, elem){
|
||||
var that = this;
|
||||
|
||||
//自动关闭
|
||||
if(config.time){
|
||||
ready.timer[that.index] = setTimeout(function(){
|
||||
layer.close(that.index);
|
||||
}, config.time*1000);
|
||||
}
|
||||
|
||||
//确认取消
|
||||
var btn = function(){
|
||||
var type = this.getAttribute('type');
|
||||
if(type == 0){
|
||||
config.no && config.no();
|
||||
layer.close(that.index);
|
||||
} else {
|
||||
config.yes ? config.yes(that.index) : layer.close(that.index);
|
||||
}
|
||||
};
|
||||
if(config.btn){
|
||||
var btns = elem[claname]('layui-m-layerbtn')[0].children, btnlen = btns.length;
|
||||
for(var ii = 0; ii < btnlen; ii++){
|
||||
ready.touch(btns[ii], btn);
|
||||
}
|
||||
}
|
||||
|
||||
//点遮罩关闭
|
||||
if(config.shade && config.shadeClose){
|
||||
var shade = elem[claname]('layui-m-layershade')[0];
|
||||
ready.touch(shade, function(){
|
||||
layer.close(that.index, config.end);
|
||||
});
|
||||
}
|
||||
|
||||
config.end && (ready.end[that.index] = config.end);
|
||||
};
|
||||
|
||||
var layer = {
|
||||
v: '2.0 m',
|
||||
index: index,
|
||||
|
||||
//核心方法
|
||||
open: function(options){
|
||||
var o = new Layer(options || {});
|
||||
return o.index;
|
||||
},
|
||||
|
||||
close: function(index){
|
||||
var ibox = S('#'+classs[0]+index)[0];
|
||||
if(!ibox) return;
|
||||
ibox.innerHTML = '';
|
||||
doc.body.removeChild(ibox);
|
||||
clearTimeout(ready.timer[index]);
|
||||
delete ready.timer[index];
|
||||
typeof ready.end[index] === 'function' && ready.end[index]();
|
||||
delete ready.end[index];
|
||||
},
|
||||
|
||||
//关闭所有layer层
|
||||
closeAll: function(){
|
||||
var boxs = doc[claname](classs[0]);
|
||||
for(var i = 0, len = boxs.length; i < len; i++){
|
||||
layer.close((boxs[0].getAttribute('index')|0));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports('layer-mobile', layer);
|
||||
|
||||
});
|
@ -0,0 +1,11 @@
|
||||
/**
|
||||
|
||||
@Name:layim mobile 开源包
|
||||
@Author:贤心
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define(function(exports){
|
||||
exports('layim-mobile', layui.v);
|
||||
});
|
@ -0,0 +1,166 @@
|
||||
/*!
|
||||
|
||||
@Title: layui.upload 单文件上传 - 全浏览器兼容版
|
||||
@Author: 贤心
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define(['layer-mobile', 'zepto'] , function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.zepto;
|
||||
var layer = layui['layer-mobile'];
|
||||
var device = layui.device();
|
||||
|
||||
var elemDragEnter = 'layui-upload-enter';
|
||||
var elemIframe = 'layui-upload-iframe';
|
||||
|
||||
var msgConf = {
|
||||
icon: 2
|
||||
,shift: 6
|
||||
}, fileType = {
|
||||
file: '文件'
|
||||
,video: '视频'
|
||||
,audio: '音频'
|
||||
};
|
||||
|
||||
layer.msg = function(content){
|
||||
return layer.open({
|
||||
content: content || ''
|
||||
,skin: 'msg'
|
||||
,time: 2 //2秒后自动关闭
|
||||
});
|
||||
};
|
||||
|
||||
var Upload = function(options){
|
||||
this.options = options;
|
||||
};
|
||||
|
||||
//初始化渲染
|
||||
Upload.prototype.init = function(){
|
||||
var that = this, options = that.options;
|
||||
var body = $('body'), elem = $(options.elem || '.layui-upload-file');
|
||||
var iframe = $('<iframe id="'+ elemIframe +'" class="'+ elemIframe +'" name="'+ elemIframe +'"></iframe>');
|
||||
|
||||
//插入iframe
|
||||
$('#'+elemIframe)[0] || body.append(iframe);
|
||||
|
||||
return elem.each(function(index, item){
|
||||
item = $(item);
|
||||
var form = '<form target="'+ elemIframe +'" method="'+ (options.method||'post') +'" key="set-mine" enctype="multipart/form-data" action="'+ (options.url||'') +'"></form>';
|
||||
|
||||
var type = item.attr('lay-type') || options.type; //获取文件类型
|
||||
|
||||
//包裹ui元素
|
||||
if(!options.unwrap){
|
||||
form = '<div class="layui-box layui-upload-button">' + form + '<span class="layui-upload-icon"><i class="layui-icon"></i>'+ (
|
||||
item.attr('lay-title') || options.title|| ('上传'+ (fileType[type]||'图片') )
|
||||
) +'</span></div>';
|
||||
}
|
||||
|
||||
form = $(form);
|
||||
|
||||
//拖拽支持
|
||||
if(!options.unwrap){
|
||||
form.on('dragover', function(e){
|
||||
e.preventDefault();
|
||||
$(this).addClass(elemDragEnter);
|
||||
}).on('dragleave', function(){
|
||||
$(this).removeClass(elemDragEnter);
|
||||
}).on('drop', function(){
|
||||
$(this).removeClass(elemDragEnter);
|
||||
});
|
||||
}
|
||||
|
||||
//如果已经实例化,则移除包裹元素
|
||||
if(item.parent('form').attr('target') === elemIframe){
|
||||
if(options.unwrap){
|
||||
item.unwrap();
|
||||
} else {
|
||||
item.parent().next().remove();
|
||||
item.unwrap().unwrap();
|
||||
}
|
||||
};
|
||||
|
||||
//包裹元素
|
||||
item.wrap(form);
|
||||
|
||||
//触发上传
|
||||
item.off('change').on('change', function(){
|
||||
that.action(this, type);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
//提交上传
|
||||
Upload.prototype.action = function(input, type){
|
||||
var that = this, options = that.options, val = input.value;
|
||||
var item = $(input), ext = item.attr('lay-ext') || options.ext || ''; //获取支持上传的文件扩展名;
|
||||
|
||||
if(!val){
|
||||
return;
|
||||
};
|
||||
|
||||
//校验文件
|
||||
switch(type){
|
||||
case 'file': //一般文件
|
||||
if(ext && !RegExp('\\w\\.('+ ext +')$', 'i').test(escape(val))){
|
||||
layer.msg('不支持该文件格式', msgConf);
|
||||
return input.value = '';
|
||||
}
|
||||
break;
|
||||
case 'video': //视频文件
|
||||
if(!RegExp('\\w\\.('+ (ext||'avi|mp4|wma|rmvb|rm|flash|3gp|flv') +')$', 'i').test(escape(val))){
|
||||
layer.msg('不支持该视频格式', msgConf);
|
||||
return input.value = '';
|
||||
}
|
||||
break;
|
||||
case 'audio': //音频文件
|
||||
if(!RegExp('\\w\\.('+ (ext||'mp3|wav|mid') +')$', 'i').test(escape(val))){
|
||||
layer.msg('不支持该音频格式', msgConf);
|
||||
return input.value = '';
|
||||
}
|
||||
break;
|
||||
default: //图片文件
|
||||
if(!RegExp('\\w\\.('+ (ext||'jpg|png|gif|bmp|jpeg') +')$', 'i').test(escape(val))){
|
||||
layer.msg('不支持该图片格式', msgConf);
|
||||
return input.value = '';
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
options.before && options.before(input);
|
||||
item.parent().submit();
|
||||
|
||||
var iframe = $('#'+elemIframe), timer = setInterval(function() {
|
||||
var res;
|
||||
try {
|
||||
res = iframe.contents().find('body').text();
|
||||
} catch(e) {
|
||||
layer.msg('上传接口存在跨域', msgConf);
|
||||
clearInterval(timer);
|
||||
}
|
||||
if(res){
|
||||
clearInterval(timer);
|
||||
iframe.contents().find('body').html('');
|
||||
try {
|
||||
res = JSON.parse(res);
|
||||
} catch(e){
|
||||
res = {};
|
||||
return layer.msg('请对上传接口返回JSON字符', msgConf);
|
||||
}
|
||||
typeof options.success === 'function' && options.success(res, input);
|
||||
}
|
||||
}, 30);
|
||||
|
||||
input.value = '';
|
||||
};
|
||||
|
||||
//暴露接口
|
||||
exports('upload-mobile', function(options){
|
||||
var upload = new Upload(options = options || {});
|
||||
upload.init();
|
||||
});
|
||||
});
|
||||
|
1646
novel-admin/src/main/resources/static/js/lay/modules/mobile/zepto.js
Normal file
1646
novel-admin/src/main/resources/static/js/lay/modules/mobile/zepto.js
Normal file
File diff suppressed because it is too large
Load Diff
1053
novel-admin/src/main/resources/static/js/lay/modules/table.js
Normal file
1053
novel-admin/src/main/resources/static/js/lay/modules/table.js
Normal file
File diff suppressed because it is too large
Load Diff
215
novel-admin/src/main/resources/static/js/lay/modules/tree.js
Normal file
215
novel-admin/src/main/resources/static/js/lay/modules/tree.js
Normal file
@ -0,0 +1,215 @@
|
||||
/**
|
||||
|
||||
@Name:layui.tree 树组件
|
||||
@Author:贤心
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
|
||||
layui.define('jquery', function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.$
|
||||
,hint = layui.hint();
|
||||
|
||||
var enterSkin = 'layui-tree-enter', Tree = function(options){
|
||||
this.options = options;
|
||||
};
|
||||
|
||||
//图标
|
||||
var icon = {
|
||||
arrow: ['', ''] //箭头
|
||||
,checkbox: ['', ''] //复选框
|
||||
,radio: ['', ''] //单选框
|
||||
,branch: ['', ''] //父节点
|
||||
,leaf: '' //叶节点
|
||||
};
|
||||
|
||||
//初始化
|
||||
Tree.prototype.init = function(elem){
|
||||
var that = this;
|
||||
elem.addClass('layui-box layui-tree'); //添加tree样式
|
||||
if(that.options.skin){
|
||||
elem.addClass('layui-tree-skin-'+ that.options.skin);
|
||||
}
|
||||
that.tree(elem);
|
||||
that.on(elem);
|
||||
};
|
||||
|
||||
//树节点解析
|
||||
Tree.prototype.tree = function(elem, children){
|
||||
var that = this, options = that.options
|
||||
var nodes = children || options.nodes;
|
||||
|
||||
layui.each(nodes, function(index, item){
|
||||
var hasChild = item.children && item.children.length > 0;
|
||||
var ul = $('<ul class="'+ (item.spread ? "layui-show" : "") +'"></ul>');
|
||||
var li = $(['<li '+ (item.spread ? 'data-spread="'+ item.spread +'"' : '') +'>'
|
||||
//展开箭头
|
||||
,function(){
|
||||
return hasChild ? '<i class="layui-icon layui-tree-spread">'+ (
|
||||
item.spread ? icon.arrow[1] : icon.arrow[0]
|
||||
) +'</i>' : '';
|
||||
}()
|
||||
|
||||
//复选框/单选框
|
||||
,function(){
|
||||
return options.check ? (
|
||||
'<i class="layui-icon layui-tree-check">'+ (
|
||||
options.check === 'checkbox' ? icon.checkbox[0] : (
|
||||
options.check === 'radio' ? icon.radio[0] : ''
|
||||
)
|
||||
) +'</i>'
|
||||
) : '';
|
||||
}()
|
||||
|
||||
//节点
|
||||
,function(){
|
||||
return '<a href="'+ (item.href || 'javascript:;') +'" '+ (
|
||||
options.target && item.href ? 'target=\"'+ options.target +'\"' : ''
|
||||
) +'>'
|
||||
+ ('<i class="layui-icon layui-tree-'+ (hasChild ? "branch" : "leaf") +'">'+ (
|
||||
hasChild ? (
|
||||
item.spread ? icon.branch[1] : icon.branch[0]
|
||||
) : icon.leaf
|
||||
) +'</i>') //节点图标
|
||||
+ ('<cite>'+ (item.name||'未命名') +'</cite></a>');
|
||||
}()
|
||||
|
||||
,'</li>'].join(''));
|
||||
|
||||
//如果有子节点,则递归继续生成树
|
||||
if(hasChild){
|
||||
li.append(ul);
|
||||
that.tree(ul, item.children);
|
||||
}
|
||||
|
||||
elem.append(li);
|
||||
|
||||
//触发点击节点回调
|
||||
typeof options.click === 'function' && that.click(li, item);
|
||||
|
||||
//伸展节点
|
||||
that.spread(li, item);
|
||||
|
||||
//拖拽节点
|
||||
options.drag && that.drag(li, item);
|
||||
});
|
||||
};
|
||||
|
||||
//点击节点回调
|
||||
Tree.prototype.click = function(elem, item){
|
||||
var that = this, options = that.options;
|
||||
elem.children('a').on('click', function(e){
|
||||
layui.stope(e);
|
||||
options.click(item)
|
||||
});
|
||||
};
|
||||
|
||||
//伸展节点
|
||||
Tree.prototype.spread = function(elem, item){
|
||||
var that = this, options = that.options;
|
||||
var arrow = elem.children('.layui-tree-spread')
|
||||
var ul = elem.children('ul'), a = elem.children('a');
|
||||
|
||||
//执行伸展
|
||||
var open = function(){
|
||||
if(elem.data('spread')){
|
||||
elem.data('spread', null)
|
||||
ul.removeClass('layui-show');
|
||||
arrow.html(icon.arrow[0]);
|
||||
a.find('.layui-icon').html(icon.branch[0]);
|
||||
} else {
|
||||
elem.data('spread', true);
|
||||
ul.addClass('layui-show');
|
||||
arrow.html(icon.arrow[1]);
|
||||
a.find('.layui-icon').html(icon.branch[1]);
|
||||
}
|
||||
};
|
||||
|
||||
//如果没有子节点,则不执行
|
||||
if(!ul[0]) return;
|
||||
|
||||
arrow.on('click', open);
|
||||
a.on('dblclick', open);
|
||||
}
|
||||
|
||||
//通用事件
|
||||
Tree.prototype.on = function(elem){
|
||||
var that = this, options = that.options;
|
||||
var dragStr = 'layui-tree-drag';
|
||||
|
||||
//屏蔽选中文字
|
||||
elem.find('i').on('selectstart', function(e){
|
||||
return false
|
||||
});
|
||||
|
||||
//拖拽
|
||||
if(options.drag){
|
||||
$(document).on('mousemove', function(e){
|
||||
var move = that.move;
|
||||
if(move.from){
|
||||
var to = move.to, treeMove = $('<div class="layui-box '+ dragStr +'"></div>');
|
||||
e.preventDefault();
|
||||
$('.' + dragStr)[0] || $('body').append(treeMove);
|
||||
var dragElem = $('.' + dragStr)[0] ? $('.' + dragStr) : treeMove;
|
||||
(dragElem).addClass('layui-show').html(move.from.elem.children('a').html());
|
||||
dragElem.css({
|
||||
left: e.pageX + 10
|
||||
,top: e.pageY + 10
|
||||
})
|
||||
}
|
||||
}).on('mouseup', function(){
|
||||
var move = that.move;
|
||||
if(move.from){
|
||||
move.from.elem.children('a').removeClass(enterSkin);
|
||||
move.to && move.to.elem.children('a').removeClass(enterSkin);
|
||||
that.move = {};
|
||||
$('.' + dragStr).remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
//拖拽节点
|
||||
Tree.prototype.move = {};
|
||||
Tree.prototype.drag = function(elem, item){
|
||||
var that = this, options = that.options;
|
||||
var a = elem.children('a'), mouseenter = function(){
|
||||
var othis = $(this), move = that.move;
|
||||
if(move.from){
|
||||
move.to = {
|
||||
item: item
|
||||
,elem: elem
|
||||
};
|
||||
othis.addClass(enterSkin);
|
||||
}
|
||||
};
|
||||
a.on('mousedown', function(){
|
||||
var move = that.move
|
||||
move.from = {
|
||||
item: item
|
||||
,elem: elem
|
||||
};
|
||||
});
|
||||
a.on('mouseenter', mouseenter).on('mousemove', mouseenter)
|
||||
.on('mouseleave', function(){
|
||||
var othis = $(this), move = that.move;
|
||||
if(move.from){
|
||||
delete move.to;
|
||||
othis.removeClass(enterSkin);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
//暴露接口
|
||||
exports('tree', function(options){
|
||||
var tree = new Tree(options = options || {});
|
||||
var elem = $(options.elem);
|
||||
if(!elem[0]){
|
||||
return hint.error('layui.tree 没有找到'+ options.elem +'元素');
|
||||
}
|
||||
tree.init(elem);
|
||||
});
|
||||
});
|
474
novel-admin/src/main/resources/static/js/lay/modules/upload.js
Normal file
474
novel-admin/src/main/resources/static/js/lay/modules/upload.js
Normal file
@ -0,0 +1,474 @@
|
||||
layui.define('layer' , function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.$
|
||||
,layer = layui.layer
|
||||
,hint = layui.hint()
|
||||
,device = layui.device()
|
||||
|
||||
//外部接口
|
||||
,upload = {
|
||||
config: {} //全局配置项
|
||||
|
||||
//设置全局项
|
||||
,set: function(options){
|
||||
var that = this;
|
||||
that.config = $.extend({}, that.config, options);
|
||||
return that;
|
||||
}
|
||||
|
||||
//事件监听
|
||||
,on: function(events, callback){
|
||||
return layui.onevent.call(this, MOD_NAME, events, callback);
|
||||
}
|
||||
}
|
||||
|
||||
//操作当前实例
|
||||
,thisUpload = function(){
|
||||
var that = this;
|
||||
return {
|
||||
upload: function(files){
|
||||
that.upload.call(that, files);
|
||||
}
|
||||
,config: that.config
|
||||
}
|
||||
}
|
||||
|
||||
//字符常量
|
||||
,MOD_NAME = 'upload', ELEM = '.layui-upload', THIS = 'layui-this', SHOW = 'layui-show', HIDE = 'layui-hide', DISABLED = 'layui-disabled'
|
||||
|
||||
,ELEM_FILE = 'layui-upload-file', ELEM_FORM = 'layui-upload-form', ELEM_IFRAME = 'layui-upload-iframe', ELEM_CHOOSE = 'layui-upload-choose', ELEM_DRAG = 'layui-upload-drag'
|
||||
|
||||
|
||||
//构造器
|
||||
,Class = function(options){
|
||||
var that = this;
|
||||
that.config = $.extend({}, that.config, upload.config, options);
|
||||
that.render();
|
||||
};
|
||||
|
||||
//默认配置
|
||||
Class.prototype.config = {
|
||||
accept: 'images' //允许上传的文件类型:images/file/video/audio
|
||||
,exts: '' //允许上传的文件后缀名
|
||||
,auto: true //是否选完文件后自动上传
|
||||
,bindAction: '' //手动上传触发的元素
|
||||
,url: '' //上传地址
|
||||
,field: 'file' //文件字段名
|
||||
,method: 'post' //请求上传的http类型
|
||||
,data: {} //请求上传的额外参数
|
||||
,drag: true //是否允许拖拽上传
|
||||
,size: 0 //文件限制大小,默认不限制
|
||||
,multiple: false //是否允许多文件上传,不支持ie8-9
|
||||
};
|
||||
|
||||
//初始渲染
|
||||
Class.prototype.render = function(options){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
options.elem = $(options.elem);
|
||||
options.bindAction = $(options.bindAction);
|
||||
|
||||
that.file();
|
||||
that.events();
|
||||
};
|
||||
|
||||
//追加文件域
|
||||
Class.prototype.file = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,elemFile = that.elemFile = $([
|
||||
'<input class="'+ ELEM_FILE +'" type="file" name="'+ options.field +'"'
|
||||
,(options.multiple ? ' multiple' : '')
|
||||
,'>'
|
||||
].join(''))
|
||||
,next = options.elem.next();
|
||||
|
||||
if(next.hasClass(ELEM_FILE) || next.hasClass(ELEM_FORM)){
|
||||
next.remove();
|
||||
}
|
||||
|
||||
//包裹ie8/9容器
|
||||
if(device.ie && device.ie < 10){
|
||||
options.elem.wrap('<div class="layui-upload-wrap"></div>');
|
||||
}
|
||||
|
||||
that.isFile() ? (
|
||||
that.elemFile = options.elem
|
||||
,options.field = options.elem[0].name
|
||||
) : options.elem.after(elemFile);
|
||||
|
||||
//初始化ie8/9的Form域
|
||||
if(device.ie && device.ie < 10){
|
||||
that.initIE();
|
||||
}
|
||||
};
|
||||
|
||||
//ie8-9初始化
|
||||
Class.prototype.initIE = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,iframe = $('<iframe id="'+ ELEM_IFRAME +'" class="'+ ELEM_IFRAME +'" name="'+ ELEM_IFRAME +'" frameborder="0"></iframe>')
|
||||
,elemForm = $(['<form target="'+ ELEM_IFRAME +'" class="'+ ELEM_FORM +'" method="'+ options.method
|
||||
,'" key="set-mine" enctype="multipart/form-data" action="'+ options.url +'">'
|
||||
,'</form>'].join(''));
|
||||
|
||||
//插入iframe
|
||||
$('#'+ ELEM_IFRAME)[0] || $('body').append(iframe);
|
||||
|
||||
//包裹文件域
|
||||
if(!options.elem.next().hasClass(ELEM_IFRAME)){
|
||||
that.elemFile.wrap(elemForm);
|
||||
|
||||
//追加额外的参数
|
||||
options.elem.next('.'+ ELEM_IFRAME).append(function(){
|
||||
var arr = [];
|
||||
layui.each(options.data, function(key, value){
|
||||
arr.push('<input type="hidden" name="'+ key +'" value="'+ value +'">')
|
||||
});
|
||||
return arr.join('');
|
||||
}());
|
||||
}
|
||||
};
|
||||
|
||||
//异常提示
|
||||
Class.prototype.msg = function(content){
|
||||
return layer.msg(content, {
|
||||
icon: 2
|
||||
,shift: 6
|
||||
});
|
||||
};
|
||||
|
||||
//判断绑定元素是否为文件域本身
|
||||
Class.prototype.isFile = function(){
|
||||
var elem = this.config.elem[0];
|
||||
if(!elem) return;
|
||||
return elem.tagName.toLocaleLowerCase() === 'input' && elem.type === 'file'
|
||||
}
|
||||
|
||||
//预读图片信息
|
||||
Class.prototype.preview = function(callback){
|
||||
var that = this;
|
||||
if(window.FileReader){
|
||||
layui.each(that.chooseFiles, function(index, file){
|
||||
var reader = new FileReader();
|
||||
reader.readAsDataURL(file);
|
||||
reader.onload = function(){
|
||||
callback && callback(index, file, this.result);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
//执行上传
|
||||
Class.prototype.upload = function(files, type){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,elemFile = that.elemFile[0]
|
||||
|
||||
//高级浏览器处理方式,支持跨域
|
||||
,ajaxSend = function(){
|
||||
layui.each(files || that.files || that.chooseFiles || elemFile.files, function(index, file){
|
||||
var formData = new FormData();
|
||||
|
||||
formData.append(options.field, file);
|
||||
|
||||
//追加额外的参数
|
||||
layui.each(options.data, function(key, value){
|
||||
formData.append(key, value);
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
url: options.url
|
||||
,type: options.method
|
||||
,data: formData
|
||||
,contentType: false
|
||||
,processData: false
|
||||
,dataType: 'json'
|
||||
,success: function(res){
|
||||
done(index, res);
|
||||
}
|
||||
,error: function(){
|
||||
that.msg('请求上传接口出现异常');
|
||||
error(index);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//低版本IE处理方式,不支持跨域
|
||||
,iframeSend = function(){
|
||||
var iframe = $('#'+ ELEM_IFRAME);
|
||||
|
||||
that.elemFile.parent().submit();
|
||||
|
||||
//获取响应信息
|
||||
clearInterval(Class.timer);
|
||||
Class.timer = setInterval(function() {
|
||||
var res, iframeBody = iframe.contents().find('body');
|
||||
try {
|
||||
res = iframeBody.text();
|
||||
} catch(e) {
|
||||
that.msg('获取上传后的响应信息出现异常');
|
||||
clearInterval(Class.timer);
|
||||
error();
|
||||
}
|
||||
if(res){
|
||||
clearInterval(Class.timer);
|
||||
iframeBody.html('');
|
||||
done(0, res);
|
||||
}
|
||||
}, 30);
|
||||
}
|
||||
|
||||
//统一回调
|
||||
,done = function(index, res){
|
||||
that.elemFile.next('.'+ ELEM_CHOOSE).remove();
|
||||
elemFile.value = '';
|
||||
if(typeof res !== 'object'){
|
||||
try {
|
||||
res = JSON.parse(res);
|
||||
} catch(e){
|
||||
res = {};
|
||||
return that.msg('请对上传接口返回有效JSON');
|
||||
}
|
||||
}
|
||||
typeof options.done === 'function' && options.done(res, index || 0, function(files){
|
||||
that.upload(files);
|
||||
});
|
||||
}
|
||||
|
||||
//统一网络异常回调
|
||||
,error = function(index){
|
||||
if(options.auto){
|
||||
elemFile.value = '';
|
||||
}
|
||||
typeof options.error === 'function' && options.error(index || 0, function(files){
|
||||
that.upload(files);
|
||||
});
|
||||
}
|
||||
|
||||
,exts = options.exts
|
||||
,check ,value = function(){
|
||||
var arr = [];
|
||||
layui.each(files || that.chooseFiles, function(i, item){
|
||||
arr.push(item.name);
|
||||
});
|
||||
return arr;
|
||||
}()
|
||||
|
||||
//回调返回的参数
|
||||
,args = {
|
||||
preview: function(callback){
|
||||
that.preview(callback);
|
||||
}
|
||||
,upload: function(index, file){
|
||||
var thisFile = {};
|
||||
thisFile[index] = file;
|
||||
that.upload(thisFile);
|
||||
}
|
||||
,pushFile: function(){
|
||||
that.files = that.files || {};
|
||||
layui.each(that.chooseFiles, function(index, item){
|
||||
that.files[index] = item;
|
||||
});
|
||||
return that.files;
|
||||
}
|
||||
}
|
||||
|
||||
//提交上传
|
||||
,send = function(){
|
||||
if(type === 'choose'){
|
||||
return options.choose && options.choose(args);
|
||||
}
|
||||
|
||||
//上传前的回调
|
||||
options.before && options.before(args);
|
||||
|
||||
//IE兼容处理
|
||||
if(device.ie){
|
||||
return device.ie > 9 ? ajaxSend() : iframeSend();
|
||||
}
|
||||
|
||||
ajaxSend();
|
||||
}
|
||||
|
||||
//校验文件格式
|
||||
value = value.length === 0
|
||||
? ((elemFile.value.match(/[^\/\\]+\..+/g)||[]) || '')
|
||||
: value;
|
||||
|
||||
switch(options.accept){
|
||||
case 'file': //一般文件
|
||||
if(exts && !RegExp('\\w\\.('+ exts +')$', 'i').test(escape(value))){
|
||||
that.msg('选择的文件中包含不支持的格式');
|
||||
return elemFile.value = '';
|
||||
}
|
||||
break;
|
||||
case 'video': //视频文件
|
||||
if(!RegExp('\\w\\.('+ (exts || 'avi|mp4|wma|rmvb|rm|flash|3gp|flv') +')$', 'i').test(escape(value))){
|
||||
that.msg('选择的视频中包含不支持的格式');
|
||||
return elemFile.value = '';
|
||||
}
|
||||
break;
|
||||
case 'audio': //音频文件
|
||||
if(!RegExp('\\w\\.('+ (exts || 'mp3|wav|mid') +')$', 'i').test(escape(value))){
|
||||
that.msg('选择的音频中包含不支持的格式');
|
||||
return elemFile.value = '';
|
||||
}
|
||||
break;
|
||||
default: //图片文件
|
||||
layui.each(value, function(i, item){
|
||||
if(!RegExp('\\w\\.('+ (exts || 'jpg|png|gif|bmp|jpeg$') +')', 'i').test(escape(item))){
|
||||
check = true;
|
||||
}
|
||||
});
|
||||
if(check){
|
||||
that.msg('选择的图片中包含不支持的格式');
|
||||
return elemFile.value = '';
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//检验文件大小
|
||||
if(options.size > 0 && !(device.ie && device.ie < 10)){
|
||||
var limitSize;
|
||||
layui.each(that.chooseFiles, function(index, file){
|
||||
if(file.size > 1024*options.size){
|
||||
var size = options.size/1024;
|
||||
size = size >= 1
|
||||
? (Math.floor(size) + (size%1 > 0 ? size.toFixed(1) : 0)) + 'MB'
|
||||
: options.size + 'KB'
|
||||
elemFile.value = '';
|
||||
limitSize = size;
|
||||
|
||||
}
|
||||
});
|
||||
if(limitSize) return that.msg('文件不能超过'+ limitSize);
|
||||
}
|
||||
send();
|
||||
};
|
||||
|
||||
//事件处理
|
||||
Class.prototype.events = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
|
||||
//设置当前选择的文件队列
|
||||
,setChooseFile = function(files){
|
||||
that.chooseFiles = {};
|
||||
layui.each(files, function(i, item){
|
||||
var time = new Date().getTime();
|
||||
that.chooseFiles[time + '-' + i] = item;
|
||||
});
|
||||
}
|
||||
|
||||
//设置选择的文本
|
||||
,setChooseText = function(files, filename){
|
||||
var elemFile = that.elemFile
|
||||
,value = files.length > 1
|
||||
? files.length + '个文件'
|
||||
: ((files[0] || {}).name || (elemFile[0].value.match(/[^\/\\]+\..+/g)||[]) || '');
|
||||
|
||||
if(elemFile.next().hasClass(ELEM_CHOOSE)){
|
||||
elemFile.next().remove();
|
||||
}
|
||||
that.upload(null, 'choose');
|
||||
if(that.isFile() || options.choose) return;
|
||||
elemFile.after('<span class="layui-inline '+ ELEM_CHOOSE +'">'+ value +'</span>');
|
||||
};
|
||||
|
||||
//点击上传容器
|
||||
options.elem.off('upload.start').on('upload.start', function(){
|
||||
var othis = $(this), data = othis.attr('lay-data');
|
||||
|
||||
if(data){
|
||||
try{
|
||||
data = new Function('return '+ data)();
|
||||
that.config = $.extend({}, options, data);
|
||||
} catch(e){
|
||||
hint.error('Upload element property lay-data configuration item has a syntax error: ' + data)
|
||||
}
|
||||
}
|
||||
|
||||
that.config.item = othis;
|
||||
that.elemFile[0].click();
|
||||
});
|
||||
|
||||
//拖拽上传
|
||||
if(!(device.ie && device.ie < 10)){
|
||||
options.elem.off('upload.over').on('upload.over', function(){
|
||||
var othis = $(this)
|
||||
othis.attr('lay-over', '');
|
||||
})
|
||||
.off('upload.leave').on('upload.leave', function(){
|
||||
var othis = $(this)
|
||||
othis.removeAttr('lay-over');
|
||||
})
|
||||
.off('upload.drop').on('upload.drop', function(e, param){
|
||||
var othis = $(this), files = param.originalEvent.dataTransfer.files || [];
|
||||
|
||||
othis.removeAttr('lay-over');
|
||||
setChooseFile(files);
|
||||
|
||||
if(options.auto){
|
||||
that.upload(files);
|
||||
} else {
|
||||
setChooseText(files);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//文件选择
|
||||
that.elemFile.off('upload.change').on('upload.change', function(){
|
||||
var files = this.files || [];
|
||||
setChooseFile(files);
|
||||
options.auto ? that.upload() : setChooseText(files); //是否自动触发上传
|
||||
});
|
||||
|
||||
//手动触发上传
|
||||
options.bindAction.off('upload.action').on('upload.action', function(){
|
||||
that.upload();
|
||||
});
|
||||
|
||||
//防止事件重复绑定
|
||||
if(options.elem.data('haveEvents')) return;
|
||||
|
||||
that.elemFile.on('change', function(){
|
||||
$(this).trigger('upload.change');
|
||||
});
|
||||
|
||||
options.elem.on('click', function(){
|
||||
if(that.isFile()) return;
|
||||
$(this).trigger('upload.start');
|
||||
});
|
||||
|
||||
if(options.drag){
|
||||
options.elem.on('dragover', function(e){
|
||||
e.preventDefault();
|
||||
$(this).trigger('upload.over');
|
||||
}).on('dragleave', function(e){
|
||||
$(this).trigger('upload.leave');
|
||||
}).on('drop', function(e){
|
||||
e.preventDefault();
|
||||
$(this).trigger('upload.drop', e);
|
||||
});
|
||||
}
|
||||
|
||||
options.bindAction.on('click', function(){
|
||||
$(this).trigger('upload.action');
|
||||
});
|
||||
|
||||
options.elem.data('haveEvents', true);
|
||||
};
|
||||
|
||||
//核心入口
|
||||
upload.render = function(options){
|
||||
var inst = new Class(options);
|
||||
return thisUpload.call(inst);
|
||||
};
|
||||
|
||||
exports(MOD_NAME, upload);
|
||||
});
|
||||
|
123
novel-admin/src/main/resources/static/js/lay/modules/util.js
Normal file
123
novel-admin/src/main/resources/static/js/lay/modules/util.js
Normal file
@ -0,0 +1,123 @@
|
||||
/**
|
||||
|
||||
@Name:layui.util 工具集
|
||||
@Author:贤心
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define('jquery', function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.$
|
||||
|
||||
//外部接口
|
||||
,util = {
|
||||
//固定块
|
||||
fixbar: function(options){
|
||||
var ELEM = 'layui-fixbar', TOP_BAR = 'layui-fixbar-top'
|
||||
,dom = $(document), body = $('body')
|
||||
,is, timer;
|
||||
|
||||
options = $.extend({
|
||||
showHeight: 200 //出现TOP的滚动条高度临界值
|
||||
}, options);
|
||||
|
||||
options.bar1 = options.bar1 === true ? '' : options.bar1;
|
||||
options.bar2 = options.bar2 === true ? '' : options.bar2;
|
||||
options.bgcolor = options.bgcolor ? ('background-color:' + options.bgcolor) : '';
|
||||
|
||||
var icon = [options.bar1, options.bar2, ''] //图标:信息、问号、TOP
|
||||
,elem = $(['<ul class="'+ ELEM +'">'
|
||||
,options.bar1 ? '<li class="layui-icon" lay-type="bar1" style="'+ options.bgcolor +'">'+ icon[0] +'</li>' : ''
|
||||
,options.bar2 ? '<li class="layui-icon" lay-type="bar2" style="'+ options.bgcolor +'">'+ icon[1] +'</li>' : ''
|
||||
,'<li class="layui-icon '+ TOP_BAR +'" lay-type="top" style="'+ options.bgcolor +'">'+ icon[2] +'</li>'
|
||||
,'</ul>'].join(''))
|
||||
,topBar = elem.find('.'+TOP_BAR)
|
||||
,scroll = function(){
|
||||
var stop = dom.scrollTop();
|
||||
if(stop >= (options.showHeight)){
|
||||
is || (topBar.show(), is = 1);
|
||||
} else {
|
||||
is && (topBar.hide(), is = 0);
|
||||
}
|
||||
};
|
||||
if($('.'+ ELEM)[0]) return;
|
||||
|
||||
typeof options.css === 'object' && elem.css(options.css);
|
||||
body.append(elem), scroll();
|
||||
|
||||
//bar点击事件
|
||||
elem.find('li').on('click', function(){
|
||||
var othis = $(this), type = othis.attr('lay-type');
|
||||
if(type === 'top'){
|
||||
$('html,body').animate({
|
||||
scrollTop : 0
|
||||
}, 200);
|
||||
}
|
||||
options.click && options.click.call(this, type);
|
||||
});
|
||||
|
||||
//Top显示控制
|
||||
dom.on('scroll', function(){
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(function(){
|
||||
scroll();
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
|
||||
//倒计时
|
||||
,countdown: function(endTime, serverTime, callback){
|
||||
var that = this
|
||||
,type = typeof serverTime === 'function'
|
||||
,end = new Date(endTime).getTime()
|
||||
,now = new Date((!serverTime || type) ? new Date().getTime() : serverTime).getTime()
|
||||
,count = end - now
|
||||
,time = [
|
||||
Math.floor(count/(1000*60*60*24)) //天
|
||||
,Math.floor(count/(1000*60*60)) % 24 //时
|
||||
,Math.floor(count/(1000*60)) % 60 //分
|
||||
,Math.floor(count/1000) % 60 //秒
|
||||
];
|
||||
|
||||
if(type) callback = serverTime;
|
||||
|
||||
var timer = setTimeout(function(){
|
||||
that.countdown(endTime, now + 1000, callback);
|
||||
}, 1000);
|
||||
|
||||
callback && callback(count > 0 ? time : [0,0,0,0], serverTime, timer);
|
||||
|
||||
if(count <= 0) clearTimeout(timer);
|
||||
return timer;
|
||||
}
|
||||
|
||||
//某个时间在当前时间的多久前
|
||||
,timeAgo: function(time, onlyDate){
|
||||
var 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;
|
||||
}
|
||||
|
||||
//30天以内,返回“多久前”
|
||||
if(stamp >= 1000*60*60*24){
|
||||
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分钟以内为:刚刚
|
||||
return ((stamp/1000/60)|0) + '分钟前';
|
||||
} else if(stamp < 0){
|
||||
return '未来';
|
||||
} else {
|
||||
return '刚刚';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports('util', util);
|
||||
});
|
Reference in New Issue
Block a user