PageSourceSearch

https://www.fedpubseminars.com/ajaxpro/core.ashx

js fedpubseminars.com collected 2026-09-28 08:46:30 UTC 15,866 bytes, 560 lines download raw bytes

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

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.