root 8 years ago
parent
commit
ffd87df46e
4 changed files with 772 additions and 0 deletions
  1. 348 0
      js/codehtml.js
  2. 161 0
      js/form.js
  3. 25 0
      js/text.js
  4. 238 0
      js/util.js

+ 348 - 0
js/codehtml.js

@ -0,0 +1,348 @@
1
(function($,doc,$body,exports){
2
	/**
3
	 * env={ ce:current Element; cd:current Data; ci:current index in
4
	 * ListElement array[ci=index] or object[ci=key] es:Element stack; Array
5
	 * ds:Data stack; Array is:index stack;Array sh:value handler
6
	 * function(env,key){return [String]} dir:directive handler
7
	 * Aarray(function(env){}.call(elementObj={},env) }
8
	 */
9
	var ch_val_buider={
10
		"c":function(/* env */){
11
			return this.k;		
12
		},
13
		"s":function(env){
14
			var v= env.cd;
15
			if(v) v= this.k?v[this.k]:v;
16
			if(v) return v;
17
			return "";			
18
		},
19
		"date":function(env){}		
20
	},
21
	simpleAttrHandler=function(env){
22
		env.ce.setAttribute(this.n,this.v);	
23
	},
24
	AttrHandler=function(env){
25
		var ret = [],va= this.v;
26
		for(var i = 0 ; i < va.length;++i){
27
			var item = va[i];
28
			ret.push[env.sh[item.h].call(this,env)];		
29
		}
30
		env.ce.setAttribute(this.n,ret.join(""));
31
	},
32
	/**
33
	 * r:array s:text value f:lslast value in array Is * Text
34
	 */
35
	strSplit_s=function(r,s,f){
36
		if(f){
37
			var tmp = r[r.length-1];
38
			tmp.k=tmp.k+s;
39
		}else{
40
			r.push({k:s,h:"c"});
41
		}
42
	},
43
	strSplit_o=function(r/* array */,shell/* trim value like {{shell}} */){
44
		var tmp = shell.split("-");
45
		var obj ={k:tmp.shift(),h:"s"};
46
		if(tmp.length){obj.h=tmp.shift();}
47
		if(tmp.length){obj.p=tmp;}
48
		r.push(obj);
49
	},
50
	strSplit=function(s){ // s.length>4
51
		var r=[],
52
		len=s.length,
53
		si=0,/* parse start index */
54
		ei,/* end shell ei = s.indexOf("}}",bi+2) */
55
		shell,/* {{shell}} */
56
		tmp,/* last shell */
57
		f/* prev is not shell */,
58
		bi=nv.indexOf("{{");	/* begin shell bi = s.indexOf("{{",si) */		
59
		if(bi>=0){
60
			ei=nv.indexOf("}}",bi);	
61
			while(si<len){
62
				if(bi>si){r.push({k:s.substring(si,bi),h:"c"});f=true;}
63
				shell = s.substring(bi+2,ei).trim();
64
				si=ei+2;
65
				if(shell.length){
66
					f=false;
67
					strSplit_o(r,shell);	
68
				}else{strSplit_s(r,s.substring(bi,si),f);f=true;}
69
				if(si>=len) return r;
70
				bi=s.indexOf("{{",si);
71
				if(bi<0){strSplit_s(r,s.substring(si),f);return r;}
72
				ei=s.indexOf("}}",bi);
73
				if(ei<0){strSplit_s(r,s.substring(si),f);return r;}
74
			}
75
		}
76
		return s;	
77
	},
78
	strCompile=function(s){
79
		var r = strSplit(s);
80
		if(typeof s !="string"){
81
			return r.length>1?r:r[0];/*
82
										 * [{k:"",h:"",p:[]},...] :
83
										 * {k:"",h:"",p:[]}
84
										 */		
85
		}
86
		return s;// String;
87
	},
88
	simpleAttrHand=function(env){
89
		env.ce.setAttribute(this.n,this.v);	
90
	},
91
	singleAttrHand=function(env){
92
		env.ce.setAttribute(this.n,env.sh[this.h].call(this.v,env));
93
	},
94
	arrayAttrHand=function(env){
95
		var item,ret =[],vs=this.v,len=vs.length;
96
		for(var i = 0 ; i < len ; ++i){
97
			item = vs[i];
98
			ret.push(env.sh[item.h].call(item,env));
99
		}
100
		env.ce.setAttribute(this.n,ret.join(""));
101
	},
102
	/* ret.h(env); attribute compiler */	
103
	attrCompile=function(attr){
104
		var s =attr.value||"",ret ={n:attr.name,v:s,h:simpleAttrHand};
105
		if(s.length>4){
106
			s = strCompile(s);
107
			if(typeof s !="string"){
108
				ret.v = s;
109
				// is Array
110
				ret.h=s.length?arrayAttrHand:singleAttrHand;
111
			}
112
		}
113
		return ret;	
114
	},
115
	simpleTextHand=function(env){
116
		env.ce.appendChild(doc.createTextNode(this.v));
117
	},
118
	singleTextHand=function(env){
119
		env.ce.appendChild(doc.createTextNode(env.sh[this.h].call(this.v,env)));
120
	},
121
	arrayTextHand=function(env){
122
		var item,ret =[],vs=this.v,len=vs.length;
123
		for(var i = 0 ; i < len ; ++i){
124
			item = vs[i];
125
			ret.push(env.sh[item.h].call(item,env));
126
		}
127
		env.ce.appendChild(doc.createTextNode(ret.join("")));
128
	},
129
	/* ret.h(env); textNode compiler */	
130
	textCompile=function(s/* s = textNode.nodeValue */){
131
		var len=s.length,ret={v:s,h:"_t"};
132
		if(len>4){
133
			s = textCompile(s);
134
			if(typeof s !="string"){
135
				ret.v = s;
136
				// is Array
137
				ret.h=s.length?"_at":"_st";
138
			}
139
		}
140
		return ret;		
141
	},ch_dir_container={
142
		/* simpleTextHand= */
143
		"_t":function(env){env.ce.appendChild(doc.createTextNode(this.v));},
144
		/* singleTextHand= */
145
		"_st":function(env){env.ce.appendChild(doc.createTextNode(env.sh[this.h].call(this.v,env)));},
146
		/* arrayTextHand= */
147
		"_at":function(env){
148
			var item,ret =[],vs=this.v,len=vs.length;
149
			for(var i = 0 ; i < len ; ++i){
150
				item = vs[i];
151
				ret.push(env.sh[item.h].call(item,env));
152
			}
153
			env.ce.appendChild(doc.createTextNode(ret.join("")));
154
		},
155
		"_":function(env){
156
			var ele = doc.createElement(this.n),as = this.as,es= this.es,item;
157
			env.ce.appendChild(ele);
158
			env.es.push(env.ce);
159
			env.ce=ele;
160
			for(var i = 0 ; i < as.length; ++i){
161
				as[i].h(env);
162
			}
163
			for(var i = 0 ; i < es.length; ++i){
164
				item=es[i];env.dir(item.h).call(item,env);
165
			}
166
			env.ce = env.es.pop();
167
		},
168
		"list":function(env){
169
			var hand=env.dir["_"],as=this.as,es=this.es,item,data = env.cd,p=this.p;
170
			if(data && p && p.length && p[0]){
171
				env.ds.push(data);
172
				data = env.cd = data[p[0]]||[];
173
				env.is.push(env.ci);
174
				for(var i = 0 ; i < data.length;++i){
175
					env.ci = i;
176
					env.cd = data[i];
177
					hand.call(this,env);
178
				}
179
				env.ci=env.is.pop();
180
				env.cd = env.ds.pop();
181
			}else if(data && data.length){
182
				env.is.push(env.ci);
183
				for(var i = 0 ; i < data.length;++i){
184
					env.ci = i;
185
					hand.call(this,env);
186
				}
187
				env.ci=env.is.pop();	
188
			}
189
		},"each":function(env){
190
			var hand=env.dir["_"],as=this.as,es=this.es,item,data = env.cd,p=this.p;
191
			if(data && p && p.length && p[0]){
192
				env.ds.push(data);
193
				env.is.push(env.ci);
194
				for(var i = 0 ; i < p.length;++i){
195
					env.ci = p[i];
196
					env.cd = data[env.ci];
197
					hand.call(this,env);
198
				}
199
				env.ci=env.is.pop();
200
				env.cd = env.ds.pop();
201
			}else if(data){
202
				env.is.push(env.ci);
203
				for(var key in data){
204
					env.ci = k;
205
					hand.call(this,env);
206
				}
207
				env.ci=env.is.pop();	
208
			}	
209
		},"val":function(env){
210
			var hand=env.dir["_"],as=this.as,es=this.es,items,item,data = env.cd,p=this.p;
211
			if(p && p.length && p[0]){
212
				items = p[0].split("\\.");
213
				env.ds.push(data);
214
				while(items.length && data){
215
					data = data[items.shift()];
216
				}
217
				if(items.length===0 && data){
218
					env.cd = data;
219
					hand.call(this,env);
220
				}
221
				env.cd = env.ds.pop();
222
			}			
223
		},"valTag":function(env){
224
			var hand=env.dir["_"],as=this.as,es=this.es,items,item,data = env.cd,p=this.p;
225
			if(p && p.length && p[0]){
226
				items = p[0].split("\\.");
227
				env.ds.push(data);
228
				while(items.length && data){
229
					data = data[items.shift()];
230
				}
231
				if(items.length===0 && data){
232
					env.cd = data;
233
					var ele = doc.createElement(this.n);
234
					env.ce.appendChild(ele);
235
					env.es.push(env.ce);
236
					env.ce=ele;
237
					for(var i = 0 ; i < as.length; ++i){
238
						as[i].h(env);
239
					}
240
					for(var i = 0 ; i < es.length; ++i){
241
						item=es[i];env.dir(item.h).call(item,env);
242
					}
243
					env.ce = env.es.pop();
244
				}
245
				env.cd = env.ds.pop();
246
			}
247
		}
248
	},
249
	childCompile=function(chs,ret){
250
		var lisT =false;
251
		for(var i = 0 ; i < chs.length ; ++i){
252
			var ch=chs[i];
253
			if(ch.nodeType==1){
254
				if(lisT){
255
					ret.push(textCompile(s));
256
				}
257
				ret.push(eleCompile(ch));
258
				lisT=false;
259
			}else if(ch.nodeType==3){
260
				s = listT?(s+ch.nodeValue):ch.nodeValue;
261
				listT=true;
262
			}
263
		}
264
		if(listT){
265
			ret.push(textCompile(s));
266
		}
267
	},
268
	/* ret.h(env) Element compiler */
269
	eleCompile=function(ele){
270
		var attrs=ele.attributes,cdir=ele.getAttribute("ch-dir")||"_", ret ={n:ele.node},as=ret.as=[],es=ret.es=[],lisT,s,ch;
271
		ch=cdir.split("-");
272
		ret.h=ch.shift();
273
		if(ch.length)ret.p=ch;		
274
		for(var i = 0 ;i < attrs.length;++i){
275
			as.push(attrCompile(attrs[i]));
276
		}
277
		childCompile(ele.children,ret.es);
278
		return tet;
279
	},parseElement=function(ele){
280
		var env={sh:{},dir:{}},chs=[];
281
		childCompile(ele.children,chs);
282
		$.extend(env.sh,ch_val_buider);
283
		$.extend(env.dir,ch_dir_container);
284
		return {
285
			"shell":function(name,hand){
286
				if(hand){
287
					env.sh[name]=hand;
288
					return this;
289
				}else return env.sh[name];
290
			},"dir":function(name,hand){
291
				if(hand){
292
					env.dir[name]=hand;
293
					return this;
294
				}else return env.dir[name];
295
			},"fill":function(pe,data){
296
				env.es=[];env.ds=[];env.is=[];env.ce=pe,env.cd=data;
297
				for(var i = 0 ; i < chs.length;++i){
298
					var ch = chs[i];
299
					env.dir[ch.h].call(ch,env);
300
				}
301
				return this;
302
			}
303
		};
304
	},	
305
	defBh=function(data){return data;},
306
	parseCode(ele)=function(ele){
307
		var hand =parseElement(ele),$ele=$(ele),bh=defBh,lses=[];
308
		return $.extend(hand,{
309
			"val":function(data){
310
				$ele.empty();
311
				data = bh(data);
312
				var docf = doc.createDocumentFragment();
313
				this.fill(docf,data);
314
				ele.appendChild(docf);
315
				for(var i = 0; i < lses.length;++i){
316
					lses[i]();
317
				}
318
				return this;
319
			},"empty":function(){
320
				$(ele).empty();
321
				return this;
322
			},"listen":function(h){
323
				if(h) lses.push(h);
324
				return this;
325
			}
326
		});
327
	},parseHtmlTemplate=function(c){
328
		var $div=$("<div style='display:none;'></div>");
329
		$div.appendTo($body).html(c);
330
		var h =parseCode($div[0]);
331
		$div.remove();
332
		return $.extend(h,{
333
			"appendTo":function(pe,data){
334
				var docf = doc.createDocumentFragment();
335
				this.fill(docf,data);
336
				pe.appendChild(docf);
337
			}
338
		});
339
	};
340
	var codeHtml ={
341
			"parse":parseElement,
342
			"element":parseCode,
343
			"template":parseHtmlTemplate
344
	};
345
	if(exports) exports.codeHteml = codeHtml;
346
	return codeHtml;
347
})(jQuery,document,$body,window);
348
 

+ 161 - 0
js/form.js

@ -0,0 +1,161 @@
1
(function($,util, exports) {
2
	var impls = [],
3
4
	/* default impl */
5
	di = function(val) {
6
		var v = val, dv = null;
7
		return {
8
			val : function(data) {
9
				if (arguments.length) {
10
					v = data;
11
					return this;
12
				}
13
				return v;
14
			},
15
			reset : function(data) {
16
				if (arguments.length) {
17
					dv = data;
18
					return this;
19
				}
20
				dv = data;
21
				validate
22
				return this;
23
			},
24
			validate : function(vds) {
25
				if (vds) {
26
					// add valid obj
27
					return this;
28
				} else {
29
					return true;
30
				}
31
			}
32
		};
33
	}, svd = function(items, vds) {
34
		for (key in vds) {
35
			var im = items[key], vd = vds[key];
36
			if (im && vd)
37
				im.validate(vd);
38
		}
39
		return this;
40
	}, vd = function(items) {
41
		for (key in items) {
42
			if (!items[key].validate())
43
				return false;
44
		}
45
		return true;
46
	}, vda = function(valids,form) {
47
		for (var i = 0; i < valids.length; ++i) {
48
			if (!valids[i](form))
49
				return false;
50
		}
51
		return true;
52
	},
53
54
	/* create form instance by jQuery obj */
55
	bf = function($e) {
56
		if ($e.length === 1) {
57
			var items = {}, valids = [];
58
			$e.find(".form-item").each(function() {
59
				var $this = $(this);
60
				for (var i = 0; i < impls.length; ++i) {
61
					var item = impls[i]($this);
62
					if (item && item.name) {
63
						items[item.name] = item;
64
					}
65
				}
66
			});
67
			return {
68
				item : function(name) {
69
					return items[name];
70
				},
71
				validate : function(vds) {
72
					if (arguments.length) {
73
						$.isArray(data) ? valids.concat(data) : svd(items, vds);
74
						return this;
75
					} else {
76
						return vd(items) ? vda(valids,this) : false;
77
					}
78
				},
79
				val : function(data) {
80
					if (arguments.length) {
81
						if (data) {
82
							for (key in data) {
83
								var ch = items[key];
84
								if (!ch) {
85
									ch = items[key] = di();
86
								}
87
								ch.val(data[key]);
88
							}
89
						}
90
						return this;
91
					}
92
					var ret = {};
93
					for (key in items) {
94
						ret[key] = items[key].val();
95
					}
96
					return ret;
97
				},
98
				reset : function(data) {
99
					if (arguments.leng) {
100
						for (key in data) {
101
							var item = itmes[key];
102
							if (item)
103
								item.reset(data[key]);
104
						}
105
					} else {
106
						for (key in items) {
107
							items[key].reset();
108
						}
109
					}
110
				},get:function(url,data,eh,config){
111
					util.get(url,data,function(rd){
112
						if(config && config.check){
113
							rd =config.ckeck(rd);
114
							if(rd){
115
								this.reset();
116
								this.val(rd);
117
							}
118
						}
119
					},eh,config);
120
				},post:function(url,data,eh,config){
121
					util.post(url,data,function(rd){
122
						if(config && config.check){
123
							rd =config.ckeck(rd);
124
							if(rd){
125
								this.reset();
126
								this.val(rd);
127
							}
128
						}
129
					},eh,config);
130
				},doGet:function(url,sh,eh,config){
131
					if(this.validate()){
132
						util.get(url,this.val(),sh,eh,config);
133
					}
134
				},doPost:function(url,sh,eh,config){
135
					if(this.validate()){
136
						util.post(url,this.val(),sh,eh,config);
137
					}
138
				},doPut:function(url,sh,eh,config){
139
					if(this.validate()){
140
						util.put(url,this.val(),sh,eh,config);
141
					}
142
				},doDel:function(url,sh,eh,config){
143
					if(this.validate()){
144
						util.del(url,this.val(),sh,eh,config);
145
					}
146
				}
147
			};
148
		}
149
		return null;
150
	}
151
152
	var ret = {
153
		build : bf,
154
		register : function(impl) {
155
			impls.push(impl)
156
		}
157
	};
158
	if (exports)
159
		exports.form = ret;
160
	return ret;
161
})(jQuery,util, window);

+ 25 - 0
js/text.js

@ -0,0 +1,25 @@
1
(function($,form){	
2
	from.register(function($e){
3
		var n=$e.attr("name")||$e.attr("name"), $,dv,t="string";
4
		if($e.hasClass("int")) t="int";
5
		if($e.hasClass("float")) t="float";		
6
		return {
7
			name:n,
8
			val:function(data){},
9
			validate:function(h){
10
				
11
			},
12
			reset:function(data){
13
				if(arguments.leng){
14
					dv=data;
15
				}else{
16
					this.val(dv);
17
				}
18
			},
19
			type:function(){
20
				return t;
21
			}
22
			
23
		};
24
	});	
25
})(jQuery,form);

+ 238 - 0
js/util.js

@ -0,0 +1,238 @@
1
(function($, $body, exports) {
2
	var noop = function() {
3
	}, infoDiv = $("#g_info"), errDiv = $("#g_err"), warnDiv = $("#g_warn"), msgDiv = $("#g_msg"), err_msg = {}, layer_curr = {
4
		index : 5000000,
5
		remove : noop,
6
		css : noop
7
	}, layer_remove = function() {
8
		this.shade.remove();
9
		this.ctn.empty();
10
		this.ctn.remove();
11
		this.prev.css("display", "block");
12
		_g_layer_curr = this.prev;
13
	}, fh = function(e) {
14
		$(this).parent().hide();
15
	}, bh = function($p) {
16
		$p.find(".click-hide-parent").on("click", fh);
17
	}, fillContent = function($c/* child node [String|Function|jQObj] */, $p) {
18
		if ($c) {
19
			if (typeof $c === "string") {
20
				$p.html(p);
21
			} else if (typeof p == "function") {
22
				$c.call($p);
23
			} else if ($c.jquery) {
24
				$p.append($c);
25
			}
26
		}
27
	}, modal = function(ctn) {
28
		var inx = _g_layer_curr.index + 2, ly = {
29
			index : inx,
30
			remove : layer_remove,
31
			prev : _g_layer_curr
32
		};
33
		ly.shade = $(
34
				"<div class='layer-shade layer-" + inx + "' style='z-index:"
35
						+ inx + ";'></div>").appendTo(body);
36
		++inx;
37
		ly.ctn = $(
38
				"<div class='layer-ctn layer-" + inx + "' style='z-index:"
39
						+ inx + ";'></div>").appendTo(body);
40
		ly.prev = layer_curr;
41
		layer_curr = ly;
42
		fillContent(ctn, ly.ctn);
43
		return ly;
44
	}, rmModal = function() {
45
		layer_curr.remove();
46
	},
47
48
	// function error message
49
	fem = function($c, $t) {
50
		var $e = $(
51
				"<div class='err-ctn'><i class='icon click-hide-parent'></i></div>")
52
				.appendTo(errDiv);
53
		$("<span></span>").appendTo($e).html($c);
54
		bh($e);
55
		setTimeout(function() {
56
			$e.remove()
57
		}, $t ? $t : 10000);
58
	},
59
	// function warn message
60
	fwm = function($c, $t) {
61
		var $w = $(
62
				"<div class='warn-ctn'><i class='icon click-hide-parent'></i></div>")
63
				.appendTo(warnDiv);
64
		$("<span></span>").appendTo($w).html($c);
65
		bh($w);
66
		setTimeout(function() {
67
			$w.remove()
68
		}, $t ? $t : 3000);
69
	}, fm = function($c, $t) {
70
		var $m = $(
71
				"<div class='warn-ctn'><i class='icon click-hide-parent'></i></div>")
72
				.appendTo(warnDiv);
73
		$("<span></span>").appendTo($w).html($c);
74
		bh($m);
75
		setTimeout(function() {
76
			$w.remove()
77
		}, $t ? $t : 3000);
78
	}, loadref = 0, loadingDiv = $("#g_loading"), loading = function() {
79
		++loadref;
80
		if (loadref === 1) {
81
			loadingDiv.show()
82
		}
83
	}, unLoading = function() {
84
		--loadref;
85
		if (loadref === 0) {
86
			loadingDiv.hide()
87
		}
88
	}, am = function(title, content, hand) {
89
		if (content) {
90
			if ($.isFunction(content)) {
91
				hand = content;
92
				content = title;
93
				title = "提示";
94
			}
95
		} else {
96
			content = title;
97
			title = "提示";
98
		}
99
		hand = hand || noop;
100
		var ly = modal('<div class="modal-dialog"><div class="modal-content"><div class="modal-header"><h4 class="modal-title"></h4></div><div class="modal-body"><p></p></div><div class="modal-footer"><button type="button" class="btn">关闭</button></div></div></div>');
101
		ly.ctn.find(".modal-title").text(title);
102
		$c = ly.ctn.find("p").text(content);
103
		ly.ctn.find("button").on("click", function() {
104
			rmModal();
105
			hand();
106
		});
107
	}, bm_addBtn = function($p, $cp, $h) {
108
		var $b = $('<button type="button" class="btn"></button>').appendTo($p);
109
		b.text($cp).on("click", function() {
110
			rmModal(), $h()
111
		});
112
	}, bm = function(obj) {
113
		var ly = modal('<div class="modal-dialog"><div class="modal-content"><div class="modal-header"><h4 class="modal-title"></h4></div><div class="modal-body"><p></p></div><div class="modal-footer"></div></div></div>');
114
		ly.ctn.find(".modal-title").text(obj.title || "确认");
115
		ly.ctn.find("p").text(obj.content);
116
		var m_footer = ly.ctn.find(".modal-footer"), btnH = function(btn) {
117
			var $btn = $('<button type="button" class="btn"></button>')
118
					.appendTo(m_footer);
119
			var caption = btn.caption || "未命名的", handler = btn.hand || noop;
120
			$btn.text(caption);
121
			$btn.on("click", function() {
122
				util.closeModalLayer();
123
				handler();
124
			});
125
		};
126
		for (var i = 0; i < obj.btns.length; ++i) {
127
			bm_addBtn(m_footer, btns[i].caption || "no name", btns[i].hand
128
					|| noop);
129
		}
130
	}, g_def_err_hand = function(ep) {
131
		fem("http access error:\r\n" + JSON.stirngify(ep));
132
	}, g_err = {
133
		"defErrHand" : function(ep) {
134
135
		},
136
		"0" : "未定义的错误",
137
	},
138
	/**
139
	 * ep={code:"",msg:"",detailMsg:"",url:""} pa=function(code,msg,detailMsg)
140
	 * pa=boolean
141
	 */
142
	ajaxErrHand = function(ep, eh) {
143
		if (eh) {
144
			var pt = $.type(eh);
145
			if (pt == "booean") {
146
				g_def_err_hand(ep);
147
			} else if (pt == "function") {
148
				eh(ep);
149
			} else {
150
				var ph = eh[ep.code] || g_err[ep.code] || eh["defErrHand"]
151
						|| g_err["defErrHand"];
152
				if (typeof ph === "string") {
153
					fem(ph);
154
				} else {
155
					ph(ep);
156
				}
157
			}
158
		}
159
	}, ajaxAccess = function(method, pUrl, pData, sh, eh, config) {
160
		config = config || {};
161
		if (false !== config.mask)
162
			loading();
163
		config.traditional = true;
164
		config.type = method;
165
		config.url = pUrl, config.data = pData;
166
		config.contentType= method ==="put" ? "application/json" : "application/x-www-form-urlencoded";
167
		config.success = function(rd) {
168
			if (rd.success) {
169
				sh(rd.data);
170
			} else {
171
				rd.code = "" + rd.code;
172
				rd.url = pUrl;
173
				ajaxErrHand(ep, eh);
174
			}
175
		};		
176
		config.error = function(jqXHR, textStatus, errorThrown) {
177
			ajaxErrHand({
178
				code : textStatus,
179
				msg : textStatus,
180
				detailMsg : textStatus,
181
				xhr : jqXHR,
182
				eObj : errorThrown,
183
				url : pUrl
184
			}, eh);
185
		};
186
		$.ajax(config).always(false !== config.mask ? unLoading : noop);
187
	};
188
189
	ret = {
190
		showModal : modal,
191
		closeModal : rmModal,
192
		showLoading : loading,
193
		hideLoading : unLoading,
194
		listModalIndex : function() {
195
			return lay_curr.index + 1;
196
		},
197
		error : fem,
198
		warn : fwm,
199
		msg : fm,
200
		alert : am,
201
		boxMsg : bm,
202
		confirm : function(msg, yes, no) {
203
			bm({
204
				content : msg,
205
				btns : [ {
206
					caption : "取消",
207
					hand : no || noop
208
				}, {
209
					caption : "确认",
210
					hand : yes
211
				} ]
212
			});
213
		},
214
		get : function(url, data, sh, eh, config) {
215
			ajaxAccess("get", url, data, sh, eh, config);
216
		},
217
		post : function(url, data, sh, eh, config) {
218
			ajaxAccess("post", url, data, sh, eh, config);
219
		},
220
		put : function(url, data, sh, eh, config) {
221
			ajaxAccess("post", url, data ? JSON.stringify(data) : "", sh, eh,
222
					config);
223
		},
224
		del : function(url, sh, eh, pObj) {
225
			ajaxAccess("post", url, null, sh, eh, pOjb);
226
		},
227
		noop : noop,
228
		returnTrue : function() {
229
			return true;
230
		},
231
		returnFalse : function() {
232
			return false;
233
		}
234
	};
235
	if (exports)
236
		exports.util = ret;
237
	return ret;
238
})(jQuery, jQuery("body"), window);