Ext


Go Back   Ext JS Forums > Ext JS Community Forums (3.0) > Ext: User Extensions and Plugins

Reply
 
Thread Tools
  #1  
Old 10-18-2009, 10:27 AM
Animal's Avatar
Animal Animal is offline
Ext JS - Community Support Team
 
Join Date: Mar 2007
Location: East Midlands, UK
Posts: 23,352
Animal will become famous soon enough
Default Add new tab button in tab strip

Usage:

        plugins: [ Ext.ux.AddTabButton ],
        createTab: function() { // Optional function which the plugin uses to create new tabs
            return {
                title: 'New Tab',
                closable: true
            };
        },
Obviously it just creates a new defaultType (whatever you configure that to for your TabPanel - defaults to Ext.Panel). It's up to you to access the newly added item and manipulate it.

Ext.ux.AddTabButton = (function() {
    function onTabPanelRender() {
        this.addTab = this.itemTpl.insertBefore(this.edge, {
            id: this.id + 'addTabButton',
            cls: 'add-tab',
            text: this.addTabText || '&#160',
            iconCls: ''
        }, true);
        this.addTab.child('em.x-tab-left').setStyle('padding-right', '6px');
        this.addTab.child('a.x-tab-right').setStyle('padding-left', '6px');
        new Ext.ToolTip({
            target: this.addTab,
            bodyCfg: {
                html: 'Add new tab'
            }
        });
        this.addTab.on({
            mousedown: stopEvent,
            click: onAddTabClick,
            scope: this
        });
    }

    function createScrollers() {
        this.scrollerWidth = (this.scrollRightWidth = this.scrollRight.getWidth()) + this.scrollLeft.getWidth();
    }

    function autoScrollTabs() {
        var scrollersVisible = (this.scrollLeft && this.scrollLeft.isVisible()),
            pos = this.tabPosition == 'top' ? 'header' : 'footer';
        if (scrollersVisible) {
            if (this.addTab.dom.parentNode === this.strip.dom) {
                if (this.addTabWrap) {
                    this.addTabWrap.show();
                } else {
                    this.addTabWrap = this[pos].createChild({
                        cls: 'x-tab-strip-wrap',
                        style: {
                            position: 'absolute',
                            right: (this.scrollRightWidth + 1) + 'px',
                            top: 0,
                            width: '30px',
                            margin: 0
                        }, cn: {
                            tag: 'ul',
                            cls: 'x-tab-strip x-tab-strip-' + this.tabPosition,
                            style: {
                                width: 'auto'
                            }
                        }
                    });
                    this.addTabWrap.setVisibilityMode(Ext.Element.DISPLAY);
                    this.addTabUl = this.addTabWrap.child('ul');
                }
                this.addTabUl.dom.appendChild(this.addTab.dom);
                this.addTab.setStyle('float', 'none');
            }
            this.stripWrap.setWidth(this[pos].getWidth(true) - (this.scrollerWidth + 31));
            this.stripWrap.setStyle('margin-right', (this.scrollRightWidth + 31) + 'px');
        } else {
//          
            if ((this.addTab.dom.parentNode !== this.strip.dom)) {
                var notEnoughSpace = (((this[pos].getWidth(true) - this.edge.getOffsetsTo(this.stripWrap)[0])) < 33)
                this.addTabWrap.hide();
                this.addTab.setStyle('float', '');
                this.strip.dom.insertBefore(this.addTab.dom, this.edge.dom);
                this.stripWrap.setWidth(this.stripWrap.getWidth() + 31);
                if (notEnoughSpace) {
                    this.autoScrollTabs();
                }
            }
        }
    }

    function autoSizeTabs() {
        this.addTab.child('.x-tab-strip-inner').setStyle('width', '14px');
    }

    function stopEvent(e) {
        e.stopEvent();
    }

    function onAddTabClick() {
        this.setActiveTab(this.add(this.createTab? this.createTab() : {
            title: 'New Tab'
        }));
    }

    return {
        init: function(tp) {
            if (tp instanceof Ext.TabPanel) {
                tp.onRender = tp.onRender.createSequence(onTabPanelRender);
                tp.createScrollers = tp.createScrollers.createSequence(createScrollers);
                tp.autoScrollTabs = tp.autoScrollTabs.createSequence(autoScrollTabs);
                tp.autoSizeTabs = tp.autoSizeTabs.createSequence(autoSizeTabs);
            }
        }
    };
})();
__________________
ExtJs forum volunteer. No official connection to the Ext Company. I do not speak for them.
ExtJs consultancy offered. £ 50/hour. Evenings+weekends. the_bagbournes@btinternet.com

Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
See Saki's samples: http://examples.extjs.eu/
Build your own Ext: http://extjs.com/products/extjs/build/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
Reply With Quote
  #2  
Old 10-18-2009, 01:12 PM
jgarcia@tdg-i.com's Avatar
jgarcia@tdg-i.com jgarcia@tdg-i.com is offline
Ext User
 
Join Date: Mar 2007
Location: Frederick MD, NYC, DC
Posts: 11,448
jgarcia@tdg-i.com is on a distinguished road
Send a message via AIM to jgarcia@tdg-i.com Send a message via Skype™ to jgarcia@tdg-i.com
Default

excellent dude.
__________________
Get 42% off by using coupon code n2442 valid until (11/24/09) -> [Book] - Ext JS In Action

My Blog || Ext JS screencasts || ext-doc || twitter

My free extensions/plugins:
Progressbar inside paging toolbar || Tab panel scroller menu || Window drawers || Icon Manager
Grid view custom 'view' filter || PanelHeaderToolbar

JavaScript Magazine August article now available.
Reply With Quote
  #3  
Old 11-05-2009, 04:12 AM
Richie1985 Richie1985 is offline
Ext User
 
Join Date: Jan 2008
Posts: 137
Richie1985 is on a distinguished road
Send a message via ICQ to Richie1985 Send a message via Skype™ to Richie1985
Default

thank you, thats sooo cool, but how can i use iconCls: 'add' ?
Reply With Quote
  #4  
Old 11-06-2009, 04:26 AM
Animal's Avatar
Animal Animal is offline
Ext JS - Community Support Team
 
Join Date: Mar 2007
Location: East Midlands, UK
Posts: 23,352
Animal will become famous soon enough
Default

OK, now you can configure your TabPabel with

    addTabText: '+'
To use text in the add tab button.

Or, use the class to give it an icon eg

    div.x-tab-strip-wrap .add-tab a span.x-tab-strip-inner {
        background: url(../../resources/images/default/dd/drop-add.gif) no-repeat center center;
    }
To give

__________________
ExtJs forum volunteer. No official connection to the Ext Company. I do not speak for them.
ExtJs consultancy offered. £ 50/hour. Evenings+weekends. the_bagbournes@btinternet.com

Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
See Saki's samples: http://examples.extjs.eu/
Build your own Ext: http://extjs.com/products/extjs/build/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
Reply With Quote
  #5  
Old Yesterday, 03:46 PM
jocampo jocampo is offline
Ext User
 
Join Date: Aug 2009
Posts: 12
jocampo is on a distinguished road
Default

Hi Animal,

There is a way to add buttons with right aligment, independent of the aligment of the tabs. I mean, all the tabs would be with left aligment and the new tab buttons with right aligment??
Reply With Quote
Reply

Thread Tools

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

All times are GMT -5. The time now is 11:41 AM.

© 2006-2009 Ext, LLC
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.