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

📄 remotecall-ajax.js

📁 Hippo CMS是一个以信息为中心的开源内容管理系统。Hippo CMS目标是供中,大型企业来管理其发布在互连网
💻 JS
📖 第 1 页 / 共 2 页
字号:
       this.log.debug("failed loading ajax context:" + contextID);
    }
    this.log.error(response,error);
    this.cleanup(contextObj);
  }
  
  function createIFrame(obj, func) {
    var uniqueId = 'rcax-iframe' + Math.floor(Math.random() * 99999);  
    var container = document.createElement('DIV');  
    container.innerHTML = '<iframe style="display:none" src="about:blank" id="'+
        uniqueId + '" name="' + uniqueId + '" onload="window.top.window.frames[\'topframe\'].Application.sm.lookup(\'framework.rc\').loadedIFrame(\'' + uniqueId + '\');"></iframe>';  
    document.body.appendChild(container);  
    
    var el = document.getElementById(uniqueId);
    el.onComplete = function(result) {
      obj[func](result);
    }  
    
    return uniqueId;  
  }
  
  function loadedIFrame(frameId) {
    top.unQueueAsBusy();
    var i = document.getElementById(frameId);  
    if (i.contentDocument) {  
       var d = i.contentDocument;  
    } else if (i.contentWindow) {  
       var d = i.contentWindow.document;  
    } else {  
       var d = window.frames[frameId].document;  
    }  
    if (d.location.href == "about:blank") {  
       return;  
    }  
    
    if (typeof(i.onComplete) == 'function') {
      i.onComplete(d.body.innerHTML);  
    }   
    document.body.removeChild(i);
  }
  
  function cleanup(obj){
     // clean up and return context to pool
    obj.reset();
    
		var busyCount = 0;
    for(t = 0; t <= this.poolSize; t++) {
      var tt = this.pool[this.ID + (t + 1)];
      if(tt && tt.busy)
        busyCount++;
    }
    if(busyCount == 0){
      window.setTimeout(function () { top.unQueueAsBusy(); }, 1);
    }
		
    //prevent mem leak in IE
    if(this.context.get("browser") == "IE") {
    	obj.requestObject.onreadystatechange = function(){};
    }
  }
}

function LoadContextAjax()
{
  if(!Cfx.Class.IsDefined(LoadContextAjax)) {
    Cfx.Class.New(LoadContextAjax);
    if(Cfx.Class.IsInitializing(LoadContextAjax))
    {
       LoadContextAjax.Method(init);
       LoadContextAjax.Method(setCallback);
       LoadContextAjax.Method(setReturnType);
       LoadContextAjax.Method(getResponse);
       
       LoadContextAjax.Method(call);
       LoadContextAjax.Method(handlePost);
       LoadContextAjax.Method(handleGet);
       
       LoadContextAjax.Method(reset);
       LoadContextAjax.Method(dispose);

       return;
    }
  }
  // Setup instance data.
  this.InitInstance();

  this.busy = true;
  this.requestObject;       
  this.callback;
  this.id = '';
  this.browser;
  this.log;
  this.sm;
  this.wrapperUrl;
  this.sync = true;
  this.returnType = RETURN_TEXT;
  
 
  // Return instance.
  return this;
  
  function init(id, browser, logger, serviceManager, wrapper) {
    this.id = id;
    this.browser = browser;
    this.log = logger;
    this.sm = serviceManager;
    this.wrapperUrl = wrapper;
  	this.requestObject = Cfx.Html.getHTTPRequest();
		//this.requestObject = new XMLHttpRequest();
  }
  
  function setCallback(_callback) {
	  this.callback = _callback;
	  this.sync = false;
  }
  
  function setReturnType(_type) {
	  this.returnType = _type;  	
  }
  
  function dispose() {
    this.reset();
    this.log = null;
    this.sm = null;
  	this.requestObject = null;
	  if(Cfx.Js.IsDefined(this.callback) && !Cfx.Js.IsNull(this.callback))
	    this.callback.dispose();
	  this.callback = null;
  }
  
  function reset() {
    this.returnType = RETURN_TEXT;
    this.busy = false;
    this.callback = null;
    this.sync = true;
    this.requestObject.onreadystatechange = function(){} //fix for IE closure?
  }
  
  function call(type, url, params) {
    this.busy = true;
   
    var sync = (Cfx.Js.IsBoolean(this.sync)) ? this.sync : true;
    params = (Cfx.Js.IsString(params) && !Cfx.Js.IsEmpty(params)) ? params : null;
    
    var myRequest = this.requestObject;
	  var myCallback = this.sm.lookup('framework.rc');
	  var myId = this.id;
	  var myReturnType = this.returnType;
		var unique = new Date().getTime() + '' + Math.floor(1000 * Math.random());  

		try{
	    myRequest.open(type, url + "?U=" + unique, !sync);
	    
	    if(!sync) {
			  myRequest.onreadystatechange = function() {
			    // only if req shows "loaded"
			    if (myRequest.readyState == 4) {
			      //get server message
						var thisStatusText = "";
						if(!Cfx.Js.IsDefined(myRequest.statusText)) {
						  thisStatusText = "HTTP Code " + myRequest.status + "\nNo server message available."
						}else {
						  thisStatusText = "HTTP Code " + myRequest.status + "\nServer responded, '" + myRequest.statusText + "'";
						}
						
						if (myRequest.status == 200) {
						  myCallback.loadSucces(myId);
						}else {
						  myCallback.loadFailed(myId, thisStatusText);
						}
				  }
			  }
		  }
      if(type.toLowerCase() == 'post') {
   	    myRequest.setRequestHeader( "Content-Type" , "application/x-www-form-urlencoded; charset=UTF-8" );
      } 
  	  myRequest.send(params);	
  	  if(sync) {
  	  	//implement get
  	  }
  	    
  	}catch(e) {
  	  this.log.error(e);
    }
  }
  
  function handlePost(toUrl, parameters) {
    if(!Cfx.Js.IsDefined(parameters) || Cfx.Js.IsNull(parameters)) {
      parameters = new Array();
    }
	  
	  var dataString = "";  
	  for(var i = 0; i < parameters.length; i++ ) {
	    if(parameters[i].key == 'url') {
	      toUrl += parameters[i].val;
	    }
	  
      parameterName = Cfx.Html.URLEncode(parameters[i].key);
	    parameterValue = Cfx.Html.URLEncode(parameters[i].val);
	    dataString += (parameterName + "=" + parameterValue);
	    
	    if(i<parameters.length) {
	      dataString += "&";
	    }
    }   
    
    if(this.log.debugging()) {
      this.log.debug("Posting a request.");
      this.log.debug("Request url: " + toUrl);
      for(var i=0; i<parameters.length ;i++) {
        this.log.debug("Parameter" + i+1 + ": " + parameters[i].key + "=" + parameters[i].val);
      }
    }
 	  //send post   
    return this.call("POST", toUrl, dataString);
  }
  
  function handleGet(toUrl) {
    if(this.log.debugging()) {
      this.log.debug("Posting a request.");
      this.log.debug("Request url: " + toUrl);
    }
    return this.call("GET", toUrl, null);
  }
  
  function getResponse() {
  	var result;
		switch(this.returnType) {
			case RETURN_XML:
			  result = this.requestObject.responseXML;
			  break;
			default:
			  result = this.requestObject.responseText;
			  break;
		}
    return result;
  }
}

function Callback()
{
  if(!Cfx.Class.IsDefined(Callback)) {
    Cfx.Class.New(Callback);
    if(Cfx.Class.IsInitializing(Callback))
    {
      Callback.Method(invokeCallback);
      Callback.Method(dispose);
      return;
    }
  }
  this.InitInstance();
  
  if(arguments.length < 2) throw new Error("Callback cannot be initialized without a callbackTarget and callbackMethod");
  this.target = arguments[0];
  this.func =   arguments[1];
  
  return this;
   
  function invokeCallback(str) {
    this.target[this.func](str);
  }
  
  function dispose() {
    this.target = null;
    this.func = null;
  }
}

⌨️ 快捷键说明

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