first commit
This commit is contained in:
296
resources/xajax/xajax_plugins/response/comet/comet.inc.php
Normal file
296
resources/xajax/xajax_plugins/response/comet/comet.inc.php
Normal file
@@ -0,0 +1,296 @@
|
||||
<?php
|
||||
define('FILE_APPEND', 1);
|
||||
|
||||
/*
|
||||
File: comet.inc.php
|
||||
|
||||
|
||||
Title: clsCometStreaming class
|
||||
|
||||
*/
|
||||
|
||||
if (false == class_exists('xajaxPlugin') || false == class_exists('xajaxPluginManager'))
|
||||
{
|
||||
$sBaseFolder = dirname(dirname(dirname(__FILE__)));
|
||||
$sXajaxCore = $sBaseFolder . '/xajax_core';
|
||||
|
||||
if (false == class_exists('xajaxPlugin'))
|
||||
require $sXajaxCore . '/xajaxPlugin.inc.php';
|
||||
if (false == class_exists('xajaxPluginManager'))
|
||||
require $sXajaxCore . '/xajaxPluginManager.inc.php';
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Class: clsCometStreaming
|
||||
*/
|
||||
class clsCometStreaming extends xajaxResponsePlugin
|
||||
{
|
||||
/*
|
||||
String: sDefer
|
||||
|
||||
Used to store the state of the scriptDeferral configuration setting. When
|
||||
script deferral is desired, this member contains 'defer' which will request
|
||||
that the browser defer loading of the javascript until the rest of the page
|
||||
has been loaded.
|
||||
*/
|
||||
var $sDefer;
|
||||
|
||||
/*
|
||||
String: sJavascriptURI
|
||||
|
||||
Used to store the base URI for where the javascript files are located. This
|
||||
enables the plugin to generate a script reference to it's javascript file
|
||||
if the javascript code is NOT inlined.
|
||||
*/
|
||||
var $sJavascriptURI;
|
||||
|
||||
/*
|
||||
Boolean: bInlineScript
|
||||
|
||||
Used to store the value of the inlineScript configuration option. When true,
|
||||
the plugin will return it's javascript code as part of the javascript header
|
||||
for the page, else, it will generate a script tag referencing the file by
|
||||
using the <clsTableUpdater->sJavascriptURI>.
|
||||
*/
|
||||
var $bInlineScript;
|
||||
|
||||
|
||||
var $fTimeOut;
|
||||
/*
|
||||
Function: clsTableUpdater
|
||||
|
||||
Constructs and initializes an instance of the table updater class.
|
||||
*/
|
||||
function clsCometStreaming()
|
||||
{
|
||||
$this->sDefer = '';
|
||||
$this->sJavascriptURI = '';
|
||||
$this->bInlineScript = false;
|
||||
}
|
||||
/*
|
||||
Function: configure
|
||||
|
||||
Receives configuration settings set by <xajax> or user script calls to
|
||||
<xajax->configure>.
|
||||
|
||||
sName - (string): The name of the configuration option being set.
|
||||
mValue - (mixed): The value being associated with the configuration option.
|
||||
*/
|
||||
function configure($sName, $mValue)
|
||||
{
|
||||
if ('scriptDeferral' == $sName) {
|
||||
if (true === $mValue || false === $mValue) {
|
||||
if ($mValue) $this->sDefer = 'defer ';
|
||||
else $this->sDefer = '';
|
||||
}
|
||||
} else if ('javascript URI' == $sName) {
|
||||
$this->sJavascriptURI = $mValue;
|
||||
} else if ('inlineScript' == $sName) {
|
||||
if (true === $mValue || false === $mValue)
|
||||
$this->bInlineScript = $mValue;
|
||||
} else if ('cometsleeptimout' == strtolower($sName) ) {
|
||||
if ( is_numeric($mValue) )
|
||||
$this->fTimeOut = $mValue;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: generateClientScript
|
||||
|
||||
Called by the <xajaxPluginManager> during the script generation phase.
|
||||
|
||||
*/
|
||||
function generateClientScript()
|
||||
{
|
||||
if ($this->bInlineScript)
|
||||
{
|
||||
echo "\n<script type='text/javascript' " . $this->sDefer . "charset='UTF-8'>\n";
|
||||
echo "/* <![CDATA[ */\n";
|
||||
|
||||
include(dirname(__FILE__) . 'xajax_plugins/response/comet/comet.js');
|
||||
|
||||
echo "/* ]]> */\n";
|
||||
echo "</script>\n";
|
||||
} else {
|
||||
echo "\n<script type='text/javascript' src='" . $this->sJavascriptURI . "xajax_plugins/response/comet/comet.js' " . $this->sDefer . "charset='UTF-8'></script>\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class xajaxCometResponse extends xajaxResponse
|
||||
{
|
||||
var $bHeaderSent = false;
|
||||
var $fTimeOut=1;
|
||||
|
||||
|
||||
/*
|
||||
Function: xajaxCometResponse
|
||||
|
||||
calls parent function xajaxResponse();
|
||||
*/
|
||||
|
||||
function xajaxCometResponse($fTimeOut=false)
|
||||
{
|
||||
|
||||
if ( false != $fTimeOut ) $this->fTimeOut=$fTimeOut;
|
||||
|
||||
parent::__construct();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
Function: printOutput
|
||||
|
||||
override the original printOutput function. It's no longer needed since the output is already sent.
|
||||
*/
|
||||
|
||||
function printOutput()
|
||||
{
|
||||
$this->flush();
|
||||
if ( "HTML5DRAFT" == $_REQUEST['xjxstreaming']) {
|
||||
|
||||
$response = "";
|
||||
$response .= "Event: xjxendstream\n";
|
||||
$response .= "data: done\n";
|
||||
$response .= "\n";
|
||||
print $response;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: flush_XHR
|
||||
|
||||
Flushes the command queue for comet browsers.
|
||||
*/
|
||||
|
||||
function flush_XHR()
|
||||
{
|
||||
|
||||
if (!$this->bHeaderSent)
|
||||
{
|
||||
$this->_sendHeaders();
|
||||
$this->bHeaderSent=true;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
$this->_printResponse_XML();
|
||||
$c = ob_get_contents();
|
||||
ob_get_clean();
|
||||
$c = str_replace(chr(1)," ",$c);
|
||||
$c = str_replace(chr(2)," ",$c);
|
||||
$c = str_replace(chr(31)," ",$c);
|
||||
$c = str_replace(""," ",$c);
|
||||
if ($c == "<xjx></xjx>") return false;
|
||||
print $c;
|
||||
ob_flush();
|
||||
flush();
|
||||
$this->sleep( $this->fTimeOut );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Function: flush_activeX
|
||||
|
||||
Flushes the command queue for ActiveX browsers.
|
||||
*/
|
||||
|
||||
function flush_activeX()
|
||||
{
|
||||
ob_start();
|
||||
$this->_printResponse_XML();
|
||||
$c = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
$c = '<?xml version="1.0" ?>'.$c;
|
||||
$c = str_replace('"','\"',$c);
|
||||
$c = str_replace("\n",'\n',$c);
|
||||
$c = str_replace("\r",'\r',$c);
|
||||
|
||||
$response = "";
|
||||
$response .= "<script>top.document.callback(\"";
|
||||
$response .= $c;
|
||||
$response .= "\");</script>";
|
||||
|
||||
|
||||
print $response;
|
||||
ob_flush();
|
||||
flush();
|
||||
$this->sleep( $this->fTimeOut-0.1 );
|
||||
}
|
||||
|
||||
/*
|
||||
Function: flush_HTML5DRAFT
|
||||
|
||||
Flushes the command queue for HTML5DRAFT browsers.
|
||||
*/
|
||||
|
||||
function flush_HTML5DRAFT()
|
||||
{
|
||||
|
||||
|
||||
if (!$this->bHeaderSent)
|
||||
{
|
||||
header("Content-Type: application/x-dom-event-stream");
|
||||
$this->bHeaderSent=1;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
$this->_printResponse_XML();
|
||||
$c = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$c = str_replace("\n",'\n',$c);
|
||||
$c = str_replace("\r",'\r',$c);
|
||||
$response = "";
|
||||
$response .= "Event: xjxstream\n";
|
||||
$response .= "data: $c\n";
|
||||
$response .= "\n";
|
||||
print $response;
|
||||
ob_flush();
|
||||
flush();
|
||||
$this->sleep( $this->fTimeOut );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Function: flush
|
||||
|
||||
Determines which browser is wating for a response and calls the according flush function.
|
||||
*/
|
||||
function flush()
|
||||
{
|
||||
if (0 == count($this->aCommands)) return false;
|
||||
if ("xhr" == $_SERVER['HTTP_STREAMING'])
|
||||
{
|
||||
$this->flush_XHR();
|
||||
}
|
||||
elseif ( "HTML5DRAFT" == $_REQUEST['xjxstreaming'])
|
||||
{
|
||||
$this->flush_HTML5DRAFT();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->flush_activeX();
|
||||
}
|
||||
$this->aCommands=array();
|
||||
}
|
||||
|
||||
/*
|
||||
Function: sleep
|
||||
|
||||
Very accurate sleep function.
|
||||
*/
|
||||
function sleep($seconds)
|
||||
{
|
||||
usleep(floor($seconds*1000000));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$objPluginManager =& xajaxPluginManager::getInstance();
|
||||
$objPluginManager->registerPlugin(new clsCometStreaming());
|
||||
102
resources/xajax/xajax_plugins/response/comet/comet.js
Normal file
102
resources/xajax/xajax_plugins/response/comet/comet.js
Normal file
@@ -0,0 +1,102 @@
|
||||
|
||||
try{if(undefined==xajax.ext)
|
||||
xajax.ext={};}
|
||||
catch(e){}
|
||||
try{if(undefined==xajax.ext.comet)
|
||||
xajax.ext.comet={};}
|
||||
catch(e){alert("Could not create xajax.ext.comet namespace");}
|
||||
xjxEc=xajax.ext.comet;xjxEc.detectSupport=function(){var agt=navigator.userAgent.toLowerCase();if(agt.indexOf("opera")!=-1)
|
||||
return 'Opera';if(agt.indexOf("staroffice")!=-1)
|
||||
return 'Star Office';if(agt.indexOf("webtv")!=-1)
|
||||
return 'WebTV';if(agt.indexOf("beonex")!=-1)
|
||||
return 'Beonex';if(agt.indexOf("chimera")!=-1)
|
||||
return 'Chimera';if(agt.indexOf("netpositive")!=-1)
|
||||
return 'NetPositive';if(agt.indexOf("phoenix")!=-1)
|
||||
return 'Phoenix';if(agt.indexOf("firefox")!=-1)
|
||||
return 'Firefox';if(agt.indexOf("safari")!=-1)
|
||||
return 'Safari';if(agt.indexOf("skipstone")!=-1)
|
||||
return 'SkipStone';if(agt.indexOf("msie")!=-1)
|
||||
return 'Internet Explorer';if(agt.indexOf("netscape")!=-1)
|
||||
return 'Netscape';if(agt.indexOf("mozilla/5.0")!=-1)
|
||||
return 'Mozilla';if(agt.indexOf('\/')!=-1){if(agt.substr(0,agt.indexOf('\/'))!='mozilla'){return navigator.userAgent.substr(0,agt.indexOf('\/'));}
|
||||
else
|
||||
return 'Netscape';}
|
||||
else if(agt.indexOf(' ')!=-1)
|
||||
return navigator.userAgent.substr(0,agt.indexOf(' '));else
|
||||
return navigator.userAgent;return false;}
|
||||
xjxEc.prepareRequestXHR=function(oRequest){if(true==oRequest.comet){var xx=xajax;var xt=xx.tools;oRequest.request=xt.getRequestObject();oRequest.setRequestHeaders=function(headers){if('object'==typeof headers){for(var optionName in headers)
|
||||
this.request.setRequestHeader(optionName,headers[optionName]);}
|
||||
}
|
||||
oRequest.setCommonRequestHeaders=function(){this.setRequestHeaders(this.commonHeaders);}
|
||||
oRequest.setPostRequestHeaders=function(){this.setRequestHeaders(this.postHeaders);}
|
||||
oRequest.setGetRequestHeaders=function(){this.setRequestHeaders(this.getHeaders);}
|
||||
oRequest.applyRequestHeaders=function(){}
|
||||
oRequest.setCommonRequestHeaders=function(){this.request.setRequestHeader('If-Modified-Since','Sat, 1 Jan 2000 00:00:00 GMT');this.request.setRequestHeader('streaming','xhr');if(typeof(oRequest.header)=="object"){for(a in oRequest.header)
|
||||
this.request.setRequestHeader(a,oRequest.header[a]);}
|
||||
}
|
||||
oRequest.comet={};oRequest.comet.LastPosition=0;oRequest.comet.inProgress=false;var pollLatestResponse=function(){console.log('pollLatestResponse');xjxEc.responseProcessor.XHR(oRequest);}
|
||||
oRequest.pollTimer=setInterval(pollLatestResponse,300);oRequest.request.onreadystatechange=function(){if(oRequest.request.readyState < 3){console.log('readyState < 3');return;}
|
||||
if(oRequest.request.readyState==4){console.log('readyState == 4');clearInterval(oRequest.pollTimer);xjxEc.responseProcessor.XHR(oRequest);xajax.completeResponse(oRequest);return;}
|
||||
}
|
||||
oRequest.finishRequest=function(){return this.returnValue;}
|
||||
if('undefined'!=typeof oRequest.userName&&'undefined'!=typeof oRequest.password){oRequest.open=function(){this.request.open(this.method,this.requestURI,true,oRequest.userName,oRequest.password);}
|
||||
}
|
||||
else{oRequest.open=function(){this.request.open(this.method,this.requestURI,true);}
|
||||
}
|
||||
if('POST'==oRequest.method){oRequest.applyRequestHeaders=function(){this.setCommonRequestHeaders();try{this.setPostRequestHeaders();}
|
||||
catch(e){this.method='GET';this.requestURI+=this.requestURI.indexOf('?')==-1 ? '?':'&';this.requestURI+=this.requestData;this.requestData='';if(0==this.requestRetry)
|
||||
this.requestRetry=1;throw e;}
|
||||
}
|
||||
}
|
||||
else{oRequest.applyRequestHeaders=function(){this.setCommonRequestHeaders();this.setGetRequestHeaders();}
|
||||
}
|
||||
return;}
|
||||
return xjxEc.prepareRequest(oRequest);}
|
||||
xjxEc.connect_htmlfile=function(url,callback,oRequest){try{xjxEc.transferDoc=new ActiveXObject("htmlfile");xjxEc.transferDoc.open();xjxEc.transferDoc.write("<html>");xjxEc.transferDoc.write("<script>document.domain='http://192.168.1.21/';</script>");xjxEc.transferDoc.write("</html>");xjxEc.transferDoc.close();xjxEc.ifrDiv=xjxEc.transferDoc.createElement("div");xjxEc.transferDoc.body.appendChild(xjxEc.ifrDiv);xjxEc.ifrDiv.innerHTML="<iframe src='"+url+"'></iframe>";xjxEc.transferDoc.callback=function(response){callback(response,oRequest);};}
|
||||
catch(ex){}
|
||||
}
|
||||
xjxEc.prepareRequestActiveX=function(oRequest){if(true==oRequest.comet){var xx=xajax;var xt=xx.tools;oRequest.requestURI+=oRequest.requestURI.indexOf('?')==-1 ? '?':'&';oRequest.requestURI+=oRequest.requestData;oRequest.requestData='';try{xjxEc.connect_htmlfile(oRequest.requestURI,xjxEc.responseProcessor.ActiveX,oRequest);if(0 < oRequest.requestRetry)
|
||||
oRequest.requestRetry=0;}
|
||||
catch(ex){}
|
||||
return;}
|
||||
return xjxEc.prepareRequest(oRequest);}
|
||||
xjxEc.prepareRequestHTMLDRAFT=function(oRequest){if(true==oRequest.comet){var xx=xajax;var xt=xx.tools;oRequest.requestURI+=oRequest.requestURI.indexOf('?')==-1 ? '?':'&';oRequest.requestURI+=oRequest.requestData;oRequest.requestURI+="&xjxstreaming=HTML5DRAFT";oRequest.inProgress=false;try{var uri=oRequest.requestURI;var es=document.createElement("event-source");es.setAttribute("src",uri);es.setAttribute("width",200);es.setAttribute("height",200);es.style.display="block";callback=function(event){xjxEc.responseProcessor.HTMLDRAFT(event.data,oRequest);};remove=function(){es.removeEventListener("xjxstream",callback,false);es.removeEventListener("xjxendstream",remove,false);}
|
||||
es.addEventListener("xjxstream",callback,false);es.addEventListener("xjxendstream",remove,false);document.body.appendChild(es);if(0 < oRequest.requestRetry)
|
||||
oRequest.requestRetry=0;}
|
||||
catch(ex){}
|
||||
return;}
|
||||
return xjxEc.prepareRequest(oRequest);}
|
||||
xajax.debug={};xajax.debug.prepareDebugText=function(text){try{text=text.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/\n/g,'<br />');return text;}
|
||||
catch(e){xajax.debug.stringReplace=function(haystack,needle,newNeedle){var segments=haystack.split(needle);haystack='';for(var i=0;i < segments.length;++i){if(0!=i)
|
||||
haystack+=newNeedle;haystack+=segments[i];}
|
||||
return haystack;}
|
||||
xajax.debug.prepareDebugText=function(text){text=xajax.debug.stringReplace(text,'&','&');text=xajax.debug.stringReplace(text,'<','<');text=xajax.debug.stringReplace(text,'>','>');text=xajax.debug.stringReplace(text,'\n','<br />');return text;}
|
||||
xajax.debug.prepareDebugText(text);}
|
||||
}
|
||||
xjxEc.responseProcessor={}
|
||||
xjxEc.responseProcessor.XHR=function(oRequest){var xx=xajax;var xt=xx.tools;var xcb=xx.callback;var gcb=xcb.global;var lcb=oRequest.callback;var oRet=oRequest.returnValue;if(""==oRequest.request.responseText)
|
||||
return;var allMessages=oRequest.request.responseText;if(true===oRequest.comet.inProgress)return;oRequest.comet.inProgress=true;do{var unprocessed=allMessages.substring(oRequest.comet.LastPosition);var messageXMLEndIndex=unprocessed.indexOf("</xjx>");if(messageXMLEndIndex!=-1){var endOfFirstMessageIndex=messageXMLEndIndex+("</xjx>").length;var anUpdate=unprocessed.substring(0,endOfFirstMessageIndex);var cmd=(new DOMParser()).parseFromString(anUpdate,"text/xml");try{var seq=0;var child=cmd.documentElement.firstChild;xt.xml.processFragment(child,seq,oRet,oRequest);}
|
||||
catch(ex){}
|
||||
xt.queue.process(xx.response);oRequest.comet.LastPosition+=endOfFirstMessageIndex;}
|
||||
}while(messageXMLEndIndex!=-1);oRequest.comet.inProgress=false;return oRet;}
|
||||
xjxEc.responseProcessor.ActiveX=function(response,oRequest){response.replace('\"','"');var xx=xajax;var xt=xx.tools;var xcb=xx.callback;var gcb=xcb.global;var lcb=oRequest.callback;var oRet=oRequest.returnValue;if(response){var cmd=(new DOMParser()).parseFromString(response,"text/xml");var seq=0;var child=cmd.documentElement.firstChild;xt.xml.processFragment(child,seq,oRequest);if(null==xx.response.timeout)
|
||||
xt.queue.process(xx.response);}
|
||||
return oRet;}
|
||||
xjxEc.responseProcessor.HTMLDRAFT=function(response,oRequest){var xx=xajax;var xt=xx.tools;var xcb=xx.callback;var gcb=xcb.global;var lcb=oRequest.callback;var oRet=oRequest.returnValue;if(oRequest.inProgress)return;if(response&&oRequest.lastResponse!==response){oRequest.inProgress=true;var cmd=(new DOMParser()).parseFromString(response,"text/xml");var seq=0;var child=cmd.documentElement.firstChild;xt.xml.processFragment(child,seq,oRequest);if(null==xx.response.timeout)
|
||||
xt.queue.process(xx.response);oRequest.inProgress=false;oRequest.lastResponse=response
|
||||
}
|
||||
return oRet;}
|
||||
xjxEc.submitRequestActiveX=function(oRequest){if(true==oRequest.comet)
|
||||
return;xjxEc.submitRequest(oRequest);}
|
||||
xjxEc.prepareRequest=xajax.prepareRequest;xjxEc.stream_support=xjxEc.detectSupport();switch(xjxEc.stream_support){case "Internet Explorer":
|
||||
xajax.prepareRequest=xjxEc.prepareRequestActiveX;xjxEc.submitRequest=xajax.submitRequest;xajax.submitRequest=xjxEc.submitRequestActiveX;break;case "Firefox":
|
||||
case "Safari":
|
||||
xajax.prepareRequest=xjxEc.prepareRequestXHR;break;case "Opera":
|
||||
xajax.prepareRequest=xjxEc.prepareRequestHTMLDRAFT;xjxEc.submitRequest=xajax.submitRequest;xajax.submitRequest=xjxEc.submitRequestActiveX;break;default:
|
||||
alert("Xajax.Ext.Comet: Your browser does not support comet streaming or is not yet supported by this plugin!");}
|
||||
if(typeof DOMParser=="undefined"){DOMParser=function(){}
|
||||
DOMParser.prototype.parseFromString=function(str,contentType){if(typeof ActiveXObject!="undefined"){var d=new ActiveXObject("Microsoft.XMLDOM");d.loadXML(str);return d;}
|
||||
else if(typeof XMLHttpRequest!="undefined"){var req=new XMLHttpRequest;req.open("GET","data:"+(contentType||"application/xml")+";charset=utf-8,"+encodeURIComponent(str),false);if(req.overrideMimeType){req.overrideMimeType(contentType);}
|
||||
req.send(null);return req.responseXML;}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,624 @@
|
||||
/*
|
||||
File: comet.js
|
||||
|
||||
Title: Comet plugin for xajax
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
@package comet plugin
|
||||
@version $Id:
|
||||
@copyright Copyright (c) 2007 by Steffen Konerow (IE)
|
||||
@license http://www.xajaxproject.org/bsd_license.txt BSD License
|
||||
*/
|
||||
|
||||
/*
|
||||
Class: xajax.ext.comet
|
||||
|
||||
This class contains all functions for using comet streaming with xajax.
|
||||
|
||||
*/
|
||||
|
||||
try
|
||||
{
|
||||
if (undefined == xajax.ext)
|
||||
xajax.ext = {
|
||||
};
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (undefined == xajax.ext.comet)
|
||||
xajax.ext.comet = {
|
||||
};
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
alert("Could not create xajax.ext.comet namespace");
|
||||
}
|
||||
|
||||
// create Shorthand for xajax.ext.comet
|
||||
xjxEc = xajax.ext.comet;
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
Function: detectSupport
|
||||
|
||||
Detects browser for using fallback methods instead of multipart XHR responses.
|
||||
*/
|
||||
xjxEc.detectSupport = function()
|
||||
{
|
||||
var agt = navigator.userAgent.toLowerCase();
|
||||
|
||||
if (agt.indexOf("opera") != -1)
|
||||
return 'Opera';
|
||||
|
||||
if (agt.indexOf("staroffice") != -1)
|
||||
return 'Star Office';
|
||||
|
||||
if (agt.indexOf("webtv") != -1)
|
||||
return 'WebTV';
|
||||
|
||||
if (agt.indexOf("beonex") != -1)
|
||||
return 'Beonex';
|
||||
|
||||
if (agt.indexOf("chimera") != -1)
|
||||
return 'Chimera';
|
||||
|
||||
if (agt.indexOf("netpositive") != -1)
|
||||
return 'NetPositive';
|
||||
|
||||
if (agt.indexOf("phoenix") != -1)
|
||||
return 'Phoenix';
|
||||
|
||||
if (agt.indexOf("firefox") != -1)
|
||||
return 'Firefox';
|
||||
|
||||
if (agt.indexOf("safari") != -1)
|
||||
return 'Safari';
|
||||
|
||||
if (agt.indexOf("skipstone") != -1)
|
||||
return 'SkipStone';
|
||||
|
||||
if (agt.indexOf("msie") != -1)
|
||||
return 'Internet Explorer';
|
||||
|
||||
if (agt.indexOf("netscape") != -1)
|
||||
return 'Netscape';
|
||||
|
||||
if (agt.indexOf("mozilla/5.0") != -1)
|
||||
return 'Mozilla';
|
||||
|
||||
if (agt.indexOf('\/') != -1)
|
||||
{
|
||||
if (agt.substr(0, agt.indexOf('\/')) != 'mozilla')
|
||||
{
|
||||
return navigator.userAgent.substr(0, agt.indexOf('\/'));
|
||||
}
|
||||
else
|
||||
return 'Netscape';
|
||||
}
|
||||
else if (agt.indexOf(' ') != -1)
|
||||
return navigator.userAgent.substr(0, agt.indexOf(' '));
|
||||
else
|
||||
return navigator.userAgent;
|
||||
|
||||
// if (navigator.appVersion.indexOf("MSIE")!=-1)
|
||||
// {
|
||||
// var version,temp;
|
||||
// temp=navigator.appVersion.split("MSIE")
|
||||
// version=parseFloat(temp[1])
|
||||
// if (version>=5.5) return "MSIE";
|
||||
// }
|
||||
// if ( "undefined" != typeof window.opera )
|
||||
// {
|
||||
// return "OPERA";
|
||||
// }
|
||||
// if ( "undefined" != typeof window.Iterator )
|
||||
// {
|
||||
// return "FF2";
|
||||
// }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
Function: prepareRequestXHR
|
||||
|
||||
Prepares the XMLHttpRequest object for this xajax request in FF/Safari browsers.
|
||||
|
||||
*/
|
||||
|
||||
xjxEc.prepareRequestXHR = function (oRequest)
|
||||
{
|
||||
if (true == oRequest.comet)
|
||||
{
|
||||
var xx = xajax;
|
||||
var xt = xx.tools;
|
||||
oRequest.request = xt.getRequestObject();
|
||||
|
||||
oRequest.setRequestHeaders = function(headers)
|
||||
{
|
||||
if ('object' == typeof headers)
|
||||
{
|
||||
for (var optionName in headers)
|
||||
this.request.setRequestHeader(optionName, headers[optionName]);
|
||||
}
|
||||
}
|
||||
oRequest.setCommonRequestHeaders = function()
|
||||
{
|
||||
this.setRequestHeaders(this.commonHeaders);
|
||||
}
|
||||
oRequest.setPostRequestHeaders = function()
|
||||
{
|
||||
this.setRequestHeaders(this.postHeaders);
|
||||
}
|
||||
oRequest.setGetRequestHeaders = function()
|
||||
{
|
||||
this.setRequestHeaders(this.getHeaders);
|
||||
}
|
||||
|
||||
oRequest.applyRequestHeaders = function()
|
||||
{
|
||||
}
|
||||
|
||||
oRequest.setCommonRequestHeaders = function()
|
||||
{
|
||||
this.request.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
|
||||
this.request.setRequestHeader('streaming', 'xhr');
|
||||
|
||||
if (typeof (oRequest.header) == "object")
|
||||
{
|
||||
for (a in oRequest.header)
|
||||
this.request.setRequestHeader(a, oRequest.header[a]);
|
||||
}
|
||||
}
|
||||
oRequest.comet = {
|
||||
};
|
||||
|
||||
oRequest.comet.LastPosition = 0;
|
||||
oRequest.comet.inProgress = false;
|
||||
var pollLatestResponse = function()
|
||||
{
|
||||
|
||||
console.log('pollLatestResponse');
|
||||
xjxEc.responseProcessor.XHR(oRequest);
|
||||
}
|
||||
oRequest.pollTimer = setInterval(pollLatestResponse, 300);
|
||||
oRequest.request.onreadystatechange = function()
|
||||
{
|
||||
if (oRequest.request.readyState < 3)
|
||||
{
|
||||
console.log('readyState < 3');
|
||||
return;
|
||||
}
|
||||
if (oRequest.request.readyState == 4)
|
||||
{
|
||||
console.log('readyState == 4');
|
||||
clearInterval(oRequest.pollTimer);
|
||||
xjxEc.responseProcessor.XHR(oRequest);
|
||||
//xajax.responseReceived(oRequest);
|
||||
xajax.completeResponse(oRequest);
|
||||
return;
|
||||
}
|
||||
}
|
||||
oRequest.finishRequest = function()
|
||||
{
|
||||
return this.returnValue;
|
||||
}
|
||||
|
||||
if ('undefined' != typeof oRequest.userName && 'undefined' != typeof oRequest.password)
|
||||
{
|
||||
oRequest.open = function()
|
||||
{
|
||||
this.request.open(this.method, this.requestURI, true, oRequest.userName, oRequest.password);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
oRequest.open = function()
|
||||
{
|
||||
this.request.open(this.method, this.requestURI, true);
|
||||
}
|
||||
}
|
||||
|
||||
if ('POST' == oRequest.method)
|
||||
{ // W3C: Method is case sensitive
|
||||
oRequest.applyRequestHeaders = function()
|
||||
{
|
||||
this.setCommonRequestHeaders();
|
||||
|
||||
try
|
||||
{
|
||||
this.setPostRequestHeaders();
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
this.method = 'GET';
|
||||
this.requestURI += this.requestURI.indexOf('?') == -1 ? '?' : '&';
|
||||
this.requestURI += this.requestData;
|
||||
this.requestData = '';
|
||||
|
||||
if (0 == this.requestRetry)
|
||||
this.requestRetry = 1;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
oRequest.applyRequestHeaders = function()
|
||||
{
|
||||
this.setCommonRequestHeaders();
|
||||
this.setGetRequestHeaders();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
return xjxEc.prepareRequest(oRequest);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
Function: connect_htmlfile
|
||||
|
||||
Create a hidden iframe for IE
|
||||
|
||||
*/
|
||||
xjxEc.connect_htmlfile = function (url, callback, oRequest)
|
||||
{
|
||||
try
|
||||
{
|
||||
xjxEc.transferDoc = new ActiveXObject("htmlfile");
|
||||
xjxEc.transferDoc.open();
|
||||
xjxEc.transferDoc.write("<html>");
|
||||
xjxEc.transferDoc.write("<script>document.domain='http://192.168.1.21/';</script>");
|
||||
xjxEc.transferDoc.write("</html>");
|
||||
xjxEc.transferDoc.close();
|
||||
xjxEc.ifrDiv = xjxEc.transferDoc.createElement("div");
|
||||
xjxEc.transferDoc.body.appendChild(xjxEc.ifrDiv);
|
||||
xjxEc.ifrDiv.innerHTML = "<iframe src='" + url + "'></iframe>";
|
||||
xjxEc.transferDoc.callback = function (response)
|
||||
{
|
||||
callback(response, oRequest);
|
||||
};
|
||||
}
|
||||
catch (ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
Function: prepareRequestActiveX
|
||||
|
||||
Prepares the Iframe for streaming with active X
|
||||
|
||||
*/
|
||||
|
||||
xjxEc.prepareRequestActiveX = function(oRequest)
|
||||
{
|
||||
if (true == oRequest.comet)
|
||||
{
|
||||
var xx = xajax;
|
||||
var xt = xx.tools;
|
||||
oRequest.requestURI += oRequest.requestURI.indexOf('?') == -1 ? '?' : '&';
|
||||
oRequest.requestURI += oRequest.requestData;
|
||||
oRequest.requestData = '';
|
||||
|
||||
try
|
||||
{
|
||||
xjxEc.connect_htmlfile(oRequest.requestURI, xjxEc.responseProcessor.ActiveX, oRequest);
|
||||
|
||||
if (0 < oRequest.requestRetry)
|
||||
oRequest.requestRetry = 0;
|
||||
}
|
||||
catch (ex)
|
||||
{
|
||||
}
|
||||
return;
|
||||
}
|
||||
return xjxEc.prepareRequest(oRequest);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
Function: prepareRequestHTMLDRAFT
|
||||
|
||||
Prepares streaming with HTML 5 Draft
|
||||
|
||||
*/
|
||||
|
||||
xjxEc.prepareRequestHTMLDRAFT = function(oRequest)
|
||||
{
|
||||
if (true == oRequest.comet)
|
||||
{
|
||||
var xx = xajax;
|
||||
var xt = xx.tools;
|
||||
oRequest.requestURI += oRequest.requestURI.indexOf('?') == -1 ? '?' : '&';
|
||||
oRequest.requestURI += oRequest.requestData;
|
||||
oRequest.requestURI += "&xjxstreaming=HTML5DRAFT";
|
||||
oRequest.inProgress = false;
|
||||
|
||||
try
|
||||
{
|
||||
var uri = oRequest.requestURI;
|
||||
var es = document.createElement("event-source");
|
||||
es.setAttribute("src", uri);
|
||||
es.setAttribute("width", 200);
|
||||
es.setAttribute("height", 200);
|
||||
es.style.display = "block";
|
||||
callback = function(event)
|
||||
{
|
||||
xjxEc.responseProcessor.HTMLDRAFT(event.data, oRequest);
|
||||
};
|
||||
remove = function()
|
||||
{
|
||||
es.removeEventListener("xjxstream", callback, false);
|
||||
es.removeEventListener("xjxendstream", remove, false);
|
||||
//document.body.removeChild(es);
|
||||
}
|
||||
|
||||
es.addEventListener("xjxstream", callback, false);
|
||||
es.addEventListener("xjxendstream", remove, false);
|
||||
document.body.appendChild(es);
|
||||
|
||||
if (0 < oRequest.requestRetry)
|
||||
oRequest.requestRetry = 0;
|
||||
}
|
||||
catch (ex)
|
||||
{
|
||||
}
|
||||
return;
|
||||
}
|
||||
return xjxEc.prepareRequest(oRequest);
|
||||
}
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
Function: responseProcessor.XHR
|
||||
|
||||
Processes the streaming response for FF/Safari
|
||||
|
||||
*/
|
||||
xajax.debug = {
|
||||
};
|
||||
|
||||
xajax.debug.prepareDebugText = function(text)
|
||||
{
|
||||
try
|
||||
{
|
||||
text = text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/\n/g, '<br />');
|
||||
return text;
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
xajax.debug.stringReplace = function(haystack, needle, newNeedle)
|
||||
{
|
||||
var segments = haystack.split(needle);
|
||||
haystack = '';
|
||||
|
||||
for (var i = 0; i < segments.length; ++i)
|
||||
{
|
||||
if (0 != i)
|
||||
haystack += newNeedle;
|
||||
haystack += segments[i];
|
||||
}
|
||||
return haystack;
|
||||
}
|
||||
xajax.debug.prepareDebugText = function(text)
|
||||
{
|
||||
text = xajax.debug.stringReplace(text, '&', '&');
|
||||
text = xajax.debug.stringReplace(text, '<', '<');
|
||||
text = xajax.debug.stringReplace(text, '>', '>');
|
||||
text = xajax.debug.stringReplace(text, '\n', '<br />');
|
||||
return text;
|
||||
}
|
||||
xajax.debug.prepareDebugText(text);
|
||||
}
|
||||
}
|
||||
xjxEc.responseProcessor = {
|
||||
}
|
||||
|
||||
xjxEc.responseProcessor.XHR = function(oRequest)
|
||||
{
|
||||
var xx = xajax;
|
||||
var xt = xx.tools;
|
||||
var xcb = xx.callback;
|
||||
var gcb = xcb.global;
|
||||
var lcb = oRequest.callback;
|
||||
var oRet = oRequest.returnValue;
|
||||
|
||||
if ("" == oRequest.request.responseText)
|
||||
return;
|
||||
var allMessages = oRequest.request.responseText;
|
||||
if (true === oRequest.comet.inProgress) return;
|
||||
oRequest.comet.inProgress = true;
|
||||
do
|
||||
{
|
||||
var unprocessed = allMessages.substring(oRequest.comet.LastPosition);
|
||||
var messageXMLEndIndex = unprocessed.indexOf("</xjx>");
|
||||
|
||||
if (messageXMLEndIndex != -1)
|
||||
{
|
||||
var endOfFirstMessageIndex = messageXMLEndIndex + ("</xjx>").length;
|
||||
var anUpdate = unprocessed.substring(0, endOfFirstMessageIndex);
|
||||
|
||||
var cmd = (new DOMParser()).parseFromString(anUpdate, "text/xml");
|
||||
|
||||
try
|
||||
{
|
||||
var seq = 0;
|
||||
var child = cmd.documentElement.firstChild;
|
||||
xt.xml.processFragment(child, seq, oRet, oRequest);
|
||||
}
|
||||
catch (ex)
|
||||
{
|
||||
}
|
||||
xt.queue.process(xx.response);
|
||||
oRequest.comet.LastPosition += endOfFirstMessageIndex;
|
||||
}
|
||||
} while (messageXMLEndIndex != -1);
|
||||
|
||||
oRequest.comet.inProgress = false;
|
||||
return oRet;
|
||||
}
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
Function: responseProcessor.ActiveX
|
||||
|
||||
Processes the streaming response for IE
|
||||
|
||||
*/
|
||||
|
||||
xjxEc.responseProcessor.ActiveX = function(response, oRequest)
|
||||
{
|
||||
response.replace('\"', '"');
|
||||
var xx = xajax;
|
||||
var xt = xx.tools;
|
||||
var xcb = xx.callback;
|
||||
var gcb = xcb.global;
|
||||
var lcb = oRequest.callback;
|
||||
var oRet = oRequest.returnValue;
|
||||
|
||||
if (response)
|
||||
{
|
||||
var cmd = (new DOMParser()).parseFromString(response, "text/xml");
|
||||
var seq = 0;
|
||||
var child = cmd.documentElement.firstChild;
|
||||
xt.xml.processFragment(child, seq, oRequest);
|
||||
|
||||
if (null == xx.response.timeout)
|
||||
xt.queue.process(xx.response);
|
||||
}
|
||||
return oRet;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
Function: responseProcessor.HTMLDRAFT
|
||||
|
||||
Processes the streaming response for HTML 5 Draft Browsers (Opera 9+)
|
||||
|
||||
*/
|
||||
|
||||
xjxEc.responseProcessor.HTMLDRAFT = function(response, oRequest)
|
||||
{
|
||||
var xx = xajax;
|
||||
var xt = xx.tools;
|
||||
var xcb = xx.callback;
|
||||
var gcb = xcb.global;
|
||||
var lcb = oRequest.callback;
|
||||
var oRet = oRequest.returnValue;
|
||||
if (oRequest.inProgress) return;
|
||||
if (response && oRequest.lastResponse !== response)
|
||||
{
|
||||
oRequest.inProgress = true;
|
||||
var cmd = (new DOMParser()).parseFromString(response, "text/xml");
|
||||
var seq = 0;
|
||||
var child = cmd.documentElement.firstChild;
|
||||
xt.xml.processFragment(child, seq, oRequest);
|
||||
|
||||
if (null == xx.response.timeout)
|
||||
xt.queue.process(xx.response);
|
||||
oRequest.inProgress=false;
|
||||
oRequest.lastResponse = response
|
||||
}
|
||||
return oRet;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
|
||||
Function: submitRequestActiveX
|
||||
|
||||
Supresses the xajax.submitRequest() function call for IE in streaming calls.
|
||||
|
||||
*/
|
||||
|
||||
xjxEc.submitRequestActiveX = function(oRequest)
|
||||
{
|
||||
if (true == oRequest.comet)
|
||||
return;
|
||||
|
||||
xjxEc.submitRequest(oRequest);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
|
||||
variable setup. Detects IE and replaces the according functions
|
||||
|
||||
*/
|
||||
|
||||
xjxEc.prepareRequest = xajax.prepareRequest;
|
||||
|
||||
xjxEc.stream_support = xjxEc.detectSupport();
|
||||
|
||||
switch (xjxEc.stream_support)
|
||||
{
|
||||
case "Internet Explorer":
|
||||
xajax.prepareRequest = xjxEc.prepareRequestActiveX;
|
||||
xjxEc.submitRequest = xajax.submitRequest;
|
||||
xajax.submitRequest = xjxEc.submitRequestActiveX;
|
||||
break;
|
||||
|
||||
case "Firefox":
|
||||
case "Safari":
|
||||
xajax.prepareRequest = xjxEc.prepareRequestXHR;
|
||||
break;
|
||||
|
||||
case "Opera":
|
||||
xajax.prepareRequest = xjxEc.prepareRequestHTMLDRAFT;
|
||||
xjxEc.submitRequest = xajax.submitRequest;
|
||||
xajax.submitRequest = xjxEc.submitRequestActiveX;
|
||||
break;
|
||||
|
||||
default:
|
||||
alert("Xajax.Ext.Comet: Your browser does not support comet streaming or is not yet supported by this plugin!");
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
|
||||
Function: DOMParser
|
||||
|
||||
Prototype DomParser for IE/Opera
|
||||
|
||||
*/
|
||||
if (typeof DOMParser == "undefined")
|
||||
{
|
||||
DOMParser = function ()
|
||||
{
|
||||
}
|
||||
|
||||
DOMParser.prototype.parseFromString = function (str, contentType)
|
||||
{
|
||||
if (typeof ActiveXObject != "undefined")
|
||||
{
|
||||
var d = new ActiveXObject("Microsoft.XMLDOM");
|
||||
d.loadXML(str);
|
||||
return d;
|
||||
}
|
||||
else if (typeof XMLHttpRequest != "undefined")
|
||||
{
|
||||
var req = new XMLHttpRequest;
|
||||
req.open("GET", "data:" + (contentType || "application/xml") + ";charset=utf-8," + encodeURIComponent(str), false);
|
||||
|
||||
if (req.overrideMimeType)
|
||||
{
|
||||
req.overrideMimeType(contentType);
|
||||
}
|
||||
req.send(null);
|
||||
return req.responseXML;
|
||||
}
|
||||
}
|
||||
}
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -0,0 +1,622 @@
|
||||
/*
|
||||
File: comet.js
|
||||
|
||||
Title: Comet plugin for xajax
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
@package comet plugin
|
||||
@version $Id:
|
||||
@copyright Copyright (c) 2007 by Steffen Konerow (IE)
|
||||
@license http://www.xajaxproject.org/bsd_license.txt BSD License
|
||||
*/
|
||||
|
||||
/*
|
||||
Class: xajax.ext.comet
|
||||
|
||||
This class contains all functions for using comet streaming with xajax.
|
||||
|
||||
*/
|
||||
|
||||
try
|
||||
{
|
||||
if (undefined == xajax.ext)
|
||||
xajax.ext = {
|
||||
};
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (undefined == xajax.ext.comet)
|
||||
xajax.ext.comet = {
|
||||
};
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
alert("Could not create xajax.ext.comet namespace");
|
||||
}
|
||||
|
||||
// create Shorthand for xajax.ext.comet
|
||||
xjxEc = xajax.ext.comet;
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
Function: detectSupport
|
||||
|
||||
Detects browser for using fallback methods instead of multipart XHR responses.
|
||||
*/
|
||||
xjxEc.detectSupport = function()
|
||||
{
|
||||
var agt = navigator.userAgent.toLowerCase();
|
||||
|
||||
if (agt.indexOf("opera") != -1)
|
||||
return 'Opera';
|
||||
|
||||
if (agt.indexOf("staroffice") != -1)
|
||||
return 'Star Office';
|
||||
|
||||
if (agt.indexOf("webtv") != -1)
|
||||
return 'WebTV';
|
||||
|
||||
if (agt.indexOf("beonex") != -1)
|
||||
return 'Beonex';
|
||||
|
||||
if (agt.indexOf("chimera") != -1)
|
||||
return 'Chimera';
|
||||
|
||||
if (agt.indexOf("netpositive") != -1)
|
||||
return 'NetPositive';
|
||||
|
||||
if (agt.indexOf("phoenix") != -1)
|
||||
return 'Phoenix';
|
||||
|
||||
if (agt.indexOf("firefox") != -1)
|
||||
return 'Firefox';
|
||||
|
||||
if (agt.indexOf("safari") != -1)
|
||||
return 'Safari';
|
||||
|
||||
if (agt.indexOf("skipstone") != -1)
|
||||
return 'SkipStone';
|
||||
|
||||
if (agt.indexOf("msie") != -1)
|
||||
return 'Internet Explorer';
|
||||
|
||||
if (agt.indexOf("netscape") != -1)
|
||||
return 'Netscape';
|
||||
|
||||
if (agt.indexOf("mozilla/5.0") != -1)
|
||||
return 'Mozilla';
|
||||
|
||||
if (agt.indexOf('\/') != -1)
|
||||
{
|
||||
if (agt.substr(0, agt.indexOf('\/')) != 'mozilla')
|
||||
{
|
||||
return navigator.userAgent.substr(0, agt.indexOf('\/'));
|
||||
}
|
||||
else
|
||||
return 'Netscape';
|
||||
}
|
||||
else if (agt.indexOf(' ') != -1)
|
||||
return navigator.userAgent.substr(0, agt.indexOf(' '));
|
||||
else
|
||||
return navigator.userAgent;
|
||||
|
||||
// if (navigator.appVersion.indexOf("MSIE")!=-1)
|
||||
// {
|
||||
// var version,temp;
|
||||
// temp=navigator.appVersion.split("MSIE")
|
||||
// version=parseFloat(temp[1])
|
||||
// if (version>=5.5) return "MSIE";
|
||||
// }
|
||||
// if ( "undefined" != typeof window.opera )
|
||||
// {
|
||||
// return "OPERA";
|
||||
// }
|
||||
// if ( "undefined" != typeof window.Iterator )
|
||||
// {
|
||||
// return "FF2";
|
||||
// }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
Function: prepareRequestXHR
|
||||
|
||||
Prepares the XMLHttpRequest object for this xajax request in FF/Safari browsers.
|
||||
|
||||
*/
|
||||
|
||||
xjxEc.prepareRequestXHR = function (oRequest)
|
||||
{
|
||||
if (true == oRequest.comet)
|
||||
{
|
||||
var xx = xajax;
|
||||
var xt = xx.tools;
|
||||
oRequest.request = xt.getRequestObject();
|
||||
|
||||
oRequest.setRequestHeaders = function(headers)
|
||||
{
|
||||
if ('object' == typeof headers)
|
||||
{
|
||||
for (var optionName in headers)
|
||||
this.request.setRequestHeader(optionName, headers[optionName]);
|
||||
}
|
||||
}
|
||||
oRequest.setCommonRequestHeaders = function()
|
||||
{
|
||||
this.setRequestHeaders(this.commonHeaders);
|
||||
}
|
||||
oRequest.setPostRequestHeaders = function()
|
||||
{
|
||||
this.setRequestHeaders(this.postHeaders);
|
||||
}
|
||||
oRequest.setGetRequestHeaders = function()
|
||||
{
|
||||
this.setRequestHeaders(this.getHeaders);
|
||||
}
|
||||
|
||||
oRequest.applyRequestHeaders = function()
|
||||
{
|
||||
}
|
||||
|
||||
oRequest.setCommonRequestHeaders = function()
|
||||
{
|
||||
this.request.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
|
||||
this.request.setRequestHeader('streaming', 'xhr');
|
||||
|
||||
if (typeof (oRequest.header) == "object")
|
||||
{
|
||||
for (a in oRequest.header)
|
||||
this.request.setRequestHeader(a, oRequest.header[a]);
|
||||
}
|
||||
}
|
||||
oRequest.comet = {
|
||||
};
|
||||
|
||||
oRequest.comet.LastPosition = 0;
|
||||
oRequest.comet.inProgress = false;
|
||||
var pollLatestResponse = function()
|
||||
{
|
||||
xjxEc.responseProcessor.XHR(oRequest);
|
||||
}
|
||||
oRequest.pollTimer = setInterval(pollLatestResponse, 300);
|
||||
oRequest.request.onreadystatechange = function()
|
||||
{
|
||||
if (oRequest.request.readyState < 3)
|
||||
{
|
||||
console.log('readyState < 3');
|
||||
return;
|
||||
}
|
||||
if (oRequest.request.readyState == 4)
|
||||
{
|
||||
console.log('readyState == 4');
|
||||
clearInterval(oRequest.pollTimer);
|
||||
xjxEc.responseProcessor.XHR(oRequest);
|
||||
//xajax.responseReceived(oRequest);
|
||||
xajax.completeResponse(oRequest);
|
||||
return;
|
||||
}
|
||||
}
|
||||
oRequest.finishRequest = function()
|
||||
{
|
||||
return this.returnValue;
|
||||
}
|
||||
|
||||
if ('undefined' != typeof oRequest.userName && 'undefined' != typeof oRequest.password)
|
||||
{
|
||||
oRequest.open = function()
|
||||
{
|
||||
this.request.open(this.method, this.requestURI, true, oRequest.userName, oRequest.password);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
oRequest.open = function()
|
||||
{
|
||||
this.request.open(this.method, this.requestURI, true);
|
||||
}
|
||||
}
|
||||
|
||||
if ('POST' == oRequest.method)
|
||||
{ // W3C: Method is case sensitive
|
||||
oRequest.applyRequestHeaders = function()
|
||||
{
|
||||
this.setCommonRequestHeaders();
|
||||
|
||||
try
|
||||
{
|
||||
this.setPostRequestHeaders();
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
this.method = 'GET';
|
||||
this.requestURI += this.requestURI.indexOf('?') == -1 ? '?' : '&';
|
||||
this.requestURI += this.requestData;
|
||||
this.requestData = '';
|
||||
|
||||
if (0 == this.requestRetry)
|
||||
this.requestRetry = 1;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
oRequest.applyRequestHeaders = function()
|
||||
{
|
||||
this.setCommonRequestHeaders();
|
||||
this.setGetRequestHeaders();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
return xjxEc.prepareRequest(oRequest);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
Function: connect_htmlfile
|
||||
|
||||
Create a hidden iframe for IE
|
||||
|
||||
*/
|
||||
xjxEc.connect_htmlfile = function (url, callback, oRequest)
|
||||
{
|
||||
try
|
||||
{
|
||||
xjxEc.transferDoc = new ActiveXObject("htmlfile");
|
||||
xjxEc.transferDoc.open();
|
||||
xjxEc.transferDoc.write("<html>");
|
||||
xjxEc.transferDoc.write("<script>document.domain='http://192.168.1.21/';</script>");
|
||||
xjxEc.transferDoc.write("</html>");
|
||||
xjxEc.transferDoc.close();
|
||||
xjxEc.ifrDiv = xjxEc.transferDoc.createElement("div");
|
||||
xjxEc.transferDoc.body.appendChild(xjxEc.ifrDiv);
|
||||
xjxEc.ifrDiv.innerHTML = "<iframe src='" + url + "'></iframe>";
|
||||
xjxEc.transferDoc.callback = function (response)
|
||||
{
|
||||
callback(response, oRequest);
|
||||
};
|
||||
}
|
||||
catch (ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
Function: prepareRequestActiveX
|
||||
|
||||
Prepares the Iframe for streaming with active X
|
||||
|
||||
*/
|
||||
|
||||
xjxEc.prepareRequestActiveX = function(oRequest)
|
||||
{
|
||||
if (true == oRequest.comet)
|
||||
{
|
||||
var xx = xajax;
|
||||
var xt = xx.tools;
|
||||
oRequest.requestURI += oRequest.requestURI.indexOf('?') == -1 ? '?' : '&';
|
||||
oRequest.requestURI += oRequest.requestData;
|
||||
oRequest.requestData = '';
|
||||
|
||||
try
|
||||
{
|
||||
xjxEc.connect_htmlfile(oRequest.requestURI, xjxEc.responseProcessor.ActiveX, oRequest);
|
||||
|
||||
if (0 < oRequest.requestRetry)
|
||||
oRequest.requestRetry = 0;
|
||||
}
|
||||
catch (ex)
|
||||
{
|
||||
}
|
||||
return;
|
||||
}
|
||||
return xjxEc.prepareRequest(oRequest);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
Function: prepareRequestHTMLDRAFT
|
||||
|
||||
Prepares streaming with HTML 5 Draft
|
||||
|
||||
*/
|
||||
|
||||
xjxEc.prepareRequestHTMLDRAFT = function(oRequest)
|
||||
{
|
||||
if (true == oRequest.comet)
|
||||
{
|
||||
var xx = xajax;
|
||||
var xt = xx.tools;
|
||||
oRequest.requestURI += oRequest.requestURI.indexOf('?') == -1 ? '?' : '&';
|
||||
oRequest.requestURI += oRequest.requestData;
|
||||
oRequest.requestURI += "&xjxstreaming=HTML5DRAFT";
|
||||
oRequest.inProgress = false;
|
||||
|
||||
try
|
||||
{
|
||||
var uri = oRequest.requestURI;
|
||||
var es = document.createElement("event-source");
|
||||
es.setAttribute("src", uri);
|
||||
es.setAttribute("width", 200);
|
||||
es.setAttribute("height", 200);
|
||||
es.style.display = "block";
|
||||
callback = function(event)
|
||||
{
|
||||
xjxEc.responseProcessor.HTMLDRAFT(event.data, oRequest);
|
||||
};
|
||||
remove = function()
|
||||
{
|
||||
es.removeEventListener("xjxstream", callback, false);
|
||||
es.removeEventListener("xjxendstream", remove, false);
|
||||
//document.body.removeChild(es);
|
||||
}
|
||||
|
||||
es.addEventListener("xjxstream", callback, false);
|
||||
es.addEventListener("xjxendstream", remove, false);
|
||||
document.body.appendChild(es);
|
||||
|
||||
if (0 < oRequest.requestRetry)
|
||||
oRequest.requestRetry = 0;
|
||||
}
|
||||
catch (ex)
|
||||
{
|
||||
}
|
||||
return;
|
||||
}
|
||||
return xjxEc.prepareRequest(oRequest);
|
||||
}
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
Function: responseProcessor.XHR
|
||||
|
||||
Processes the streaming response for FF/Safari
|
||||
|
||||
*/
|
||||
xajax.debug = {
|
||||
};
|
||||
|
||||
xajax.debug.prepareDebugText = function(text)
|
||||
{
|
||||
try
|
||||
{
|
||||
text = text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/\n/g, '<br />');
|
||||
return text;
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
xajax.debug.stringReplace = function(haystack, needle, newNeedle)
|
||||
{
|
||||
var segments = haystack.split(needle);
|
||||
haystack = '';
|
||||
|
||||
for (var i = 0; i < segments.length; ++i)
|
||||
{
|
||||
if (0 != i)
|
||||
haystack += newNeedle;
|
||||
haystack += segments[i];
|
||||
}
|
||||
return haystack;
|
||||
}
|
||||
xajax.debug.prepareDebugText = function(text)
|
||||
{
|
||||
text = xajax.debug.stringReplace(text, '&', '&');
|
||||
text = xajax.debug.stringReplace(text, '<', '<');
|
||||
text = xajax.debug.stringReplace(text, '>', '>');
|
||||
text = xajax.debug.stringReplace(text, '\n', '<br />');
|
||||
return text;
|
||||
}
|
||||
xajax.debug.prepareDebugText(text);
|
||||
}
|
||||
}
|
||||
xjxEc.responseProcessor = {
|
||||
}
|
||||
|
||||
xjxEc.responseProcessor.XHR = function(oRequest)
|
||||
{
|
||||
var xx = xajax;
|
||||
var xt = xx.tools;
|
||||
var xcb = xx.callback;
|
||||
var gcb = xcb.global;
|
||||
var lcb = oRequest.callback;
|
||||
var oRet = oRequest.returnValue;
|
||||
|
||||
if ("" == oRequest.request.responseText)
|
||||
return;
|
||||
var allMessages = oRequest.request.responseText;
|
||||
if (true === oRequest.comet.inProgress) return;
|
||||
oRequest.comet.inProgress = true;
|
||||
do
|
||||
{
|
||||
var unprocessed = allMessages.substring(oRequest.comet.LastPosition);
|
||||
var messageXMLEndIndex = unprocessed.indexOf("</xjx>");
|
||||
|
||||
if (messageXMLEndIndex != -1)
|
||||
{
|
||||
var endOfFirstMessageIndex = messageXMLEndIndex + ("</xjx>").length;
|
||||
var anUpdate = unprocessed.substring(0, endOfFirstMessageIndex);
|
||||
|
||||
var cmd = (new DOMParser()).parseFromString(anUpdate, "text/xml");
|
||||
|
||||
try
|
||||
{
|
||||
var seq = 0;
|
||||
var child = cmd.documentElement.firstChild;
|
||||
xt.xml.processFragment(child, seq, oRet, oRequest);
|
||||
}
|
||||
catch (ex)
|
||||
{
|
||||
}
|
||||
xt.queue.process(xx.response);
|
||||
oRequest.comet.LastPosition += endOfFirstMessageIndex;
|
||||
}
|
||||
} while (messageXMLEndIndex != -1);
|
||||
|
||||
oRequest.comet.inProgress = false;
|
||||
return oRet;
|
||||
}
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
Function: responseProcessor.ActiveX
|
||||
|
||||
Processes the streaming response for IE
|
||||
|
||||
*/
|
||||
|
||||
xjxEc.responseProcessor.ActiveX = function(response, oRequest)
|
||||
{
|
||||
response.replace('\"', '"');
|
||||
var xx = xajax;
|
||||
var xt = xx.tools;
|
||||
var xcb = xx.callback;
|
||||
var gcb = xcb.global;
|
||||
var lcb = oRequest.callback;
|
||||
var oRet = oRequest.returnValue;
|
||||
|
||||
if (response)
|
||||
{
|
||||
var cmd = (new DOMParser()).parseFromString(response, "text/xml");
|
||||
var seq = 0;
|
||||
var child = cmd.documentElement.firstChild;
|
||||
xt.xml.processFragment(child, seq, oRequest);
|
||||
|
||||
if (null == xx.response.timeout)
|
||||
xt.queue.process(xx.response);
|
||||
}
|
||||
return oRet;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
Function: responseProcessor.HTMLDRAFT
|
||||
|
||||
Processes the streaming response for HTML 5 Draft Browsers (Opera 9+)
|
||||
|
||||
*/
|
||||
|
||||
xjxEc.responseProcessor.HTMLDRAFT = function(response, oRequest)
|
||||
{
|
||||
var xx = xajax;
|
||||
var xt = xx.tools;
|
||||
var xcb = xx.callback;
|
||||
var gcb = xcb.global;
|
||||
var lcb = oRequest.callback;
|
||||
var oRet = oRequest.returnValue;
|
||||
if (oRequest.inProgress) return;
|
||||
if (response && oRequest.lastResponse !== response)
|
||||
{
|
||||
oRequest.inProgress = true;
|
||||
var cmd = (new DOMParser()).parseFromString(response, "text/xml");
|
||||
var seq = 0;
|
||||
var child = cmd.documentElement.firstChild;
|
||||
xt.xml.processFragment(child, seq, oRequest);
|
||||
|
||||
if (null == xx.response.timeout)
|
||||
xt.queue.process(xx.response);
|
||||
oRequest.inProgress=false;
|
||||
oRequest.lastResponse = response
|
||||
}
|
||||
return oRet;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
|
||||
Function: submitRequestActiveX
|
||||
|
||||
Supresses the xajax.submitRequest() function call for IE in streaming calls.
|
||||
|
||||
*/
|
||||
|
||||
xjxEc.submitRequestActiveX = function(oRequest)
|
||||
{
|
||||
if (true == oRequest.comet)
|
||||
return;
|
||||
|
||||
xjxEc.submitRequest(oRequest);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
|
||||
variable setup. Detects IE and replaces the according functions
|
||||
|
||||
*/
|
||||
|
||||
xjxEc.prepareRequest = xajax.prepareRequest;
|
||||
|
||||
xjxEc.stream_support = xjxEc.detectSupport();
|
||||
|
||||
switch (xjxEc.stream_support)
|
||||
{
|
||||
case "Internet Explorer":
|
||||
xajax.prepareRequest = xjxEc.prepareRequestActiveX;
|
||||
xjxEc.submitRequest = xajax.submitRequest;
|
||||
xajax.submitRequest = xjxEc.submitRequestActiveX;
|
||||
break;
|
||||
|
||||
case "Firefox":
|
||||
case "Safari":
|
||||
xajax.prepareRequest = xjxEc.prepareRequestXHR;
|
||||
break;
|
||||
|
||||
case "Opera":
|
||||
xajax.prepareRequest = xjxEc.prepareRequestHTMLDRAFT;
|
||||
xjxEc.submitRequest = xajax.submitRequest;
|
||||
xajax.submitRequest = xjxEc.submitRequestActiveX;
|
||||
break;
|
||||
|
||||
default:
|
||||
alert("Xajax.Ext.Comet: Your browser does not support comet streaming or is not yet supported by this plugin!");
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
|
||||
Function: DOMParser
|
||||
|
||||
Prototype DomParser for IE/Opera
|
||||
|
||||
*/
|
||||
if (typeof DOMParser == "undefined")
|
||||
{
|
||||
DOMParser = function ()
|
||||
{
|
||||
}
|
||||
|
||||
DOMParser.prototype.parseFromString = function (str, contentType)
|
||||
{
|
||||
if (typeof ActiveXObject != "undefined")
|
||||
{
|
||||
var d = new ActiveXObject("Microsoft.XMLDOM");
|
||||
d.loadXML(str);
|
||||
return d;
|
||||
}
|
||||
else if (typeof XMLHttpRequest != "undefined")
|
||||
{
|
||||
var req = new XMLHttpRequest;
|
||||
req.open("GET", "data:" + (contentType || "application/xml") + ";charset=utf-8," + encodeURIComponent(str), false);
|
||||
|
||||
if (req.overrideMimeType)
|
||||
{
|
||||
req.overrideMimeType(contentType);
|
||||
}
|
||||
req.send(null);
|
||||
return req.responseXML;
|
||||
}
|
||||
}
|
||||
}
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -0,0 +1,232 @@
|
||||
<?php
|
||||
/*
|
||||
File: xajaxCometFunction.inc.php
|
||||
|
||||
Contains the xajaxCometFunction class
|
||||
|
||||
Title: xajaxCometFunction class
|
||||
|
||||
Please see <copyright.inc.php> for a detailed description, copyright
|
||||
and license information.
|
||||
*/
|
||||
|
||||
/*
|
||||
@package xajax
|
||||
@version $Id: xajaxCometFunction.inc.php 362 2007-05-29 15:32:24Z calltoconstruct $
|
||||
@copyright Copyright (c) 2005-2006 by Jared White & J. Max Wilson
|
||||
@license http://www.xajaxproject.org/bsd_license.txt BSD License
|
||||
*/
|
||||
|
||||
/*
|
||||
Class: xajaxCometFunction
|
||||
|
||||
Construct instances of this class to define functions that will be registered
|
||||
with the <xajax> request processor. This class defines the parameters that
|
||||
are needed for the definition of a xajax enabled function. While you can
|
||||
still specify functions by name during registration, it is advised that you
|
||||
convert to using this class when you wish to register external functions or
|
||||
to specify call options as well.
|
||||
*/
|
||||
class xajaxCometFunction
|
||||
{
|
||||
/*
|
||||
String: sAlias
|
||||
|
||||
An alias to use for this function. This is useful when you want
|
||||
to call the same xajax enabled function with a different set of
|
||||
call options from what was already registered.
|
||||
*/
|
||||
var $sAlias;
|
||||
|
||||
/*
|
||||
Object: uf
|
||||
|
||||
A string or array which defines the function to be registered.
|
||||
*/
|
||||
var $uf;
|
||||
|
||||
/*
|
||||
String: sInclude
|
||||
|
||||
The path and file name of the include file that contains the function.
|
||||
*/
|
||||
var $sInclude;
|
||||
|
||||
/*
|
||||
Array: aConfiguration
|
||||
|
||||
An associative array containing call options that will be sent to the
|
||||
browser curing client script generation.
|
||||
*/
|
||||
var $aConfiguration;
|
||||
|
||||
/*
|
||||
Function: xajaxCometFunction
|
||||
|
||||
Constructs and initializes the <xajaxCometFunction> object.
|
||||
|
||||
$uf - (mixed): A function specification in one of the following formats:
|
||||
|
||||
- a three element array:
|
||||
(string) Alternate function name: when a method of a class has the same
|
||||
name as another function in the system, you can provide an alias to
|
||||
help avoid collisions.
|
||||
(object or class name) Class: the name of the class or an instance of
|
||||
the object which contains the function to be called.
|
||||
(string) Method: the name of the method that will be called.
|
||||
- a two element array:
|
||||
(object or class name) Class: the name of the class or an instance of
|
||||
the object which contains the function to be called.
|
||||
(string) Method: the name of the method that will be called.
|
||||
- a string:
|
||||
the name of the function that is available at global scope (not in a
|
||||
class.
|
||||
$sInclude - (string, optional): The path and file name of the include file
|
||||
that contains the class or function to be called.
|
||||
|
||||
$aConfiguration - (array, optional): An associative array of call options
|
||||
that will be used when sending the request from the client.
|
||||
|
||||
Examples:
|
||||
|
||||
$myFunction = array('alias', 'myClass', 'myMethod');
|
||||
$myFunction = array('alias', &$myObject, 'myMethod');
|
||||
$myFunction = array('myClass', 'myMethod');
|
||||
$myFunction = array(&$myObject, 'myMethod');
|
||||
$myFunction = 'myFunction';
|
||||
|
||||
$myUserFunction = new xajaxCometFunction($myFunction, 'myFile.inc.php', array(
|
||||
'method' => 'get',
|
||||
'mode' => 'synchronous'
|
||||
));
|
||||
|
||||
$xajax->register(XAJAX_FUNCTION, $myUserFunction);
|
||||
*/
|
||||
function xajaxCometFunction($uf, $sInclude=NULL, $aConfiguration=array())
|
||||
{
|
||||
$this->sAlias = '';
|
||||
$this->uf =& $uf;
|
||||
$this->sInclude = $sInclude;
|
||||
$this->aConfiguration = array();
|
||||
foreach ($aConfiguration as $sKey => $sValue)
|
||||
$this->configure($sKey, $sValue);
|
||||
|
||||
if (is_array($this->uf) && 2 < count($this->uf))
|
||||
{
|
||||
$this->sAlias = $this->uf[0];
|
||||
$this->uf = array_slice($this->uf, 1);
|
||||
}
|
||||
|
||||
//SkipDebug
|
||||
if (is_array($this->uf) && 2 != count($this->uf))
|
||||
trigger_error(
|
||||
'Invalid function declaration for xajaxCometFunction.',
|
||||
E_USER_ERROR
|
||||
);
|
||||
//EndSkipDebug
|
||||
}
|
||||
|
||||
/*
|
||||
Function: getName
|
||||
|
||||
Get the name of the function being referenced.
|
||||
|
||||
Returns:
|
||||
|
||||
string - the name of the function contained within this object.
|
||||
*/
|
||||
function getName()
|
||||
{
|
||||
// Do not use sAlias here!
|
||||
if (is_array($this->uf))
|
||||
return $this->uf[1];
|
||||
return $this->uf;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: configure
|
||||
|
||||
Call this to set call options for this instance.
|
||||
*/
|
||||
function configure($sName, $sValue)
|
||||
{
|
||||
if ('alias' == $sName)
|
||||
$this->sAlias = $sValue;
|
||||
else
|
||||
$this->aConfiguration[$sName] = $sValue;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: generateRequest
|
||||
|
||||
Constructs and returns a <xajaxRequest> object which is capable
|
||||
of generating the javascript call to invoke this xajax enabled
|
||||
function.
|
||||
*/
|
||||
function generateRequest($sXajaxPrefix)
|
||||
{
|
||||
$sAlias = $this->getName();
|
||||
if (0 < strlen($this->sAlias))
|
||||
$sAlias = $this->sAlias;
|
||||
return new xajaxRequest("{$sXajaxPrefix}{$sAlias}");
|
||||
}
|
||||
|
||||
/*
|
||||
Function: generateClientScript
|
||||
|
||||
Called by the <xajaxPlugin> that is referencing this function
|
||||
reference during the client script generation phase. This function
|
||||
will generate the javascript function stub that is sent to the
|
||||
browser on initial page load.
|
||||
*/
|
||||
function generateClientScript($sXajaxPrefix)
|
||||
{
|
||||
$sFunction = $this->getName();
|
||||
$sAlias = $sFunction;
|
||||
if (0 < strlen($this->sAlias))
|
||||
$sAlias = $this->sAlias;
|
||||
echo "{$sXajaxPrefix}{$sAlias} = function() { ";
|
||||
echo "return xajax.request( ";
|
||||
echo "{ xjxcomet: '{$sFunction}' }, ";
|
||||
echo "{ parameters: arguments, mode:'comet'";
|
||||
|
||||
$sSeparator = ", ";
|
||||
foreach ($this->aConfiguration as $sKey => $sValue)
|
||||
echo "{$sSeparator}{$sKey}: {$sValue}";
|
||||
|
||||
echo " } ); ";
|
||||
echo "};\n";
|
||||
}
|
||||
|
||||
/*
|
||||
Function: call
|
||||
|
||||
Called by the <xajaxPlugin> that references this function during the
|
||||
request processing phase. This function will call the specified
|
||||
function, including an external file if needed and passing along
|
||||
the specified arguments.
|
||||
*/
|
||||
function call($aArgs=array())
|
||||
{
|
||||
$objResponseManager =& xajaxResponseManager::getInstance();
|
||||
|
||||
if (NULL != $this->sInclude)
|
||||
{
|
||||
ob_start();
|
||||
require_once $this->sInclude;
|
||||
$sOutput = ob_get_clean();
|
||||
|
||||
//SkipDebug
|
||||
if (0 < strlen($sOutput))
|
||||
{
|
||||
$sOutput = 'From include file: ' . $this->sInclude . ' => ' . $sOutput;
|
||||
$objResponseManager->debug($sOutput);
|
||||
}
|
||||
//EndSkipDebug
|
||||
}
|
||||
|
||||
$mFunction = $this->uf;
|
||||
$objResponseManager->append(call_user_func_array($mFunction, $aArgs));
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user