<commit_before>﻿import IHistoryManager = require('./IHistoryManager');
import HistoryNavigator = require('./HistoryNavigator');
import State = require('../config/State');

class HashHistoryManager implements IHistoryManager {
    disabled: boolean = (typeof window === 'undefined') || !('onhashchange' in window);

    init() {
        if (!this.disabled) {
            if (window.addEventListener)
                window.addEventListener('hashchange', HistoryNavigator.navigateHistory);
            else
                window.attachEvent('onhashchange', HistoryNavigator.navigateHistory);
        }
    }

    addHistory(state: State, url: string) {
        if (state.title && (typeof document !== 'undefined'))
            document.title = state.title;
        if (!this.disabled && location.hash.substring(1) !== url)
            location.hash = url;
    }

    getCurrentUrl(): string {
        return location.hash.substring(1);
    }

    getHref(url: string): string {
        if (!url)
            throw new Error('The Url is invalid');
        return '#' + url;
    }

    getUrl(anchor: HTMLAnchorElement) {
        return anchor.hash.substring(1);
    }
}
export = HashHistoryManager;<commit_msg>Replaced ? with # in Url hash<commit_after>﻿import IHistoryManager = require('./IHistoryManager');
import HistoryNavigator = require('./HistoryNavigator');
import State = require('../config/State');

class HashHistoryManager implements IHistoryManager {
    disabled: boolean = (typeof window === 'undefined') || !('onhashchange' in window);

    init() {
        if (!this.disabled) {
            if (window.addEventListener)
                window.addEventListener('hashchange', HistoryNavigator.navigateHistory);
            else
                window.attachEvent('onhashchange', HistoryNavigator.navigateHistory);
        }
    }

    addHistory(state: State, url: string) {
        if (state.title && (typeof document !== 'undefined'))
            document.title = state.title;
        url = this.encode(url);
        if (!this.disabled && location.hash.substring(1) !== url)
            location.hash = url;
    }

    getCurrentUrl(): string {
        return this.decode(location.hash.substring(1));
    }

    getHref(url: string): string {
        if (!url)
            throw new Error('The Url is invalid');
        return '#' + this.encode(url);
    }

    getUrl(anchor: HTMLAnchorElement) {
        return this.decode(anchor.hash.substring(1));
    }

    private encode(url: string): string {
        return url.replace('?', '#');
    }

    private decode(hash: string): string {
        return hash.replace('#', '?');
    }
}
export = HashHistoryManager;
{'fraction_non_alphanumeric': 0.1366181410974244, 'fraction_numerical': 0.0022396416573348264, 'mean_word_length': 2.641304347826087, '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': '2550146', 'n_tokens_mistral': 720, 'n_tokens_neox': 701, 'n_words': 159}