{"size": 2314, "ext": "js", "max_stars_repo_path": "src/window/history.js", "max_stars_repo_name": "thatcher/env-js", "max_stars_repo_stars_event_min_datetime": "2015-01-14T09:37:24.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-04T05:50:15.000Z", "max_issues_repo_path": "src/window/history.js", "max_issues_repo_name": "thatcher/env-js", "max_issues_repo_issues_event_min_datetime": "2015-09-10T23:23:46.000Z", "max_issues_repo_issues_event_max_datetime": "2018-04-23T17:47:38.000Z", "max_forks_repo_path": "src/window/history.js", "max_forks_repo_name": "thatcher/env-js", "max_forks_repo_forks_event_min_datetime": "2015-02-06T18:58:50.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-07T19:43:43.000Z"}
{"max_stars_count": 77, "max_issues_count": 1, "max_forks_count": 23, "avg_line_length": 25.4285714286, "max_line_length": 75, "alphanum_fraction": 0.3988764045}

/*
 *  TODO: Document the History object via HTML5 spec
 *
 */
(function(){

var log = Envjs.logger();
Envjs.once('tick', function(){
	log = Envjs.logger('Envjs.Window.History').
		debug('history logger available');
});

exports.History = History = function(owner) {
    var $current = 0,
        $history = [null],
        $owner = owner;

    return {
        go : function(target) {
            if (typeof target === "number") {
                target = $current + target;
                if (target > -1 && target < $history.length){
                    if ($history[target].type === "hash") {
                        if ($owner.location) {
                            $owner.location.hash = $history[target].value;
                        }
                    } else {
                        if ($owner.location) {
                            $owner.location = $history[target].value;
                        }
                    }
                    $current = target;
                }
            } else {
                //TODO: walk through the history and find the 'best match'?
            }
        },

        get length() {
            return $history.length;
        },

        back : function(count) {
            if (count) {
                this.go(-count);
            } else {
                this.go(-1);
            }
        },

        get current() {
            return this.item($current);
        },

        get previous() {
            return this.item($current-1);
        },

        forward : function(count) {
            if (count) {
                this.go(count);
            } else {
                this.go(1);
            }
        },

        item: function(idx) {
            if (idx >= 0 && idx < $history.length) {
                return $history[idx];
            } else {
                return null;
            }
        },

        add: function(newLocation, type) {
            //not a standard interface, we expose it to simplify
            //history state modifications
            if (newLocation !== $history[$current]) {
                $history.slice(0, $current);
                $history.push({
                    type: type || 'href',
                    value: newLocation
                });
            }
        }
    }; 
};

}(/*History*/));
