ExtJS Learning Notes (8) the use of _tabpanel

Source: Internet
Author: User

Don't say anything, directly on the code:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<link rel= "stylesheet" type= text/css "href=". /resources/css/ext-all.css "/>
<script type= "Text/javascript" src= ". /adapter/ext/ext-base.js "></script>
<script type= "Text/javascript" src= ". /ext-all.js "></script>
<style type= "Text/css" >
*{font-size:12px;line-height:130%;}
. list {list-style:square;width:500px;padding-left:16px;}
. List li{padding:2px;font-size:8pt;}
Pre {
font-size:11px;
}
. x-tab-panel-body. x-panel-body {
padding:10px;
}
/* Default loading indicator for AJAX calls * *
. loading-indicator {
font-size:8pt;
Background-image:url ('.. /resources/images/default/grid/loading.gif ');
Background-repeat:no-repeat;
Background-position:left;
padding-left:20px;
}
. new-tab {
Background-image:url (.. /examples/feed-viewer/images/new_tab.gif)!important;
}
. tabs {
Background-image:url (.. /examples/desktop/images/tabs.gif)!important;
}
</style>
<title>tabs demo</title>
<body>
<script type= "Text/javascript" >
Ext.onready (function () {
var tabs = new Ext.tabpanel ({
RenderTo:Ext.getBody (),
Resizetabs:true,//Turn on tab resizing
mintabwidth:115,
tabwidth:135,
Enabletabscroll:true,
width:600,
height:150,
Defaults: {autoscroll:true},
Plugins:new Ext.ux.TabCloseMenu (),
Tbar: [{text: ' new tab ', Iconcls: ' New-tab ', Handler:addtab}]
});
Tab Generation Code
var index = 0;
while (Index < 2) {
AddTab ();
}
function addtab (tab) {
if (Tabs.items.length > 9) {
Ext.MessageBox.alert ("Hint", "can only create 10 new tab!");
Tabs.tbar.setVisible (FALSE);
return false;
}
Tabs.add ({
Title: ' New Tab ' + (++index),
Iconcls: ' Tabs ',
HTML: ' Tab body ' + (index),
Closable:true
). Show ();
}
});

Right-click pop-up menu
Ext.ux.TabCloseMenu = function () {
var tabs, menu, Ctxitem;
This.init = function (TP) {
tabs = TP;
Tabs.on (' ContextMenu ', oncontextmenu);
}
function OnContextMenu (TS, item, e) {
if (!menu) {//Create context menu on the right click
menu = new Ext.menu.Menu ([{
Id:tabs.id + '-close ',
Text: ' Close current ',
Handler:function () {tabs.remove (ctxitem);}
}, {
Id:tabs.id + '-close-others ',
Text: ' Close other ',
Handler:function () {
Tabs.items.each (function (item) {
if (item.closable && item!= ctxitem) {
Tabs.remove (item);
}
});
}
}]);
}
Ctxitem = Item;
var items = Menu.Items;
Items.get (tabs.id + '-close '). setdisabled (!item.closable);
When only one is left, disable the shutdown.
if (tabs.items.length = = 1) {
Items.get (tabs.id + '-close '). Setdisabled (True);
// }
var disableothers = true;
Tabs.items.each (function () {
if (this!= item && this.closable) {
Disableothers = false;
return false;
}
});
Items.get (tabs.id + '-close-others '). setdisabled (Disableothers);
Menu.showat (E.getpoint ());
}
};
</script>
</body>

The effect chart is as follows:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.