PageSourceSearch

https://sjs.com.cn/ajaxpro/core.ashx

js sjs.com.cn collected 2026-09-27 05:37:27 UTC 16,371 bytes, 565 lines download raw bytes

1//--------------------------------------------------------------
2// Copyright (C) 2006 Michael Schwarz (http://www.ajaxpro.info).
3// All rights reserved.
4//--------------------------------------------------------------
5
6// core.js
7Object.extend(Function.prototype, {
8	getArguments: function() {
9		var args = [];
10		for(var i=0; i<this.arguments.length; i++) {
11			args.push(this.arguments[i]);
12		}
13		return args;
14	}
15}, false);
16
17var MS = {"Browser":{}};
18
19Object.extend(MS.Browser, {
20	isIE: navigator.userAgent.indexOf('MSIE') != -1,
21	isFirefox: navigator.userAgent.indexOf('Firefox') != -1,
22	isOpera: window.opera != null
23}, false);
24
25var AjaxPro = {};
26
27AjaxPro.IFrameXmlHttp = function() {};
28AjaxPro.IFrameXmlHttp.prototype = {
29	onreadystatechange: null, headers: [], method: "POST", url: null, async: true, iframe: null,
30	status: 0, readyState: 0, responseText: null,
31	abort: function() {
32	},
33	readystatechanged: function() {
34		var doc = this.iframe.contentDocument || this.iframe.document;
35		if(doc != null && doc.readyState == "complete" && doc.body != null && doc.body.res != null) {
36			this.status = 200;
37			this.statusText = "OK";
38			this.readyState = 4;
39			this.responseText = doc.body.res;
40			this.onreadystatechange();
41			return;
42		}
43		setTimeout(this.readystatechanged.bind(this), 10);
44	},
45	open: function(method, url, async) {
46		if(async == false) {
47			alert("Synchronous call using IFrameXMLHttp is not supported.");
48			return;
49		}
50		if(this.iframe == null) {
51			var iframeID = "hans";
52			if (document.createElement && document.documentElement &&
53				(window.opera || navigator.userAgent.indexOf('MSIE 5.0') == -1))
54			{
55				var ifr = document.createElement('iframe');
56				ifr.setAttribute('id', iframeID);
57				ifr.style.visibility = 'hidden';
58				ifr.style.position = 'absolute';
59				ifr.style.width = ifr.style.height = ifr.borderWidth = '0px';
60
61				this.iframe = document.getElementsByTagName('body')[0].appendChild(ifr);
62			}
63			else if (document.body && document.body.insertAdjacentHTML)
64			{
65				document.body.insertAdjacentHTML('beforeEnd', '<iframe name="' + iframeID + '" id="' + iframeID + '" style="border:1px solid black;display:none"></iframe>');
66			}
67			if (window.frames && window.frames[iframeID]) {
68				this.iframe = window.frames[iframeID];
69			}
70			this.iframe.name = iframeID;
71			this.iframe.document.open();
72			this.iframe.document.write("<"+"html><"+"body></"+"body></"+"html>");
73			this.iframe.document.close();
74		}
75		this.method = method;
76		this.url = url;
77		this.async = async;
78	},
79	setRequestHeader: function(name, value) {
80		for(var i=0; i<this.headers.length; i++) {
81			if(this.headers[i].name == name) {
82				this.headers[i].value = value;
83				return;
84			}
85		}
86		this.headers.push({"name":name,"value":value});
87	},
88	getResponseHeader: function(name, value) {
89		return null;
90	},
91	addInput: function(doc, form, name, value) {
92		var ele;
93		var tag = "input";
94		if(value.indexOf("\n") >= 0) {
95			tag = "textarea";
96		}
97		
98		if(doc.all) {
99			ele = doc.createElement("<" + tag + " name=\"" + name + "\" />");
100		}else{
101			ele = doc.createElement(tag);
102			ele.setAttribute("name", name);
103		}
104		ele.setAttribute("value", value);
105		form.appendChild(ele);
106		ele = null;
107	},
108	send: function(data) {
109		if(this.iframe == null) {
110			return;
111		}
112		var doc = this.iframe.contentDocument || this.iframe.document;
113		var form = doc.createElement("form");
114		
115		doc.body.appendChild(form);
116		
117		form.setAttribute("action", this.url);
118		form.setAttribute("method", this.method);
119		form.setAttribute("enctype", "application/x-www-form-urlencoded");
120		
121		for(var i=0; i<this.headers.length; i++) {
122			switch(this.headers[i].name.toLowerCase()) {
123				case "content-length":
124				case "accept-encoding":
125				case "content-type":
126					break;
127				default:
128					this.addInput(doc, form, this.headers[i].name, this.headers[i].value);
129			}
130		}
131		this.addInput(doc, form, "data", data);
132		form.submit();
133		
134		setTimeout(this.readystatechanged.bind(this), 0);
135	}
136};
137
138var progids = ["Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
139var progid = null;
140
141if(typeof ActiveXObject != "undefined") {
142	var ie7xmlhttp = false;
143	if(typeof XMLHttpRequest == "object") {
144		try{ var o = new XMLHttpRequest(); ie7xmlhttp = true; }catch(e){}
145	}
146	if(typeof XMLHttpRequest == "undefined" || !ie7xmlhttp) {
147		XMLHttpRequest = function() {
148			var xmlHttp = null;
149			if(!AjaxPro.noActiveX) {
150				if(progid != null) {
151					return new ActiveXObject(progid);
152				}
153				for(var i=0; i<progids.length && xmlHttp == null; i++) {
154					try {
155						xmlHttp = new ActiveXObject(progids[i]);
156						progid = progids[i];
157
158					}catch(e){}
159				}
160			}
161			if(xmlHttp == null && MS.Browser.isIE) {
162				return new AjaxPro.IFrameXmlHttp();
163			}
164			return xmlHttp;
165		};
166	}
167}
168
169Object.extend(AjaxPro, {
170	noOperation: function() {},
171	onLoading: function() {},
172	onError: function() {},
173	onTimeout: function() { return true; },
174	onStateChanged: function() {},
175	cryptProvider: null,
176	queue: null,
177	token: "",
178	version: "9.2.17.1",
179	ID: "AjaxPro",
180	noActiveX: false,
181	timeoutPeriod: 15*1000,
182	queue: null,
183	noUtcTime: false,
184	regExDate: function(str,p1, p2,offset,s) {
185        str = str.substring(1).replace('"','');
186        var date = str;
187        
188        if (str.substring(0,7) == "\\\/Date(") {
189            str = str.match(/Date\((.*?)\)/)[1];                        
190            date = "new Date(" +  parseInt(str) + ")";
191        }
192        else { // ISO Date 2007-12-31T23:59:59Z                                     
193            var matches = str.split( /[-,:,T,Z]/);        
194            matches[1] = (parseInt(matches[1],0)-1).toString();                     
195            date = "new Date(Date.UTC(" + matches.join(",") + "))";         
196       }                  
197        return date;
198    },
199    parse: function(text) {
200		// not yet possible as we still return new type() JSON
201//		if (!(!(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
202//		text.replace(/"(\\.|[^"\\])*"/g, '')))  ))
203//			throw new Error("Invalid characters in JSON parse string.");                 
204
205        var regEx = /(\"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}.*?\")|(\"\\\/Date\(.*?\)\\\/")/g;
206        text = text.replace(regEx,this.regExDate);      
207
208        return eval('(' + text + ')');    
209    },
210	m : {
211		'\b': '\\b',
212		'\t': '\\t',
213		'\n': '\\n',
214		'\f': '\\f',
215		'\r': '\\r',
216		'"' : '\\"',
217		'\\': '\\\\'
218	},
219	toJSON: function(o) {	
220		if(o == null) {
221			return "null";
222		}
223		var v = [];
224		var i;
225		var c = o.constructor;
226		if(c == Number) {
227			return isFinite(o) ? o.toString() : AjaxPro.toJSON(null);
228		} else if(c == Boolean) {
229			return o.toString();
230		} else if(c == String) {
231			if (/["\\\x00-\x1f]/.test(o)) {
232				o = o.replace(/([\x00-\x1f\\"])/g, function(a, b) {
233					var c = AjaxPro.m[b];
234					if (c) {
235						return c;
236					}
237					c = b.charCodeAt();
238					return '\\u00' +
239						Math.floor(c / 16).toString(16) +
240						(c % 16).toString(16);
241				});
242            }
243			return '"' + o + '"';
244		} else if (c == Array) {
245			for(i=0; i<o.length; i++) {
246				v.push(AjaxPro.toJSON(o[i]));
247			}
248			return "[" + v.join(",") + "]";
249		} else if (c == Date) {
250//			var d = {};
251//			d.__type = "System.DateTime";
252//			if(AjaxPro.noUtcTime == true) {
253//				d.Year = o.getFullYear();
254//				d.Month = o.getMonth() +1;
255//				d.Day = o.getDate();
256//				d.Hour = o.getHours();
257//				d.Minute = o.getMinutes();
258//				d.Second = o.getSeconds();
259//				d.Millisecond = o.getMilliseconds();
260//			} else {
261//				d.Year = o.getUTCFullYear();
262//				d.Month = o.getUTCMonth() +1;
263//				d.Day = o.getUTCDate();
264//				d.Hour = o.getUTCHours();
265//				d.Minute = o.getUTCMinutes();
266//				d.Second = o.getUTCSeconds();
267//				d.Millisecond = o.getUTCMilliseconds();
268//			}
269			return AjaxPro.toJSON("/Date(" + new Date(Date.UTC(o.getUTCFullYear(), o.getUTCMonth(), o.getUTCDate(), o.getUTCHours(), o.getUTCMinutes(), o.getUTCSeconds(), o.getUTCMilliseconds())).getTime() + ")/");
270		}
271		if(typeof o.toJSON == "function") {
272			return o.toJSON();
273		}
274		if(typeof o == "object") {
275			for(var attr in o) {
276				if(typeof o[attr] != "function") {
277					v.push('"' + attr + '":' + AjaxPro.toJSON(o[attr]));
278				}
279			}
280			if(v.length>0) {
281				return "{" + v.join(",") + "}";
282			}
283			return "{}";		
284		}
285		return o.toString();
286	},
287	dispose: function() {
288		if(AjaxPro.queue != null) {
289			AjaxPro.queue.dispose();
290		}
291	}
292}, false);
293
294addEvent(window, "unload", AjaxPro.dispose);
295
296AjaxPro.Request = function(url) {
297	this.url = url;
298	this.xmlHttp = null;
299};
300
301AjaxPro.Request.prototype = {
302	url: null,
303	callback: null,
304	onLoading: null,
305	onError: null,
306	onTimeout: null,
307	onStateChanged: null,
308	args: null,
309	context: null,
310	isRunning: false,
311	abort: function() {
312		if(this.timeoutTimer != null) {
313			clearTimeout(this.timeoutTimer);
314		}
315		if(this.xmlHttp) {
316			this.xmlHttp.onreadystatechange = AjaxPro.noOperation;
317			this.xmlHttp.abort();
318		}
319		if(this.isRunning) {
320			this.isRunning = false;
321			this.onLoading(false);
322		}
323	},
324	dispose: function() {
325		this.abort();
326	},
327	getEmptyRes: function() {
328		return {
329			error: null,
330			value: null,
331			request: {method:this.method, args:this.args},
332			context: this.context,
333			duration: this.duration
334		};	
335	},
336	endRequest: function(res) {
337		this.abort();
338		if(res.error != null) {
339			this.onError(res.error, this);
340		}
341
342		if(typeof this.callback == "function") {
343			this.callback(res, this);
344		}
345	},
346	mozerror: function() {
347		if(this.timeoutTimer != null) {
348			clearTimeout(this.timeoutTimer);
349		}
350		var res = this.getEmptyRes();
351		res.error = {Message:"Unknown",Type:"ConnectFailure",Status:0};
352		this.endRequest(res);
353	},
354	doStateChange: function() {
355		this.onStateChanged(this.xmlHttp.readyState, this);
356		if(this.xmlHttp.readyState != 4 || !this.isRunning) {
357			return;
358		}
359		this.duration = new Date().getTime() - this.__start;
360		if(this.timeoutTimer != null) {
361			clearTimeout(this.timeoutTimer);
362		}
363		var res = this.getEmptyRes();
364		if(this.xmlHttp.status == 200 && this.xmlHttp.statusText == "OK") {
365			res = this.createResponse(res);
366		} else {
367			res = this.createResponse(res, true);
368			res.error = {Message:this.xmlHttp.statusText,Type:"ConnectFailure",Status:this.xmlHttp.status};
369		}
370		
371		this.endRequest(res);
372	},
373	createResponse: function(r, noContent) {
374		if(!noContent) {
375			if(typeof(this.xmlHttp.responseText) == "unknown") {
376				r.error = {Message: "XmlHttpRequest error reading property responseText.", Type: "XmlHttpRequestException"};
377				return r;
378			}
379		
380			var responseText = "" + this.xmlHttp.responseText;
381
382			if(AjaxPro.cryptProvider != null && typeof AjaxPro.cryptProvider.decrypt == "function") {
383				responseText = AjaxPro.cryptProvider.decrypt(responseText);
384			}
385
386			if(this.xmlHttp.getResponseHeader("Content-Type") == "text/xml") {
387				r.value = this.xmlHttp.responseXML;
388			} else {
389				if(responseText != null && responseText.trim().length > 0) {
390					r.json = responseText;
391					var v = null;
392					v = AjaxPro.parse(responseText);
393					if(v != null) {
394						if(typeof v.value != "undefined") r.value = v.value;
395						else if(typeof v.error != "undefined") r.error = v.error;
396					}
397				}
398			}
399		}
400		/* if(this.xmlHttp.getResponseHeader("X-" + AjaxPro.ID + "-Cache") == "server") {
401			r.isCached = true;
402		} */
403		return r;
404	},
405	timeout: function() {
406try { 
407
408		this.duration = new Date().getTime() - this.__start;
409		var r = this.onTimeout(this.duration, this);
410		if(typeof r == "undefined" || r != false) {
411			this.abort();
412		} else {
413			this.timeoutTimer = setTimeout(this.timeout.bind(this), AjaxPro.timeoutPeriod);
414		}
415}catch(error){}
416	},
417	invoke: function(method, args, callback, context) {
418		this.__start = new Date().getTime();
419
420		// if(this.xmlHttp == null) {
421			this.xmlHttp = new XMLHttpRequest();
422		// }
423
424		this.isRunning = true;
425		this.method = method;
426		this.args = args;
427		this.callback = callback;
428		this.context = context;
429		
430		var async = typeof(callback) == "function" && callback != AjaxPro.noOperation;
431		
432		if(async) {
433			if(MS.Browser.isIE) {
434				this.xmlHttp.onreadystatechange = this.doStateChange.bind(this);
435			} else {
436				this.xmlHttp.onload = this.doStateChange.bind(this);
437				this.xmlHttp.onerror = this.mozerror.bind(this);
438			}
439			this.onLoading(true);
440		}
441		
442		var json = AjaxPro.toJSON(args) + "";
443		if(AjaxPro.cryptProvider != null && typeof AjaxPro.cryptProvider.encrypt == "function") {
444			json = AjaxPro.cryptProvider.encrypt(json);
445		}
446		
447		this.xmlHttp.open("POST", this.url, async);
448		this.xmlHttp.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
449		this.xmlHttp.setRequestHeader("X-" + AjaxPro.ID + "-Method", method);
450		
451		if(AjaxPro.token != null && AjaxPro.token.length > 0) {
452			this.xmlHttp.setRequestHeader("X-" + AjaxPro.ID + "-Token", AjaxPro.token);
453		}
454
455		/* if(!MS.Browser.isIE) {
456			this.xmlHttp.setRequestHeader("Connection", "close");
457		} */
458
459		this.timeoutTimer = setTimeout(this.timeout.bind(this), AjaxPro.timeoutPeriod);
460
461		try{ this.xmlHttp.send(json); }catch(e){}	// IE offline exception
462
463		if(!async) {
464			return this.createResponse({error: null,value: null});
465		}
466
467		return true;	
468	}
469};
470
471AjaxPro.RequestQueue = function(conc) {
472	this.queue = [];
473	this.requests = [];
474	this.timer = null;
475	
476	if(isNaN(conc)) { conc = 2; }
477
478	for(var i=0; i<conc; i++) {		// max 2 http connections
479		this.requests[i] = new AjaxPro.Request();
480		this.requests[i].callback = function(res) {
481			var r = res.context;
482			res.context = r[3][1];
483
484			r[3][0](res, this);
485		};
486		this.requests[i].callbackHandle = this.requests[i].callback.bind(this.requests[i]);
487	}
488	
489	this.processHandle = this.process.bind(this);
490};
491
492AjaxPro.RequestQueue.prototype = {
493	process: function() {
494		this.timer = null;
495		if(this.queue.length == 0) {
496			return;
497		}
498		for(var i=0; i<this.requests.length && this.queue.length > 0; i++) {
499			if(this.requests[i].isRunning == false) {
500				var r = this.queue.shift();
501
502				this.requests[i].url = r[0];
503				this.requests[i].onLoading = r[3].length >2 && r[3][2] != null && typeof r[3][2] == "function" ? r[3][2] : AjaxPro.onLoading;
504				this.requests[i].onError = r[3].length >
5043 && r[3][3] != null && typeof r[3][3] == "function" ? r[3][3] : AjaxPro.onError;
505				this.requests[i].onTimeout = r[3].length >4 && r[3][4] != null && typeof r[3][4] == "function" ? r[3][4] : AjaxPro.onTimeout;
506				this.requests[i].onStateChanged = r[3].length >5 && r[3][5] != null && typeof r[3][5] == "function" ? r[3][5] : AjaxPro.onStateChanged;
507
508				this.requests[i].invoke(r[1], r[2], this.requests[i].callbackHandle, r);
509				r = null;
510			}
511		}
512		if(this.queue.length > 0 && this.timer == null) {
513			this.timer = setTimeout(this.processHandle, 0);
514		}
515	},
516	add: function(url, method, args, e) {
517		this.queue.push([url, method, args, e]);
518		if(this.timer == null) {
519			this.timer = setTimeout(this.processHandle, 0);
520		}
521		// this.process();
522	},
523	abort: function() {
524		this.queue.length = 0;
525		if (this.timer != null) {
526			clearTimeout(this.timer);
527		}
528		this.timer = null;
529		for(var i=0; i<this.requests.length; i++) {
530			if(this.requests[i].isRunning == true) {
531				this.requests[i].abort();
532			}
533		}
534	},
535	dispose: function() {
536		for(var i=0; i<this.requests.length; i++) {
537			var r = this.requests[i];
538			r.dispose();
539		}
540		this.requests.clear();
541	}
542};
543
544AjaxPro.queue = new AjaxPro.RequestQueue(2);	// 2 http connections
545
546AjaxPro.AjaxClass = function(url) {
547	this.url = url;
548};
549
550AjaxPro.AjaxClass.prototype = {
551    invoke: function(method, args, e) {
552
553        if (e != null) {
554            if (e.length != 6) {
555                for (; e.length < 6; ) { e.push(null); }
556            }
557            if (e[0] != null && typeof (e[0]) == "function") {
558                return AjaxPro.queue.add(this.url, method, args, e);
559            }
560        }
561        var r = new AjaxPro.Request();
562        r.url = this.url;
563        return r.invoke(method, args);
564    }
565};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.