Commit 858b97d2 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Make history navigation work in IE.

Docs.History now uses Ext.util.History instead of history.pushState.
parent e2e9e523
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -87,6 +87,11 @@
    </div>
  </div>

  <form id="history-form" class="x-hide-display">
    <input type="hidden" id="x-history-field" />
    <iframe id="x-history-frame"></iframe>
  </form>

  <script type="text/javascript" src="extjs/ext-all-debug.js"></script>
  <script type="text/javascript" src="prettify/prettify.js"></script>
  <script type="text/javascript">
+12 −25
Original line number Diff line number Diff line
/**
 * Browser history management with history.pushState for compliant
 * browsers.
 * Browser history management using Ext.util.History.
 */
Ext.define("Docs.History", {
    singleton: true,
    compliant: window.history && window.history.pushState,

    /**
     * Initializes history management.
     */
    init: function() {
        if (!this.compliant) {
            return;
        }

        window.addEventListener('popstate', Ext.bind(function(e) {
            e.preventDefault();
            this.navigate();
            return false;
        }, this), false);

        this.navigate();
        Ext.util.History.init(function() {
            this.navigate(Ext.util.History.getToken());
        }, this);
        Ext.util.History.on("change", this.navigate, this);
    },

    // Parses current URL and navigates to the page
    navigate: function() {
        var url = this.parseUrl();
    navigate: function(token) {
        var url = this.parseToken(token);
        if (url.type === "api") {
            Docs.ClassLoader.load(url.key, true);
            Ext.getCmp('treePanelCmp').selectClass(url.key.replace(/-.*$/, ''));
@@ -40,21 +31,17 @@ Ext.define("Docs.History", {
    },

    // Parses current browser location
    parseUrl: function() {
        var matches = document.location.hash.match(/#\/(api|guide)\/(.*)/);
    parseToken: function(token) {
        var matches = token && token.match(/\/(api|guide)\/(.*)/);
        return matches ? {type: matches[1], key: matches[2]} : {};
    },

    /**
     * Adds URL to history
     *
     * @param {String} url  the part of URL after #
     * @param {String} token  the part of URL after #
     */
    push: function(url) {
        if (!this.compliant) {
            return;
        }
        var fullUrl = Docs.App.getBaseUrl() + "#" + url;
        window.history.pushState({}, '', fullUrl);
    push: function(token) {
        Ext.util.History.add(token);
    }
});