Last change
on this file since 619 was
619,
checked in by ramonb, 15 years ago
|
lib/:
- added new AJAX dependancies: ExtJS, pChart, Lightbox2
|
File size:
1.4 KB
|
Line | |
---|
1 | // Very simple plugin for adding a close context menu to tabs |
---|
2 | Ext.ux.TabCloseMenu = function(){ |
---|
3 | var tabs, menu, ctxItem; |
---|
4 | this.init = function(tp){ |
---|
5 | tabs = tp; |
---|
6 | tabs.on('contextmenu', onContextMenu); |
---|
7 | } |
---|
8 | |
---|
9 | function onContextMenu(ts, item, e){ |
---|
10 | if(!menu){ // create context menu on first right click |
---|
11 | menu = new Ext.menu.Menu([{ |
---|
12 | id: tabs.id + '-close', |
---|
13 | text: 'Close Tab', |
---|
14 | handler : function(){ |
---|
15 | tabs.remove(ctxItem); |
---|
16 | } |
---|
17 | },{ |
---|
18 | id: tabs.id + '-close-others', |
---|
19 | text: 'Close Other Tabs', |
---|
20 | handler : function(){ |
---|
21 | tabs.items.each(function(item){ |
---|
22 | if(item.closable && item != ctxItem){ |
---|
23 | tabs.remove(item); |
---|
24 | } |
---|
25 | }); |
---|
26 | } |
---|
27 | }]); |
---|
28 | } |
---|
29 | ctxItem = item; |
---|
30 | var items = menu.items; |
---|
31 | items.get(tabs.id + '-close').setDisabled(!item.closable); |
---|
32 | var disableOthers = true; |
---|
33 | tabs.items.each(function(){ |
---|
34 | if(this != item && this.closable){ |
---|
35 | disableOthers = false; |
---|
36 | return false; |
---|
37 | } |
---|
38 | }); |
---|
39 | items.get(tabs.id + '-close-others').setDisabled(disableOthers); |
---|
40 | menu.showAt(e.getPoint()); |
---|
41 | } |
---|
42 | }; |
---|
Note: See
TracBrowser
for help on using the repository browser.