[Jifty-commit] r2091 - in jifty/trunk: share/web/static/js
share/web/templates/=
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Mon Oct 30 23:48:53 EST 2006
Author: jesse
Date: Mon Oct 30 23:48:53 2006
New Revision: 2091
Added:
jifty/trunk/share/web/templates/=/subs_infinite_iframe
- copied, changed from r2090, /jifty/trunk/share/web/templates/=/subs
Removed:
jifty/trunk/share/web/templates/=/subs
Modified:
jifty/trunk/ (props changed)
jifty/trunk/share/web/static/js/jifty_subs.js
Log:
r29565 at pinglin: jesse | 2006-10-30 19:04:19 -0500
* Doc for how subscription stuff works. a bit of refactoring toward a second transport
Modified: jifty/trunk/share/web/static/js/jifty_subs.js
==============================================================================
--- jifty/trunk/share/web/static/js/jifty_subs.js (original)
+++ jifty/trunk/share/web/static/js/jifty_subs.js Mon Oct 30 23:48:53 2006
@@ -2,25 +2,44 @@
{
+ /* onPushHandler is called for each new pushed element.
+ (currently, this is always a <pushfrag>).
+ This routine takes the pushed element and extracts render mode (Before, After, Replace, Delete)
+ , region name and other rendering information. Then it calls jifty's "apply_fragment_updates to the
+ item inside the <pushfrag> (the actual fragment);
+
+ f is the specification for the new fragment. (region, path, mode and other infomration extracted from the fragment)
+
+ */
+
var onPushHandler = function(t) {
- var mode = t.attributes['mode'].nodeValue;
- var rid = t.firstChild.attributes['id'].nodeValue;
- var f = { region: rid, path: '', mode: mode };
- f = prepare_element_for_update(f);
- apply_fragment_updates(t.firstChild, f);
+ var mode = t.attributes['mode'].nodeValue;
+ var rid = t.firstChild.attributes['id'].nodeValue;
+ var f = { region: rid, path: '', mode: mode };
+ f = prepare_element_for_update(f);
+ apply_fragment_updates(t.firstChild, f);
};
+
+
+ /* This function constructs a new Jifty.Subs object and sets up a callback with HTTP.Push to run our onPushHandler each time a new element is added to the hidden iframe's body.
+
+ We could instead say "sets up our transport. every time the transport gets a new item, call onPushHandler"
+ */
+
+ /* Jifty.Subs.start() will connect to the transport */
+
Jifty.Subs = function(args) {
- var window_id = args.window_id; // XXX: not yet
- var uri = args.uri;
- if (!uri)
- uri = "/=/subs?";
- var push = new HTTP.Push({ "uri": uri, interval : 100,
- "onPush" : onPushHandler});
-
- this.start = function() {
- push.start();
- };
+ var window_id = args.window_id; // XXX: not yet
+ var uri = args.uri;
+ if (!uri)
+ uri = "/=/subs_infinite_iframe?";
+ var push = new HTTP.Push({ "uri": uri, interval : 100,
+ "onPush" : onPushHandler});
+
+ this.start = function() {
+ push.start();
+ };
}
}
Copied: jifty/trunk/share/web/templates/=/subs_infinite_iframe (from r2090, /jifty/trunk/share/web/templates/=/subs)
==============================================================================
--- /jifty/trunk/share/web/templates/=/subs (original)
+++ jifty/trunk/share/web/templates/=/subs_infinite_iframe Mon Oct 30 23:48:53 2006
@@ -1,3 +1,6 @@
+<%args>
+$forever => 1
+</%args>
<%init>
$r->content_type("text/html; charset=utf-8");
@@ -14,18 +17,38 @@
<html><head><title></title></head>
END
chomp $begin;
-my $whitespace = " " x (1024 - length $begin);
-$begin =~ s/<body>$/$whitespace<body>/s;
+my $id = Jifty->web->session->id;
+
+if ($forever) {
+ my $whitespace = " " x ( 1024 - length $begin );
+ $begin =~ s/<body>$/$whitespace<body>/s;
+}
$m->print($begin);
$m->flush_buffer;
+$writer->startTag("body");
-$writer->startTag( "body" );
+if ($forever) {
-my $id = Jifty->web->session->id;
+ while (1) {
+ write_subs_once($writer);
+ flush STDOUT;
+ sleep 1;
+ }
+
+}
-while (1) {
+else {
+ write_subs_once($writer);
+ $writer->endTag();
+ return;
+}
+
+
+
+sub write_subs_once {
+ my $writer = shift;
Jifty::Subs::Render->render(
$id,
sub {
@@ -36,10 +59,5 @@
$writer->endTag();
$writer->endTag();
} );
-
- flush STDOUT;
- sleep 1;
}
-$writer->endTag();
-
</%init>
More information about the Jifty-commit
mailing list