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

📄 remotecall.js

📁 Hippo CMS是一个以信息为中心的开源内容管理系统。Hippo CMS目标是供中,大型企业来管理其发布在互连网
💻 JS
字号:
/*
* Copyright 2001-2007 Hippo (www.hippo.nl)
*
* 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.
*/

function RemoteCall()
{
  if(!Cfx.Class.IsDefined(RemoteCall)) {
    Cfx.Class.New(RemoteCall, baseComponent);
    if(Cfx.Class.IsInitializing(RemoteCall))
    {
      RemoteCall.Method(init);
      RemoteCall.Method(doCall);
      RemoteCall.Method(doForm);         
      RemoteCall.Method(getContextID);
      RemoteCall.Method(loaded);
      RemoteCall.Method(loadedError);

      // this notation for IE only, MOZ doesnt recognize
      this.targetFrame = null;
      this.maxPoolSize = 0;
      this.poolSize = 0;
      this.pool = null;

      return;
    }
  }
  this.InitInstance();
  return this;
   
  function init() {
    if (this.log.debugging()) {
      this.log.debug("initializing RemoteCall");
    }
    this.targetFrame = this.context.get(this.config.container);
    this.maxPoolSize = this.config.maxPoolSize;
    this.poolSize = 0;
    this.pool = new Array(this.maxPoolSize);
    
  }
   
  function doCall(app, callback, params) {
    var contextObj = this.pool[this.getContextID()];
    if (contextObj) {
      if (this.log.debugging()) {
        this.log.debug("got a context object from pool");
      }
      contextObj.callback = callback;
      contextObj.busy = true;
      
      if (this.context.get("browser") == 'IE' || this.context.get("browser") == 'MOZ' || this.context.get("browser") == 'OPR') {
        var par1 = this.config.wrapper + app;
        var par2 = params;
        window.setTimeout(function () { top.queueAsBusy();  }, 1);
        window.setTimeout(function () { contextObj.post(par1, par2); }, 1);
      }
      return contextObj.id;
    } 
    else {
      return null;
    }
  }
   
  function doForm(url, callback, formHtml, formObject) {
    var contextObj = this.pool[this.getContextID()];
    if (contextObj) {
      if (this.log.debugging()) {
        this.log.debug("got a context object from pool");
      }
      contextObj.callback = callback;
      contextObj.busy = true;
      if ( this.context.get("browser") == 'IE' || this.context.get("browser") == 'MOZ' || this.context.get("browser") == 'OPR') {
        window.setTimeout(function () { contextObj.postForm(url, formHtml, formObject); }, 1);
        window.setTimeout(function () { top.queueAsBusy();  }, 1);
      }  
      return contextObj.id;
    }
    else {
      return null;
    }
  }
   
   
  function getContextID() {
    var contextObj;
    for(var i = 1; i <= this.poolSize; i++)
    {
      contextObj = this.pool['jsrs' + i];
      if(!contextObj.busy)
      {
        if (this.log.debugging()) {
          this.log.debug("found free context!");
        }
        contextObj.busy = true;
        return contextObj.id;
      }
    }
    // if we got here, there are no existing free contexts
    if (this.log.debugging()) {
      this.log.debug("no free context's in pool, poolSize=" + this.poolSize);
    }
    if(this.poolSize <= this.maxPoolSize)
    {
      // create new context
      var contextID = "jsrs" +(this.poolSize + 1);
      this.pool[contextID] = new LoadContext(contextID, this.context.get("browser"), this.targetFrame, this.log.getChildLogger("loadContext-" + contextID));
      this.poolSize++;
      return contextID;
    }
    else 
    {
      if (this.log.debugging()) {
        this.log.debug("context pool full");
      }
      return null;
    }
  }
    
  function loaded( contextID ) {

    if (this.log.debugging()) {
       this.log.debug("finished loading context:" + contextID);
    }
    
    // get context object and invoke callback
    var contextObj = this.pool[contextID];
    if(contextObj.callback != null) {
      if (this.log.debugging()) {
        this.log.debug("invoking context callback handler");  
      }
      contextObj.callback.load(contextObj.getPayLoad());
    }

    // clean up and return context to pool
    contextObj.callback = null;
    contextObj.busy = false;

    var busyCount = 0;
    for(t = 0; t <= this.poolSize; t++) {
      var tt = this.pool["jsrs" + (t + 1)];
      if(tt && tt.busy)
        busyCount++;
    }
    if(busyCount == 0){
      window.setTimeout(function () { top.unQueueAsBusy(); }, 1);
    }
    if (this.log.debugging()) {  
      this.log.debug("still " + busyCount + " loadContext obj in busy state");
    }
  }
  
  function loadedError( contextID ) {

    if (this.log.debugging()) {
       this.log.debug("finished loading context:" + contextID);
    }
    
    // get context object and invoke callback
    var contextObj = this.pool[contextID];
    if(contextObj.callback != null) {
      if (this.log.debugging()) {
        this.log.debug("invoking context callback handler");  
      }
      this.log.error(contextObj.getPayLoad())
      //contextObj.callback.load(contextObj.getPayLoad());
    }

    // clean up and return context to pool
    contextObj.callback = null;
    contextObj.busy = false;

    var busyCount = 0;
    for(t = 0; t <= this.poolSize; t++) {
      var tt = this.pool["jsrs" + (t + 1)];
      if(tt && tt.busy)
        busyCount++;
    }
    if(busyCount == 0){
      window.setTimeout(function () { top.unQueueAsBusy(); }, 1);
    }
    if (this.log.debugging()) {  
      this.log.debug("still " + busyCount + " loadContext obj in busy state");
    }
  }  
  
 }

function LoadContext()
{
  if(!Cfx.Class.IsDefined(LoadContext)) {
    Cfx.Class.New(LoadContext);
    if(Cfx.Class.IsInitializing(LoadContext))
    {
       LoadContext.Method(get);
       LoadContext.Method(post);
       LoadContext.Method(postForm);         
       LoadContext.Method(getPayLoad);
       LoadContext.Method(createContainer);

       LoadContext.busy = true;
       LoadContext.callback = null;
       LoadContext.container = null;
       return;
    }
  }
  // Setup instance data.
  this.InitInstance();
  if (arguments.length) {
    this.id = arguments[0];
    this.browser = arguments[1];
    this.targetFrame = arguments[2];
    this.log = arguments[3];
  }
  else {
    this.id = '';
  }

  this.createContainer();

  // Return instance.
  return this;
   
  function get() {}


  function postForm(url, formHtml, formObject) {
    // formHtml variable has become useless (NvK 20050526)
  
    if (this.browser == "IE")
    {
      var inEl = formObject.document.createElement("input");
      inEl.name = "C";
      inEl.id = "C";
      inEl.type = "hidden";
      inEl.value = this.id;
      formObject.appendChild(inEl);
      var actionPrefix = url.substring(0, url.lastIndexOf('/') + 1);
      var action = formObject.action;
      action = (action.indexOf('/') >= 0)?action.substring(action.lastIndexOf('/')+1):action; 
      formObject.action = "/workbench/remoteCall" +  actionPrefix + action;
      formObject.target = this.container.name;
      formObject.submit();
    }
    else if (this.browser == "MOZ")
    {
      var doc = this.container.contentDocument;
      doc.open();
      doc.write('<html><body>');
      var inEl = document.createElement("input");
      inEl.name = "C";
      inEl.id = "C";
      inEl.type = "hidden";
      inEl.value = this.id;
      formObject.appendChild(inEl);
      doc.body.appendChild(formObject);
      doc.write('</body></html>');
      doc.close();
      var actionPrefix = url.substring(0, url.lastIndexOf('/') + 1);
      var action = doc.forms[0].action;
      action = (action.indexOf('/') >= 0)?action.substring(action.lastIndexOf('/')+1):action; 
      doc.forms[0].action = "/workbench/remoteCall" +  actionPrefix + action;

      if (this.log.debugging()) {
        this.log.debug("postForm: form " + doc.forms[0].action);
      }  
      doc.forms[0].submit();
    } 
  }
  
  
  function post(rsPage, parms) {
    if(this.log.debugging())
      this.log.debug("handling a post to: " + rsPage);

    var d = new Date();
    var unique = d.getTime() + '' + Math.floor(1000 * Math.random());

    var doc = (this.browser == "IE" ) ? this.container.document : this.container.contentDocument;
    if (parms != null) {
      for( var i = 0; i < parms.length; i++ ) {

        if(this.log.debugging())
          this.log.debug("parameter: " + parms[i].key + "=" + parms[i].val);
  
        if(parms[i].key=='url') {
          rsPage += parms[i].val;
        }
      }
    }
    doc.open();
    doc.write('<html><body>');
    doc.write('<form name="jsrsForm" id="jsrsForm" method="post" target="" ');
    doc.write(' action="' + rsPage + '?U=' + unique + '">');
    doc.write('<input type="hidden" name="C" id="C" value="' + this.id + '">');
    
    if (parms != null){
      if (typeof(parms) == "string"){
        // single parameter
        doc.write( '<input type="hidden" name="P0" id="PO" '
                 + 'value="[' + jsrsEscapeQQ(parms) + ']">');
      } 
      else {
        // assume parms is array of strings
        for( var i=0; i < parms.length; i++ ){
          doc.write( '<input type="hidden" id='+parms[i].key+ '" name="'+parms[i].key+'" '
                   + 'value="'+parms[i].val+'">');
        }
      } // parm type
    } // parms

    doc.write('</form></body></html>');
    doc.close();
    doc.forms['jsrsForm'].submit();
    doc = null;
    
    if(this.log.debugging())
      this.log.debug("and posted it!");
  }
   
  function getPayLoad() {
    switch( this.browser ) {
      case 'NS':
        return this.container.document.forms['jsrs_Form'].elements['jsrs_Payload'].value;
      case 'IE':
        //return this.container.document.forms['jsrs_Form']['jsrs_Payload'].value;
        return this.container.document.getElementById('loaded').innerHTML;
      case 'MOZ':
        //alert(this.container.contentDocument.getElementById('loaded').innerHTML);
      		return this.container.contentDocument.getElementById('loaded').innerHTML;
        //return window.frames[this.container.name].document.forms['jsrs_Form']['jsrs_Payload'].value; 
      case 'OPR':
        return this.container.contentDocument.getElementById('loaded').innerHTML;
        //var textElement = window.frames[this.container.name].document.getElementById("jsrs_Payload");
      case 'KONQ':
        var textElement = window.frames[this.container.name].document.getElementById("jsrs_Payload");
        return textElement.value;
    }  
  }
   
  function createContainer() {
    if(this.log.debugging())
      this.log.debug("creating a hidden container");
      
    switch(this.browser) {
      case 'NS' : 
        this.container = new this.targetFrame.Layer(100);
        this.container.name = this.id;
        this.container.visibility = 'hidden';
        this.container.clip.width = 100;
        this.container.clip.height = 100;
        break;
      case 'IE' : 
        this.targetFrame.document.body.insertAdjacentHTML("afterBegin", '<span id="SPAN' + this.id + '"></span>');
        var span = this.targetFrame.document.all("SPAN" + this.id);
        var html = '<iframe name="' + this.id+ '" src=""></iframe>';
        span.innerHTML = html;
        span.style.display = 'none';
        this.container = window.frames[this.id];
        break;
      case 'MOZ' :
        var span = this.targetFrame.document.createElement('SPAN');
        span.id = "SPAN" + this.id;
        this.targetFrame.document.body.appendChild(span);
        var iframe = this.targetFrame.document.createElement('IFRAME');
        iframe.name = this.id;
        iframe.id = this.id;
        span.appendChild(iframe);
        // Comment the next line to show the hidden div's
        span.style.visibility='hidden';
        this.container = iframe;            
        break;
      case 'OPR' :
        var span = this.targetFrame.document.createElement('SPAN');
        span.id = "SPAN" + this.id;
        // Comment the next line to show the hidden div's
        //span.style.display='none';
        this.targetFrame.document.body.appendChild(span);
        var iframe = this.targetFrame.document.createElement('IFRAME');
        iframe.name = this.id;
        iframe.id = this.id;
        span.appendChild(iframe);
        this.container = iframe;            
        break;
            /*            
         case 'KONQ' :
            var span = document.createElement('SPAN');
            span.id = "SPAN" + containerName;
            document.body.appendChild(span);
            var iframe = document.createElement('IFRAME');
            iframe.name = containerName;
            iframe.id = containerName;
            span.appendChild(iframe);
            container = iframe;
            // Needs to be hidden for Konqueror, otherwise it'll appear on the page
            span.style.display = none;
            iframe.style.display = none;
            iframe.style.visibility = hidden;
            iframe.height = 0;
            iframe.width = 0;
            break; */
      }
   }
}

⌨️ 快捷键说明

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