Changeset - 553f38960a5a
[Not reviewed]
default
0 1 0
Mads Kiilerich - 7 years ago 2018-12-25 20:23:42
mads@kiilerich.com
files: Extract load_state function

To be used when dropping native.history.js ...
1 file changed with 20 insertions and 18 deletions:
0 comments (0 inline, 0 general)
kallithea/templates/files/files.html
Show inline comments
 
@@ -87,12 +87,30 @@ var ypjax_links = function(){
 
        //now we're sure that we can do ypjax things
 
        e.preventDefault();
 
        return false;
 
    });
 
}
 

	
 
var load_state = function(state) {
 
    var $files_data = $('#files_data');
 
    var cache_key = state.url;
 
    var _cache_obj = CACHE[cache_key];
 
    var _cur_time = new Date().getTime();
 
    if (_cache_obj !== undefined && _cache_obj[0] > _cur_time) {
 
        $files_data.html(_cache_obj[1]);
 
        $files_data.css('opacity', '1.0');
 
        post_load_state(state);
 
    } else {
 
        asynchtml(State.url, $files_data, function() {
 
                  post_load_state(state);
 
                  var expire_on = new Date().getTime() + CACHE_EXPIRE;
 
                  CACHE[cache_key] = [expire_on, $files_data.html()];
 
            });
 
    }
 
}
 

	
 
var post_load_state = function(state) {
 
    ypjax_links();
 
    tooltip_activate();
 

	
 
    if(state !== undefined) {
 
        //initially loaded stuff
 
@@ -195,33 +213,17 @@ var post_load_state = function(state) {
 
        });
 
    });
 
}
 

	
 
$(document).ready(function(){
 
    ypjax_links();
 
    var $files_data = $('#files_data');
 
    //Bind to StateChange Event
 
    History.Adapter.bind(window,'statechange',function(){
 
        var State = History.getState();
 
        cache_key = State.url;
 
        //check if we have this request in cache maybe ?
 
        var _cache_obj = CACHE[cache_key];
 
        var _cur_time = new Date().getTime();
 
        // get from cache if it's there and not yet expired !
 
        if(_cache_obj !== undefined && _cache_obj[0] > _cur_time){
 
            $files_data.html(_cache_obj[1]);
 
            $files_data.css('opacity','1.0');
 
            post_load_state(State.data);
 
        }
 
        else{
 
            asynchtml(State.url, $files_data, function(){
 
                    post_load_state(State.data);
 
                    var expire_on = new Date().getTime() + CACHE_EXPIRE;
 
                    CACHE[cache_key] = [expire_on, $files_data.html()];
 
                });
 
        }
 
        if (State.data)
 
            load_state(State.data);
 
    });
 

	
 
    // init the search filter
 
    var _node_list_url = node_list_url.replace('__REV__', ${h.js(c.changeset.raw_id)}).replace('__FPATH__', ${h.js(h.safe_unicode(c.file.path))});
 
    var _url_base = url_base.replace('__REV__', ${h.js(c.changeset.raw_id)});
 
    fileBrowserListeners(_node_list_url, _url_base);
0 comments (0 inline, 0 general)