Sha256: 61c5d29c567f3d8a68a56516d36fa604524ba7146bdb072520e1d4f764f5b7cf

Contents?: true

Size: 1.07 KB

Versions: 14

Compression:

Stored size: 1.07 KB

Contents

// A very simple history implementation. Generates events on the `document.body` element when the
// hash changes, and includes a parsed object of parameters or a string from the hash.

var History = (function() {

    var currentHash = null;

    function getMemo() {
        return currentHash.toParameters();
    }

    function getHash() {
        return window.location.hash.substring(1);
    }

    function poll() {
        var hash = getHash();
        if (currentHash !== hash) {
            currentHash = hash;
            $(document.body).trigger("hashchange", [getMemo()]);
        }
    }

    $(document).ready(function() {
        currentHash = getHash();

        if ('onhashchange' in window) {
            $(window).on('hashchange', poll);
        } else {
            setInterval(poll, 50);
        }

        $(document.body).trigger("hashchange", [getMemo()]);
    });

    return {
        add: function(params) {
            window.location.hash = "#" + $.objToQueryStr(params);
        },
        currentHash: function() {
            return getHash();
        }
    }

})();

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
sports_db-0.2.2 app/assets/javascripts/core/History.js
sports_db-0.2.1 app/assets/javascripts/core/History.js
sports_db-0.2 app/assets/javascripts/core/History.js
sports_db-0.0.13 app/assets/javascripts/core/History.js
sports_db-0.1.3 app/assets/javascripts/core/History.js
sports_db-0.1.2 app/assets/javascripts/core/History.js
sports_db-0.1.1 app/assets/javascripts/core/History.js
sports_db-0.1.0 app/assets/javascripts/core/History.js
sports_db-0.0.9 app/assets/javascripts/core/History.js
sports_db-0.0.8 app/assets/javascripts/core/History.js
sports_db-0.0.7 app/assets/javascripts/core/History.js
sports_db-0.0.6 app/assets/javascripts/core/History.js
sports_db-0.0.5 app/assets/javascripts/core/History.js
sports_db-0.0.4 app/assets/javascripts/core/History.js