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

Merge branch 'alt-tabs' into ext4-theme

parents 9698facd fc239e14
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ module JsDuck
          icons.merge!(extract_icons(child))
        end
      else
        icons[node[:id]] = node[:iconCls]
        icons[node[:clsName]] = node[:iconCls]
      end
      icons
    end
+1 −56
Original line number Diff line number Diff line
@@ -2,13 +2,8 @@
 * Browser history management using Ext.util.History.
 */
Ext.define("Docs.History", {
    extend: 'Docs.LocalStore',
    storeName: 'History',
    singleton: true,

    // Maximum number of items to keep in history store
    maxHistoryLength: 25,

    /**
     * Initializes history management.
     */
@@ -17,16 +12,10 @@ Ext.define("Docs.History", {
            this.navigate(Ext.util.History.getToken());
        }, this);
        Ext.util.History.on("change", this.navigate, this);
        this.callParent();
    },

    // Parses current URL and navigates to the page
    navigate: function(token) {
        if (this.ignoreChange) {
            this.ignoreChange = false;
            return;
        }

        var url = this.parseToken(token);
        if (url.type === "api") {
            Docs.App.getController('Classes').loadClass(url.key, true);
@@ -35,7 +24,7 @@ Ext.define("Docs.History", {
            Docs.App.getController('Classes').showGuide(url.key, true);
        }
        else {
            Ext.getCmp('container').layout.setActiveItem(0);
            Ext.getCmp('card-panel').layout.setActiveItem(0);
        }
    },

@@ -45,56 +34,12 @@ Ext.define("Docs.History", {
        return matches ? {type: matches[1], key: matches[2]} : {};
    },

    // Extracts class name from history token
    // Returns false when it's not class-related token.
    parseClassName: function(token) {
        var url = this.parseToken(token);
        if (url.type === "api") {
            return url.key.replace(/-.*$/, '');
        }
        else {
            return false;
        }
    },

    /**
     * Adds URL to history
     *
     * @param {String} token  the part of URL after #
     */
    push: function(token) {
        this.ignoreChange = true;
        Ext.util.History.add(token);

        // Add class name to history store if it's not there already
        var cls = this.parseClassName(token);
        if (cls) {
            // When class already in history remove it and add again.
            // This way the most recently visited items will always be at the top.
            var oldIndex = this.store.findExact('cls', cls);
            if (oldIndex > -1) {
                this.store.removeAt(oldIndex);
            }

            // Add new item at the beginning
            this.store.insert(0, {cls: cls});

            // Remove items from the end of history if there are too many
            while (this.store.getAt(this.maxHistoryLength)) {
                this.store.removeAt(this.maxHistoryLength);
            }
            this.syncStore();
        }
    },

    /**
     * Removes class from History store
     *
     * @param {String} cls
     */
    removeClass: function(cls) {
        var index = this.store.findExact('cls', cls);
        this.store.removeAt(index);
        this.syncStore();
    }
});
+19 −2
Original line number Diff line number Diff line
/**
 * Provides methods dealing with localStorage- and memory-store.
 *
 * Base class for History and Favorites.
 * Base class for Favorites and Settings.
 */
Ext.define("Docs.LocalStore", {
    storeName: '',
@@ -15,7 +15,24 @@ Ext.define("Docs.LocalStore", {
    init: function() {
        this.localStorage = ('localStorage' in window && window['localStorage'] !== null);
        this.store = Ext.getStore(this.storeName);
        this.localStorage && this.store.load();

        if (this.localStorage) {
            this.store.load();
            if (window.addEventListener) {
                window.addEventListener("storage", Ext.Function.bind(this.onStorageChange, this), false);
            }
            else {
                window.attachEvent("onstorage", Ext.Function.bind(this.onStorageChange, this));
            }
        }
    },

    // When records in localstorage change, reload the store.
    onStorageChange: function(e) {
        e = e || window.event;
        if (e.key === this.store.getProxy().id) {
            this.store.load();
        }
    },

    /**
+34 −32
Original line number Diff line number Diff line
@@ -12,13 +12,11 @@ Ext.define('Docs.controller.Classes', {

    stores: [
        'Favorites',
        'History',
        'Settings'
    ],

    models: [
        'Favorite',
        'History',
        'Setting'
    ],

@@ -32,15 +30,26 @@ Ext.define('Docs.controller.Classes', {
            selector: 'classheader'
        },
        {
            ref: 'tabPanel',
            selector: 'classtabpanel'
            ref: 'overview',
            selector: 'classoverview'
        },
        {
            ref: 'tree',
            selector: 'classtree'
        },
        {
            ref: 'favoritesGrid',
            selector: '#favorites-grid'
        },
        {
            ref: 'historyGrid',
            selector: '#history-grid'
        }
    ],

    // Code for the middle mouse button
    MIDDLE: 1,

    init: function() {
        this.addEvents(
            /**
@@ -64,8 +73,8 @@ Ext.define('Docs.controller.Classes', {
            "showGuide"
        );

        Ext.getBody().addListener('click', function(cmp, el) {
            this.loadClass(el.rel);
        Ext.getBody().addListener('click', function(event, el) {
            (event.button === this.MIDDLE) ? window.open(el.href) : this.loadClass(el.rel);
        }, this, {
            preventDefault: true,
            delegate: '.docClass'
@@ -73,20 +82,20 @@ Ext.define('Docs.controller.Classes', {

        this.control({
            'classtree': {
                // Can't simply assign the loadClass function as event
                // handler, because an extra event options object is
                // appended to the event arguments, which we don't
                // want to give to the loadClass, as this would render
                // the noHistory parameter to true.
                classclick: function(cls) {
                    this.loadClass(cls);
                classclick: function(cls, event) {
                    (event.button === this.MIDDLE) ? window.open("#/api/" + cls) : this.loadClass(cls);
                }
            },
            'classgrid': {
                classclick: function(cls, event) {
                    (event.button === this.MIDDLE) ? window.open("#/api/" + cls) : this.loadClass(cls);
                }
            },

            'indexcontainer': {
                afterrender: function(cmp) {
                    cmp.el.addListener('click', function(cmp, el) {
                        this.showGuide(el.rel);
                    cmp.el.addListener('click', function(event, el) {
                        (event.button === this.MIDDLE) ? window.open(el.href) : this.loadClass(el.rel);
                    }, this, {
                        preventDefault: true,
                        delegate: '.guide'
@@ -126,7 +135,7 @@ Ext.define('Docs.controller.Classes', {
        var cls = clsUrl;
        var member;

        Ext.getCmp('container').layout.setActiveItem(1);
        Ext.getCmp('card-panel').layout.setActiveItem(1);

        // separate class and member name
        var matches = clsUrl.match(/^(.*?)(?:-(.*))?$/);
@@ -142,8 +151,8 @@ Ext.define('Docs.controller.Classes', {
        if (this.cache[cls]) {
            this.showClass(this.cache[cls], member);
        } else {
            if (this.getTabPanel()) {
                this.getTabPanel().setLoading(true);
            if (this.getOverview()) {
                this.getOverview().setLoading(true);
            }

            Ext.data.JsonP.request({
@@ -162,34 +171,27 @@ Ext.define('Docs.controller.Classes', {
    },

    showClass: function(cls, anchor) {
        var classOverview = this.getTabPanel().down('classoverview');

        if (this.currentCls != cls) {
            this.getViewport().setPageTitle(cls.name);
            this.getHeader().load(cls);
            this.getOverview().load(cls);

            // Init overview tab if not already available
            if (!classOverview) {
                classOverview = Ext.create('Docs.view.cls.Overview');
                this.getTabPanel().add(classOverview);
                this.getTabPanel().setActiveTab(0);
            }
            classOverview.load(cls);

            this.getTabPanel().setLoading(false);
            this.getOverview().setLoading(false);

            this.getTree().selectClass(cls.name);
            this.fireEvent('showClass', cls.name);
        }

        if (anchor) {
            classOverview.scrollToEl("#" + anchor);
            this.getOverview().scrollToEl("#" + anchor);
            this.fireEvent('showMember', cls.name, anchor);
        } else {
            classOverview.getEl().down('.x-panel-body').scrollTo('top', 0);
            this.getOverview().getEl().down('.x-panel-body').scrollTo('top', 0);
        }

        this.currentCls = cls;

        this.getFavoritesGrid().selectClass(cls.name);
    },

    showGuide: function(name, noHistory) {
@@ -201,7 +203,7 @@ Ext.define('Docs.controller.Classes', {
            success: function(json) {
                this.getViewport().setPageTitle(json.guide.match(/<h1>(.*)<\/h1>/)[1]);
                Ext.getCmp("guide").update(json.guide);
                Ext.getCmp('container').layout.setActiveItem(2);
                Ext.getCmp('card-panel').layout.setActiveItem(2);
                Docs.Syntax.highlight(Ext.get("guide"));
                this.fireEvent('showGuide', name);
            },

template/app/model/History.js

deleted100644 → 0
+0 −11
Original line number Diff line number Diff line
/**
 * Previously visited classes / guides
 */
Ext.define('Docs.model.History', {
    fields: ['id', 'cls'],
    extend: 'Ext.data.Model',
    proxy: {
        type: ('localStorage' in window && window['localStorage'] !== null) ? 'localstorage' : 'memory',
        id  : 'docs-history'
    }
});
Loading