/* artDialog v6.0.2 | https://github.com/aui/artDialog */
!function(){function a(b){var d=c[b],e="exports";return"object"==typeof d?d:(d[e]||(d[e]={},d[e]=d.call(d[e],a,d[e],d)||d[e]),d[e])}function b(a,b){c[a]=b}var c={};b("jquery",function(){return jQuery}),b("popup",function(a){function b(){this.destroyed=!1,this.__popup=c("
").attr({tabindex:"-1"}).css({display:"none",position:"absolute",outline:0}).html(this.innerHTML).appendTo("body"),this.__backdrop=c(""),this.node=this.__popup[0],this.backdrop=this.__backdrop[0],d++}var c=a("jquery"),d=0,e=!("minWidth"in c("html")[0].style),f=!e;return c.extend(b.prototype,{node:null,backdrop:null,fixed:!1,destroyed:!0,open:!1,returnValue:"",autofocus:!0,align:"bottom left",backdropBackground:"#000",backdropOpacity:.7,innerHTML:"",className:"ui-popup",show:function(a){if(this.destroyed)return this;var b=this,d=this.__popup;return this.__activeElement=this.__getActive(),this.open=!0,this.follow=a||this.follow,this.__ready||(d.addClass(this.className),this.modal&&this.__lock(),d.html()||d.html(this.innerHTML),e||c(window).on("resize",this.__onresize=function(){b.reset()}),this.__ready=!0),d.addClass(this.className+"-show").attr("role",this.modal?"alertdialog":"dialog").css("position",this.fixed?"fixed":"absolute").fadeIn(300),this.__backdrop.show(),this.reset().focus(),this.__dispatchEvent("show"),this},showModal:function(){return this.modal=!0,this.show.apply(this,arguments)},close:function(a){return!this.destroyed&&this.open&&(void 0!==a&&(this.returnValue=a),this.__popup.hide().removeClass(this.className+"-show"),this.__backdrop.hide(),this.open=!1,this.blur(),this.__dispatchEvent("close")),this},remove:function(){if(this.destroyed)return this;this.__dispatchEvent("beforeremove"),b.current===this&&(b.current=null),this.__unlock(),this.__popup.remove(),this.__backdrop.remove(),e||c(window).off("resize",this.__onresize),this.__dispatchEvent("remove");for(var a in this)delete this[a];return this},reset:function(){var a=this.follow;return a?this.__follow(a):this.__center(),this.__dispatchEvent("reset"),this},focus:function(){var a=this.node,d=b.current;if(d&&d!==this&&d.blur(!1),!c.contains(a,this.__getActive())){var e=this.__popup.find("[autofocus]")[0];!this._autofocus&&e?this._autofocus=!0:e=a,this.__focus(e)}return b.current=this,this.__popup.addClass(this.className+"-focus"),this.__zIndex(),this.__dispatchEvent("focus"),this},blur:function(){var a=this.__activeElement,b=arguments[0];return b!==!1&&this.__focus(a),this._autofocus=!1,this.__popup.removeClass(this.className+"-focus"),this.__dispatchEvent("blur"),this},addEventListener:function(a,b){return this.__getEventListener(a).push(b),this},removeEventListener:function(a,b){for(var c=this.__getEventListener(a),d=0;dH[E[b]][1]&&(b=B[a]=D[b]),F[a][b]Loading..',title:"",statusbar:"",button:null,ok:null,cancel:null,okValue:"确定",cancelValue:"取消",cancelDisplay:!0,width:"",height:"",padding:"",skin:"",quickClose:!1,cssUri:"../css/ui-dialog.css",innerHTML:''}),b("dialog",function(a){var b=a("jquery"),c=a("popup"),d=a("dialog-config"),e=d.cssUri;if(e){var f=a[a.toUrl?"toUrl":"resolve"];f&&(e=f(e),e='',b("base")[0]?b("base").before(e):b("head").append(e))}var g=0,h=new Date-0,i=!("minWidth"in b("html")[0].style),j="createTouch"in document&&!("onmousemove"in document)||/(iPhone|iPad|iPod)/i.test(navigator.userAgent),k=!i&&!j,l=function(a,c,d){var e=a=a||{};("string"==typeof a||1===a.nodeType)&&(a={content:a,fixed:!j}),a=b.extend(!0,{},l.defaults,a),a._=e;var f=a.id=a.id||h+g,i=l.get(f);return i?i.focus():(k||(a.fixed=!1),a.quickClose&&(a.modal=!0,e.backdropOpacity||(a.backdropOpacity=0)),b.isArray(a.button)||(a.button=[]),void 0!==d&&(a.cancel=d),a.cancel&&a.button.push({id:"cancel",className:"default",value:a.cancelValue,callback:a.cancel,display:a.cancelDisplay}),void 0!==c&&(a.ok=c),a.ok&&a.button.push({id:"ok",className:"primary",value:a.okValue,callback:a.ok,autofocus:!0}),l.list[f]=new l.create(a))},m=function(){};m.prototype=c.prototype;var n=l.prototype=new m;return l.create=function(a){var d=this;b.extend(this,new c);var e=b(this.node).html(a.innerHTML);return this.options=a,this._popup=e,b.each(a,function(a,b){"function"==typeof d[a]?d[a](b):d[a]=b}),a.zIndex&&(c.zIndex=a.zIndex),e.attr({"aria-labelledby":this._$("title").attr("id","title:"+this.id).attr("id"),"aria-describedby":this._$("content").attr("id","content:"+this.id).attr("id")}),this._$("close").css("display",this.cancel===!1?"none":"").attr("title",this.cancelValue).on("click",function(a){d._trigger("cancel"),a.preventDefault()}),this._$("dialog").addClass(this.skin),e.on("click","[data-id]",function(a){var c=b(this);c.attr("disabled")||d._trigger(c.data("id")),a.preventDefault()}),a.quickClose&&b(this.backdrop).on("onmousedown"in document?"mousedown":"click",function(){return d._trigger("cancel"),!1}),this._esc=function(a){var b=a.target,e=b.nodeName,f=/^input|textarea$/i,g=c.current===d,h=a.keyCode;!g||f.test(e)&&"button"!==b.type||27===h&&d._trigger("cancel")},b(document).on("keydown",this._esc),this.addEventListener("remove",function(){b(document).off("keydown",this._esc),delete l.list[this.id]}),g++,l.oncreate(this),this},l.create.prototype=n,b.extend(n,{content:function(a){return this._$("content").empty("")["object"==typeof a?"append":"html"](a),this.reset()},title:function(a){return this._$("title").text(a),this._$("header")[a?"show":"hide"](),this},width:function(a){return this._$("content").css("width",a),this.reset()},height:function(a){return this._$("content").css("height",a),this.reset()},button:function(a){a=a||[];var c=this,d="",e=0;return this.callbacks={},"string"==typeof a?d=a:b.each(a,function(a,b){b.id=b.id||b.value,c.callbacks[b.id]=b.callback;var f="";b.display===!1?f=' style="display:none"':e++,d+=' '}),this._$("footer")[e?"show":"hide"](),this._$("button").html(d),this},statusbar:function(a){return this._$("statusbar").html(a)[a?"show":"hide"](),this},_$:function(a){return this._popup.find("[i="+a+"]")},_trigger:function(a){var b=this.callbacks[a];return"function"!=typeof b||b.call(this)!==!1?this.close().remove():this}}),l.oncreate=b.noop,l.getCurrent=function(){return c.current},l.get=function(a){return void 0===a?l.list:l.list[a]},l.list={},l.defaults=d,l}),b("drag",function(a){var b=a("jquery"),c=b(window),d=b(document),e="createTouch"in document,f=document.documentElement,g=!("minWidth"in f.style),h=!g&&"onlosecapture"in f,i="setCapture"in f,j={start:e?"touchstart":"mousedown",over:e?"touchmove":"mousemove",end:e?"touchend":"mouseup"},k=e?function(a){return a.touches||(a=a.originalEvent.touches.item(0)),a}:function(a){return a},l=function(){this.start=b.proxy(this.start,this),this.over=b.proxy(this.over,this),this.end=b.proxy(this.end,this),this.onstart=this.onover=this.onend=b.noop};return l.types=j,l.prototype={start:function(a){return a=this.startFix(a),d.on(j.over,this.over).on(j.end,this.end),this.onstart(a),!1},over:function(a){return a=this.overFix(a),this.onover(a),!1},end:function(a){return a=this.endFix(a),d.off(j.over,this.over).off(j.end,this.end),this.onend(a),!1},startFix:function(a){return a=k(a),this.target=b(a.target),this.selectstart=function(){return!1},d.on("selectstart",this.selectstart).on("dblclick",this.end),h?this.target.on("losecapture",this.end):c.on("blur",this.end),i&&this.target[0].setCapture(),a},overFix:function(a){return a=k(a)},endFix:function(a){return a=k(a),d.off("selectstart",this.selectstart).off("dblclick",this.end),h?this.target.off("losecapture",this.end):c.off("blur",this.end),i&&this.target[0].releaseCapture(),a}},l.create=function(a,e){var f,g,h,i,j=b(a),k=new l,m=l.types.start,n=function(){},o=a.className.replace(/^\s|\s.*/g,"")+"-drag-start",p={onstart:n,onover:n,onend:n,off:function(){j.off(m,k.start)}};return k.onstart=function(b){var e="fixed"===j.css("position"),k=d.scrollLeft(),l=d.scrollTop(),m=j.width(),n=j.height();f=0,g=0,h=e?c.width()-m+f:d.width()-m,i=e?c.height()-n+g:d.height()-n;var q=j.offset(),r=this.startLeft=e?q.left-k:q.left,s=this.startTop=e?q.top-l:q.top;this.clientX=b.clientX,this.clientY=b.clientY,j.addClass(o),p.onstart.call(a,b,r,s)},k.onover=function(b){var c=b.clientX-this.clientX+this.startLeft,d=b.clientY-this.clientY+this.startTop,e=j[0].style;c=Math.max(f,Math.min(h,c)),d=Math.max(g,Math.min(i,d)),e.left=c+"px",e.top=d+"px",p.onover.call(a,b,c,d)},k.onend=function(b){var c=j.position(),d=c.left,e=c.top;j.removeClass(o),p.onend.call(a,b,d,e)},k.off=function(){j.off(m,k.start)},e?k.start(e):j.on(m,k.start),p},l}),b("dialog-plus",function(a){var b=a("jquery"),c=a("dialog"),d=a("drag");return c.oncreate=function(a){var c,e=a.options,f=e._,g=e.url,h=e.oniframeload;if(g&&(this.padding=e.padding=0,c=b(""),c.attr({src:g,name:a.id,width:"100%",height:"100%",allowtransparency:"yes",frameborder:"no",scrolling:"no"}).on("load",function(){var b;try{b=c[0].contentWindow.frameElement}catch(d){}b&&(e.width||a.width(c.contents().width()),e.height||a.height(c.contents().height())),h&&h.call(a)}),a.addEventListener("beforeremove",function(){c.attr("src","about:blank").remove()},!1),a.content(c[0]),a.iframeNode=c[0]),!(f instanceof Object))for(var i=function(){a.close().remove()},j=0;jpop box,2=>side tip(parent.next.find; with default pop),3=>side tip(siblings; with default pop),4=>side tip(siblings; none pop),默认为1,也可以传入一个function函数,自定义提示信息的显示方式(可以实现你想要的任何效果,具体参见demo页);
ignoreHidden:false,//可选项 true | false 默认为false,当为true时对:hidden的表单元素将不做验证;
dragonfly:false,//可选项 true | false 默认false,当为true时,值为空时不做验证;
tipSweep:true,//可选项 true | false 默认为false,只在表单提交时触发检测,blur事件将不会触发检测(实时验证会在后台进行,不会显示检测结果);
label:".label",//可选项 选择符,在没有绑定nullmsg时查找要显示的提示文字,默认查找".Validform_label"下的文字;
showAllError:false,//可选项 true | false,true:提交表单时所有错误提示信息都会显示,false:一碰到验证不通过的就停止检测后面的元素,只显示该元素的错误信息;
postonce:true, //可选项 表单是否只能提交一次,true开启,不填则默认关闭;
ajaxPost:true, //使用ajax方式提交表单数据,默认false,提交地址就是action指定地址;
datatype:{//传入自定义datatype类型,可以是正则,也可以是函数(函数内会传入一个参数);
"*6-20": /^[^\s]{6,20}$/,
"z2-4" : /^[\u4E00-\u9FA5\uf900-\ufa2d]{2,4}$/,
"username":function(gets,obj,curform,regxp){
//参数gets是获取到的表单元素值,obj为当前表单元素,curform为当前验证的表单,regxp为内置的一些正则表达式的引用;
var reg1=/^[\w\.]{4,16}$/,
reg2=/^[\u4E00-\u9FA5\uf900-\ufa2d]{2,8}$/;
if(reg1.test(gets)){return true;}
if(reg2.test(gets)){return true;}
return false;
//注意return可以返回true 或 false 或 字符串文字,true表示验证通过,返回字符串表示验证失败,字符串作为错误提示显示,返回false则用errmsg或默认的错误提示;
},
"phone":function(){
// 5.0 版本之后,要实现二选一的验证效果,datatype 的名称 不 需要以 "option_" 开头;
}
},
usePlugin:{
swfupload:{},
datepicker:{},
passwordstrength:{},
jqtransform:{
selector:"select,input"
}
},
beforeCheck:function(curform){
//在表单提交执行验证之前执行的函数,curform参数是当前表单对象。
//这里明确return false的话将不会继续执行验证操作;
},
beforeSubmit:function(curform){
//在验证成功后,表单提交前执行的函数,curform参数是当前表单对象。
//这里明确return false的话表单将不会提交;
},
callback:function(data){
//返回数据data是json格式,{"info":"demo info","status":"y"}
//info: 输出提示信息;
//status: 返回提交数据的状态,是否提交成功。如可以用"y"表示提交成功,"n"表示提交失败,在ajax_post.php文件返回数据里自定字符,主要用在callback函数里根据该值执行相应的回调操作;
//你也可以在ajax_post.php文件返回更多信息在这里获取,进行相应操作;
//ajax遇到服务端错误时也会执行回调,这时的data是{ status:**, statusText:**, readyState:**, responseText:** };
//这里执行回调操作;
//注意:如果不是ajax方式提交表单,传入callback,这时data参数是当前表单对象,回调函数会在表单验证全部通过后执行,然后判断是否提交表单,如果callback里明确return false,则表单不会提交,如果return true或没有return,则会提交表单。
}
});
Validform对象的方法和属性:
tipmsg:自定义提示信息,通过修改Validform对象的这个属性值来让同一个页面的不同表单使用不同的提示文字;
dataType:获取内置的一些正则;
eq(n):获取Validform对象的第n个元素;
ajaxPost(flag,sync,url):以ajax方式提交表单。flag为true时,跳过验证直接提交,sync为true时将以同步的方式进行ajax提交,传入了url地址时,表单会提交到这个地址;
abort():终止ajax的提交;
submitForm(flag,url):以参数里设置的方式提交表单,flag为true时,跳过验证直接提交,传入了url地址时,表单会提交到这个地址;
resetForm():重置表单;
resetStatus():重置表单的提交状态。传入了postonce参数的话,表单成功提交后状态会设置为"posted",重置提交状态可以让表单继续可以提交;
getStatus():获取表单的提交状态,normal:未提交,posting:正在提交,posted:已成功提交过;
setStatus(status):设置表单的提交状态,可以设置normal,posting,posted三种状态,不传参则设置状态为posting,这个状态表单可以验证,但不能提交;
ignore(selector):忽略对所选择对象的验证;
unignore(selector):将ignore方法所忽略验证的对象重新获取验证效果;
addRule(rule):可以通过Validform对象的这个方法来给表单元素绑定验证规则;
check(bool,selector):对指定对象进行验证(默认验证当前整个表单),通过返回true,否则返回false(绑定实时验证的对象,格式符合要求时返回true,而不会等ajax的返回结果),bool为true时则只验证不显示提示信息;
config(setup):可以通过这个方法来修改初始化参数,指定表单的提交地址,给表单ajax和实时验证的ajax里设置参数;
*/
(function($,win,undef){
var errorobj=null,msgobj=null;//pop box object
var tipmsg={//默认提示文字;
tit:"提示信息",
w:{
"*":"不能为空!",
"*6-16":"请填写6到16位任意字符!",
"n":"请填写数字!",
"n6-16":"请填写6到16位数字!",
"s":"不能输入特殊字符!",
"s6-18":"请填写6到18位字符!",
"p":"请填写邮政编码!",
"m":"请填写手机号码!",
"e":"邮箱地址格式不对!",
"url":"请填写网址!",
"money":"请填写正确的金额!"
},
def:"请填写正确信息!",
undef:"datatype未定义!",
reck:"两次输入的内容不一致!",
r:"",
c:"正在检测信息…",
s:"请{填写|选择}{0|信息}!",
v:"所填信息没有经过验证,请稍后…",
// p:"数据正在提交中..."
}
$.Tipmsg=tipmsg;
var Validform=function(forms,settings,inited){
var settings=$.extend({},Validform.defaults,settings);
settings.datatype && $.extend(Validform.util.dataType,settings.datatype);
var brothers=this;
brothers.tipmsg={w:{}};
brothers.forms=forms;
brothers.objects=[];
//创建子对象时不再绑定事件;
if(inited===true){
return false;
}
forms.each(function(){
//已经绑定事件时跳过,避免事件重复绑定;
if(this.validform_inited=="inited"){return true;}
this.validform_inited="inited";
var curform=this;
curform.settings=$.extend({},settings);
var $this=$(curform);
//防止表单按钮双击提交两次;
curform.validform_status="normal"; //normal | posting | posted;
//让每个Validform对象都能自定义tipmsg;
$this.data("tipmsg",brothers.tipmsg);
//bind the blur event;
$this.delegate("[datatype]","blur",function(){
//判断是否是在提交表单操作时触发的验证请求;
var subpost=arguments[1];
Validform.util.check.call(this,$this,subpost);
});
$this.delegate(":text","keypress",function(event){
if(event.keyCode==13 && $this.find(":submit").length==0){
$this.submit();
}
});
//点击表单元素,默认文字消失效果;
//表单元素值比较时的信息提示增强;
//radio、checkbox提示信息增强;
//外调插件初始化;
Validform.util.enhance.call($this,curform.settings.tiptype,curform.settings.usePlugin,curform.settings.tipSweep);
curform.settings.btnSubmit && $this.find(curform.settings.btnSubmit).bind("click",function(){
$this.trigger("submit");
return false;
});
$this.submit(function(){
var subflag=Validform.util.submitForm.call($this,curform.settings);
subflag === undef && (subflag=true);
return subflag;
});
$this.find("[type='reset']").add($this.find(curform.settings.btnReset)).bind("click",function(){
Validform.util.resetForm.call($this);
});
});
}
Validform.defaults={
tiptype:1,
tipSweep:false,
showAllError:false,
postonce:false,
ajaxPost:true,
beforeSubmit:function(curform){
//在验证成功后,表单提交前执行的函数,curform参数是当前表单对象。
//这里明确return false的话表单将不会提交;
try {
if (curform.attr("func") != 'undefined') {
var funcSuffix = 'beforeCallback' + curform.attr("func");
if (typeof(eval(funcSuffix)) == "function") {
callback = eval(funcSuffix + "(curform)");
if (!callback) {
return false;
}
}
}
} catch (e) {}
},
callback: function (curform,data){
try {
if (curform.attr("func") != 'undefined') {
var funcSuffix = 'afterCallback' + curform.attr("func");
if (typeof(eval(funcSuffix)) == "function") {
callback = eval(funcSuffix + "(curform,data)");
if (!callback) {
return false
}
}
}
} catch (e) {}
if(data.status==1){
setTimeout(function(){
location.href = data.url;
},1000);
}
}
}
Validform.util={
dataType:{
"*":/[\w\W]+/,
"*6-16":/^[\w\W]{6,16}$/,
"n":/^\d+$/,
"n6-16":/^\d{6,16}$/,
"s":/^[\u4E00-\u9FA5\uf900-\ufa2d\w\.\s]+$/,
"s6-18":/^[\u4E00-\u9FA5\uf900-\ufa2d\w\.\s]{6,18}$/,
"p":/^[0-9]{6}$/,
"m":/^1[3|4|5|7|8][0-9]{9}$/,
"e":/^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
"url":/^(\w+:\/\/)?\w+(\.\w+)+.*$/,
"money":/^-?[1-9]+(\.\d+)?$|^-?0(\.\d+)?$|^-?[1-9]+[0-9]*(\.\d+)?$/,
"f":/^[0-9]+(.[0-9]{0,9})?$/,
/* 8-30位密码(必须包含数字字母和特殊字符)*/
"pwd":/(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{8,30}$/,
/* 8-30位密码(必须包含数字和字母)*/
"pwd_num_str":/^(?![\d]+$)(?![a-zA-Z]+$)(?![^\da-zA-Z]+$).{8,30}$/,
"fixed":/^(?!.{0})(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$/,
"decimal":function(gets,obj,curform,regxp){//验证小数
return true && (gets.length == 0 || /^[1-9]\d*(\.\d{1,2})?$|^0(\.\d{1,2})?$/.test(gets));
},
"gt":function(gets,obj,curform,regxp){//大于
return true && (!obj.data('gt_than') || gets > obj.data('gt_than'));
},
"egt":function(gets,obj,curform,regxp){//大于等于
return true && (!obj.data('gt_than') || gets >= obj.data('gt_than'));
},
"lt":function(gets,obj,curform,regxp){//小于
return true && (!obj.data('lt_than') || ( gets>0 && gets < obj.data('lt_than')));
},
"elt":function(gets,obj,curform,regxp){//小于等于
return true && (!obj.data('lt_than') || ( gets>0 && gets <= obj.data('lt_than')));
},
"idcard":function(gets,obj,curform,datatype){//验证身份证
var Wi = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1 ];// 加权因子;
var ValideCode = [ 1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2 ];// 身份证验证位值,10代表X;
var _result = false;
switch(gets.length){
case 0:
return true;
case 15:
_result = isValidityBrithBy15IdCard(gets);
break;
case 18:
_result = isValidityBrithBy18IdCard(gets)&&isTrueValidateCodeBy18IdCard(gets.split(""));
break;
default:
;
}
return _result;
function isTrueValidateCodeBy18IdCard(a_idCard) {
var sum = 0; // 声明加权求和变量
if (a_idCard[17].toLowerCase() == 'x') {
a_idCard[17] = 10;// 将最后位为x的验证码替换为10方便后续操作
}
for ( var i = 0; i < 17; i++) {
sum += Wi[i] * a_idCard[i];// 加权求和
}
valCodePosition = sum % 11;// 得到验证码所位置
if (a_idCard[17] == ValideCode[valCodePosition]) {
return true;
}
return false;
}
function isValidityBrithBy18IdCard(idCard18){
var year = idCard18.substring(6,10);
var month = idCard18.substring(10,12);
var day = idCard18.substring(12,14);
var temp_date = new Date(year,parseFloat(month)-1,parseFloat(day));
// 这里用getFullYear()获取年份,避免千年虫问题
if(temp_date.getFullYear()!=parseFloat(year) || temp_date.getMonth()!=parseFloat(month)-1 || temp_date.getDate()!=parseFloat(day)){
return false;
}
return true;
}
function isValidityBrithBy15IdCard(idCard15){
var year = idCard15.substring(6,8);
var month = idCard15.substring(8,10);
var day = idCard15.substring(10,12);
var temp_date = new Date(year,parseFloat(month)-1,parseFloat(day));
// 对于老身份证中的你年龄则不需考虑千年虫问题而使用getYear()方法
if(temp_date.getYear()!=parseFloat(year) || temp_date.getMonth()!=parseFloat(month)-1 || temp_date.getDate()!=parseFloat(day)){
return false;
}
return true;
}
}
},
toString:Object.prototype.toString,
isEmpty:function(val){
return val==="" || val===$.trim(this.attr("tip"));
},
getValue:function(obj){
var inputval,
curform=this;
if(obj.is(":radio")){
inputval=curform.find(":radio[name='"+obj.attr("name")+"']:checked").val();
inputval= inputval===undef ? "" : inputval;
}else if(obj.is(":checkbox")){
inputval="";
curform.find(":checkbox[name='"+obj.attr("name")+"']:checked").each(function(){
inputval +=$(this).val()+',';
})
inputval= inputval===undef ? "" : inputval;
}else{
inputval=obj.val();
}
inputval=$.trim(inputval);
return Validform.util.isEmpty.call(obj,inputval) ? "" : inputval;
},
enhance:function(tiptype,usePlugin,tipSweep,addRule){
var curform=this;
//页面上不存在提示信息的标签时,自动创建;
if(curform.find(".js_validTips").length<=0){
curform.find("[datatype]").each(function(){
if(tiptype==2){
if($(this).parent().parent().next().find(".Validform_checktip").length==0){
$(this).parent().next().append("");
$(this).parent().parent().find(".Validform_checktip").remove();
}
}else if(tiptype==3 || tiptype==4){
if($(this).parent().parent().find(".Validform_checktip").length==0){
$(this).parent().append("");
$(this).parent().parent().next().find(".Validform_checktip").remove();
}
}
})
}
//表单元素值比较时的信息提示增强;
curform.find("input[recheck]").each(function(){
//已经绑定事件时跳过;
if(this.validform_inited=="inited"){return true;}
this.validform_inited="inited";
var _this=$(this);
var recheckinput=curform.find("input[name='"+$(this).attr("recheck")+"']");
recheckinput.bind("keyup",function(){
if(recheckinput.val()==_this.val() && recheckinput.val() != ""){
if(recheckinput.attr("tip")){
if(recheckinput.attr("tip") == recheckinput.val()){return false;}
}
_this.trigger("blur");
}
}).bind("blur",function(){
if(recheckinput.val()!=_this.val() && _this.val()!=""){
if(_this.attr("tip")){
if(_this.attr("tip") == _this.val()){return false;}
}
_this.trigger("blur");
}
});
});
//hasDefaultText;
curform.find("[tip]").each(function(){//tip是表单元素的默认提示信息,这是点击清空效果;
//已经绑定事件时跳过;
if(this.validform_inited=="inited"){return true;}
this.validform_inited="inited";
var defaultvalue=$(this).attr("tip");
var altercss=$(this).attr("altercss");
$(this).focus(function(){
if($(this).val()==defaultvalue){
$(this).val('');
if(altercss){$(this).removeClass(altercss);}
}
}).blur(function(){
if($.trim($(this).val())===''){
$(this).val(defaultvalue);
if(altercss){$(this).addClass(altercss);}
}
});
});
//enhance info feedback for checkbox & radio;
curform.find(":checkbox[datatype],:radio[datatype]").each(function(){
//已经绑定事件时跳过;
if(this.validform_inited=="inited"){return true;}
this.validform_inited="inited";
var _this=$(this);
var name=_this.attr("name");
curform.find("[name='"+name+"']").filter(":checkbox,:radio").bind("click",function(){
//避免多个事件绑定时的取值滞后问题;
setTimeout(function(){
_this.trigger("blur");
},0);
});
});
//select multiple;
curform.find("select[datatype][multiple]").bind("click",function(){
var _this=$(this);
setTimeout(function(){
_this.trigger("blur");
},0);
});
//plugins here to start;
Validform.util.usePlugin.call(curform,usePlugin,tiptype,tipSweep,addRule);
},
usePlugin:function(plugin,tiptype,tipSweep,addRule){
/*
plugin:settings.usePlugin;
tiptype:settings.tiptype;
tipSweep:settings.tipSweep;
addRule:是否在addRule时触发;
*/
var curform=this,
plugin=plugin || {};
//swfupload;
if(curform.find("input[plugin='swfupload']").length && typeof(swfuploadhandler) != "undefined"){
var custom={
custom_settings:{
form:curform,
showmsg:function(msg,type,obj){
Validform.util.showmsg.call(curform,msg,tiptype,{obj:curform.find("input[plugin='swfupload']"),type:type,sweep:tipSweep});
}
}
};
custom=$.extend(true,{},plugin.swfupload,custom);
curform.find("input[plugin='swfupload']").each(function(n){
if(this.validform_inited=="inited"){return true;}
this.validform_inited="inited";
$(this).val("");
swfuploadhandler.init(custom,n);
});
}
//datepicker;
if(curform.find("input[plugin='datepicker']").length && $.fn.datePicker){
plugin.datepicker=plugin.datepicker || {};
if(plugin.datepicker.format){
Date.format=plugin.datepicker.format;
delete plugin.datepicker.format;
}
if(plugin.datepicker.firstDayOfWeek){
Date.firstDayOfWeek=plugin.datepicker.firstDayOfWeek;
delete plugin.datepicker.firstDayOfWeek;
}
curform.find("input[plugin='datepicker']").each(function(n){
if(this.validform_inited=="inited"){return true;}
this.validform_inited="inited";
plugin.datepicker.callback && $(this).bind("dateSelected",function(){
var d=new Date( $.event._dpCache[this._dpId].getSelected()[0] ).asString(Date.format);
plugin.datepicker.callback(d,this);
});
$(this).datePicker(plugin.datepicker);
});
}
//passwordstrength;
if(curform.find("input[plugin*='passwordStrength']").length && $.fn.passwordStrength){
plugin.passwordstrength=plugin.passwordstrength || {};
plugin.passwordstrength.showmsg=function(obj,msg,type){
Validform.util.showmsg.call(curform,msg,tiptype,{obj:obj,type:type,sweep:tipSweep});
};
curform.find("input[plugin='passwordStrength']").each(function(n){
if(this.validform_inited=="inited"){return true;}
this.validform_inited="inited";
$(this).passwordStrength(plugin.passwordstrength);
});
}
//jqtransform;
if(addRule!="addRule" && plugin.jqtransform && $.fn.jqTransSelect){
if(curform[0].jqTransSelected=="true"){return;};
curform[0].jqTransSelected="true";
var jqTransformHideSelect = function(oTarget){
var ulVisible = $('.jqTransformSelectWrapper ul:visible');
ulVisible.each(function(){
var oSelect = $(this).parents(".jqTransformSelectWrapper:first").find("select").get(0);
//do not hide if click on the label object associated to the select
if( !(oTarget && oSelect.oLabel && oSelect.oLabel.get(0) == oTarget.get(0)) ){$(this).hide();}
});
};
/* Check for an external click */
var jqTransformCheckExternalClick = function(event) {
if ($(event.target).parents('.jqTransformSelectWrapper').length === 0) { jqTransformHideSelect($(event.target)); }
};
var jqTransformAddDocumentListener = function (){
$(document).mousedown(jqTransformCheckExternalClick);
};
if(plugin.jqtransform.selector){
curform.find(plugin.jqtransform.selector).filter('input:submit, input:reset, input[type="button"]').jqTransInputButton();
curform.find(plugin.jqtransform.selector).filter('input:text, input:password').jqTransInputText();
curform.find(plugin.jqtransform.selector).filter('input:checkbox').jqTransCheckBox();
curform.find(plugin.jqtransform.selector).filter('input:radio').jqTransRadio();
curform.find(plugin.jqtransform.selector).filter('textarea').jqTransTextarea();
if(curform.find(plugin.jqtransform.selector).filter("select").length > 0 ){
curform.find(plugin.jqtransform.selector).filter("select").jqTransSelect();
jqTransformAddDocumentListener();
}
}else{
curform.jqTransform();
}
curform.find(".jqTransformSelectWrapper").find("li a").click(function(){
$(this).parents(".jqTransformSelectWrapper").find("select").trigger("blur");
});
}
},
getNullmsg:function(curform){
var obj=this;
var reg=/[\u4E00-\u9FA5\uf900-\ufa2da-zA-Z\s]+/g;
var nullmsg;
var label=curform[0].settings.label || ".Validform_label";
label=obj.siblings(label).eq(0).text() || obj.siblings().find(label).eq(0).text() || obj.parent().siblings(label).eq(0).text() || obj.parent().siblings().find(label).eq(0).text();
label=label.replace(/\s(?![a-zA-Z])/g,"").match(reg);
label=label? label.join("") : [""];
reg=/\{(.+)\|(.+)\}/;
nullmsg=curform.data("tipmsg").s || tipmsg.s;
if(label != ""){
nullmsg=nullmsg.replace(/\{0\|(.+)\}/,label);
if(obj.attr("recheck")){
nullmsg=nullmsg.replace(/\{(.+)\}/,"");
obj.attr("nullmsg",nullmsg);
return nullmsg;
}
}else{
nullmsg=obj.is(":checkbox,:radio,select") ? nullmsg.replace(/\{0\|(.+)\}/,"") : nullmsg.replace(/\{0\|(.+)\}/,"$1");
}
nullmsg=obj.is(":checkbox,:radio,select") ? nullmsg.replace(reg,"$2") : nullmsg.replace(reg,"$1");
obj.attr("nullmsg",nullmsg);
return nullmsg;
},
getErrormsg:function(curform,datatype,recheck){
var regxp=/^(.+?)((\d+)-(\d+))?$/,
regxp2=/^(.+?)(\d+)-(\d+)$/,
regxp3=/(.*?)\d+(.+?)\d+(.*)/,
mac=datatype.match(regxp),
temp,str;
//如果是值不一样而报错;
if(recheck=="recheck"){
str=curform.data("tipmsg").reck || tipmsg.reck;
return str;
}
var tipmsg_w_ex=$.extend({},tipmsg.w,curform.data("tipmsg").w);
//如果原来就有,直接显示该项的提示信息;
if(mac[0] in tipmsg_w_ex){
return curform.data("tipmsg").w[mac[0]] || tipmsg.w[mac[0]];
}
//没有的话在提示对象里查找相似;
for(var name in tipmsg_w_ex){
if(name.indexOf(mac[1])!=-1 && regxp2.test(name)){
str=(curform.data("tipmsg").w[name] || tipmsg.w[name]).replace(regxp3,"$1"+mac[3]+"$2"+mac[4]+"$3");
curform.data("tipmsg").w[mac[0]]=str;
return str;
}
}
return curform.data("tipmsg").def || tipmsg.def;
},
_regcheck:function(datatype,gets,obj,curform){
var curform=curform,
info=null,
passed=false,
reg=/\/.+\//g,
regex=/^(.+?)(\d+)-(\d+)$/,
type=3;//default set to wrong type, 2,3,4;
//datatype有三种情况:正则,函数和直接绑定的正则;
//直接是正则;
if(reg.test(datatype)){
var regstr=datatype.match(reg)[0].slice(1,-1);
var param=datatype.replace(reg,"");
var rexp=RegExp(regstr,param);
passed=rexp.test(gets);
//function;
}else if(Validform.util.toString.call(Validform.util.dataType[datatype])=="[object Function]"){
passed=Validform.util.dataType[datatype](gets,obj,curform,Validform.util.dataType);
if(passed === true || passed===undef){
passed = true;
}else{
info= passed;
passed=false;
}
//自定义正则;
}else{
//自动扩展datatype;
if(!(datatype in Validform.util.dataType)){
var mac=datatype.match(regex),
temp;
if(!mac){
passed=false;
info=curform.data("tipmsg").undef||tipmsg.undef;
}else{
for(var name in Validform.util.dataType){
temp=name.match(regex);
if(!temp){continue;}
if(mac[1]===temp[1]){
var str=Validform.util.dataType[name].toString(),
param=str.match(/\/[mgi]*/g)[1].replace("\/",""),
regxp=new RegExp("\\{"+temp[2]+","+temp[3]+"\\}","g");
str=str.replace(/\/[mgi]*/g,"\/").replace(regxp,"{"+mac[2]+","+mac[3]+"}").replace(/^\//,"").replace(/\/$/,"");
Validform.util.dataType[datatype]=new RegExp(str,param);
break;
}
}
}
}
if(Validform.util.toString.call(Validform.util.dataType[datatype])=="[object RegExp]"){
passed=Validform.util.dataType[datatype].test(gets);
}
}
if(passed){
type=2;
info=obj.attr("sucmsg") || curform.data("tipmsg").r||tipmsg.r;
//规则验证通过后,还需要对绑定recheck的对象进行值比较;
if(obj.attr("recheck")){
var theother=curform.find("input[name='"+obj.attr("recheck")+"']:first");
if(gets!=theother.val()){
passed=false;
type=3;
info=obj.attr("errormsg") || Validform.util.getErrormsg.call(obj,curform,datatype,"recheck");
}
}
}else{
info=info || obj.attr("errormsg") || Validform.util.getErrormsg.call(obj,curform,datatype);
//验证不通过且为空时;
if(Validform.util.isEmpty.call(obj,gets)){
info=obj.attr("nullmsg") || Validform.util.getNullmsg.call(obj,curform);
}
}
return{
passed:passed,
type:type,
info:info
};
},
regcheck:function(datatype,gets,obj){
/*
datatype:datatype;
gets:inputvalue;
obj:input object;
*/
var curform=this,
info=null,
passed=false,
type=3;//default set to wrong type, 2,3,4;
//ignore;
if(obj.attr("ignore")==="ignore" && Validform.util.isEmpty.call(obj,gets)){
if(obj.data("cked")){
info="";
}
return {
passed:true,
type:4,
info:info
};
}
obj.data("cked","cked");//do nothing if is the first time validation triggered;
var dtype=Validform.util.parseDatatype(datatype);
var res;
for(var eithor=0; eithor[["/regexp/"],["phone"],["tel","s","e"],["f","e"]];
*/
var reg=/\/.+?\/[mgi]*(?=(,|$|\||\s))|[\w\*-]+/g,
dtype=datatype.match(reg),
sepor=datatype.replace(reg,"").replace(/\s*/g,"").split(""),
arr=[],
m=0;
arr[0]=[];
arr[0].push(dtype[0]);
for(var n=0;n正在检测 | 2=>通过, sweep:true | false},
triggered:在blur或提交表单触发的验证中,有些情况不需要显示提示文字,如自定义弹出提示框的显示方式,不需要每次blur时就马上弹出提示;
tiptype:1\2\3时都有坑能会弹出自定义提示框
tiptype:1时在triggered bycheck时不弹框
tiptype:2\3时在ajax时弹框
tipSweep为true时在triggered bycheck时不触发showmsg,但ajax出错的情况下要提示
*/
//如果msg为undefined,那么就没必要执行后面的操作,ignore有可能会出现这情况;
if(msg==undef){return;}
//tipSweep为true,且当前不是处于错误状态时,blur事件不触发信息显示;
if(triggered=="bycheck" && o.sweep && (o.obj && !o.obj.is(".error") || typeof type == "function")){return;}
$.extend(o,{curform:this});
if(o.obj.is("form")){
var curformObj=o.obj;
}else{
var curformObj=o.obj.parents("form");
}
if(typeof type == "function"){
type(msg,o,Validform.util.cssctl);
return;
}
var curformTips=curformObj.find(".js_validTips");
//tiptypt=1时,blur触发showmsg,验证是否通过都不弹框,提交表单触发的话,只要验证出错,就弹框;
if(type==1 && triggered!="bycheck" && o.type!=2 || triggered=="byajax" && type!=4){
if(curformTips.length<=0){
var status_img='loading.gif';
if(o.type==1){
$(this).find("input[type=submit]").addClass('disable').prop('disabled',true);
}else{
$(this).find("input[type=submit]").removeClass('disable').prop('disabled',false);
}
if(o.type==2){
status_img='icon_success.png';
}else if(o.type==3){
status_img='icon_error.png';
}
var icon='';
if(msgobj==null){
msgobj = dialog({
fixed: true,
content: icon+msg,
lock: true
});
msgobj.showModal();
}else{
msgobj.content(icon+msg).showModal();
setTimeout(function(){
msgobj.close();
},1500);
}
}else{
if(curformTips.length<=0){
var obj=curformObj.parent().parent().next().find(".Validform_checktip");
}else{
var obj=curformObj.find(".js_validTips .js_tipContent");
curformTips.show();
}
obj.html(msg);
Validform.util.cssctl(obj,o.type);
}
}else{
if(type==2 && curformObj){
if(curformTips.length<=0){
var obj=o.obj.parent().parent().next().find(".Validform_checktip");
}else{
var obj=curformObj.find(".js_validTips .js_tipContent");
curformTips.show();
}
obj.html(msg);
if(msg!=""){
Validform.util.cssctl(obj,o.type);
}else{
curformTips.find(".js_tipContent").removeClass("success error wait");
}
}
if((type==3 || type==4) && curformObj){
if(curformTips.length<=0){
var obj=o.obj.parent().parent().find(".Validform_checktip");
}else{
var obj=curformObj.find(".js_validTips .js_tipContent");
curformTips.show();
}
obj.html(msg);
if(msg!=""){
Validform.util.cssctl(obj,o.type);
}else{
curformTips.find(".js_tipContent").removeClass("success error wait");
Validform.util.cssctl(obj,o.type);
}
}
}
},
cssctl:function(obj,status){
switch(status){
case 1:
obj.removeClass("success error").addClass("Validform_checktip wait");//checking;
break;
case 2:
obj.removeClass("error wait").addClass("Validform_checktip success");//passed;
break;
case 4:
obj.removeClass("success error wait").addClass("Validform_checktip");//for ignore;
break;
default:
obj.removeClass("success wait").addClass("Validform_checktip error");//wrong;
}
},
check:function(curform,subpost,bool){
/*
检测单个表单元素;
验证通过返回true,否则返回false、实时验证返回值为ajax;
bool,传入true则只检测不显示提示信息;
*/
var settings=curform[0].settings;
var subpost=subpost || "";
var inputval=Validform.util.getValue.call(curform,$(this));
//隐藏或绑定dataIgnore的表单对象不做验证;
if(settings.ignoreHidden && $(this).is(":hidden") || $(this).data("dataIgnore")==="dataIgnore"){
return true;
}
//dragonfly=true时,没有绑定ignore,值为空不做验证,但验证不通过;
if(settings.dragonfly && !$(this).data("cked") && Validform.util.isEmpty.call($(this),inputval) && $(this).attr("ignore")!="ignore"){
return false;
}
var flag=Validform.util.regcheck.call(curform,$(this).attr("datatype"),inputval,$(this));
//值没变化不做检测,这时要考虑recheck情况;
//不是在提交表单时触发的ajax验证;
if(inputval==this.validform_lastval && !$(this).attr("recheck") && subpost==""){
return flag.passed ? true : false;
}
this.validform_lastval=inputval;//存储当前值;
var _this;
errorobj=_this=$(this);
if(!flag.passed){
//取消正在进行的ajax验证;
Validform.util.abort.call(_this[0]);
if(!bool){
//传入"bycheck",指示当前是check方法里调用的,当tiptype=1时,blur事件不让触发错误信息显示;
Validform.util.showmsg.call(curform,flag.info,settings.tiptype,{obj:$(this),type:flag.type,sweep:settings.tipSweep},"bycheck");
!settings.tipSweep && _this.addClass("error");
}
return false;
}
//验证通过的话,如果绑定有ajaxurl,要执行ajax检测;
//当ignore="ignore"时,为空值可以通过验证,这时不需要ajax检测;
var ajaxurl=$(this).attr("ajaxurl");
if(ajaxurl && !Validform.util.isEmpty.call($(this),inputval) && !bool){
var inputobj=$(this);
//当提交表单时,表单中的某项已经在执行ajax检测,这时需要让该项ajax结束后继续提交表单;
if(subpost=="postform"){
inputobj[0].validform_subpost="postform";
}else{
inputobj[0].validform_subpost="";
}
if(inputobj[0].validform_valid==="posting" && inputval==inputobj[0].validform_ckvalue){return "ajax";}
inputobj[0].validform_valid="posting";
inputobj[0].validform_ckvalue=inputval;
Validform.util.showmsg.call(curform,curform.data("tipmsg").c||tipmsg.c,settings.tiptype,{obj:inputobj,type:1,sweep:settings.tipSweep},"bycheck");
Validform.util.abort.call(_this[0]);
var ajaxsetup=$.extend(true,{},settings.ajaxurl || {});
var localconfig={
type: "POST",
cache:false,
url: ajaxurl,
data: "param="+encodeURIComponent(inputval)+"&name="+encodeURIComponent($(this).attr("name")),
success: function(data){
if(data.status==1){
inputobj[0].validform_valid="true";
data.info && inputobj.attr("sucmsg",data.info);
Validform.util.showmsg.call(curform,inputobj.attr("sucmsg") || curform.data("tipmsg").r||tipmsg.r,settings.tiptype,{obj:inputobj,type:2,sweep:settings.tipSweep},"bycheck");
_this.removeClass("error");
errorobj=null;
if(inputobj[0].validform_subpost=="postform"){
curform.trigger("submit");
}
}else{
inputobj[0].validform_valid=data.info;
Validform.util.showmsg.call(curform,data.info,settings.tiptype,{obj:inputobj,type:3,sweep:settings.tipSweep});
_this.addClass("error");
}
_this[0].validform_ajax=null;
},
error: function(data){
if(data.status=="200"){
if(data.responseText=="y"){
ajaxsetup.success({"status":"y"});
}else{
ajaxsetup.success({"status":"n","info":data.responseText});
}
return false;
}
//正在检测时,要检测的数据发生改变,这时要终止当前的ajax。不是这种情况引起的ajax错误,那么显示相关错误信息;
if(data.statusText!=="abort"){
var msg="status: "+data.status+"; statusText: "+data.statusText;
Validform.util.showmsg.call(curform,msg,settings.tiptype,{obj:inputobj,type:3,sweep:settings.tipSweep});
_this.addClass("error");
}
inputobj[0].validform_valid=data.statusText;
_this[0].validform_ajax=null;
//localconfig.error返回true表示还需要执行temp_err;
return true;
}
}
if(ajaxsetup.success){
var temp_suc=ajaxsetup.success;
ajaxsetup.success=function(data){
localconfig.success(data);
temp_suc(data,inputobj);
}
}
if(ajaxsetup.error){
var temp_err=ajaxsetup.error;
ajaxsetup.error=function(data){
//localconfig.error返回false表示不需要执行temp_err;
localconfig.error(data) && temp_err(data,inputobj);
}
}
ajaxsetup=$.extend({},localconfig,ajaxsetup,{dataType:"json"});
_this[0].validform_ajax=$.ajax(ajaxsetup);
return "ajax";
}else if(ajaxurl && Validform.util.isEmpty.call($(this),inputval)){
Validform.util.abort.call(_this[0]);
_this[0].validform_valid="true";
}
if(!bool){
Validform.util.showmsg.call(curform,flag.info,settings.tiptype,{obj:$(this),type:flag.type,sweep:settings.tipSweep},"bycheck");
_this.removeClass("error");
}
errorobj=null;
return true;
},
submitForm:function(settings,flg,url,ajaxPost,sync){
/*
flg===true时跳过验证直接提交;
ajaxPost==="ajaxPost"指示当前表单以ajax方式提交;
*/
var curform=this;
//表单正在提交时点击提交按钮不做反应;
if(curform[0].validform_status==="posting"){return false;}
//要求只能提交一次时;
if(settings.postonce && curform[0].validform_status==="posted"){return false;}
var beforeCheck=settings.beforeCheck && settings.beforeCheck(curform);
if(beforeCheck===false){return false;}
var flag=true,
inflag;
curform.find("[datatype]").each(function(){
//跳过验证;
if(flg){
return false;
}
//隐藏或绑定dataIgnore的表单对象不做验证;
if(settings.ignoreHidden && $(this).is(":hidden") || $(this).data("dataIgnore")==="dataIgnore"){
return true;
}
var inputval=Validform.util.getValue.call(curform,$(this)),
_this;
errorobj=_this=$(this);
inflag=Validform.util.regcheck.call(curform,$(this).attr("datatype"),inputval,$(this));
if(!inflag.passed){
Validform.util.showmsg.call(curform,inflag.info,settings.tiptype,{obj:$(this),type:inflag.type,sweep:settings.tipSweep});
_this.addClass("error");
if(!settings.showAllError){
_this.focus();
flag=false;
return false;
}
flag && (flag=false);
return true;
}
//当ignore="ignore"时,为空值可以通过验证,这时不需要ajax检测;
if($(this).attr("ajaxurl") && !Validform.util.isEmpty.call($(this),inputval)){
if(this.validform_valid!=="true"){
var thisobj=$(this);
Validform.util.showmsg.call(curform,curform.data("tipmsg").v||tipmsg.v,settings.tiptype,{obj:thisobj,type:3,sweep:settings.tipSweep});
_this.addClass("error");
thisobj.trigger("blur",["postform"]);//continue the form post;
if(!settings.showAllError){
flag=false;
return false;
}
flag && (flag=false);
return true;
}
}else if($(this).attr("ajaxurl") && Validform.util.isEmpty.call($(this),inputval)){
Validform.util.abort.call(this);
this.validform_valid="true";
}
Validform.util.showmsg.call(curform,inflag.info,settings.tiptype,{obj:$(this),type:inflag.type,sweep:settings.tipSweep});
_this.removeClass("error");
errorobj=null;
});
if(settings.showAllError){
curform.find(".error:first").focus();
}
if(flag){
var beforeSubmit=settings.beforeSubmit && settings.beforeSubmit(curform);
if(beforeSubmit===false){return false;}
curform[0].validform_status="posting";
if(settings.ajaxPost || ajaxPost==="ajaxPost"){
//获取配置参数;
var ajaxsetup=$.extend(true,{},settings.ajaxpost || {});
//有可能需要动态的改变提交地址,所以把action所指定的url层级设为最低;
ajaxsetup.url=url || ajaxsetup.url || settings.url || curform.attr("action");
//byajax:ajax时,tiptye为1、2或3需要弹出提示框;
Validform.util.showmsg.call(curform,curform.data("tipmsg").p||tipmsg.p,settings.tiptype,{obj:curform,type:1,sweep:settings.tipSweep},"byajax");
//方法里的优先级要高;
//有undefined情况;
if(sync){
ajaxsetup.async=false;
}else if(sync===false){
ajaxsetup.async=true;
}
if(ajaxsetup.success){
var temp_suc=ajaxsetup.success;
ajaxsetup.success=function(data){
settings.callback && settings.callback(curform,data);
curform[0].validform_ajax=null;
if(data.status==1){
curform[0].validform_status="posted";
}else{
curform[0].validform_status="normal";
}
temp_suc(data,curform);
}
}
if(ajaxsetup.error){
var temp_err=ajaxsetup.error;
ajaxsetup.error=function(data){
settings.callback && settings.callback(curform,data);
curform[0].validform_status="normal";
curform[0].validform_ajax=null;
temp_err(data,curform);
}
}
var localconfig={
type: "POST",
async:true,
data: curform.serializeArray(),
success: function(data){
if(data.status==1){
//成功提交;
curform[0].validform_status="posted";
Validform.util.showmsg.call(curform,data.info,settings.tiptype,{obj:curform,type:2,sweep:settings.tipSweep},"byajax");
}else{
//提交出错;
curform[0].validform_status="normal";
Validform.util.showmsg.call(curform,data.info,settings.tiptype,{obj:curform,type:3,sweep:settings.tipSweep},"byajax");
}
settings.callback && settings.callback(curform,data);
curform[0].validform_ajax=null;
},
error: function(data){
var msg="status: "+data.status+"; statusText: "+data.statusText;
Validform.util.showmsg.call(curform,msg,settings.tiptype,{obj:curform,type:3,sweep:settings.tipSweep},"byajax");
settings.callback && settings.callback(curform,data);
curform[0].validform_status="normal";
curform[0].validform_ajax=null;
}
}
ajaxsetup=$.extend({},localconfig,ajaxsetup,{dataType:"json"});
curform[0].validform_ajax=$.ajax(ajaxsetup);
}else{
if(!settings.postonce){
curform[0].validform_status="normal";
}
var url=url || settings.url;
if(url){
curform.attr("action",url);
}
return settings.callback && settings.callback(curform);
}
}
return false;
},
resetForm:function(){
var brothers=this;
brothers.each(function(){
this.reset && this.reset();
this.validform_status="normal";
});
brothers.parent().find(".success").text("");
brothers.parent().find(".passwordStrength").children().removeClass("bgStrength");
brothers.parent().find(".Validform_checktip").removeClass("error success wait");
brothers.parent().find(".error").removeClass("error");
brothers.parent().find("[datatype]").removeData("cked").removeData("dataIgnore").each(function(){
this.validform_lastval=null;
});
brothers.parent().eq(0).find("input:first").focus();
},
abort:function(){
if(this.validform_ajax){
this.validform_ajax.abort();
}
}
}
$.Datatype=Validform.util.dataType;
Validform.prototype={
dataType:Validform.util.dataType,
eq:function(n){
var obj=this;
if(n>=obj.forms.length){
return null;
}
if(!(n in obj.objects)){
obj.objects[n]=new Validform($(obj.forms[n]).get(),{},true);
}
return obj.objects[n];
},
resetStatus:function(){
var obj=this;
$(obj.forms).each(function(){
this.validform_status="normal";
});
return this;
},
setStatus:function(status){
var obj=this;
$(obj.forms).each(function(){
this.validform_status=status || "posting";
});
return this;
},
getStatus:function(){
var obj=this;
var status=$(obj.forms)[0].validform_status;
return status;
},
ignore:function(selector){
var obj=this;
var selector=selector || "[datatype]"
$(obj.forms).find(selector).each(function(){
$(this).data("dataIgnore","dataIgnore").removeClass("error");
});
return this;
},
unignore:function(selector){
var obj=this;
var selector=selector || "[datatype]"
$(obj.forms).find(selector).each(function(){
$(this).removeData("dataIgnore");
});
return this;
},
addRule:function(rule){
/*
rule => [{
ele:"#id",
datatype:"*",
errormsg:"出错提示文字!",
nullmsg:"为空时的提示文字!",
tip:"默认显示的提示文字",
altercss:"gray",
ignore:"ignore",
ajaxurl:"valid.php",
recheck:"password",
plugin:"passwordStrength"
},{},{},...]
*/
var obj=this;
var rule=rule || [];
for(var index=0; index'+msg+'',
ok:function(){
ajax_get(_this,target);
},
cancel:function(){
d.close().remove();
return false;
},
lock:true
});
d.showModal();
}else{
ajax_get(_this,target);
}
return false;
});
$(document).on("click",".ajax-post",function(){
var target,query,form;
var target_form = $(this).attr('target-form');
var _this = $(this);
var nead_confirm=false;
var text = $(this).html() || $(this).val();
var ico="ask";
if(_this.attr("font_ico")){
var ico=_this.attr("font_ico");
}
if( (_this.attr('type')=='submit') || (target = _this.attr('href')) || (target = _this.attr('url')) ){
form = $('.'+target_form);
if($(this).attr('time')){
var time=$(this).attr('time');
}else{
var time=2000;
}
if ( form.get(0).nodeName=='FORM' ){
if ( $(this).hasClass('confirm') ) {
if($(this).attr('tips')){
var msg=$(this).attr('tips');
}else{
var msg='确认要执行该操作吗?';
}
var d=dialog({
fixed: true,
title:"系统提示",
content:''+msg+'
',
ok:function(){
if(_this.attr('url') !== undefined){
target = _this.attr('url');
}else{
target = form.get(0).action;
}
var query=form.serialize();
ajax_post(_this,target,query);
},
cancel:function(){
d.close().remove();
return false;
},
lock:true
});
d.showModal();
}else{
if(_this.attr('url') !== undefined){
target = _this.attr('url');
}else{
target = form.get(0).action;
}
var query=form.serialize();
ajax_post(_this,target,query);
}
}else if( form.get(0).nodeName=='INPUT' || form.get(0).nodeName=='SELECT'){
form.each(function(k,v){
if(v.type=='checkbox' && v.checked==true){
nead_confirm = true;
}
})
if ( nead_confirm && $(this).hasClass('confirm') ) {
if($(this).attr('tips')){
var msg=$(this).attr('tips');
}else{
var msg='确认要执行该操作吗?';
}
var d=dialog({
fixed: true,
title:"系统提示",
content:''+msg+'
',
ok:function(){
query = form.serialize();
ajax_post(_this,target,query);
},
cancel:function(){
d.close().remove();
return false;
},
lock:true
});
d.showModal();
}else{
query = form.serialize();
ajax_post(_this,target,query);
}
}else if (form.get(0)==undefined){
return false;
}
}
return false;
});
//弹窗
$(document).on("click",".dialog",function(event){
var c_this=$(this);
event.preventDefault();
var padding=40;
var _id = c_this.attr('data-id');
if(c_this.attr('padding')){
padding=c_this.attr('padding');
}
var myDialog = dialog({
title:c_this.attr('title'),
padding:padding,
id:_id,
lock:true
});
myDialog.showModal();
$.ajax({
url:$(this).attr('href'),
success: function(data) {
myDialog.content(data);// 填充对话框内容
/*
ajax提交表单(带表单验证功能)
康利民 2016/05/20
*/
$('.js_form').each(function(){
$(this).super_validform({"set":{tiptype:4,ajaxPost:true}});
});
/* validform封装 -E */
}
});
})
// 开关切换
$(document).on('click', '.switch_input', function(event) {
event.preventDefault();
var _el = $(this).find('ul')
if(_el.hasClass('active')){
_el.removeClass('active');
_el.find('.switch_val').val(0)
}else{
_el.addClass('active');
_el.find('.switch_val').val(1)
}
});
$(".js_check_all").on("click",function(){
var _child=$(this).attr("data-target");
$("input[data-child="+_child+"]").prop("checked",this.checked);
if(this.checked){
$(this).parent().addClass('checked');
$("input[data-child="+_child+"]").parent().parent().addClass("checked");
}else{
$("input[data-child="+_child+"]").parent().parent().removeClass("checked");
$(this).parent().removeClass('checked');
}
})
$("input[type=checkbox]").on("click",function(){
var _childAttr=$(this).attr("data-child");
var _child=$("input[data-child="+_childAttr+"]").length;
var _child_checked=$("input[data-child="+_childAttr+"]:checked").length;
if(_child==_child_checked){
$("input[data-target="+_childAttr+"]").prop("checked",this.checked);
}else{
$("input[data-target="+_childAttr+"]").prop("checked",false);
}
if(this.checked){
$(this).parent().parent().addClass("checked");
}else{
$(this).parent().parent().removeClass("checked");
}
})
/* 设置选中行背景颜色 -S */
$(".js_table tr td").on("click",function(){
if($(this).find("a").length<=0 && $(this).find(".ids").length<=0){
var child=$(this).parent();
if(child.parent().parent().find(".ids").length>0){
if(child.find(".ids").prop("checked")){
child.find(".ids").prop("checked",false);
child.removeClass("checked");
}else{
child.find(".ids").prop("checked",true);
child.addClass("checked");
}
var _childAttr=child.find(".ids").attr("data-child");
var _child=$("input[data-child="+_childAttr+"]").length;
var _child_checked=$("input[data-child="+_childAttr+"]:checked").length;
if(_child==_child_checked){
$("input[data-target="+_childAttr+"]").prop("checked",true);
}else{
$("input[data-target="+_childAttr+"]").prop("checked",false);
}
}else{
child.parent().parent().find(".checked").removeClass('checked');
child.addClass('checked');
}
}
})
/* 设置选中行背景颜色 -E */
/* 获取所有选中行,并设置选中背景颜色 -S */
$(".js_table tr").each(function(){
if($(this).find(".ids").prop("checked")){
$(this).addClass("checked");
}else{
$(this).removeClass("checked");
}
})
/* 获取所有选中行,并设置选中背景颜色 -E */
//头部搜索
$('.search_top').on('click','li',function(){
$(this).addClass("active");
$(this).siblings().removeClass('active');
var key = $(this).attr('keyword-type');
$('.'+key).css({'display':'block'});
$('.'+key).siblings().css({'display':'none'});
var urlStr = $(this).attr('data-url');
$('.search_box').find('form').attr('action',urlStr);
});
$('.js_menuList>li').each(function(){
var $obj = $(this).find('.drop_down');
$obj.find('dl:last>dd').css({'border-bottom':'none'});
$obj = null;
});
$('.bus_list>ul').on('mouseover','li:last',function(){
$(this).css({'border-color':'#fff'});
});
$('.drop_down>dl:last>dd').css({'border-bottom':'none'});
$('.js_menuList').on('mouseover','li',function(){
$(this).find('.drop_down').css({'display':'block'});
$(this).siblings().find('.drop_down').css({'display':'none'});
});
$('.js_menuList').on('mouseleave','li',function(){
$(this).find('.drop_down').css({'display':'none'});
});
//切页判断
$('.pages').on('keyup','.js_check',function(){
var val = $(this).val(),count = Number($('.js_count').text());
$(this).val(val.replace(/[^\d]/g,''));
var $obj = $('.js_user');
val = Number($(this).val());
if(val < 1 || val > count){
$obj.attr('disabled','disabled').removeAttr('type').css({'cursor':'default'});
}else{
$obj.removeAttr('disabled').attr('type','submit').css({'cursor':'pointer'});
}
$obj = null;
});
$(document).on('click','.js_cut li',function(){
var _winW = $(window).width();
var _this = $(this);
var _index = $('.js_cut li').index(this);
switch(_index){
case 0:
_this.addClass('active').siblings().removeClass('active');
$('.js_m_active').hide();
$('.mobile_classify,.tab_cover').css({display: 'block'});
$('.mobile_classify').children('.tab_menu').stop().animate({
'left' : 0,
'width': _winW-40
},100);
$('.mobile_classify').children('.tab_cover').click(function(){
$('.tab_menu').stop().animate({
'left': -1000,
},150,function(){
$('.tab_cover').fadeOut('1000');
});
});
//菜单点击事件
$('.js_title li').click(function(){
var _thisT = $('.js_title li');
var _indexT = _thisT.index(this);
$(this).addClass('active').siblings().removeClass('active');
$(this).parents('.js_title').siblings('.js_body').find('li').eq(_indexT).show().siblings().hide();
});
break;
case 1:
_this.addClass('active').siblings().removeClass('active');
_this.children('.js_m_active').fadeToggle();
_this.find('.js_m_active li').click(function(){
$(this).addClass('active').siblings().removeClass('active');
});
break;
}
});
//PC端菜单效果
$(".js_navLen li").hover(function(){
var subTop=($(".js_navLen li").index(this)*($(this).height()+1));
var boxWidth=$(this).parent().width();
var boxHeiht=$(".menu_dd").height();
if($(".dorpdown_layer",this).length>0){
$(this).addClass("hover");
}
if($(".dorpdown_layer",this).height()+40>=boxHeiht){
$(".dorpdown_layer",this).css({'top':'0px'}).show();
}else if((subTop+$(".dorpdown_layer",this).height()+40)>boxHeiht){
$(".dorpdown_layer",this).css({'top':"auto",'bottom':"0px"}).show();
}else{
var topVal=subTop-($(".dorpdown_layer",this).height()+40-$(this).height())/2;
if(topVal>0){
$(".dorpdown_layer",this).css({'top':topVal+'px'}).show();
}else{
$(".dorpdown_layer",this).css({'top':'0px'}).show();
}
}
$(".dorpdown_layer",this).css({'left':boxWidth}).show();
},function(){
$(".dorpdown_layer",this).hide();
$(this).removeClass("hover");
})
/*
ajax提交表单(带表单验证功能)
康利民 2016/05/20
*/
$('.js_form').each(function(){
$(this).super_validform({"set":{tiptype:3}});
});
/* validform封装 -E */
$(".js_selected_box").on("click",function(){
var _this=$(this);
if(_this.next().is(":hidden")){
_this.next().fadeIn(50);
_this.next().find("li").on("click",function(){
var val=$(this).attr("data-option");
var text=$(this).text();
_this.html(text+'');
_this.prev().val(val);
_this.next().fadeOut(50);
})
}else{
_this.next().fadeOut(50);
}
})
$(".js_select_box").on("mouseleave",function(){
$(".js_select_list",this).fadeOut(50);
})
if($(".wdate").length>0){
$("head").append('');
}
//删除已经添加到数据库的图片
$(document).on("click",".js_delThis",function(){
var delObj=$(this);
var image_id=delObj.attr('index');
var table=delObj.attr('data-table');
var multi=delObj.attr('data-status');
if(confirm("确定删除吗?")){
var url=_CONTROLLER_+'/ajaxDelete_'+table;
var data_id=$(this).attr('index');
$.post(url,{'id':data_id},function(data){
if(data.status==1){
delObj.parent().remove();
tips(data.info,1000,'success');
}else{
tips(data.info,1500,'danger');
}
},'json');
}
})
//删除临时上传的图片,也就是上传后还没有点击发布的图片
$(document).on("click",".js_delCache",function(){
var delObj=$(this);
var table=delObj.attr('data-table');
var multi=delObj.attr('data-status');
if(confirm("确定删除吗?")){
if(multi!=true){
$('.file_btn',delObj.parents(".upload_img_box")).val("");
}
var temp_id=$(this).attr('index');
$.post(_CONTROLLER_+"/delTempFile",{id:temp_id},function(data){
if(data.status==1){
delObj.parent().remove();
tips(data.info,1000,'success');
}else{
tips(data.info,1500,'danger');
}
})
}
})
});
function ajax_get(obj, target) {
if (obj.attr('time')) {
var time = obj.attr('time')
} else {
var time = 2000
} if ((target = obj.attr('href')) || (target = obj.attr('url'))) {
$.get(target).success(function(data) {
var callback = false;
try {
if (obj.attr("func") != 'undefined') {
var funcSuffix = 'ajaxGetCallback' + obj.attr("func");
if (typeof(eval(funcSuffix)) == "function") {
callback = eval(funcSuffix + "(obj,data.status,data.info)");
if (!callback) {
return false
}
}
}
} catch (e) {}
if (data.status == 1) {
if (data.url) {
location.href = data.url
} else {
location.reload()
}
} else {
tips(data.info, 2000, "danger");
setTimeout(function() {
obj.addClass('disable').attr('autocomplete', 'off').prop('disabled', false)
}, time)
}
})
}
}
function ajax_post(obj, target, query) {
if (obj.attr('time')) {
var time = obj.attr('time')
} else {
var time = 2000
}
obj.addClass('disable').attr('autocomplete', 'off').prop('disabled', true);
$.post(target, query).success(function(data) {
var callback = false;
try {
if (obj.attr("func") != 'undefined') {
var funcSuffix = 'ajaxPostCallback' + obj.attr("func");
if (typeof(eval(funcSuffix)) == "function") {
callback = eval(funcSuffix + "(obj,data.status,data.info)");
if (!callback) {
return false;
}
}
}
} catch (e) {}
if (data.status == 1) {
if (data.url) {
location.href = data.url
} else {
location.reload()
}
} else {
tips(data.info, 2000, "danger");
setTimeout(function() {
obj.removeClass('disable').attr('autocomplete', 'off').prop('disabled', false)
}, time)
}
})
}
/**
* js提示弹窗
* 参数解释
* info : 提示内容
* time : 显示时间,单位为毫秒,1000毫秒为1秒
* status : 显示状态(success,danger,warning,ask,info
*
* @author MyMelody <1753290024@qq.com>
*/
function tips(info, time, status) {
var icon=''+info+'
';
if($(document).find(".js_tips_box").size()<=0){
$("body").append(icon);
}
var tips_width=$(".js_tips_box").width();
var tips_height=$(".js_tips_box").height();
var tips_obj=$(document).find(".js_tips_box");
var tips_top=$(document).height()/2-tips_height/2;
var tips_init_top=tips_top/2+(tips_top/2)/2;
tips_obj.css({"left":$(document).width()/2-tips_width/2,"top":tips_init_top,}).animate({"top":tips_top,"opacity":1},500);
setTimeout(function() {
tips_obj.animate({"top":tips_top/2+(tips_top/2)/2,"opacity":0},100,function(){
tips_obj.remove();
});
}, time)
}
/*
* 将字符串根据指定字符分隔成为数组,使用方法和php的explode一样
* 参数解释:
* separator:指定用什么字符来分割
* string: 指定分割什么字符串
* 示例:
* var str="www.cnsunrun.com";
* var str_arr=explode('.',str);
* console.log(str_arr);
* 在调试工具的console里会看到输出的数组:["www", "cnsunrun", "com"]
*
* @author MyMelody <3027788306@@qq.com>
*/
function explode(separator, string) {
string = new String(string);
separator = new String(separator);
if (separator == "undefined") {
separator = " :;"
}
fixedExplode = new Array(1);
currentElement = "";
count = 0;
for (x = 0; x < string.length; x++) {
str = string.charAt(x);
if (separator.indexOf(str) != -1) {
fixedExplode[count] = currentElement;
count++;
currentElement = ""
} else {
currentElement += str
}
}
fixedExplode[count] = currentElement;
return fixedExplode
}
//数组合并
function array_merge(des, src, override) {
if (src instanceof Array) {
for (var i = 0, len = src.length; i < len; i++) array_merge(des, src[i], override)
}
for (var i in src) {
if (override || !(i in des)) {
des[i] = src[i]
}
}
return des
}
/*
* 常用于传入一个完整的文件路径,返回文件名与后缀
*/
function basename(str) {
var str2 = "/";
var s = str.lastIndexOf(str2);
if (s == -1) {
str2 = "\\";
var s = str.lastIndexOf(str2)
}
if (s == -1) {
alert("字符串非法")
} else {
return (str.substring(s + 1, str.length))
}
return ""
}
/**
* number_format
*
* @param int or float number
* @param int decimals
* @param string dec_point
* @param string thousands_sep
* @return string
* example 1: number_format(1234.56);
returns 1: '1,235'
* example 2: number_format(1234.56, 2, ',', ' ');
returns 2: '1 234,56'
* example 3: number_format(1234.5678, 2, '.', '');
returns 3: '1234.57'
* example 4: number_format(67, 2, ',', '.');
returns 4: '67,00'
* example 5: number_format(1000);
returns 5: '1,000'
* example 6: number_format(67.311, 2);
returns 6: '67.31'
* example 7: number_format(1000.55, 1);
returns 7: '1,000.6'
* example 8: number_format(67000, 5, ',', '.');
returns 8: '67.000,00000'
* example 9: number_format(0.9, 0);
returns 9: '1'
* example 10: number_format('1.20', 2);
returns 10: '1.20'
* example 11: number_format('1.20', 4);
returns 11: '1.2000'
* example 12: number_format('1.2000', 3);
returns 12: '1.200'
*/
function number_format(number, decimals, dec_point, thousands_sep) {
var n = !isFinite(+number) ? 0 : +number,
prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
s = '',
toFixedFix = function(n, prec) {
var k = Math.pow(10, prec);
return '' + Math.round(n * k) / k
};
s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
if (s[0].length > 3) {
s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep)
}
if ((s[1] || '').length < prec) {
s[1] = s[1] || '';
s[1] += new Array(prec - s[1].length + 1).join('0')
}
return s.join(dec)
}