<commit_before>/**
 * model/fancy/location.js
 */

function changePathGen (method) {
    return function (path) {
        window['history'][method + 'State']({}, '', path);
        $(window).trigger(method + 'state');
    };
}

models['location'] = baseModel.extend({
    /**
     * Example:
     * var loc = tbone.models.location.make();
     * T(function () {
     *     console.log('the hash is ' + loc('hash'));
     * });
     * loc('hash', '#this-is-the-new-hash');
     */
    initialize: function () {
        var self = this;
        function updateHash () {
            self('hash', location.hash);
        }
        function updatePath () {
            self('pathname', location.pathname);
        }

        $(window).bind('hashchange', updateHash);
        $(window).bind('popstate pushstate replacestate', updatePath);
        updateHash();
        updatePath();

        self(function () {
            var hash = self('hash');
            if (location.hash !== hash) {
                location.hash = hash;
            }
        });
        self(function () {
            var pathname = self('pathname');
            if (location.pathname !== pathname) {
                self['pushPath'](pathname);
            }
        });
    },

    'pushPath': changePathGen('push'),

    'replacePath': changePathGen('replace')
});<commit_msg>Add search to location model<commit_after>/**
 * model/fancy/location.js
 */

function changePathGen (method) {
    return function (path) {
        window['history'][method + 'State']({}, '', path);
        $(window).trigger(method + 'state');
    };
}

models['location'] = baseModel.extend({
    /**
     * Example:
     * var loc = tbone.models.location.make();
     * T(function () {
     *     console.log('the hash is ' + loc('hash'));
     * });
     * loc('hash', '#this-is-the-new-hash');
     */
    initialize: function () {
        var self = this;
        var recentlyChanged;
        function update (ev) {
            recentlyChanged = self('hash') !== location.hash ||
                              self('search') !== location.search ||
                              self('pathname') !== location.pathname;
            if (recentlyChanged) {
                self('hash', location.hash);
                self('pathname', location.pathname);
                self('search', location.search);
            }
        }
        $(window).bind('hashchange popstate pushstate replacestate', update);
        update();

        self(function () {
            var pathname = self('pathname');
            var search = self('search');
            var hash = self('hash');
            if (!recentlyChanged) {
                self['pushPath'](pathname + (search || '') + (hash ? '#' + hash : ''));
            }
            recentlyChanged = false;
        });
    },

    'pushPath': changePathGen('push'),
    'replacePath': changePathGen('replace')
});
{'fraction_non_alphanumeric': 0.17074010327022376, 'fraction_numerical': 0.0, 'mean_word_length': 1.8687068114511352, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6483115', 'n_tokens_mistral': 801, 'n_tokens_neox': 790, 'n_words': 151}