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

📄 swato-engine.js

📁 JS库
💻 JS
字号:
/*
 *  (c) 2005 Zhijie Chen <zigzag.chen@gmail.com>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *	  http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

Swato.Engine = Class.create();

Swato.Engine.prototype = {

	initialize: function(url,options) {
		this.url = url;
		this.conn_id = Math.floor(Math.random()*100000000);
		this.options = options;
	},

	call: function(catcher,remoteObjectID,methodName,params,options) {
		if ( this.url == null ) return;
		if ($("loading_img")) {
			$("loading_img").style.display="" ;
		}
		if (document.getElementById(catcher)!=null) {
			new Ajax.Updater(catcher, this.url+"/"+remoteObjectID,
				this._requestOptions(remoteObjectID.hashCode||remoteObjectID,methodName,params,options));
		} else if (catcher!=null){
			var option=new Object();
			option.extend(options);
			option.onComplete=this._onRequestComplete.bind(catcher);
			new Ajax.Request(this.url+"/"+remoteObjectID,
				this._requestOptions(remoteObjectID.hashCode||remoteObjectID,methodName,params,option));
		}
	},

	fetch: function(catcher,url,options) {
		if ( url == null ) return;
		if ($("loading_img")) {
			$("loading_img").style.display="" ;
		}
		if (typeof(debug)== 'function') debug(">>> "+url);
		if (document.getElementById(catcher)!=null) {
			new Ajax.Updater(catcher, url,options);
		} else if (catcher!=null){
			var option=new Object();
			option.extend(options);
			option.onComplete=this._onRequestComplete.bind(catcher);
			new Ajax.Request(url,option);
		}
	},	

//	fetch: function(catcher,remoteObjectID,options) {
//		this.call(catcher,remoteObjectID,'',[],options);
//	},
	
	send: function(catcher,jsObject,remoteObjectID,options) {
		this.call(catcher,remoteObjectID,'',[jsObject],options);
	},

	_requestOptions: function(remoteObjectID,methodName,params,options) {
		var sendingData=
			{"params":params,
			"method":methodName,
			"id":remoteObjectID,
			"conn_id":this.conn_id};
		var requestOptions=new Object();
		requestOptions.extend(this.options);
		requestOptions.extend(options);
		requestOptions.parameters=JSON.stringify(sendingData);
		if (typeof(debug)== 'function') debug(">>> "+requestOptions.parameters);
		return requestOptions;
	},

	_onRequestComplete : function(response) {
		if (response.status != 200) {
			if (typeof(FVL_log)== 'function') FVL_log("Response Status: "+response.status,FVL_ERROR);
			return;
		}
		if ($("loading_img")) {
			$("loading_img").style.display="none" ;
		}
		if (typeof(debug)== 'function')	debug("<<< "+response.responseText);
		var root;
		var result;
		var error;
		//try parse XML
		root=XMLUtil.getDocumentElement(response);
		if (root){ 
			//deal with xml
			var d2j = new JKL.ParseXML.JSON();
			result = d2j.parseDocument( root );
			if (typeof(debug)== 'function') {
				debug("XML parse result: "+JSON.stringify(result));
			}
		}else { 
			//deal with json
			var responseText;
			eval("responseText = " + response.responseText);
			result=responseText.result;
			error=responseText.error;
			this.hashCode=responseText.hashCode;
		}

		if (this.gotResult!=null){
			this.gotResult.apply(this, [result]);
		}
		if (this.gotError!=null) {
			this.gotError.apply(this, [error]);
		}
	}
};

var XMLUtil = {
	getForIE: function(response){
		var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.loadXML(response.responseText);
		return xmlDoc.documentElement;
	},

	getDocumentElement: function(response) {
		if (response.responseText!=null && response.responseText.charAt(0)=='{') return null;
		if (response.responseXML!=null && response.responseXML.documentElement!=null)
			return response.responseXML.documentElement;
		if (response.documentElement!=null) return response.documentElement;
		return (XMLUtil.getForIE(response));
	}
}

⌨️ 快捷键说明

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