Commit db67c9b4 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Forget scrollstate after closing a tab.

Moved scrollstate handling to Tabs controller.
parent 2f5702da
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -45,7 +45,6 @@ Ext.define('Docs.controller.Classes', {
    ],

    cache: {},
    scrollState: {},

    init: function() {
        this.addEvents(
@@ -118,7 +117,7 @@ Ext.define('Docs.controller.Classes', {
                    });

                    cmp.body.addListener('scroll', function(cmp, el) {
                        this.scrollState['#!/api/' + this.currentCls.name] = el.scrollTop;
                        this.setScrollState('#!/api/' + this.currentCls.name, el.scrollTop);
                    }, this);
                }
            }
@@ -224,7 +223,7 @@ Ext.define('Docs.controller.Classes', {
    scrollContent: function() {
        if (this.currentCls) {
            var baseUrl = '#!/api/' + this.currentCls.name;
            this.getOverview().getEl().down('.x-panel-body').scrollTo('top', this.scrollState[baseUrl] || 0);
            this.getOverview().getEl().down('.x-panel-body').scrollTo('top', this.getScrollState(baseUrl));
        }
    }

+14 −1
Original line number Diff line number Diff line
@@ -19,6 +19,19 @@ Ext.define('Docs.controller.Content', {
     */
    getBaseUrl: function() {
        return document.location.href.replace(/#.*/, "").replace(/index.html/, "");
    }
    },

    /**
     * Mediates Tabs controller getScrollState()
     */
    getScrollState: function(url) {
        return Docs.App.getController('Tabs').getScrollState(url);
    },

    /**
     * Mediates Tabs controller setScrollState()
     */
    setScrollState: function(url, scroll) {
        Docs.App.getController('Tabs').setScrollState(url, scroll);
    }
});
+2 −3
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@ Ext.define('Docs.controller.Guides', {
    ],

    cache: {},
    scrollState: {},

    init: function() {
        this.addEvents(
@@ -52,7 +51,7 @@ Ext.define('Docs.controller.Guides', {
            '#guide': {
                afterrender: function(cmp) {
                    cmp.el.addListener('scroll', function(cmp, el) {
                        this.scrollState[this.activeUrl] = el.scrollTop;
                        this.setScrollState(this.activeUrl, el.scrollTop);
                    }, this);
                }
            }
@@ -141,7 +140,7 @@ Ext.define('Docs.controller.Guides', {
    },

    scrollContent: function() {
        Ext.get('guide').scrollTo('top', this.scrollState[this.activeUrl] || 0);
        Ext.get('guide').scrollTo('top', this.getScrollState(this.activeUrl));
    }

});
+26 −1
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ Ext.define('Docs.controller.Tabs', {
        }
    ],

    scrollState: {},

    init: function() {
        this.getController('Classes').addListener({
            showClass: function(cls) {
@@ -114,7 +116,10 @@ Ext.define('Docs.controller.Tabs', {
        cmp.el.addListener('click', function(event, el) {
            cmp.justClosed = true;
            var docTab = Ext.get(el).up('.doctab');
            var next = Ext.getCmp('doctabs').removeTab(docTab.down('.tabUrl').getAttribute('href'));
            var url = docTab.down('.tabUrl').getAttribute('href');
            // Forget the scrollstate of a tab after closing
            delete this.scrollState[url];
            var next = Ext.getCmp('doctabs').removeTab(url);
            if (next) {
                Ext.getCmp('doctabs').activateTab(next);
                Docs.History.push(next);
@@ -162,6 +167,26 @@ Ext.define('Docs.controller.Tabs', {
    activateTab: function(url, activateOverview) {
        Ext.getCmp('doctabs').activateTab(url, activateOverview);
        Docs.History.push(url);
    },

    /**
     * Saves scrollstate of a tab.
     *
     * @param {String} url  URL of the tab.
     * @param {Number} scroll  the scroll amount.
     */
    setScrollState: function(url, scroll) {
        this.scrollState[url] = scroll;
    },

    /**
     * Returns scrollstate of a tab.
     *
     * @param {String} url  URL of the tab.
     * @return {Number} the scroll amount.
     */
    getScrollState: function(url) {
        return this.scrollState[url] || 0;
    }

});