changeset 7473:d66201a7ce6e

files: change "callbacks" function to the more descriptive name "post_load_state" and let it take an actual state data object Makes the function more independent of native.history.js .
author Mads Kiilerich <mads@kiilerich.com>
date Tue, 25 Dec 2018 20:23:42 +0100
parents 9004225eb812
children 55af73733793
files kallithea/templates/files/files.html kallithea/templates/files/files_source.html
diffstat 2 files changed, 11 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/templates/files/files.html	Tue Dec 11 01:14:16 2018 +0100
+++ b/kallithea/templates/files/files.html	Tue Dec 25 20:23:42 2018 +0100
@@ -90,20 +90,19 @@
     });
 }
 
-// callbacks needed to process the ypjax filebrowser
-var callbacks = function(State){
+var post_load_state = function(state) {
     ypjax_links();
     tooltip_activate();
 
-    if(State !== undefined){
+    if(state !== undefined) {
         //initially loaded stuff
-        var _f_path = State.data.f_path;
-        var _rev = State.data.rev;
+        var _f_path = state.f_path;
+        var _rev = state.rev;
 
-        fileBrowserListeners(State.data.node_list_url, State.data.url_base);
+        fileBrowserListeners(state.node_list_url, state.url_base);
         // Inform Google Analytics of the change
         if ( typeof window.pageTracker !== 'undefined' ) {
-            window.pageTracker._trackPageview(State.url);
+            window.pageTracker._trackPageview(state.url);
         }
     }
 
@@ -211,12 +210,11 @@
         if(_cache_obj !== undefined && _cache_obj[0] > _cur_time){
             $files_data.html(_cache_obj[1]);
             $files_data.css('opacity','1.0');
-            //callbacks after ypjax call
-            callbacks(State);
+            post_load_state(State.data);
         }
         else{
             asynchtml(State.url, $files_data, function(){
-                    callbacks(State);
+                    post_load_state(State.data);
                     var expire_on = new Date().getTime() + CACHE_EXPIRE;
                     CACHE[cache_key] = [expire_on, $files_data.html()];
                 });
--- a/kallithea/templates/files/files_source.html	Tue Dec 11 01:14:16 2018 +0100
+++ b/kallithea/templates/files/files_source.html	Tue Dec 25 20:23:42 2018 +0100
@@ -80,16 +80,12 @@
 
 <script>
     $(document).ready(function(){
-        // fake html5 history state
-        var _State = {
-           url: ${h.js(h.url.current())},
-           data: {
+        var state = {
              node_list_url: node_list_url.replace('__REV__',${h.js(c.changeset.raw_id)}).replace('__FPATH__', ${h.js(h.safe_unicode(c.file.path))}),
              url_base: url_base.replace('__REV__',${h.js(c.changeset.raw_id)}),
-             rev:${h.js(c.changeset.raw_id)},
+             rev: ${h.js(c.changeset.raw_id)},
              f_path: ${h.js(h.safe_unicode(c.file.path))}
-           }
         }
-        callbacks(_State); // defined in files.html, main callbacks. Triggered in pjax calls
+        post_load_state(State.data); // defined in files.html
     });
 </script>