Commit db986eea authored by Nick Poulden's avatar Nick Poulden
Browse files

Tidying up Tab code

parent 5ef7d808
Loading
Loading
Loading
Loading
+19 −24
Original line number Diff line number Diff line
@@ -228,10 +228,6 @@ Ext.define('Docs.controller.Classes', {

            this.getTree().selectUrl("/api/"+cls.name);
            this.fireEvent('showClass', cls.name);

            var iconCls = this.getTree().findRecordByUrl("/api/"+cls.name);
            var clsName = cls.name.match(/([^\.]+)$/)[0];
            Ext.getCmp('doctabs').addTab({href: '#/api/' + cls.name, text: clsName, iconCls: iconCls.raw.iconCls})
        }

        if (anchor) {
@@ -242,8 +238,6 @@ Ext.define('Docs.controller.Classes', {
        }

        this.currentCls = cls;

        // this.getFavoritesGrid().selectUrl("/api/"+cls.name);
    },

    /**
@@ -258,24 +252,25 @@ Ext.define('Docs.controller.Classes', {

        noHistory || Docs.History.push(url);

        var name = url.match(/^\/guide\/(.*)$/)[1];
        var name = url.match(/^\/guide\/(.*)$/);
        if (name) {
            Ext.data.JsonP.request({
            url: this.getBaseUrl() + "/guides/" + name + "/README.js",
            callbackName: name,
                url: this.getBaseUrl() + "/guides/" + name[1] + "/README.js",
                callbackName: name[1],
                success: function(json) {
                    this.getViewport().setPageTitle(json.guide.match(/<h1>(.*)<\/h1>/)[1]);
                    Ext.getCmp("guide").update(json.guide);
                    Ext.getCmp('card-panel').layout.setActiveItem(2);
                    Docs.Syntax.highlight(Ext.get("guide"));
                this.fireEvent('showGuide', name);
                    this.fireEvent('showGuide', name[1]);
                    this.getTree().selectUrl(url);
                this.getFavoritesGrid().selectUrl(url);
                },
                failure: function(response, opts) {
                this.showFailure("Guide <b>"+name+"</b> was not found.");
                    this.showFailure("Guide <b>"+name[1]+"</b> was not found.");
                },
                scope: this
            });
        }
    },

    /**
+107 −57
Original line number Diff line number Diff line
@@ -4,21 +4,67 @@
Ext.define('Docs.controller.Tabs', {
    extend: 'Ext.app.Controller',

    refs: [
        {
            ref: 'tree',
            selector: 'classtree'
        }
    ],

    init: function() {

        this.getController('Classes').addListener({
            showClass: function(cls) {
                this.addTabFromTree("/api/"+cls);
            },
            showGuide: function(guide) {
                this.addTabFromTree("/guide/"+guide);
            },
            scope: this
        });

        this.control({
            'container [componentCls=doctabs]': {
                afterrender: function(cmp) {
                    this.addTabIconListeners(cmp);
                    this.addTabListeners(cmp);
                }
            }
        });
    },

    /**
     * Adds a tab based on information from the class tree
     * @param {String} url The url of the record in the tree
     */
    addTabFromTree: function(url) {
        var treeRecord = this.getTree().findRecordByUrl(url);
        Ext.getCmp('doctabs').addTab({
            href: '#' + treeRecord.raw.url,
            text: treeRecord.raw.text,
            iconCls: treeRecord.raw.iconCls
        })
    },

    /**
     * Adds mouse interaction listeners to the tab icon
     * @private
     */
    addTabIconListeners: function(cmp) {

        cmp.el.addListener('mouseover', function(event, el) {
            Ext.get(el).addCls('ovr');
        }, this, {
            delegate: '.icn'
        });

        cmp.el.addListener('mouseout', function(event, el) {
            Ext.get(el).removeCls('ovr');
        }, this, {
            delegate: '.icn'
        });
                    cmp.el.addListener('click', function(evt, el) {

        cmp.el.addListener('click', function(event, el) {
            cmp.justClosed = true;
            var docTab = Ext.get(el).up('.doctab');
            Ext.getCmp('doctabs').removeTab(docTab.down('.docClass').getAttribute('href'));
@@ -37,7 +83,13 @@ Ext.define('Docs.controller.Tabs', {
            delegate: '.icn',
            preventDefault: true
        });
    },

    /**
     * Adds mouse interaction listeners to the tab
     * @private
     */
    addTabListeners: function(cmp) {
        cmp.el.addListener('click', function(event, el) {
            if (cmp.justClosed) {
                cmp.justClosed = false;
@@ -59,6 +111,7 @@ Ext.define('Docs.controller.Tabs', {
        }, this, {
            delegate: '.doctab'
        });

        cmp.el.addListener('mouseout', function(event, el) {
            var icn = Ext.get(el).down('.icn');
            if (icn) {
@@ -68,8 +121,5 @@ Ext.define('Docs.controller.Tabs', {
            delegate: '.doctab'
        });
    }
            }
        });
    }

});
+3 −3
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ $docs-monospace-font: "Menlo", "Courier New", Courier, monospace;
  .icon-component {
    background: url(../images/icons.png) no-repeat -3px -137px !important; }
  .icon-guide {
    background: url(../images/icons.png) no-repeat -3px -5px !important; }
    background: url(../images/icons.png) no-repeat -3px -7px !important; }
  .icon-event {
    background: url(../images/icons.png) no-repeat -3px -245px !important; }
  .icon-property {
@@ -508,7 +508,7 @@ a {
  margin-bottom: 4px; }

#guide {
  padding-right: 10px;
  padding: 10px;
  font-size: 14px;
  h1 {
    background: url(../images/doc-m.png) no-repeat -5px -5px;
@@ -860,7 +860,7 @@ a {
    }
  }
  .doctab.home .m a {
    background: url(../images/tab-icons.png) no-repeat 7px 0;
    background: url(../images/tab-icons.png) no-repeat 7px 1px;
    padding-left: 16px; padding-right: 4px; padding-bottom: 20px;
  }
  .doctab.api .m a {