⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 saja.js

📁 this is a saja for php code ingra ajax interface
💻 JS
字号:
var saja = {
	procOn:0,
	ClearAlert: function(doClear){
		if(!doClear){
			if(saja.timeOut)
				clearTimeout(saja.timeOut)
			saja.timeOut = setTimeout(function(){saja.ClearAlert(1)},6000)
		}
		else{
			ob=document.getElementById('alertOutput');
			ob.innerHTML = '';
			clearTimeout(saja.timeOut)
		}
	},
	ChangeIndicator: function(ob,procStatus){
		if(!document.getElementById('sajaStatus'))
			return false;
		//saja is working
		if(procStatus){
			ob.style.cursor = 'wait';
			document.body.style.cursor = 'wait';
			saja.Put('Working...', 'sajaStatus', 'r', 'innerHTML');
		}
		//saja is finished
		else{
			ob.style.cursor = 'default';
			document.body.style.cursor = 'default';
			saja.Put('', 'sajaStatus', 'r', 'innerHTML');
		}
	},
	NewReq: function(){
		if(window.XMLHttpRequest)
			try{return new XMLHttpRequest();}catch(e){}
		else if(window.ActiveXObject)
			try{return new ActiveXObject("Microsoft.XMLHTTP");}catch(e){
				try{return new ActiveXObject("Msxml2.XMLHTTP");}catch(e){}}
	},
	RunPhp: function(php, id, act, property, ob, session_id){
		if(req = saja.NewReq()){
			if(!saja.procOn)
				saja.ChangeIndicator(ob,1);
			saja.procOn++;
			saja.ExecReq(req, php, id, act, property, SAJA_PATH + 'saja.process.php', 'POST', ob, session_id);
		}
			
	},
	ExecReq: function(req, args, id, act, property, file, fmethod, ob, session_id){
		req.open(fmethod,file,true);
		req.send((SAJA_HTTP_KEY ? escape(saja.rc4(SAJA_HTTP_KEY, args)) : args) +'~|session_id|~'+session_id);
		req.onreadystatechange=function(){
			if (req.readyState==4 && req.status==200){	
				actions = req.responseText.split('<saja_split>');
				if(actions[0])
					saja.Put(actions[0], id, act, property)
				if(actions[1])
					eval(actions[1]);
				saja.procOn--;
				if(!saja.procOn)
					saja.ChangeIndicator(ob,0);
			}
		}
	},
	Put: function(content, id, act, property){
		if(property){
			try{ob = document.getElementById(id);}catch(e){}
			if(act=='p')
				ob[property] = content + ob[property];
			else if(act=='a')
				ob[property] += ob[property];
			else if(property.split('.')[0]=='style')
				ob.style[property.split('.')[1]] = content;
			else
				ob[property] = content;
		}
		else
			window[id] = content;
	},
	Get: function(id, property){
		if(!property)
			return window[id];
		var ob = document.getElementById(id);
		val = ob[property];
		if(typeof val == 'object')
			val = GetOb(val);
		return val;
	},
	GetOb: function(ob){
		var tarray = [];
		for(var i=0; i<ob.length; i++){
			if(ob[i].name && ob[i].length)
				tarray.push('\'' + ob[i].name + '\' => ' + GetSelected(ob[i]));
			else if(ob[i].checked == true || (ob[i].type != 'checkbox' && ob[i].type != 'radio'))
				tarray.push('\'' + ob[i].name + '\' => ' + SafePhp(ob[i].value));
		}
		return 'array(' + tarray.join(',') + ')';
	},
	SafePhp: function(string){
		return 'urldecode(\'' + escape(string) + '\')';
	},
	GetSelected: function(ob){
		var tarray = new Array;
		var k=0;
		for(var i=0; i<ob.length; i++){
			if(ob[i].selected){
				tarray.push('\'' + k + '\' => ' + saja.SafePhp(ob[i].value) );
				k++;
			}
		}
		return 'array(' + tarray.join(',') + ')';
	},
	GetAsQuoted: function(id, property){
		return '\'' + escape(saja.Get(id, property)) + '\'';
	},
	SetStyle: function(ob, styleString){
		document.getElementById(ob).style.cssText = styleString;	
	},
	rc4: function(pwd, data)
	{
		pwd_length = pwd.length;
		data_length = data.length;
		var key = new Array();
		var box = new Array();
		var cipher = '';
		for (var i=0; i<256; i++){
			key[i] = pwd.charCodeAt(i % pwd_length);
			box[i] = i;
		}
		for (j = i = 0; i < 256; i++){
			j = (j + box[i] + key[i]) % 256;
			tmp = box[i];
			box[i] = box[j];
			box[j] = tmp;
		}
		for (a = j = i = 0; i < data_length; i++){
			a = (a + 1) % 256;
			j = (j + box[a]) % 256;
			tmp = box[a];
			box[a] = box[j];
			box[j] = tmp;
			k = box[((box[a] + box[j]) % 256)];
			cipher += String.fromCharCode(data[i].charCodeAt(0) ^ k);
		}
		return cipher;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -