Changeset - 006d68c4d7b9
[Not reviewed]
default
1 4 0
Mads Kiilerich - 7 years ago 2018-12-25 20:23:42
mads@kiilerich.com
files: use the web browsers built-in js history instead of native.history.js

The history API is available in all web browsers we support.

window.history.pushState is called to register a state that we can go
back/forward to. (But contrary to native.history.js, it doesn't do any
immediate processing of the state and doesn't actually navigate to it.)

When navigation occurs, we get the popstate event and invoke load_state to
actually load the state.
5 files changed with 9 insertions and 2023 deletions:
0 comments (0 inline, 0 general)
LICENSE.md
Show inline comments
 
@@ -177,55 +177,24 @@ Kallithea uses some CSS from a system ca
 
is:
 

	
 
Copyright © 2013 Tom Terrace (and likely others)
 

	
 
and licensed under the MIT-permissive license, which is
 
[included in this distribution](MIT-Permissive-License.txt).
 

	
 
It is not distributed with Kallithea, but will be downloaded
 
using the ''kallithea-cli front-end-build'' command.
 

	
 

	
 

	
 
History.js
 
----------
 

	
 
Kallithea incorporates some CSS from a system called History.js, which is
 

	
 
Copyright 2010-2011 Benjamin Arthur Lupton <contact@balupton.com>
 

	
 
Redistribution and use in source and binary forms, with or without
 
modification, are permitted provided that the following conditions are met:
 

	
 
1. Redistributions of source code must retain the above copyright notice,
 
   this list of conditions and the following disclaimer.
 

	
 
2. Redistributions in binary form must reproduce the above copyright notice,
 
   this list of conditions and the following disclaimer in the documentation
 
   and/or other materials provided with the distribution.
 

	
 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 
POSSIBILITY OF SUCH DAMAGE.
 

	
 

	
 

	
 
Flot
 
----
 

	
 
Kallithea uses some parts of a Javascript system called
 
[Flot](http://www.flotcharts.org/), which is:
 

	
 
Copyright (c) 2007-2014 IOLA and Ole Laursen
 

	
 
Permission is hereby granted, free of charge, to any person
 
obtaining a copy of this software and associated documentation
 
files (the "Software"), to deal in the Software without
 
restriction, including without limitation the rights to use,
kallithea/public/js/native.history.js
Show inline comments
 
deleted file
kallithea/templates/base/root.html
Show inline comments
 
@@ -63,40 +63,30 @@
 
            var REPO_NAME = "";
 
            %if hasattr(c, 'repo_name'):
 
                var REPO_NAME = ${h.js(c.repo_name)};
 
            %endif
 

	
 
            var _authentication_token = ${h.js(h.authentication_token())};
 
        </script>
 
        <script type="text/javascript" src="${h.url('/js/jquery.min.js', ver=c.kallithea_version)}"></script>
 
        <script type="text/javascript" src="${h.url('/js/jquery.dataTables.js', ver=c.kallithea_version)}"></script>
 
        <script type="text/javascript" src="${h.url('/js/dataTables.bootstrap.js', ver=c.kallithea_version)}"></script>
 
        <script type="text/javascript" src="${h.url('/js/bootstrap.js', ver=c.kallithea_version)}"></script>
 
        <script type="text/javascript" src="${h.url('/js/select2.js', ver=c.kallithea_version)}"></script>
 
        <script type="text/javascript" src="${h.url('/js/native.history.js', ver=c.kallithea_version)}"></script>
 
        <script type="text/javascript" src="${h.url('/js/jquery.caret.min.js', ver=c.kallithea_version)}"></script>
 
        <script type="text/javascript" src="${h.url('/js/jquery.atwho.min.js', ver=c.kallithea_version)}"></script>
 
        <script type="text/javascript" src="${h.url('/js/base.js', ver=c.kallithea_version)}"></script>
 
        ## EXTRA FOR JS
 
        <%block name="js_extra"/>
 
        <script type="text/javascript">
 
            (function(window,undefined){
 
                var History = window.History; // Note: We are using a capital H instead of a lower h
 
                if ( !History.enabled ) {
 
                     // History.js is disabled for this browser.
 
                     // This is because we can optionally choose to support HTML4 browsers or not.
 
                    return false;
 
                }
 
            })(window);
 

	
 
            $(document).ready(function(){
 
              tooltip_activate();
 
              show_more_event();
 
              // routes registration
 
              pyroutes.register('home', ${h.js(h.url('home'))}, []);
 
              pyroutes.register('new_gist', ${h.js(h.url('new_gist'))}, []);
 
              pyroutes.register('gists', ${h.js(h.url('gists'))}, []);
 
              pyroutes.register('new_repo', ${h.js(h.url('new_repo'))}, []);
 

	
 
              pyroutes.register('summary_home', ${h.js(h.url('summary_home', repo_name='%(repo_name)s'))}, ['repo_name']);
 
              pyroutes.register('changelog_home', ${h.js(h.url('changelog_home', repo_name='%(repo_name)s'))}, ['repo_name']);
 
              pyroutes.register('files_home', ${h.js(h.url('files_home', repo_name='%(repo_name)s',revision='%(revision)s',f_path='%(f_path)s'))}, ['repo_name', 'revision', 'f_path']);
kallithea/templates/files/files.html
Show inline comments
 
@@ -44,25 +44,25 @@ var url_base = ${h.js(h.url("files_home"
 
//send the nodelist request to this url
 
var node_list_url = ${h.js(h.url("files_nodelist_home",repo_name=c.repo_name,revision='__REV__',f_path='__FPATH__'))};
 

	
 
## new pyroutes URLs
 
pyroutes.register('files_nodelist_home', ${h.js(h.url('files_nodelist_home', repo_name=c.repo_name,revision='%(revision)s',f_path='%(f_path)s'))}, ['revision', 'f_path']);
 
pyroutes.register('files_history_home', ${h.js(h.url('files_history_home', repo_name=c.repo_name,revision='%(revision)s',f_path='%(f_path)s'))}, ['revision', 'f_path']);
 
pyroutes.register('files_authors_home', ${h.js(h.url('files_authors_home', repo_name=c.repo_name,revision='%(revision)s',f_path='%(f_path)s'))}, ['revision', 'f_path']);
 

	
 
var ypjax_links = function(){
 
    $('.ypjax-link').click(function(e){
 

	
 
        //don't do ypjax on middle click
 
        if(e.which == 2 || !History.enabled){
 
        if (e.which == 2) {
 
            return true;
 
        }
 

	
 
        var el = e.currentTarget;
 
        var url = el.href;
 

	
 
        var _base_url = ${h.jshtml(h.url("files_home",repo_name=c.repo_name,revision='',f_path=''))};
 
        _base_url = _base_url.replace('//','/');
 

	
 
        //extract rev and the f_path from url.
 
        parts = url.split(_base_url);
 
        if(parts.length != 2){
 
@@ -73,25 +73,26 @@ var ypjax_links = function(){
 
        var rev = parts2.shift(); // pop the first element which is the revision
 
        var f_path = parts2.join('/');
 

	
 
        //page title - make this consistent with title mako block above
 
        var title = ${h.jshtml(_('%s Files') % c.repo_name)} + " \u00B7 " + (f_path || '/') + " \u00B7 " + ${h.jshtml(c.site_name)};
 

	
 
        var _node_list_url = node_list_url.replace('__REV__',rev).replace('__FPATH__', f_path);
 
        var _url_base = url_base.replace('__REV__',rev);
 

	
 
        // Change our States and save some data for handling events
 
        var state = {url:url, title:title, url_base:_url_base,
 
                     node_list_url:_node_list_url, rev:rev, f_path:f_path};
 
        History.pushState(state, null, url);
 
        window.history.pushState(state, null, url);
 
        load_state(state);
 

	
 
        //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();
 
@@ -209,29 +210,29 @@ var post_load_state = function(state) {
 
            url: pyroutes.url('files_authors_home', {'revision': _rev, 'f_path': _f_path}),
 
            success: function(data) {
 
                $('#file_authors').html(data);
 
                $('#file_authors').show();
 
                tooltip_activate();
 
            }
 
        });
 
    });
 
}
 

	
 
$(document).ready(function(){
 
    ypjax_links();
 
    //Bind to StateChange Event
 
    History.Adapter.bind(window,'statechange',function(){
 
        var State = History.getState();
 
        if (State.data)
 
            load_state(State.data);
 

	
 
    // Process history navigation event and load its state
 
    window.addEventListener('popstate', function(e){
 
        if (e.state)
 
            load_state(e.state);
 
    });
 

	
 
    // 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);
 

	
 
    // change branch filter
 
    $("#branch_selector").select2({
 
        dropdownAutoWidth: true,
 
        maxResults: 50,
 
        sortResults: branchSort
kallithea/templates/files/files_source.html
Show inline comments
 
@@ -77,15 +77,15 @@
 
      %endif
 
    </div>
 
</div>
 

	
 
<script>
 
    $(document).ready(function(){
 
        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)},
 
             f_path: ${h.js(h.safe_unicode(c.file.path))}
 
        }
 
        post_load_state(State.data); // defined in files.html
 
        window.history.pushState(state, null, ${h.js(h.url.current())});
 
    });
 
</script>
0 comments (0 inline, 0 general)