forked from jquery/jquery-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuihelper.js
More file actions
127 lines (126 loc) · 3.11 KB
/
uihelper.js
File metadata and controls
127 lines (126 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/**
* helper function接受的第一个参数严格为ui
*
* @author 13
*/
(function($,root){
var yawrap=root.yawrap,
sl=yawrap.sl,
regx=yawrap.regx,
uihelper=yawrap.uihelper||{},
Solution=sl.Solution;
//浏览器特征检测
(function(){
/*Modernizr.testStyles(' #modernizr { position: fixed; } ', function(elem, rule){
Modernizr.addTest('posfixed', $(elem).css('position') == 'fixed');
});*/
}());
_.extend(uihelper,{
vtypes:{
"trim":"trim",
"email":regx.email,
"mobile":regx.mobile,
"user":regx.user,
"pwd":regx.pwd,
/**
* @param {Object} opts 额外配置
*/
"confirmpwd":function(v,opts){
var pwdJq=$(opts.pwdSelector,this.element),
pwdValue=$.trim(pwdJq.val());
if(v==pwdValue){
return true;
}else{
return false;
}
}
},
/**
* 添加圆角
* @param {Object} ui
* @param {Jq} boxJq 需要圆角效果的box
* @return
*/
"addCornerH":function(ui,boxJq){
boxJq.addClass('sl-npx-round-corner');
},
"addPieH":function(ui,effectNames,boxJq){
var effectJq=boxJq.children('.ui-pie-effect'),
effectArr=effectNames.split(/\s/);
effectArr=_.map(effectArr,function(effectName){
return 'ui-pie-'+effectName;
});
if(effectJq.length===0){
boxJq.wrapInner('<div class="ui-pie-effect '+effectArr.join(' ')+'"></div>');
effectJq=boxJq.children('.ui-pie-effect');
if(window.PIE){
PIE.attach(effectJq.get(0));
}
boxJq.addClass('ui-widget-pie');
}
},
advancedThemeH:function(ui,effectNames,boxJq){
var effectArr=effectNames.split(/\s/);
_.each(effectArr,function(v){
new Solution(v,{
hostSelector:boxJq,
//slClsName:'ui-widget-shadow'
slClsName:""
}).doSolution();
});
},
removeOutline:function(ui,boxJq){
if($.browser.msie){ //ie
$('a,button,input[type="button"],input[type="submit"]',boxJq).attr('hidefocus',true);
}
},
/**
* 添加和获取vtype
*/
vtype:function(ui,vtypeName,opts){
var vtypes=uihelper.vtypes,
vtype=vtypes[vtypeName],
validateFn,
elJq=opts.element, //待验证的dom
errorMsg=opts.errorMsg[opts.vtypeIndex]||'error'; //验证失败提示信息
if(!!vtype){
if(_.isFunction(vtype)){
validateFn=function(v){
return vtype.apply(this,arguments);
};
}else if(_.isRegExp(vtype)){
validateFn=function(v){
return vtype.test(v);
};
}else if(_.isString(vtype)){
if(vtype=="trim"){
validateFn=function(v){
if(v.length>0){
return true;
}else{
return false;
}
};
}
}
return function(v){
var validV,
validMsgJq=elJq.data('validmsg');
v=$.trim(v); //v trim过滤
if(!validMsgJq){
validMsgJq=$('<div class="ui-form-field-message"></div>').insertAfter(elJq);
elJq.data('validmsg',validMsgJq);
}
validMsgJq.removeClass('ui-state-error').empty();
validV=validateFn.apply(ui,[v,opts]);
if(!validV&&errorMsg){
validMsgJq.addClass('ui-state-error').html(errorMsg);
}
return validV;
};
}
return false;
}
});
yawrap.uihelper=uihelper;
}(jQuery,this));