source: trunk/web/addons/job_monarch/lib/extjs/examples/tabs/TabCloseMenu.js @ 619

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.5 KB
Line 
1/*
2 * Ext JS Library 2.2.1
3 * Copyright(c) 2006-2009, Ext JS, LLC.
4 * licensing@extjs.com
5 *
6 * http://extjs.com/license
7 */
8
9
10// Very simple plugin for adding a close context menu to tabs
11
12Ext.ux.TabCloseMenu = function(){
13    var tabs, menu, ctxItem;
14    this.init = function(tp){
15        tabs = tp;
16        tabs.on('contextmenu', onContextMenu);
17    }
18
19    function onContextMenu(ts, item, e){
20        if(!menu){ // create context menu on first right click
21            menu = new Ext.menu.Menu([{
22                id: tabs.id + '-close',
23                text: 'Close Tab',
24                handler : function(){
25                    tabs.remove(ctxItem);
26                }
27            },{
28                id: tabs.id + '-close-others',
29                text: 'Close Other Tabs',
30                handler : function(){
31                    tabs.items.each(function(item){
32                        if(item.closable && item != ctxItem){
33                            tabs.remove(item);
34                        }
35                    });
36                }
37            }]);
38        }
39        ctxItem = item;
40        var items = menu.items;
41        items.get(tabs.id + '-close').setDisabled(!item.closable);
42        var disableOthers = true;
43        tabs.items.each(function(){
44            if(this != item && this.closable){
45                disableOthers = false;
46                return false;
47            }
48        });
49        items.get(tabs.id + '-close-others').setDisabled(disableOthers);
50        menu.showAt(e.getPoint());
51    }
52};
Note: See TracBrowser for help on using the repository browser.