[Jifty-commit] r5757 - jifty/trunk/share/plugins/Jifty/Plugin/SinglePage/web/static/js/singlepage

Jifty commits jifty-commit at lists.jifty.org
Tue Aug 19 13:44:51 EDT 2008


Author: hlb
Date: Tue Aug 19 13:44:50 2008
New Revision: 5757

Modified:
   jifty/trunk/share/plugins/Jifty/Plugin/SinglePage/web/static/js/singlepage/spa.js

Log:
rewrite SinglePage plugin:

* it does not append #spa_start any longer.
* it does not force browsers to reload page when users pastes URL in location bar, nor clicks back button from other sites.
* simplified logic.


Modified: jifty/trunk/share/plugins/Jifty/Plugin/SinglePage/web/static/js/singlepage/spa.js
==============================================================================
--- jifty/trunk/share/plugins/Jifty/Plugin/SinglePage/web/static/js/singlepage/spa.js	(original)
+++ jifty/trunk/share/plugins/Jifty/Plugin/SinglePage/web/static/js/singlepage/spa.js	Tue Aug 19 13:44:50 2008
@@ -1,20 +1,23 @@
+window.dhtmlHistory.create({
+    toJSON: function(o) {
+        return JSON.stringify(o);
+    }
+    , fromJSON: function(s) {
+        return JSON.parse(s);
+    }
+});
+
 (function($) {
     SPA = {
-        initialHash: "spa_start",
-        currentHash: null,
-        currentLocation: null,
+        initialHash: null,
         historyChange: function(newLocation, historyData, first) {
-
-            /* reload if user goes to the first page */
-            if (newLocation == SPA.initialHash) {
-                location.href = location.pathname + location.search;
-            }
-
             if (first) {
                 dhtmlHistory.add(newLocation, historyData);
             } else {
                 if (historyStorage.hasKey(newLocation)) {
                     Jifty.update(historyStorage.get(newLocation), "");
+                } else {
+                    Jifty.update({ "continuation": {}, "actions": {}, "fragments": [ { "mode": "Replace", "args": {}, "region": "__page", "path": SPA.initialHash } ], "action_arguments":{} }, "");
                 }
             }
         },
@@ -64,34 +67,10 @@
         }
     };
 
-    /*
-     * If user paste /#/abc in location bar, or click the reload button,
-     * then we should redirect him to the right page
-     */
-    SPA.currentHash = location.hash;
-    if (SPA.currentHash.length) {
-        if (SPA.currentHash.charAt(0) == '#' && SPA.currentHash.charAt(1) == '/') {
-            SPA.currentLocation = SPA.currentHash.slice(1);
-            location.href = SPA.currentLocation;
-        }
-    }
-
     $(document).ready(function(){
+        SPA.initialHash = location.pathname + location.search;
         dhtmlHistory.initialize();
         dhtmlHistory.addListener(SPA.historyChange);
-        if (dhtmlHistory.isFirstLoad()) {
-            dhtmlHistory.add(SPA.initialHash, "");
-        }
     });
     
 })(jQuery);
-
-
-window.dhtmlHistory.create({
-    toJSON: function(o) {
-        return JSON.stringify(o);
-    }
-    , fromJSON: function(s) {
-        return JSON.parse(s);
-    }
-});


More information about the Jifty-commit mailing list