[Phpfreechat-svn] SF.net SVN: phpfreechat: [1076] branches/pfc-comet/misc/comet-tests/iframe2
Status: Beta
Brought to you by:
kerphi
|
From: <ke...@us...> - 2007-08-02 16:44:19
|
Revision: 1076
http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1076&view=rev
Author: kerphi
Date: 2007-08-02 09:44:15 -0700 (Thu, 02 Aug 2007)
Log Message:
-----------
Add the javascript callback handling
Modified Paths:
--------------
branches/pfc-comet/misc/comet-tests/iframe2/pfccomet.class.php
branches/pfc-comet/misc/comet-tests/iframe2/pfccomet.js
branches/pfc-comet/misc/comet-tests/iframe2/tester.php
Modified: branches/pfc-comet/misc/comet-tests/iframe2/pfccomet.class.php
===================================================================
--- branches/pfc-comet/misc/comet-tests/iframe2/pfccomet.class.php 2007-08-02 16:27:50 UTC (rev 1075)
+++ branches/pfc-comet/misc/comet-tests/iframe2/pfccomet.class.php 2007-08-02 16:44:15 UTC (rev 1076)
@@ -8,6 +8,9 @@
var $backend_callback = null;
var $backend_loop = false;
var $backend_loop_sleep = 1;
+ var $onresponse_callback = null;
+ var $onconnect_callback = null;
+ var $ondisconnect_callback = null;
function pfcComet()
{
@@ -29,23 +32,25 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<script type="text/javascript">
- // KHTML browser don\'t share javascripts between iframes
- var is_khtml = navigator.appName.match("Konqueror") || navigator.appVersion.match("KHTML");
- if (is_khtml)
- {
- var prototypejs = document.createElement("script");
- prototypejs.setAttribute("type","text/javascript");
- prototypejs.setAttribute("src","'.$this->prototypejs_url.'");
- var head = document.getElementsByTagName("head");
- head[0].appendChild(prototypejs);
- }
+// // KHTML browser don\'t share javascripts between iframes
+// var is_khtml = navigator.appName.match("Konqueror") || navigator.appVersion.match("KHTML");
+// if (is_khtml)
+// {
+// var prototypejs = document.createElement("script");
+// prototypejs.setAttribute("type","text/javascript");
+// prototypejs.setAttribute("src","'.$this->prototypejs_url.'");
+// var head = document.getElementsByTagName("head");
+// head[0].appendChild(prototypejs);
+// }
// load the comet object
var pfccomet = window.parent.pfccomet;
-</script>';
+</script>
+<body>
+';
flush();
// trigger the onConnect callback
- echo '<script type="text/javascript">pfccomet._onConnect();</script>';
+ echo '<script type="text/javascript">pfccomet._onConnect();</script>'."\n";
flush();
// trigger the backend callback
@@ -64,7 +69,8 @@
} while($this->backend_loop);
// trigger the onDisconnect callback
- echo '<script type="text/javascript">pfccomet._onDisconnect();</script>';
+ echo '<script type="text/javascript">pfccomet._onDisconnect();</script>'."\n";
+ echo '</body></html>';
flush();
die();
@@ -73,7 +79,7 @@
function formatResponse($data)
{
- return '<script type="text/javascript">pfccomet._onResponse(\''.addslashes($data).'\');</script>';
+ return '<script type="text/javascript">pfccomet._onResponse(\''.addslashes($data).'\');</script>'."\n";
}
function printJavascript($return = false)
@@ -82,10 +88,14 @@
$output .= '<script type="text/javascript" src="'.$this->pfccometjs_url.'"></script>'."\n";
$output .= '<script type="text/javascript">
Event.observe(window, "load", function() {
- pfccomet = new pfcComet({"url":"'.$this->backend_url.'?'.$this->backend_param.'"});
- pfccomet.onConnect = function(comet) { alert("connected"); };
- pfccomet.onDisconnect = function(comet) { alert("disconnected"); };
- pfccomet.onResponse = function(comet,data) { alert("response:"+data); };
+ pfccomet = new pfcComet({"url":"'.$this->backend_url.'?'.$this->backend_param.'"});'."\n";
+ if ( $this->onresponse_callback )
+ $output .= ' pfccomet.onResponse = '.$this->onresponse_callback.';'."\n";
+ if ( $this->onconnect_callback )
+ $output .= ' pfccomet.onConnect = '.$this->onconnect_callback.';'."\n";
+ if ( $this->ondisconnect_callback )
+ $output .= ' pfccomet.onDisconnect = '.$this->ondisconnect_callback.';'."\n";
+ $output .= '
pfccomet.connect();
});
</script>'."\n";
@@ -97,4 +107,4 @@
}
-?>
+?>
\ No newline at end of file
Modified: branches/pfc-comet/misc/comet-tests/iframe2/pfccomet.js
===================================================================
--- branches/pfc-comet/misc/comet-tests/iframe2/pfccomet.js 2007-08-02 16:27:50 UTC (rev 1075)
+++ branches/pfc-comet/misc/comet-tests/iframe2/pfccomet.js 2007-08-02 16:44:15 UTC (rev 1076)
@@ -93,7 +93,11 @@
_onDisconnect: function()
{
if (this._iframe) {
- if (navigator.appVersion.indexOf("MSIE") == -1) { this._iframe.remove(); }
+ if (navigator.appVersion.indexOf("MSIE") == -1 &&
+ navigator.appVersion.indexOf("KHTML") == -1) // or Konqueror will crash
+ {
+ this._iframe.remove();
+ }
this._iframe = false; // release the iframe to prevent problems with IE when reloading the page
}
this._isconnected = false;
Modified: branches/pfc-comet/misc/comet-tests/iframe2/tester.php
===================================================================
--- branches/pfc-comet/misc/comet-tests/iframe2/tester.php 2007-08-02 16:27:50 UTC (rev 1075)
+++ branches/pfc-comet/misc/comet-tests/iframe2/tester.php 2007-08-02 16:44:15 UTC (rev 1076)
@@ -1,7 +1,7 @@
<?php
function macallback($pfccomet) {
- return $pfccomet->formatResponse('test macallback');
+ return $pfccomet->formatResponse(time());
}
require_once 'pfccomet.class.php';
@@ -9,7 +9,8 @@
$pfccomet->pfccometjs_url = './pfccomet.js';
$pfccomet->prototypejs_url = '../../../data/public/js/prototype.js';
$pfccomet->backend_url = './tester.php';
-$pfccomet->backend_callback = 'macallback';
+$pfccomet->backend_callback = 'macallback';
+$pfccomet->onresponse_callback = 'update_servertime_area';
$pfccomet->run();
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
@@ -17,9 +18,21 @@
<head>
<title>pfcComet tester</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <?php $pfccomet->printJavascript(); ?>
+
+<script type="text/javascript">
+function update_servertime_area(comet,time)
+{
+ document.getElementById('date').innerHTML = time;
+}
+</script>
+
+<?php $pfccomet->printJavascript(); ?>
+
+
</head>
<body>
-tester
+
+ <div id="date">here will be displayed the server time</div>
+
</body>
</html>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|