clear
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
/**
|
||||
|
||||
@Name:用于打包移动完整版
|
||||
@Author:贤心
|
||||
@License:LGPL
|
||||
|
||||
*/
|
||||
|
||||
layui.define(function(exports){
|
||||
exports('layui.mobile', layui.v);
|
||||
});
|
||||
@@ -1,15 +0,0 @@
|
||||
/**
|
||||
|
||||
@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);
|
||||
});
|
||||
@@ -1,61 +0,0 @@
|
||||
/**
|
||||
|
||||
@Name:layui.code 代码修饰器
|
||||
@Author:贤心
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define('jquery', function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.jquery;
|
||||
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');
|
||||
@@ -1,403 +0,0 @@
|
||||
/**
|
||||
|
||||
@Name:layui.element 常用元素操作
|
||||
@Author:贤心
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define('jquery', function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.jquery
|
||||
,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(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)
|
||||
,contElem = tabElem.children('.layui-tab-content');
|
||||
titElem.append('<li lay-id="'+ (options.id||'') +'">'+ (options.title||'unnaming') +'</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')
|
||||
,filter = parents.attr('lay-filter');
|
||||
|
||||
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');
|
||||
|
||||
if(othis.find('.'+NAV_CHILD)[0]) return;
|
||||
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){
|
||||
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 = setTimeout(function(){
|
||||
bar.css({
|
||||
width: othis.width()
|
||||
,opacity: 1
|
||||
});
|
||||
}, device.ie && device.ie < 10 ? 0 : TIME);
|
||||
|
||||
clearTimeout(timeEnd);
|
||||
if(child.css('display') === 'block'){
|
||||
clearTimeout(timerMore);
|
||||
}
|
||||
timerMore = setTimeout(function(){
|
||||
child.addClass(SHOW)
|
||||
othis.find('.'+NAV_MORE).addClass(NAV_MORE+'d');
|
||||
}, 300);
|
||||
}
|
||||
}
|
||||
|
||||
$(NAV_ELEM).each(function(){
|
||||
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);
|
||||
}).on('mouseleave', function(){
|
||||
if(!othis.hasClass(NAV_TREE)){
|
||||
clearTimeout(timerMore);
|
||||
timerMore = setTimeout(function(){
|
||||
othis.find('.'+NAV_CHILD).removeClass(SHOW);
|
||||
othis.find('.'+NAV_MORE).removeClass(NAV_MORE+'d');
|
||||
}, 300);
|
||||
}
|
||||
});
|
||||
othis.on('mouseleave', function(){
|
||||
clearTimeout(timer)
|
||||
timeEnd = 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, function(options){
|
||||
return element.set(options);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,176 +0,0 @@
|
||||
/**
|
||||
|
||||
@Name:layui.flow 流加载
|
||||
@Author:贤心
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
|
||||
layui.define('jquery', function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.jquery, 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());
|
||||
});
|
||||
@@ -1,443 +0,0 @@
|
||||
/**
|
||||
|
||||
@Name:layui.form 表单组件
|
||||
@Author:贤心
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define('layer', function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.jquery
|
||||
,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: [
|
||||
/^\d+$/
|
||||
,'只能填写数字'
|
||||
]
|
||||
,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(MOD_NAME, events, callback);
|
||||
};
|
||||
|
||||
//表单控件渲染
|
||||
Form.prototype.render = function(type){
|
||||
var that = this, items = {
|
||||
|
||||
//下拉选择框
|
||||
select: function(){
|
||||
var TIPS = '请选择', CLASS = 'layui-form-select', TITLE = 'layui-select-title'
|
||||
,NONE = 'layui-select-none', initValue = '', thatInput
|
||||
|
||||
,selects = $(ELEM).find('select'), hide = function(e, clear){
|
||||
if(!$(e.target).parent().hasClass(TITLE) || clear){
|
||||
$('.'+CLASS).removeClass(CLASS+'ed');
|
||||
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(){
|
||||
reElem.addClass(CLASS+'ed');
|
||||
dds.removeClass(HIDE);
|
||||
}, hideDown = function(){
|
||||
reElem.removeClass(CLASS+'ed');
|
||||
input.blur();
|
||||
|
||||
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;
|
||||
|
||||
select.val(value).removeClass('layui-form-danger'), input.val(othis.text());
|
||||
othis.addClass(THIS).siblings().removeClass(THIS);
|
||||
layui.event.call(this, MOD_NAME, 'select('+ filter +')', {
|
||||
elem: select[0]
|
||||
,value: value
|
||||
,othis: reElem
|
||||
});
|
||||
|
||||
hideDown();
|
||||
|
||||
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;
|
||||
var value = select.value, selected = $(select.options[select.selectedIndex]); //获取当前选中项
|
||||
|
||||
if(typeof othis.attr('lay-ignore') === 'string') return othis.show();
|
||||
|
||||
var isSearch = typeof othis.attr('lay-search') === 'string';
|
||||
|
||||
//替代元素
|
||||
var reElem = $(['<div class="layui-unselect '+ CLASS + (disabled ? ' layui-select-disabled' : '') +'">'
|
||||
,'<div class="'+ TITLE +'"><input type="text" placeholder="'+ (select.options[0].innerHTML ? select.options[0].innerHTML : TIPS) +'" value="'+ (value ? selected.html() : '') +'" '+ (isSearch ? '' : 'readonly') +' class="layui-input layui-unselect'+ (disabled ? (' '+DISABLED) : '') +'">'
|
||||
,'<i class="layui-edge"></i></div>'
|
||||
,'<dl class="layui-anim layui-anim-upbit'+ (othis.find('optgroup')[0] ? ' layui-select-group' : '') +'">'+ function(options){
|
||||
var arr = [];
|
||||
layui.each(options, function(index, item){
|
||||
if(index === 0 && !item.value) return;
|
||||
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>');
|
||||
}
|
||||
});
|
||||
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 = $(ELEM).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 = $(ELEM).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);
|
||||
form.render();
|
||||
|
||||
//表单reset重置渲染
|
||||
dom.on('reset', ELEM, function(){
|
||||
setTimeout(function(){
|
||||
form.render();
|
||||
}, 50);
|
||||
});
|
||||
|
||||
//表单提交事件
|
||||
dom.on('submit', ELEM, submit)
|
||||
.on('click', '*[lay-submit]', submit);
|
||||
|
||||
exports(MOD_NAME, function(options){
|
||||
return form.set(options);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
10986
src/lay/modules/jquery.js
vendored
10986
src/lay/modules/jquery.js
vendored
File diff suppressed because it is too large
Load Diff
@@ -1,832 +0,0 @@
|
||||
/**
|
||||
|
||||
@Name : layDate v1.1 日期控件
|
||||
@Author: 贤心
|
||||
@Date: 2014-06-25
|
||||
|
||||
*/
|
||||
|
||||
layui.define(function(exports){
|
||||
"use strict";
|
||||
|
||||
var win = window;
|
||||
|
||||
//全局配置,如果采用默认均不需要改动
|
||||
var config = {
|
||||
path: '', //laydate所在路径
|
||||
skin: 'default', //初始化皮肤
|
||||
format: 'YYYY-MM-DD', //日期格式
|
||||
min: '1900-01-01 00:00:00', //最小日期
|
||||
max: '2099-12-31 23:59:59', //最大日期
|
||||
isv: false,
|
||||
init: true
|
||||
};
|
||||
|
||||
var Dates = {}, doc = document, creat = 'createElement', byid = 'getElementById', tags = 'getElementsByTagName';
|
||||
var as = ['laydate_box', 'laydate_void', 'laydate_click', 'LayDateSkin', 'skins/', '/laydate.css'];
|
||||
|
||||
|
||||
//主接口
|
||||
win.laydate = function(options){
|
||||
options = options || {};
|
||||
Dates.run(options);
|
||||
return laydate;
|
||||
};
|
||||
|
||||
laydate.v = '1.1';
|
||||
|
||||
Dates.trim = function(str){
|
||||
str = str || '';
|
||||
return str.replace(/^\s|\s$/g, '').replace(/\s+/g, ' ');
|
||||
};
|
||||
|
||||
//补齐数位
|
||||
Dates.digit = function(num){
|
||||
return num < 10 ? '0' + (num|0) : num;
|
||||
};
|
||||
|
||||
Dates.stopmp = function(e){
|
||||
e = e || win.event;
|
||||
e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true;
|
||||
return this;
|
||||
};
|
||||
|
||||
Dates.each = function(arr, fn){
|
||||
var i = 0, len = arr.length;
|
||||
for(; i < len; i++){
|
||||
if(fn(i, arr[i]) === false){
|
||||
break
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Dates.hasClass = function(elem, cls){
|
||||
elem = elem || {};
|
||||
return new RegExp('\\b' + cls +'\\b').test(elem.className);
|
||||
};
|
||||
|
||||
Dates.addClass = function(elem, cls){
|
||||
elem = elem || {};
|
||||
Dates.hasClass(elem, cls) || (elem.className += ' ' + cls);
|
||||
elem.className = Dates.trim(elem.className);
|
||||
return this;
|
||||
};
|
||||
|
||||
Dates.removeClass = function(elem, cls) {
|
||||
elem = elem || {};
|
||||
if (Dates.hasClass(elem, cls)) {
|
||||
var reg = new RegExp('\\b' + cls +'\\b');
|
||||
elem.className = elem.className.replace(reg, '');
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
//清除css属性
|
||||
Dates.removeCssAttr = function(elem, attr){
|
||||
var s = elem.style;
|
||||
if(s.removeProperty){
|
||||
s.removeProperty(attr);
|
||||
} else {
|
||||
s.removeAttribute(attr);
|
||||
}
|
||||
};
|
||||
|
||||
//显示隐藏
|
||||
Dates.shde = function(elem, type){
|
||||
elem.style.display = type ? 'none' : 'block';
|
||||
};
|
||||
|
||||
//简易选择器
|
||||
Dates.query = function(node){
|
||||
if(node && node.nodeType === 1){
|
||||
if(node.tagName.toLowerCase() !== 'input'){
|
||||
throw new Error('选择器elem错误');
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
var node = (Dates.trim(node)).split(' '), elemId = doc[byid](node[0].substr(1)), arr;
|
||||
if(!elemId){
|
||||
return;
|
||||
} else if(!node[1]){
|
||||
return elemId;
|
||||
} else if(/^\./.test(node[1])){
|
||||
var find, child = node[1].substr(1), exp = new RegExp('\\b' + child +'\\b');
|
||||
arr = []
|
||||
find = doc.getElementsByClassName ? elemId.getElementsByClassName(child) : elemId[tags]('*');
|
||||
Dates.each(find, function(ii, that){
|
||||
exp.test(that.className) && arr.push(that);
|
||||
});
|
||||
return arr[0] ? arr : '';
|
||||
} else {
|
||||
arr = elemId[tags](node[1]);
|
||||
return arr[0] ? elemId[tags](node[1]) : '';
|
||||
}
|
||||
};
|
||||
|
||||
//事件监听器
|
||||
Dates.on = function(elem, even, fn){
|
||||
elem.attachEvent ? elem.attachEvent('on'+ even, function(){
|
||||
fn.call(elem, win.even);
|
||||
}) : elem.addEventListener(even, fn, false);
|
||||
return Dates;
|
||||
};
|
||||
|
||||
//阻断mouseup
|
||||
Dates.stopMosup = function(evt, elem){
|
||||
if(evt !== 'mouseup'){
|
||||
Dates.on(elem, 'mouseup', function(ev){
|
||||
Dates.stopmp(ev);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Dates.run = function(options){
|
||||
var S = Dates.query, elem = options.elem, devt;
|
||||
|
||||
if(!elem) return;
|
||||
|
||||
as.elemv = /textarea|input/.test(elem.tagName.toLocaleLowerCase()) ? 'value' : 'innerHTML';
|
||||
if (('init' in options ? options.init : config.init) && (!elem[as.elemv])) elem[as.elemv] = laydate.now(null, options.format || config.format);
|
||||
|
||||
Dates.view(elem, options);
|
||||
Dates.reshow();
|
||||
|
||||
};
|
||||
|
||||
Dates.scroll = function(type){
|
||||
type = type ? 'scrollLeft' : 'scrollTop';
|
||||
return doc.body[type] | doc.documentElement[type];
|
||||
};
|
||||
|
||||
Dates.winarea = function(type){
|
||||
return document.documentElement[type ? 'clientWidth' : 'clientHeight']
|
||||
};
|
||||
|
||||
//判断闰年
|
||||
Dates.isleap = function(year){
|
||||
return (year%4 === 0 && year%100 !== 0) || year%400 === 0;
|
||||
};
|
||||
|
||||
//检测是否在有效期
|
||||
Dates.checkVoid = function(YY, MM, DD){
|
||||
var back = [];
|
||||
YY = YY|0;
|
||||
MM = MM|0;
|
||||
DD = DD|0;
|
||||
if(YY < Dates.mins[0]){
|
||||
back = ['y'];
|
||||
} else if(YY > Dates.maxs[0]){
|
||||
back = ['y', 1];
|
||||
} else if(YY >= Dates.mins[0] && YY <= Dates.maxs[0]){
|
||||
if(YY == Dates.mins[0]){
|
||||
if(MM < Dates.mins[1]){
|
||||
back = ['m'];
|
||||
} else if(MM == Dates.mins[1]){
|
||||
if(DD < Dates.mins[2]){
|
||||
back = ['d'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if(YY == Dates.maxs[0]){
|
||||
if(MM > Dates.maxs[1]){
|
||||
back = ['m', 1];
|
||||
} else if(MM == Dates.maxs[1]){
|
||||
if(DD > Dates.maxs[2]){
|
||||
back = ['d', 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return back;
|
||||
};
|
||||
|
||||
//时分秒的有效检测
|
||||
Dates.timeVoid = function(times, index){
|
||||
if(Dates.ymd[1]+1 == Dates.mins[1] && Dates.ymd[2] == Dates.mins[2]){
|
||||
if(index === 0 && (times < Dates.mins[3])){
|
||||
return 1;
|
||||
} else if(index === 1 && times < Dates.mins[4] && Dates.hmsin[0].value <= Dates.mins[3]){
|
||||
return 1;
|
||||
} else if(index === 2 && times < Dates.mins[5]){
|
||||
return 1;
|
||||
}
|
||||
} else if(Dates.ymd[1]+1 == Dates.maxs[1] && Dates.ymd[2] == Dates.maxs[2]){
|
||||
if(index === 0 && times > Dates.maxs[3]){
|
||||
return 1;
|
||||
} else if(index === 1 && times > Dates.maxs[4]){
|
||||
return 1;
|
||||
} else if(index === 2 && times > Dates.maxs[5]){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if(times > (index ? 59 : 23)){
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
//检测日期是否合法
|
||||
Dates.check = function(){
|
||||
var reg = Dates.options.format.replace(/YYYY|MM|DD|hh|mm|ss/g,'\\d+\\').replace(/\\$/g, '');
|
||||
var exp = new RegExp(reg), value = Dates.elem[as.elemv];
|
||||
var arr = value.match(/\d+/g) || [], isvoid = Dates.checkVoid(arr[0], arr[1], arr[2]);
|
||||
if(value.replace(/\s/g, '') !== ''){
|
||||
if(!exp.test(value)){
|
||||
Dates.elem[as.elemv] = '';
|
||||
Dates.msg('日期不符合格式,请重新选择。');
|
||||
return 1;
|
||||
} else if(isvoid[0]){
|
||||
Dates.elem[as.elemv] = '';
|
||||
Dates.msg('日期不在有效期内,请重新选择。');
|
||||
return 1;
|
||||
} else {
|
||||
isvoid.value = Dates.elem[as.elemv].match(exp).join();
|
||||
arr = isvoid.value.match(/\d+/g);
|
||||
if(arr[1] < 1){
|
||||
arr[1] = 1;
|
||||
isvoid.auto = 1;
|
||||
} else if(arr[1] > 12){
|
||||
arr[1] = 12;
|
||||
isvoid.auto = 1;
|
||||
} else if(arr[1].length < 2){
|
||||
isvoid.auto = 1;
|
||||
}
|
||||
if(arr[2] < 1){
|
||||
arr[2] = 1;
|
||||
isvoid.auto = 1;
|
||||
} else if(arr[2] > Dates.months[(arr[1]|0)-1]){
|
||||
arr[2] = 31;
|
||||
isvoid.auto = 1;
|
||||
} else if(arr[2].length < 2){
|
||||
isvoid.auto = 1;
|
||||
}
|
||||
if(arr.length > 3){
|
||||
if(Dates.timeVoid(arr[3], 0)){
|
||||
isvoid.auto = 1;
|
||||
};
|
||||
if(Dates.timeVoid(arr[4], 1)){
|
||||
isvoid.auto = 1;
|
||||
};
|
||||
if(Dates.timeVoid(arr[5], 2)){
|
||||
isvoid.auto = 1;
|
||||
};
|
||||
}
|
||||
if(isvoid.auto){
|
||||
Dates.creation([arr[0], arr[1]|0, arr[2]|0], 1);
|
||||
} else if(isvoid.value !== Dates.elem[as.elemv]){
|
||||
Dates.elem[as.elemv] = isvoid.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//生成日期
|
||||
Dates.months = [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
||||
Dates.viewDate = function(Y, M, D){
|
||||
var S = Dates.query, log = {}, De = new Date();
|
||||
Y < (Dates.mins[0]|0) && (Y = (Dates.mins[0]|0));
|
||||
Y > (Dates.maxs[0]|0) && (Y = (Dates.maxs[0]|0));
|
||||
|
||||
De.setFullYear(Y, M, D);
|
||||
log.ymd = [De.getFullYear(), De.getMonth(), De.getDate()];
|
||||
|
||||
Dates.months[1] = Dates.isleap(log.ymd[0]) ? 29 : 28;
|
||||
|
||||
De.setFullYear(log.ymd[0], log.ymd[1], 1);
|
||||
log.FDay = De.getDay();
|
||||
|
||||
log.PDay = Dates.months[M === 0 ? 11 : M - 1] - log.FDay + 1;
|
||||
log.NDay = 1;
|
||||
|
||||
//渲染日
|
||||
Dates.each(as.tds, function(i, elem){
|
||||
var YY = log.ymd[0], MM = log.ymd[1] + 1, DD;
|
||||
elem.className = '';
|
||||
if(i < log.FDay){
|
||||
elem.innerHTML = DD = i + log.PDay;
|
||||
Dates.addClass(elem, 'laydate_nothis');
|
||||
MM === 1 && (YY -= 1);
|
||||
MM = MM === 1 ? 12 : MM - 1;
|
||||
} else if(i >= log.FDay && i < log.FDay + Dates.months[log.ymd[1]]){
|
||||
elem.innerHTML = DD = i - log.FDay + 1;
|
||||
if(i - log.FDay + 1 === log.ymd[2]){
|
||||
Dates.addClass(elem, as[2]);
|
||||
log.thisDay = elem;
|
||||
}
|
||||
} else {
|
||||
elem.innerHTML = DD = log.NDay++;
|
||||
Dates.addClass(elem, 'laydate_nothis');
|
||||
MM === 12 && (YY += 1);
|
||||
MM = MM === 12 ? 1 : MM + 1;
|
||||
}
|
||||
|
||||
if(Dates.checkVoid(YY, MM, DD)[0]){
|
||||
Dates.addClass(elem, as[1]);
|
||||
}
|
||||
|
||||
Dates.options.festival && Dates.festival(elem, MM + '.' + DD);
|
||||
elem.setAttribute('y', YY);
|
||||
elem.setAttribute('m', MM);
|
||||
elem.setAttribute('d', DD);
|
||||
YY = MM = DD = null;
|
||||
});
|
||||
|
||||
Dates.valid = !Dates.hasClass(log.thisDay, as[1]);
|
||||
Dates.ymd = log.ymd;
|
||||
|
||||
//锁定年月
|
||||
as.year.value = Dates.ymd[0] + '年';
|
||||
as.month.value = Dates.digit(Dates.ymd[1] + 1) + '月';
|
||||
|
||||
//定位月
|
||||
Dates.each(as.mms, function(i, elem){
|
||||
var getCheck = Dates.checkVoid(Dates.ymd[0], (elem.getAttribute('m')|0) + 1);
|
||||
if(getCheck[0] === 'y' || getCheck[0] === 'm'){
|
||||
Dates.addClass(elem, as[1]);
|
||||
} else {
|
||||
Dates.removeClass(elem, as[1]);
|
||||
}
|
||||
Dates.removeClass(elem, as[2]);
|
||||
getCheck = null
|
||||
});
|
||||
Dates.addClass(as.mms[Dates.ymd[1]], as[2]);
|
||||
|
||||
//定位时分秒
|
||||
log.times = [
|
||||
Dates.inymd[3]|0 || 0,
|
||||
Dates.inymd[4]|0 || 0,
|
||||
Dates.inymd[5]|0 || 0
|
||||
];
|
||||
Dates.each(new Array(3), function(i){
|
||||
Dates.hmsin[i].value = Dates.digit(Dates.timeVoid(log.times[i], i) ? Dates.mins[i+3]|0 : log.times[i]|0);
|
||||
});
|
||||
|
||||
//确定按钮状态
|
||||
Dates[Dates.valid ? 'removeClass' : 'addClass'](as.ok, as[1]);
|
||||
};
|
||||
|
||||
//节日
|
||||
Dates.festival = function(td, md){
|
||||
var str;
|
||||
switch(md){
|
||||
case '1.1':
|
||||
str = '元旦';
|
||||
break;
|
||||
case '3.8':
|
||||
str = '妇女';
|
||||
break;
|
||||
case '4.5':
|
||||
str = '清明';
|
||||
break;
|
||||
case '5.1':
|
||||
str = '劳动';
|
||||
break;
|
||||
case '6.1':
|
||||
str = '儿童';
|
||||
break;
|
||||
case '9.10':
|
||||
str = '教师';
|
||||
break;
|
||||
case '10.1':
|
||||
str = '国庆';
|
||||
break;
|
||||
};
|
||||
str && (td.innerHTML = str);
|
||||
str = null;
|
||||
};
|
||||
|
||||
//生成年列表
|
||||
Dates.viewYears = function(YY){
|
||||
var S = Dates.query, str = '';
|
||||
Dates.each(new Array(14), function(i){
|
||||
if(i === 7) {
|
||||
str += '<li '+ (parseInt(as.year.value) === YY ? 'class="'+ as[2] +'"' : '') +' y="'+ YY +'">'+ YY +'年</li>';
|
||||
} else {
|
||||
str += '<li y="'+ (YY-7+i) +'">'+ (YY-7+i) +'年</li>';
|
||||
}
|
||||
});
|
||||
S('#laydate_ys').innerHTML = str;
|
||||
Dates.each(S('#laydate_ys li'), function(i, elem){
|
||||
if(Dates.checkVoid(elem.getAttribute('y'))[0] === 'y'){
|
||||
Dates.addClass(elem, as[1]);
|
||||
} else {
|
||||
Dates.on(elem, 'click', function(ev){
|
||||
Dates.stopmp(ev).reshow();
|
||||
Dates.viewDate(this.getAttribute('y')|0, Dates.ymd[1], Dates.ymd[2]);
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
//初始化面板数据
|
||||
Dates.initDate = function(){
|
||||
var S = Dates.query, log = {}, De = new Date();
|
||||
var ymd = Dates.elem[as.elemv].match(/\d+/g) || [];
|
||||
if(ymd.length < 3){
|
||||
ymd = Dates.options.start.match(/\d+/g) || [];
|
||||
if(ymd.length < 3){
|
||||
ymd = [De.getFullYear(), De.getMonth()+1, De.getDate()];
|
||||
}
|
||||
}
|
||||
Dates.inymd = ymd;
|
||||
Dates.viewDate(ymd[0], ymd[1]-1, ymd[2]);
|
||||
};
|
||||
|
||||
//是否显示零件
|
||||
Dates.iswrite = function(){
|
||||
var S = Dates.query, log = {
|
||||
time: S('#laydate_hms')
|
||||
};
|
||||
Dates.shde(log.time, !Dates.options.istime);
|
||||
Dates.shde(as.oclear, !('isclear' in Dates.options ? Dates.options.isclear : 1));
|
||||
Dates.shde(as.otoday, !('istoday' in Dates.options ? Dates.options.istoday : 1));
|
||||
Dates.shde(as.ok, !('issure' in Dates.options ? Dates.options.issure : 1));
|
||||
};
|
||||
|
||||
//方位辨别
|
||||
Dates.orien = function(obj, pos){
|
||||
var tops, rect = Dates.elem.getBoundingClientRect();
|
||||
if(rect.left < $(window).width() - 250)
|
||||
obj.style.left = rect.left + (pos ? 0 : Dates.scroll(1)) + 'px';
|
||||
else
|
||||
obj.style.left = ($(window).width() - 250) + 'px';
|
||||
if(rect.bottom + obj.offsetHeight/1.5 <= Dates.winarea()){
|
||||
tops = rect.bottom - 1;
|
||||
} else {
|
||||
tops = rect.top > obj.offsetHeight/1.5 ? rect.top - obj.offsetHeight + 1 : Dates.winarea() - obj.offsetHeight;
|
||||
}
|
||||
obj.style.top = Math.max(tops + (pos ? 0 : Dates.scroll()),1) + 'px';
|
||||
};
|
||||
|
||||
//吸附定位
|
||||
Dates.follow = function(obj){
|
||||
if(Dates.options.fixed){
|
||||
obj.style.position = 'fixed';
|
||||
Dates.orien(obj, 1);
|
||||
} else {
|
||||
obj.style.position = 'absolute';
|
||||
Dates.orien(obj);
|
||||
}
|
||||
};
|
||||
|
||||
//生成表格
|
||||
Dates.viewtb = (function(){
|
||||
var tr, view = [], weeks = [ '日', '一', '二', '三', '四', '五', '六'];
|
||||
var log = {}, table = doc[creat]('table'), thead = doc[creat]('thead');
|
||||
thead.appendChild(doc[creat]('tr'));
|
||||
log.creath = function(i){
|
||||
var th = doc[creat]('th');
|
||||
th.innerHTML = weeks[i];
|
||||
thead[tags]('tr')[0].appendChild(th);
|
||||
th = null;
|
||||
};
|
||||
|
||||
Dates.each(new Array(6), function(i){
|
||||
view.push([]);
|
||||
tr = table.insertRow(0);
|
||||
Dates.each(new Array(7), function(j){
|
||||
view[i][j] = 0;
|
||||
i === 0 && log.creath(j);
|
||||
tr.insertCell(j);
|
||||
});
|
||||
});
|
||||
|
||||
table.insertBefore(thead, table.children[0]);
|
||||
table.id = table.className = 'laydate_table';
|
||||
tr = view = null;
|
||||
return table.outerHTML.toLowerCase();
|
||||
}());
|
||||
|
||||
//渲染控件骨架
|
||||
Dates.view = function(elem, options){
|
||||
var S = Dates.query, div, log = {};
|
||||
options = options || elem;
|
||||
|
||||
Dates.elem = elem;
|
||||
Dates.options = options;
|
||||
Dates.options.format || (Dates.options.format = config.format);
|
||||
Dates.options.start = Dates.options.start || '';
|
||||
Dates.mm = log.mm = [Dates.options.min || config.min, Dates.options.max || config.max];
|
||||
Dates.mins = log.mm[0].match(/\d+/g);
|
||||
Dates.maxs = log.mm[1].match(/\d+/g);
|
||||
|
||||
if(!Dates.box){
|
||||
div = doc[creat]('div');
|
||||
div.id = as[0];
|
||||
div.className = as[0];
|
||||
div.style.cssText = 'position: absolute;';
|
||||
div.setAttribute('name', 'laydate-v'+ laydate.v);
|
||||
|
||||
div.innerHTML = log.html = '<div class="laydate_top">'
|
||||
+'<div class="laydate_ym laydate_y" id="laydate_YY">'
|
||||
+'<a class="laydate_choose laydate_chprev laydate_tab"><cite></cite></a>'
|
||||
+'<input id="laydate_y" readonly><label></label>'
|
||||
+'<a class="laydate_choose laydate_chnext laydate_tab"><cite></cite></a>'
|
||||
+'<div class="laydate_yms">'
|
||||
+'<a class="laydate_tab laydate_chtop"><cite></cite></a>'
|
||||
+'<ul id="laydate_ys"></ul>'
|
||||
+'<a class="laydate_tab laydate_chdown"><cite></cite></a>'
|
||||
+'</div>'
|
||||
+'</div>'
|
||||
+'<div class="laydate_ym laydate_m" id="laydate_MM">'
|
||||
+'<a class="laydate_choose laydate_chprev laydate_tab"><cite></cite></a>'
|
||||
+'<input id="laydate_m" readonly><label></label>'
|
||||
+'<a class="laydate_choose laydate_chnext laydate_tab"><cite></cite></a>'
|
||||
+'<div class="laydate_yms" id="laydate_ms">'+ function(){
|
||||
var str = '';
|
||||
Dates.each(new Array(12), function(i){
|
||||
str += '<span m="'+ i +'">'+ Dates.digit(i+1) +'月</span>';
|
||||
});
|
||||
return str;
|
||||
}() +'</div>'
|
||||
+'</div>'
|
||||
+'</div>'
|
||||
|
||||
+ Dates.viewtb
|
||||
|
||||
+'<div class="laydate_bottom">'
|
||||
+'<ul id="laydate_hms">'
|
||||
+'<li class="laydate_sj">时间</li>'
|
||||
+'<li><input readonly>:</li>'
|
||||
+'<li><input readonly>:</li>'
|
||||
+'<li><input readonly></li>'
|
||||
+'</ul>'
|
||||
+'<div class="laydate_time" id="laydate_time"></div>'
|
||||
+'<div class="laydate_btn">'
|
||||
+'<a id="laydate_clear">清空</a>'
|
||||
+'<a id="laydate_today">今天</a>'
|
||||
+'<a id="laydate_ok">确认</a>'
|
||||
+'</div>'
|
||||
+(config.isv ? '<a href="http://sentsin.com/layui/laydate/" class="laydate_v" target="_blank">laydate-v'+ laydate.v +'</a>' : '')
|
||||
+'</div>';
|
||||
doc.body.appendChild(div);
|
||||
Dates.box = S('#'+as[0]);
|
||||
Dates.events();
|
||||
div = null;
|
||||
} else {
|
||||
Dates.shde(Dates.box);
|
||||
}
|
||||
Dates.follow(Dates.box);
|
||||
options.zIndex ? Dates.box.style.zIndex = options.zIndex : Dates.removeCssAttr(Dates.box, 'z-index');
|
||||
Dates.stopMosup('click', Dates.box);
|
||||
|
||||
Dates.initDate();
|
||||
Dates.iswrite();
|
||||
Dates.check();
|
||||
};
|
||||
|
||||
//隐藏内部弹出元素
|
||||
Dates.reshow = function(){
|
||||
Dates.each(Dates.query('#'+ as[0] +' .laydate_show'), function(i, elem){
|
||||
Dates.removeClass(elem, 'laydate_show');
|
||||
});
|
||||
return this;
|
||||
};
|
||||
|
||||
//关闭控件
|
||||
Dates.close = function(){
|
||||
Dates.reshow();
|
||||
Dates.shde(Dates.query('#'+ as[0]), 1);
|
||||
Dates.elem = null;
|
||||
};
|
||||
|
||||
//转换日期格式
|
||||
Dates.parse = function(ymd, hms, format){
|
||||
ymd = ymd.concat(hms);
|
||||
format = format || (Dates.options ? Dates.options.format : config.format);
|
||||
return format.replace(/YYYY|MM|DD|hh|mm|ss/g, function(str, index){
|
||||
ymd.index = ++ymd.index|0;
|
||||
return Dates.digit(ymd[ymd.index]);
|
||||
});
|
||||
};
|
||||
|
||||
//返回最终日期
|
||||
Dates.creation = function(ymd, hide){
|
||||
var S = Dates.query, hms = Dates.hmsin;
|
||||
var getDates = Dates.parse(ymd, [hms[0].value, hms[1].value, hms[2].value]);
|
||||
Dates.elem[as.elemv] = getDates;
|
||||
if(!hide){
|
||||
Dates.close();
|
||||
typeof Dates.options.choose === 'function' && Dates.options.choose(getDates);
|
||||
}
|
||||
};
|
||||
|
||||
//事件
|
||||
Dates.events = function(){
|
||||
var S = Dates.query, log = {
|
||||
box: '#'+as[0]
|
||||
};
|
||||
|
||||
Dates.addClass(doc.body, 'laydate_body');
|
||||
|
||||
as.tds = S('#laydate_table td');
|
||||
as.mms = S('#laydate_ms span');
|
||||
as.year = S('#laydate_y');
|
||||
as.month = S('#laydate_m');
|
||||
|
||||
//显示更多年月
|
||||
Dates.each(S(log.box + ' .laydate_ym'), function(i, elem){
|
||||
Dates.on(elem, 'click', function(ev){
|
||||
Dates.stopmp(ev).reshow();
|
||||
Dates.addClass(this[tags]('div')[0], 'laydate_show');
|
||||
if(!i){
|
||||
log.YY = parseInt(as.year.value);
|
||||
Dates.viewYears(log.YY);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Dates.on(S(log.box), 'click', function(){
|
||||
Dates.reshow();
|
||||
});
|
||||
|
||||
//切换年
|
||||
log.tabYear = function(type){
|
||||
if(type === 0){
|
||||
Dates.ymd[0]--;
|
||||
} else if(type === 1) {
|
||||
Dates.ymd[0]++;
|
||||
} else if(type === 2) {
|
||||
log.YY -= 14;
|
||||
} else {
|
||||
log.YY += 14;
|
||||
}
|
||||
if(type < 2){
|
||||
Dates.viewDate(Dates.ymd[0], Dates.ymd[1], Dates.ymd[2]);
|
||||
Dates.reshow();
|
||||
} else {
|
||||
Dates.viewYears(log.YY);
|
||||
}
|
||||
};
|
||||
Dates.each(S('#laydate_YY .laydate_tab'), function(i, elem){
|
||||
Dates.on(elem, 'click', function(ev){
|
||||
Dates.stopmp(ev);
|
||||
log.tabYear(i);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
//切换月
|
||||
log.tabMonth = function(type){
|
||||
if(type){
|
||||
Dates.ymd[1]++;
|
||||
if(Dates.ymd[1] === 12){
|
||||
Dates.ymd[0]++;
|
||||
Dates.ymd[1] = 0;
|
||||
}
|
||||
} else {
|
||||
Dates.ymd[1]--;
|
||||
if(Dates.ymd[1] === -1){
|
||||
Dates.ymd[0]--;
|
||||
Dates.ymd[1] = 11;
|
||||
}
|
||||
}
|
||||
Dates.viewDate(Dates.ymd[0], Dates.ymd[1], Dates.ymd[2]);
|
||||
};
|
||||
Dates.each(S('#laydate_MM .laydate_tab'), function(i, elem){
|
||||
Dates.on(elem, 'click', function(ev){
|
||||
Dates.stopmp(ev).reshow();
|
||||
log.tabMonth(i);
|
||||
});
|
||||
});
|
||||
|
||||
//选择月
|
||||
Dates.each(S('#laydate_ms span'), function(i, elem){
|
||||
Dates.on(elem, 'click', function(ev){
|
||||
Dates.stopmp(ev).reshow();
|
||||
if(!Dates.hasClass(this, as[1])){
|
||||
Dates.viewDate(Dates.ymd[0], this.getAttribute('m')|0, Dates.ymd[2]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//选择日
|
||||
Dates.each(S('#laydate_table td'), function(i, elem){
|
||||
Dates.on(elem, 'click', function(ev){
|
||||
if(!Dates.hasClass(this, as[1])){
|
||||
Dates.stopmp(ev);
|
||||
Dates.creation([this.getAttribute('y')|0, this.getAttribute('m')|0, this.getAttribute('d')|0]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//清空
|
||||
as.oclear = S('#laydate_clear');
|
||||
Dates.on(as.oclear, 'click', function(){
|
||||
Dates.elem[as.elemv] = '';
|
||||
Dates.close();
|
||||
});
|
||||
|
||||
//今天
|
||||
as.otoday = S('#laydate_today');
|
||||
Dates.on(as.otoday, 'click', function(){
|
||||
var now = new Date();
|
||||
Dates.creation([now.getFullYear(), now.getMonth() + 1, now.getDate()]);
|
||||
});
|
||||
|
||||
//确认
|
||||
as.ok = S('#laydate_ok');
|
||||
Dates.on(as.ok, 'click', function(){
|
||||
if(Dates.valid){
|
||||
Dates.creation([Dates.ymd[0], Dates.ymd[1]+1, Dates.ymd[2]]);
|
||||
}
|
||||
});
|
||||
|
||||
//选择时分秒
|
||||
log.times = S('#laydate_time');
|
||||
Dates.hmsin = log.hmsin = S('#laydate_hms input');
|
||||
log.hmss = ['小时', '分钟', '秒数'];
|
||||
log.hmsarr = [];
|
||||
|
||||
//生成时分秒或警告信息
|
||||
Dates.msg = function(i, title){
|
||||
var str = '<div class="laydte_hsmtex">'+ (title || '提示') +'<span>×</span></div>';
|
||||
if(typeof i === 'string'){
|
||||
str += '<p>'+ i +'</p>';
|
||||
Dates.shde(S('#'+as[0]));
|
||||
Dates.removeClass(log.times, 'laydate_time1').addClass(log.times, 'laydate_msg');
|
||||
} else {
|
||||
if(!log.hmsarr[i]){
|
||||
str += '<div id="laydate_hmsno" class="laydate_hmsno">';
|
||||
Dates.each(new Array(i === 0 ? 24 : 60), function(i){
|
||||
str += '<span>'+ i +'</span>';
|
||||
});
|
||||
str += '</div>'
|
||||
log.hmsarr[i] = str;
|
||||
} else {
|
||||
str = log.hmsarr[i];
|
||||
}
|
||||
Dates.removeClass(log.times, 'laydate_msg');
|
||||
Dates[i=== 0 ? 'removeClass' : 'addClass'](log.times, 'laydate_time1');
|
||||
}
|
||||
Dates.addClass(log.times, 'laydate_show');
|
||||
log.times.innerHTML = str;
|
||||
};
|
||||
|
||||
log.hmson = function(input, index){
|
||||
var span = S('#laydate_hmsno span'), set = Dates.valid ? null : 1;
|
||||
Dates.each(span, function(i, elem){
|
||||
if(set){
|
||||
Dates.addClass(elem, as[1]);
|
||||
} else if(Dates.timeVoid(i, index)){
|
||||
Dates.addClass(elem, as[1]);
|
||||
} else {
|
||||
Dates.on(elem, 'click', function(ev){
|
||||
if(!Dates.hasClass(this, as[1])){
|
||||
input.value = Dates.digit(this.innerHTML|0);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
Dates.addClass(span[input.value|0], 'laydate_click');
|
||||
};
|
||||
|
||||
//展开选择
|
||||
Dates.each(log.hmsin, function(i, elem){
|
||||
Dates.on(elem, 'click', function(ev){
|
||||
Dates.stopmp(ev).reshow();
|
||||
Dates.msg(i, log.hmss[i]);
|
||||
log.hmson(this, i);
|
||||
});
|
||||
});
|
||||
|
||||
Dates.on(doc, 'mouseup', function(){
|
||||
var box = S('#'+as[0]);
|
||||
if(box && box.style.display !== 'none'){
|
||||
Dates.check() || Dates.close();
|
||||
}
|
||||
}).on(doc, 'keydown', function(event){
|
||||
event = event || win.event;
|
||||
var codes = event.keyCode;
|
||||
|
||||
//如果在日期显示的时候按回车
|
||||
if(codes === 13 && Dates.elem){
|
||||
Dates.creation([Dates.ymd[0], Dates.ymd[1]+1, Dates.ymd[2]]);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
//重置定位
|
||||
laydate.reset = function(){
|
||||
(Dates.box && Dates.elem) && Dates.follow(Dates.box);
|
||||
};
|
||||
|
||||
//返回指定日期
|
||||
laydate.now = function(timestamp, format){
|
||||
var De = new Date((timestamp|0) ? function(tamp){
|
||||
return tamp < 86400000 ? (+new Date + tamp*86400000) : tamp;
|
||||
}(parseInt(timestamp)) : +new Date);
|
||||
return Dates.parse(
|
||||
[De.getFullYear(), De.getMonth()+1, De.getDate()],
|
||||
[De.getHours(), De.getMinutes(), De.getSeconds()],
|
||||
format
|
||||
);
|
||||
};
|
||||
|
||||
//加载组件所需的css
|
||||
layui.addcss('modules/laydate/laydate.css', function(){
|
||||
}, 'laydatecss');
|
||||
|
||||
exports('laydate', laydate);
|
||||
|
||||
});
|
||||
@@ -1,650 +0,0 @@
|
||||
/**
|
||||
|
||||
@Name:layui.layedit 富文本编辑器
|
||||
@Author:贤心
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define(['layer', 'form'], function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.jquery
|
||||
,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({
|
||||
url: uploadImage.url
|
||||
,method: uploadImage.type
|
||||
,elem: $(that).find('input')[0]
|
||||
,unwrap: true
|
||||
,success: 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);
|
||||
});
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,162 +0,0 @@
|
||||
/**
|
||||
|
||||
@Name : layui.laypage 分页组件
|
||||
@Author:贤心
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define(function(exports){
|
||||
"use strict";
|
||||
|
||||
function laypage(options){
|
||||
var skin = 'laypagecss';
|
||||
new Page(options);
|
||||
}
|
||||
|
||||
var doc = document, id = 'getElementById', tag = 'getElementsByTagName';
|
||||
var index = 0, Page = function(options){
|
||||
var that = this;
|
||||
var conf = that.config = options || {};
|
||||
conf.item = index++;
|
||||
that.render(true);
|
||||
};
|
||||
|
||||
Page.on = function(elem, even, fn){
|
||||
elem.attachEvent ? elem.attachEvent('on'+ even, function(){
|
||||
fn.call(elem, window.even); //for ie, this指向为当前dom元素
|
||||
}) : elem.addEventListener(even, fn, false);
|
||||
return Page;
|
||||
};
|
||||
|
||||
//判断传入的容器类型
|
||||
Page.prototype.type = function(){
|
||||
var conf = this.config;
|
||||
if(typeof conf.cont === 'object'){
|
||||
return conf.cont.length === undefined ? 2 : 3;
|
||||
}
|
||||
};
|
||||
|
||||
//分页视图
|
||||
Page.prototype.view = function(){
|
||||
var that = this, conf = that.config, view = [], dict = {};
|
||||
conf.pages = conf.pages|0;
|
||||
conf.curr = (conf.curr|0) || 1;
|
||||
conf.groups = 'groups' in conf ? (conf.groups|0) : 5;
|
||||
conf.first = 'first' in conf ? conf.first : '首页';
|
||||
conf.last = 'last' in conf ? conf.last : '末页';
|
||||
conf.prev = 'prev' in conf ? conf.prev : '上一页';
|
||||
conf.next = 'next' in conf ? conf.next : '下一页';
|
||||
|
||||
if(conf.pages <= 1){
|
||||
return '';
|
||||
}
|
||||
|
||||
if(conf.groups > conf.pages){
|
||||
conf.groups = conf.pages;
|
||||
}
|
||||
|
||||
//计算当前组
|
||||
dict.index = Math.ceil((conf.curr + ((conf.groups > 1 && conf.groups !== conf.pages) ? 1 : 0))/(conf.groups === 0 ? 1 : conf.groups));
|
||||
|
||||
//当前页非首页,则输出上一页
|
||||
if(conf.curr > 1 && conf.prev){
|
||||
view.push('<a href="javascript:;" class="layui-laypage-prev" data-page="'+ (conf.curr - 1) +'">'+ conf.prev +'</a>');
|
||||
}
|
||||
|
||||
//当前组非首组,则输出首页
|
||||
if(dict.index > 1 && conf.first && conf.groups !== 0){
|
||||
view.push('<a href="javascript:;" class="laypage_first" data-page="1" title="首页">'+ conf.first +'</a><span>…</span>');
|
||||
}
|
||||
|
||||
//输出当前页组
|
||||
dict.poor = Math.floor((conf.groups-1)/2);
|
||||
dict.start = dict.index > 1 ? conf.curr - dict.poor : 1;
|
||||
dict.end = dict.index > 1 ? (function(){
|
||||
var max = conf.curr + (conf.groups - dict.poor - 1);
|
||||
return max > conf.pages ? conf.pages : max;
|
||||
}()) : conf.groups;
|
||||
if(dict.end - dict.start < conf.groups - 1){ //最后一组状态
|
||||
dict.start = dict.end - conf.groups + 1;
|
||||
}
|
||||
for(; dict.start <= dict.end; dict.start++){
|
||||
if(dict.start === conf.curr){
|
||||
view.push('<span class="layui-laypage-curr"><em class="layui-laypage-em" '+ (/^#/.test(conf.skin) ? 'style="background-color:'+ conf.skin +';"' : '') +'></em><em>'+ dict.start +'</em></span>');
|
||||
} else {
|
||||
view.push('<a href="javascript:;" data-page="'+ dict.start +'">'+ dict.start +'</a>');
|
||||
}
|
||||
}
|
||||
|
||||
//总页数大于连续分页数,且当前组最大页小于总页,输出尾页
|
||||
if(conf.pages > conf.groups && dict.end < conf.pages && conf.last && conf.groups !== 0){
|
||||
view.push('<span>…</span><a href="javascript:;" class="layui-laypage-last" title="尾页" data-page="'+ conf.pages +'">'+ conf.last +'</a>');
|
||||
}
|
||||
|
||||
//当前页不为尾页时,输出下一页
|
||||
dict.flow = !conf.prev && conf.groups === 0;
|
||||
if(conf.curr !== conf.pages && conf.next || dict.flow){
|
||||
view.push((function(){
|
||||
return (dict.flow && conf.curr === conf.pages)
|
||||
? '<span class="layui-laypage-nomore" title="已没有更多">'+ conf.next +'</span>'
|
||||
: '<a href="javascript:;" class="layui-laypage-next" data-page="'+ (conf.curr + 1) +'">'+ conf.next +'</a>';
|
||||
}()));
|
||||
}
|
||||
|
||||
return '<div class="layui-box layui-laypage layui-laypage-'+ (conf.skin ? (function(skin){
|
||||
return /^#/.test(skin) ? 'molv' : skin;
|
||||
}(conf.skin)) : 'default') +'" id="layui-laypage-'+ that.config.item +'">'+ view.join('') + function(){
|
||||
return conf.skip
|
||||
? '<span class="layui-laypage-total">到第 <input type="number" min="1" onkeyup="this.value=this.value.replace(/\\D/, \'\');" value="'+ conf.curr +'" class="layui-laypage-skip"> 页 '
|
||||
+ '<button type="button" class="layui-laypage-btn">确定</button></span>'
|
||||
: '';
|
||||
}() +'</div>';
|
||||
};
|
||||
|
||||
//跳页
|
||||
Page.prototype.jump = function(elem){
|
||||
if(!elem) return;
|
||||
var that = this, conf = that.config, childs = elem.children;
|
||||
var btn = elem[tag]('button')[0];
|
||||
var input = elem[tag]('input')[0];
|
||||
for(var i = 0, len = childs.length; i < len; i++){
|
||||
if(childs[i].nodeName.toLowerCase() === 'a'){
|
||||
Page.on(childs[i], 'click', function(){
|
||||
var curr = this.getAttribute('data-page')|0;
|
||||
conf.curr = curr;
|
||||
that.render();
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
if(btn){
|
||||
Page.on(btn, 'click', function(){
|
||||
var curr = input.value.replace(/\s|\D/g, '')|0;
|
||||
if(curr && curr <= conf.pages){
|
||||
conf.curr = curr;
|
||||
that.render();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
//渲染分页
|
||||
Page.prototype.render = function(load){
|
||||
var that = this, conf = that.config, type = that.type();
|
||||
var view = that.view();
|
||||
if(type === 2){
|
||||
conf.cont.innerHTML = view;
|
||||
} else if(type === 3){
|
||||
conf.cont.html(view);
|
||||
} else {
|
||||
doc[id](conf.cont).innerHTML = view;
|
||||
}
|
||||
conf.jump && conf.jump(conf, load);
|
||||
that.jump(doc[id]('layui-laypage-' + conf.item));
|
||||
if(conf.hash && !load){
|
||||
location.hash = '!'+ conf.hash +'='+ conf.curr;
|
||||
}
|
||||
};
|
||||
|
||||
exports('laypage', laypage);
|
||||
|
||||
});
|
||||
@@ -1,111 +0,0 @@
|
||||
/**
|
||||
|
||||
@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);
|
||||
|
||||
});
|
||||
@@ -1,30 +0,0 @@
|
||||
/**
|
||||
|
||||
@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
|
||||
});
|
||||
});
|
||||
@@ -1,189 +0,0 @@
|
||||
/*!
|
||||
|
||||
@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);
|
||||
|
||||
});
|
||||
@@ -1,11 +0,0 @@
|
||||
/**
|
||||
|
||||
@Name:layim mobile 开源包
|
||||
@Author:贤心
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define(function(exports){
|
||||
exports('layim-mobile', layui.v);
|
||||
});
|
||||
@@ -1,166 +0,0 @@
|
||||
/*!
|
||||
|
||||
@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();
|
||||
});
|
||||
});
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,215 +0,0 @@
|
||||
/**
|
||||
|
||||
@Name:layui.tree 树组件
|
||||
@Author:贤心
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
|
||||
layui.define('jquery', function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.jquery;
|
||||
var 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);
|
||||
});
|
||||
});
|
||||
@@ -1,158 +0,0 @@
|
||||
/*!
|
||||
|
||||
@Title: layui.upload 单文件上传 - 全浏览器兼容版
|
||||
@Author: 贤心
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define('layer' , function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.jquery;
|
||||
var layer = layui.layer;
|
||||
var device = layui.device();
|
||||
|
||||
var elemDragEnter = 'layui-upload-enter';
|
||||
var elemIframe = 'layui-upload-iframe';
|
||||
|
||||
var msgConf = {
|
||||
icon: 2
|
||||
,shift: 6
|
||||
}, fileType = {
|
||||
file: '文件'
|
||||
,video: '视频'
|
||||
,audio: '音频'
|
||||
};
|
||||
|
||||
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', function(options){
|
||||
var upload = new Upload(options = options || {});
|
||||
upload.init();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
/**
|
||||
|
||||
@Name:layui.util 工具集
|
||||
@Author:贤心
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define('jquery', function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.jquery
|
||||
|
||||
,util = {
|
||||
//固定块
|
||||
fixbar: function(options){
|
||||
options = options || {};
|
||||
options.bgcolor = options.bgcolor ? ('background-color:' + options.bgcolor) : '';
|
||||
|
||||
var TOP_BAR = 'layui-fixbar-top', timer, is, icon = [
|
||||
options.bar1 === true ? '' : options.bar1 //bar1 - 信息图标
|
||||
,options.bar2 === true ? '' : options.bar2 //bar2 - 问号图标
|
||||
,'' //置顶
|
||||
]
|
||||
|
||||
,dom = $(['<ul class="layui-fixbar">'
|
||||
,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 = dom.find('.'+TOP_BAR)
|
||||
|
||||
,scroll = function(){
|
||||
var stop = $(document).scrollTop();
|
||||
if(stop >= (options.showHeight || 200)){
|
||||
is || (topbar.show(), is = 1);
|
||||
} else {
|
||||
is && (topbar.hide(), is = 0);
|
||||
}
|
||||
};
|
||||
|
||||
if($('.layui-fixbar')[0]) return;
|
||||
typeof options.css === 'object' && (dom.css(options.css));
|
||||
$('body').append(dom), scroll();
|
||||
|
||||
//bar点击事件
|
||||
dom.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显示控制
|
||||
$(document).on('scroll', function(){
|
||||
if(timer) clearTimeout(timer);
|
||||
timer = setTimeout(function(){
|
||||
scroll();
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
exports('util', util);
|
||||
});
|
||||
Reference in New Issue
Block a user