Changeset - 006d68c4d7b9
[Not reviewed]
default
1 4 0
Mads Kiilerich (kiilerix) - 6 years ago 2018-12-25 19: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) First comment
LICENSE.md
Show inline comments
 
@@ -186,37 +186,6 @@ using the ''kallithea-cli front-end-buil
 

	
 

	
 

	
 
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/public/js/native.history.js
Show inline comments
 
deleted file
kallithea/templates/base/root.html
Show inline comments
 
@@ -72,22 +72,12 @@
 
        <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();
kallithea/templates/files/files.html
Show inline comments
 
@@ -53,7 +53,7 @@ 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;
 
        }
 

	
 
@@ -82,7 +82,8 @@ var ypjax_links = function(){
 
        // 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();
 
@@ -218,11 +219,11 @@ var post_load_state = function(state) {
 

	
 
$(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
kallithea/templates/files/files_source.html
Show inline comments
 
@@ -86,6 +86,6 @@
 
             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) First comment
You need to be logged in to comment. Login now