source: trunk/web/addons/job_monarch/lib/extjs-30/examples/ux/TabCloseMenu.js @ 625

Last change on this file since 625 was 625, checked in by ramonb, 15 years ago

lib/extjs-30:

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