common_1.2.js
3.39 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
128
129
130
131
132
133
134
135
136
137
/**
* @desc website公用JavaScript
* Website.Util and jquery扩展
* @author jiangchengyong
*/
(function(){
window.NAMESPACE = function(str){
var arr = str.split('.'),o = this;
for (var i = (arr[0] == 'GLOBAL')? 1 : 0; i < arr.length; i++) {
o[arr[i]] = o[arr[i]] || {};
o = o[arr[i]];
}
}
//公用系统域名
window.DiliPath = {
homePath : "http://www.nong12.com/",
userPath : "http://user.nong12.com/",
staticPath : "http://static.nong12.com/",
shopPath : "http://shop.nong12.com/",
loginPath : "https://passport.nong12.com/uc/login.aspx",
registPath : "https://passport.nong12.com/regedit/regedit.aspx",
loadingImgPath : "http://static.nong12.com/static/common/images/gg/loading.gif",
payPath:"http://pay.nong12.com/pay/payment/index.do",
packageProductPath : function(productId) {
return DiliPath.homePath + "product/" + productId + ".html";
}
};
window.Money = {
centToYuan : function(cent) {
cent = parseInt(cent);
if (cent <= 0) {
return "0.00";
}
yuan = (cent / 100).toFixed(2);
var result = yuan.toString();
if(result.indexOf(".") <= 0) {
result = result + ".00";
}
return result;
}
};
window.Website = {};
Website.Util = {
/**
* @param fn
* @returns
* @author jiangchengyong
*/
checkLogin : function(fn){
var flag = false;
jQuery.ajax({
type : "POST",
url : DiliPath.homePath + "common/checkLogin.html",
dataType : "json",
success : function(data) {
if(fn && typeof(fn) == 'function'){
fn(data);
}
if(data.code == "000"){
flag = true;
}
}
});
return flag;
},
/**
* 控制文本框只能输入数字
* @param e
*/
controlInput : function(e){
var evt = e || window.event;
var keyCode = evt.keyCode ? evt.keyCode : (evt.which ? evt.which :evt.charCode);
if(arguments.length>1){
for (var i = 1; i < arguments.length; i++) {
if(keyCode == arguments[i]){
return true;
}
}
}
if(keyCode != 9 && keyCode != 8 && keyCode != 127 && (keyCode<48 || keyCode>57)) {
if(window.event){
evt.returnValue=false;
}else{
e.preventDefault();
}
}
},
/**
* 校验输入的数字是否合法
* @param obj
*/
validateNum : function(obj,isDecimal){
var reg=isDecimal?/^[0-9]+([.]{1}[0-9]{1,2})?$/ : /^[0-9]+$/;
if(!reg.test($(obj).val())){
$(obj).val('');
}
},
/**
* @desc 将图片url按照type进行转换
* @param url
* @param type
* @param type 30*30 type=5
* 50*50 type=4
* 160*160 type=3
* 170*170 type=2
* 400*400 type=1
* 800*800 type=0
* @returns
*/
transformImageUrl : function(url,type){
return url?url.replace(/\/i[0-5]/g,'/i'+type):'';
}
};
/**
* jQuery 扩展方法
*
* $.Object.count( p )
* 获取一个对象的长度,需要指定上下文,通过 call/apply 调用
* 示例: $.Object.count.call( obj, true );
* @param {p} 是否跳过 null / undefined / 空值
* @author jiangchengyong
*/
$.extend({
// 获取对象的长度,需要指定上下文 this
Object: {
count: function( p ) {
p = p || false;
return $.map( this, function(o) {
if( !p ) return o;
return true;
}).length;
}
}
});
})(this);