PageSourceSearch

https://forsmi.com/components/com_jcomments/libraries/joomlatune/ajax.js

js forsmi.com collected 2026-10-03 21:47:54 UTC 3,978 bytes, 145 lines download raw bytes

1/* based on xajax Javascript library (http://www.xajaxproject.org) */
2if (!window.jtajax) {
3
4function jtAJAX()
5{
6	this.options = {url: '',type: 'post',nocache: true,data: ''};
7
8	this.$ = function(id) {if(!id){return null;}var o=document.getElementById(id);if(!o&&document.all){o=document.all[id];}return o;};
9	this.extend = function(o, e){for(var k in (e||{}))o[k]=e[k];return o;};
10	this.encode = function(t){return encodeURIComponent(t);};
11	this.setup = function(options) {this.options = this.extend(this.options, options);};
12
13	this.xhr = function()
14	{
15		var xhr = null;
16		if ('undefined' != typeof XMLHttpRequest) xhr = new XMLHttpRequest();
17		if (!xhr && 'undefined' != typeof ActiveXObject) {
18			var msxmlhttp = new Array('Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP');
19			for (var i=0;i<msxmlhttp.length;i++){try{xhr=new ActiveXObject(msxmlhttp[i]);}catch(e){xhr=null;}}
20		}       	
21		return xhr;
22	};
23	
24	this.form2query = function(sId)
25	{
26		var frm = this.$(sId);
27		if (frm && frm.tagName.toUpperCase() == 'FORM') {
28			var e = frm.elements, query = [];
29			for (var i=0; i < e.length; i++) {
30				var name = e[i].name, value;
31				if (!name) continue;
32				if (e[i].type && ('radio' == e[i].type || 'checkbox' == e[i].type) && false === e[i].checked) continue;
33				if ('select-multiple' == e[i].type) {
34					for (var j = 0; j < e[i].length; j++) {
35						if (true === e[i].options[j].selected)
36							query.push(name+"="+this.encode(e[i].options[j].value));
37					}
38				} else { query.push(name+"="+this.encode(e[i].value)); 
39				}
40			}
41			return query.join('&');
42		}
43		return '';
44	};
45
46	this.startLoading = function(){};
47	this.finishLoading = function(){};
48
49	this.ajax = function(options)
50	{
51		var xhr = this.xhr();
52		if (!xhr) return false;
53		var o = this.extend(this.options, options);
54		var url = o.url, jtx = this;
55		
56		if ('get' == o.type) {
57			if (true === o.nocache) {
58				var ts=new Date().getTime();
59				url += (url.indexOf("?")==-1 ? '?' : '&') + '_jtxr_' + ts;
60			}
61			if (o.data) {
62				url += (url.indexOf("?")==-1 ? '?' : '&') + o.data;
63				o.data = null;
64			}
65		}
66
67		xhr.open(o.type.toUpperCase(), url, true);
68
69		if ('post' == o.type)
70			try {xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");}catch(e){}
71		if (true === o.nocache)
72			xhr.setRequestHeader('If-Modified-Since', 'Thu, 01 Jan 1970 00:00:00 GMT');
73
74		xhr.onreadystatechange = function() {
75			if (xhr.readyState != 4) return;
76			jtx.finishLoading();
77			if (xhr.status==200) {
78				jtx.processResponse(xhr.responseText);
79			}
80			delete xhr;
81			xhr = null;
82		};
83		try {
84			jtx.startLoading();
85			xhr.send(o.data);
86		} catch(e) { jtx.finishLoading(); }
87
88		delete jtx;
89		delete xhr;
90		delete o;
91		return true;
92	};
93
94	this.call = function(sFunction, aArgs, sType, sForm)
95	{
96		var params = 'jtxf=' + this.encode(sFunction);
97		if (aArgs) {
98			for (var i=0;i<aArgs.length;i++) {
99				params += '&jtxa[]=' + this.encode(aArgs[i]);
100			}
101		} else if (sForm) {
102			params += '&' + this.form2query(sForm);
103		}
104
105		this.ajax({type: sType, data: params});
106		return true;
107	};
108
109	this.processResponse = function(sText)
110	{
111		if(sText==='') return false;
112		if(sText.substring(0,3)!='[ {'){var idx=sText.indexOf('[ {');sText=sText.substr(idx);}
113		var result;try {result=eval(sText);}catch(e){}
114		if ('undefined' == typeof result) {return false;}
115
116		var cmd, id, property, data, obj = null;
117
118		for (var i=0;i<result.length;i++) {
119			cmd 		= result[i]['n'];
120			id 		= result[i]['t'];
121			property	= result[i]['p'];
122			data 		= result[i]['d'];
123			obj 		= this.$(id);
124
125			switch(cmd) {
126				case 'as': if(obj){eval("obj."+property+"=data;");} break;
127				case 'al': if(data){alert(data);} break;
128				case 'js': if(data){eval(data);} break;
129				default: this.error('Unknown command: ' + cmd);break;
130			}
131		}
132		
133		delete result;
134		delete cmd;
135		delete id;
136		delete property;
137		delete data;
138		delete obj;
139		return true;
140	};
141
142	this.error = function(){};
143}
144var jtajax = new jtAJAX();
145}

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.