Sha256: 0f912701da9bc3d38953fb23899b0769ae83c43edb2a3eb5899b0c7c49e159ad

Contents?: true

Size: 1.07 KB

Versions: 16

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.

window.History = (function() {

    var currentHash = null;

    function getMemo() {
        return $.deserialize(currentHash);
    }

    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(obj) {
            window.location.hash = "#" + $.serialize(obj);
        },
        currentHash: function() {
            return getHash();
        }
    };

})();

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
sports_db-0.2.19 app/assets/javascripts/core/History.js
sports_db-0.2.18 app/assets/javascripts/core/History.js
sports_db-0.2.17 app/assets/javascripts/core/History.js
sports_db-0.2.16 app/assets/javascripts/core/History.js
sports_db-0.2.15 app/assets/javascripts/core/History.js
sports_db-0.2.14 app/assets/javascripts/core/History.js
sports_db-0.2.13 app/assets/javascripts/core/History.js
sports_db-0.2.12 app/assets/javascripts/core/History.js
sports_db-0.2.11 app/assets/javascripts/core/History.js
sports_db-0.2.10 app/assets/javascripts/core/History.js
sports_db-0.2.9 app/assets/javascripts/core/History.js
sports_db-0.2.8 app/assets/javascripts/core/History.js
sports_db-0.2.7 app/assets/javascripts/core/History.js
sports_db-0.2.6 app/assets/javascripts/core/History.js
sports_db-0.2.5 app/assets/javascripts/core/History.js
sports_db-0.2.4 app/assets/javascripts/core/History.js