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

Jifty commits jifty-commit at lists.jifty.org
Fri Jun 26 05:58:19 EDT 2009


Author: c9s
Date: Fri Jun 26 05:58:18 2009
New Revision: 7278

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

Log:
fix spa history event on page load and page reload.

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	Fri Jun 26 05:58:18 2009
@@ -11,13 +11,24 @@
     SPA = {
         initialHash: null,
         historyChange: function(newLocation, historyData, first) {
+            // if has first history, meaning ! is first load
             if (first) {
                 dhtmlHistory.add(newLocation, historyData);
-            } else {
+            } 
+            else {
+                // first page load
                 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":{} }, "");
+                } 
+                else {
+                    // go back to initail hash or initail path
+                    Jifty.update({ 
+                             "continuation": {}, "actions": {}, 
+                                "fragments": [ { "mode": "Replace", "args": {}, 
+                                   "region": "__page", 
+                                     "path": SPA.initialHash } ], 
+                         "action_arguments":{} }, ""
+                    );
                 }
             }
         },
@@ -67,10 +78,23 @@
         }
     };
 
+    // for page load event
     $(document).ready(function(){
-        SPA.initialHash = location.pathname + location.search;
+
+        if( location.hash ) {
+            SPA.initialHash = location.hash.slice(1) ; 
+        }
+        else {
+            SPA.initialHash = location.pathname + location.search; // /entrypoint
+        }
+
         dhtmlHistory.initialize();
         dhtmlHistory.addListener(SPA.historyChange);
+
+        // fire history event manually
+        if( dhtmlHistory.isFirstLoad() && location.hash ) {
+            dhtmlHistory.fireHistoryEvent( location.hash.slice(1) );
+        }
     });
     
 })(jQuery);


More information about the Jifty-commit mailing list