[Phpfreechat-svn] SF.net SVN: phpfreechat: [1069] branches/pfc-comet/misc/comet-tests
Status: Beta
Brought to you by:
kerphi
|
From: <ke...@us...> - 2007-08-01 14:37:04
|
Revision: 1069
http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1069&view=rev
Author: kerphi
Date: 2007-08-01 07:37:04 -0700 (Wed, 01 Aug 2007)
Log Message:
-----------
basic comet implement using iframe (from www.zeitoun.net)
Added Paths:
-----------
branches/pfc-comet/misc/comet-tests/iframe/
branches/pfc-comet/misc/comet-tests/iframe/backend.php
branches/pfc-comet/misc/comet-tests/iframe/client.html
Added: branches/pfc-comet/misc/comet-tests/iframe/backend.php
===================================================================
--- branches/pfc-comet/misc/comet-tests/iframe/backend.php (rev 0)
+++ branches/pfc-comet/misc/comet-tests/iframe/backend.php 2007-08-01 14:37:04 UTC (rev 1069)
@@ -0,0 +1,44 @@
+<?php
+
+header("Cache-Control: no-cache, must-revalidate");
+header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
+flush();
+
+?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <title>Comet php backend</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+</head>
+<body>
+
+<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','../../../data/public/js/prototype.js');
+ var head = document.getElementsByTagName('head');
+ head[0].appendChild(prototypejs);
+ }
+ // load the comet object
+ var comet = window.parent.comet;
+</script>
+
+<?php
+
+while(1) {
+ echo '<script type="text/javascript">';
+ echo 'comet.printServerTime('.time().');';
+ echo '</script>';
+ flush(); // used to send the echoed data to the client
+ sleep(1); // a little break to unload the server CPU
+}
+
+?>
+
+
+</body>
+</html>
\ No newline at end of file
Added: branches/pfc-comet/misc/comet-tests/iframe/client.html
===================================================================
--- branches/pfc-comet/misc/comet-tests/iframe/client.html (rev 0)
+++ branches/pfc-comet/misc/comet-tests/iframe/client.html 2007-08-01 14:37:04 UTC (rev 1069)
@@ -0,0 +1,80 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>Comet demo</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <script type="text/javascript" src="../../../data/public/js/prototype.js"></script>
+ </head>
+ <body>
+ <div id="content">The server time will be shown here</div>
+
+<script type="text/javascript">
+var comet = {
+ connection : false,
+ iframediv : false,
+
+ initialize: function() {
+ if (navigator.appVersion.indexOf("MSIE") != -1) {
+
+ // For IE browsers
+ comet.connection = new ActiveXObject("htmlfile");
+ comet.connection.open();
+ comet.connection.write("<html>");
+ comet.connection.write("<script>document.domain = '"+document.domain+"'");
+ comet.connection.write("</html>");
+ comet.connection.close();
+ comet.iframediv = comet.connection.createElement("div");
+ comet.connection.appendChild(comet.iframediv);
+ comet.connection.parentWindow.comet = comet;
+ comet.iframediv.innerHTML = "<iframe id='comet_iframe' src='./backend.php'></iframe>";
+
+ } else if (navigator.appVersion.indexOf("KHTML") != -1) {
+
+ // for KHTML browsers
+ comet.connection = document.createElement('iframe');
+ comet.connection.setAttribute('id', 'comet_iframe');
+ comet.connection.setAttribute('src', './backend.php');
+ with (comet.connection.style) {
+ position = "absolute";
+ left = top = "-100px";
+ height = width = "1px";
+ visibility = "hidden";
+ }
+ document.body.appendChild(comet.connection);
+
+ } else {
+
+ // For other browser (Firefox...)
+ comet.connection = document.createElement('iframe');
+ comet.connection.setAttribute('id', 'comet_iframe');
+ with (comet.connection.style) {
+ left = top = "-100px";
+ height = width = "1px";
+ visibility = "hidden";
+ display = 'none';
+ }
+ comet.iframediv = document.createElement('iframe');
+ comet.iframediv.setAttribute('src', './backend.php');
+ comet.connection.appendChild(comet.iframediv);
+ document.body.appendChild(comet.connection);
+
+ }
+ },
+
+ // this function will be called from backend.php
+ printServerTime: function (time) {
+ $('content').innerHTML = time;
+ },
+
+ onUnload: function() {
+ if (comet.connection) {
+ comet.connection = false; // release the iframe to prevent problems with IE when reloading the page
+ }
+ }
+}
+Event.observe(window, "load", comet.initialize);
+Event.observe(window, "unload", comet.onUnload);
+</script>
+
+</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.
|