TabCloseMenu_wev8.js 2.21 KB
Ext.ux.TabCloseMenu=function(){var a,c,b;this.init=function(e){a=e;a.on("contextmenu",d)};function d(h,g,i){c=new Ext.menu.Menu([{id:a.id+"-close",text:"关闭",handler:function(){try{a.remove(b)}catch(e){b.iframe.setSrc(contextPath+"/blank.htm");b.on("domready",function(){a.remove(b)})}}},{id:a.id+"-close-others",text:"关闭其他选项卡",handler:function(){a.items.each(function(e){if(e.closable&&e!=b){a.remove(e)}})}},{id:a.id+"-refresh",text:"刷新",handler:function(){if(!b.iframe.src){b.setSrc(b.iframe.src,true)}else{b.getFrameWindow().location.reload(true)}}}]);c.addSeparator();a.items.each(function(n,e,m){try{this.getFrameDoc().on("click",function(o){Ext.menu.MenuMgr.hideAll()})}catch(l){}for(var k=0;k<this.getFrameWindow().frames.length;k++){try{this.getFrameWindow().frames[k].document.onclick=function(){top.frames[1].hideContextMenu()}}catch(l){}}c.add(new Ext.menu.CheckItem({group:"tabs",text:this.title,tabIndex:e,checked:this==a.getActiveTab(),handler:function(){a.activate(a.items.get(this.tabIndex))}}))});b=g;var f=c.items;f.get(a.id+"-close").setDisabled(!g.closable);var j=true;a.items.each(function(){if(this!=g&&this.closable){j=false;return false}});f.get(a.id+"-close-others").setDisabled(j);c.showAt(i.getPoint())}};Ext.override(Ext.TabPanel,{initEvents:function(){Ext.TabPanel.superclass.initEvents.call(this);this.on("add",this.onAdd,this);this.on("remove",this.onRemove,this);this.strip.on("dblclick",this.onStripDblClick,this);this.strip.on("mousedown",this.onStripMouseDown,this);this.strip.on("click",this.onStripClick,this);this.strip.on("contextmenu",this.onStripContextMenu,this);if(this.enableTabScroll){this.strip.on("mousewheel",this.onWheel,this)}},onStripMouseDown:function(d){d.preventDefault();if(d.button!=0){return}var c=this.findTargets(d);var a=this;if(c.close){try{this.remove(c.item)}catch(b){c.item.setSrc(contextPath+"/blank.htm");c.item.on("domready",function(){a.remove(c.item)})}return}if(c.item&&c.item!=this.activeTab){this.setActiveTab(c.item)}},onStripDblClick:function(d){d.preventDefault();var c=this.findTargets(d);var a=this;if(c.item&&c.item.closable){try{this.remove(c.item)}catch(b){c.item.setSrc(contextPath+"/blank.htm");c.item.on("domready",function(){a.remove(c.item)})}return}}});