[Jifty-commit] r4956 - jifty/branches/jquery/share/web/static/js

Jifty commits jifty-commit at lists.jifty.org
Tue Jan 29 01:47:27 EST 2008


Author: gugod
Date: Tue Jan 29 01:47:26 2008
New Revision: 4956

Modified:
   jifty/branches/jquery/share/web/static/js/jifty_subs.js

Log:
Replace the use to Ajax.PeriodicalUpdator with a simple implementation
of jQuery.ajax(). Also fix the case when SinglePage plugin is
enabled, region names are prefixed with "__page-", makes it always
failed to address the correct region.


Modified: jifty/branches/jquery/share/web/static/js/jifty_subs.js
==============================================================================
--- jifty/branches/jquery/share/web/static/js/jifty_subs.js	(original)
+++ jifty/branches/jquery/share/web/static/js/jifty_subs.js	Tue Jan 29 01:47:26 2008
@@ -1,6 +1,6 @@
 if (typeof Jifty == "undefined") Jifty = { };
 
-{
+(function(){
 
     /* onPushHandler is called for each new pushed element.
        (currently, this is always a <pushfrag>).  This routine takes
@@ -18,12 +18,19 @@
     	var mode = t.getAttribute('mode');
     	var rid =  t.firstChild.getAttribute('id');
     	var f = { region: rid, path: '', mode: mode };
+
+        // If SinglePlugin is enabled, region name will be prefixed
+        // "__page-" by the time that region was rendered. Therefore
+        // it should also be prefixed the same here.
+        if(Jifty.fragments["__page"] != null) {
+            f['region'] = "__page-" + f['region']
+        }
+
     	f = prepare_element_for_update(f);
+        if (f == null) return;
     	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
@@ -38,34 +45,30 @@
     	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});
+    	    uri = "/=/subs?forever=0";
     	
     	this.start = function() {
     	    //push.start();
+            var self = this;
 
-	    new Ajax.PeriodicalUpdater({},'/=/subs?forever=0',
-	    {
-	        'decay': 1, 'frequency': 0,
-	        'asynchronous':true, 
-	        'evalScripts':false,
-	        'method': 'get',
-	        'onSuccess': onSuccess,
-	        'onFailure': onFailure
-	    });
-	    	};
+            jQuery.ajax({
+                url: uri,
+                type: "get",
+                success: function(responseText) {
+                    var container = document.createElement('div');
+                    container.innerHTML = responseText;
+                    jQuery("pushfrag", container).each(function() {
+                        onPushHandler(this);
+                    });
+
+                    setTimeout(function() {
+                        self.start();
+                    }, 1000)
+                },
+                error: function() {
+                }
+            });
+        }          
     }
 
-
-    function onSuccess(req, json) {
-        var container = document.createElement('div');
-        container.innerHTML = req.responseText;
-        var frags = container.getElementsByTagName('pushfrag');
-        for(var i = 0 ; i < frags.length; i++) {
-            onPushHandler(frags[i]);
-        }
-    }
-    function onFailure(req) { }
-
-}
-
+})();


More information about the Jifty-commit mailing list