📄 dhtmlxtabbar.js
字号:
/*
Copyright DHTMLX LTD. http://www.dhtmlx.com
You allowed to use this component or parts of it under GPL terms
To use it on other terms or get Professional edition of the component please contact us at sales@dhtmlx.com
*/
function dhtmlXTabBar(parentObject,mode,height)
{this._isIE7s=((_isIE)&&window.XMLHttpRequest&&(document.compatMode != "BackCompat"));mode=mode||"top";this._mode=mode+"/";this._eczF=true;if (_isIE)this.preventIECashing(true);if (typeof(parentObject)!="object")
this.entBox=document.getElementById(parentObject);else
this.entBox=parentObject;this.width = this.entBox.getAttribute("width") || this.entBox.style.width || (window.getComputedStyle?window.getComputedStyle(this.entBox,null)["width"]:(this.entBox.currentStyle?this.entBox.currentStyle["width"]:0));this.height = this.entBox.getAttribute("height") || this.entBox.style.height || (window.getComputedStyle?window.getComputedStyle(this.entBox,null)["height"]:(this.entBox.currentStyle?this.entBox.currentStyle["height"]:0));if (((this.width||"").indexOf("%")!=-1)||((this.width||"").indexOf("%")!=-1))
this.enableAutoReSize(true,true);if ((!this.width)||(this.width=="auto")||(this.width.indexOf("%")!=-1)||(parseInt(this.width)==0))
this.width=this.entBox.offsetWidth+"px";if ((!this.height)||(this.height.indexOf("%")!=-1)||(this.height=="auto"))
this.height=this.entBox.offsetHeight+"px";this.activeTab = null;this.tabsId = new Object();this._align="left";this._offset=5;this._margin=1;this._height=parseInt(height||20);this._bMode=(mode=="right"||mode=="bottom");this._tabSize='150';this._content=new Array();this._tbst="win_text";this._styles={winDflt:["p_left.gif","p_middle.gif","p_right.gif","a_left.gif","a_middle.gif","a_right.gif","a_middle.gif",3,3,6,"#F4F3EE","#F0F8FF",false],
winScarf:["with_bg/p_left.gif","with_bg/p_middle.gif","with_bg/p_right_skos.gif","with_bg/a_left.gif","with_bg/a_middle.gif","with_bg/a_right_skos.gif","with_bg/p_middle_over.gif",3,18,6,false,false,false],
winBiScarf:["with_bg/p_left_skos.gif","with_bg/p_middle.gif","with_bg/p_right_skos.gif","with_bg/a_left_skos.gif","with_bg/a_middle.gif","with_bg/a_right_skos.gif","with_bg/p_middle_over.gif",18,18,6,false,false,false],
winRound:["circuses/p_left.gif","circuses/p_middle.gif","circuses/p_right.gif","circuses/a_left.gif","circuses/a_middle.gif","circuses/a_right.gif","circuses/p_middle_over.gif",10,10,6,false,false,false],
silver:["silver/p_left.gif","silver/p_middle.gif","silver/p_right.gif","silver/a_left.gif","silver/a_middle.gif","silver/a_right.gif","silver/p_middle.gif",7,8,6,"#F4F3EE","#F0F8FF","white"],
modern:["modern/p_left.gif","modern/p_middle.gif","modern/p_right.gif","modern/a_left.gif","modern/a_middle.gif","modern/a_right.gif","modern/p_middle_over.gif",5,5,6,false,false,"white"]
};this._createSelf(mode=="right"||mode=="left");this.setStyle("winDflt");this._TabCloseButton = false;this._TabCloseButtonSrc = 'close.png';this._enableAutoRowAdd = false;return this};dhtmlXTabBar.prototype.setOffset = function(offset){this._offset=offset};dhtmlXTabBar.prototype.setAlign = function(align){if (align=="top")align="left";if (align=="bottom")align="right";this._align=align};dhtmlXTabBar.prototype.setMargin = function(margin){this._margin=margin};dhtmlXTabBar.prototype._createSelf = function(vMode)
{this._tabAll=document.createElement("DIV");this._tabZone=document.createElement("DIV");this._conZone=document.createElement("DIV");this.entBox.appendChild(this._tabAll);if (this._bMode){this._tabAll.appendChild(this._conZone);this._tabAll.appendChild(this._tabZone)}else
{this._tabAll.appendChild(this._tabZone);this._tabAll.appendChild(this._conZone)};this._vMode=vMode;if (vMode){this._tabAll.className='dhx_tabbar_zoneV';this._setSizes=this._setSizesV;this._redrawRow=this._redrawRowV}else
this._tabAll.className='dhx_tabbar_zone';if (this._bMode)this._tabAll.className+='B';this._tabZone.className='dhx_tablist_zone';this._conZone.className='dhx_tabcontent_zone';this._tabZone.onselectstart = function(){return false};this._tabAll.onclick = this._onClickHandler;this._tabAll.onmouseover = this._onMouseOverHandler;if (_isFF)this._tabZone.onmouseout = this._onMouseOutHandler;else
this._tabZone.onmouseleave = this._onMouseOutHandler;this._tabAll.tabbar=this;this._lineA=document.createElement("div");this._lineA.className="dhx_tablist_line";this._lineA.style[vMode?"left":"top"]=(this._bMode?0:(this._height+2))+"px";this._lineA.style[vMode?"height":"width"]=parseInt(this[vMode?"height":"width"])+((_isIE && document.compatMode!="BackCompat")?2:0)+"px";if(vMode)this._conZone.style.height=parseInt(this.height)+"px";else
this._conZone.style.width=parseInt(this.width)-(_isFF?2:0)+"px";this.rows=new Array();this.rowscount=1;this._createRow();this._setSizes()};dhtmlXTabBar.prototype._createRow = function(){var z=document.createElement("DIV");z.className='dhx_tabbar_row';this._tabZone.appendChild(z);z._rowScroller=document.createElement('DIV');z._rowScroller.style.display="none";z.appendChild(z._rowScroller);this.rows[this.rows.length]=z;if (this._vMode){z.style.width=this._height+3+"px";z.style.height=parseInt(this.height)+"px";if (!this._bMode)this.setRowSizesA();else
this.setRowSizesB()}else
{z.style.height=parseInt(this._height)+3+"px";z.style.width=parseInt(this.width)+((_isIE && document.compatMode!="BackCompat")?2:0)+"px"};z.appendChild(this._lineA)};dhtmlXTabBar.prototype._removeRow=function(row){row.parentNode.removeChild(row);var z=new Array();for (var i=0;i<this.rows.length;i++)if (this.rows[i]!=row)z[z.length]=this.rows[i];this.rows=z};dhtmlXTabBar.prototype._checkSizes = function(row){var count=parseInt(this._offset);for (var i=0;i<row.tabCount;i++){if (row.childNodes[i].style.display=="none")continue;count+=row.childNodes[i]._offsetSize+this._margin*1};return (row.offsetWidth<(count-this._margin*1))};dhtmlXTabBar.prototype._setSizes = function(){this._tabAll.height=this.height;this._tabAll.width=this.width;if (this._tabZone.childNodes.length)var z=this._tabZone.lastChild.offsetTop-this._tabZone.firstChild.offsetTop+this._height;else
var z=this._height+(_isIE?5:0);var a=z-2;this._tabZone.style.height=(a>0?a:0)+"px";a=parseInt(this.height)-z-4;this._conZone.style.height=(a>0?a:0)+"px"};dhtmlXTabBar.prototype._setSizesV = function(){this._tabAll.height=this.height;this._tabAll.width=this.width;var z=this._height*this.rows.length;if (!this._bMode){this._tabZone.style.width=z+3+"px";this._conZone.style.width=parseInt(this.width)-(z+(_isFF?5:3))+"px";this._conZone.style.left= z+3+"px"}else{this._tabZone.style.width=z+3+"px";this._conZone.style.width=parseInt(this.width)-(z+3)+"px";this._tabZone.style.left=parseInt(this.width)-(z+3)+"px"};this._conZone.style.height=parseInt(this.height)-(_isFF?2:0)+"px";this._tabZone.style.height=parseInt(this.height)+"px"};dhtmlXTabBar.prototype._redrawRowV=function(row){var talign=this._align=="left"?"top":"bottom";var count=parseInt(this._offset);for (var i=0;i<row.tabCount;i++){if (row.childNodes[i].style.display=="none")continue;row.childNodes[i]._cInd=i;row.childNodes[i].style[talign]=count+"px";count+=row.childNodes[i]._offsetSize+parseInt(this._margin)};if ((row.offsetHeight<count-parseInt(this._margin))||(parseInt(row.childNodes[0].style[this._align=="left"?"top":"bottom"])<0))
this._showRowScroller(row);else
this._hideRowScroller(row)};dhtmlXTabBar.prototype._setTabTop=function(tab){if (!this._vMode){if (tab.parentNode!=this.rows[0])this._tabZone.insertBefore(tab.parentNode,this.rows[0])};var j=new Array();j[j.length]=tab.parentNode;for (var i=0;i<this.rows.length;i++)if (this.rows[i]!=tab.parentNode)j[j.length]=this.rows[i];this.rows=j;if (this._vMode)this.setRowSizesB();else this.setRowSizesC();this._lineA.parentNode.removeChild(this._lineA);this.rows[0].appendChild(this._lineA)};dhtmlXTabBar.prototype.setRowSizesA=function(){for (var i=0;i<this.rows.length;i++){this.rows[i].style.left=i*this._height+"px";this.rows[i].style.zIndex=5+i}};dhtmlXTabBar.prototype.setRowSizesB=function(){for (var i=this.rows.length-1;i>=0;i--){this.rows[i].style.left=i*this._height+"px";this.rows[i].style.zIndex=15-i}};dhtmlXTabBar.prototype.setRowSizesC=function(){for (var i=this.rows.length-1;i>=0;i--){this.rows[i].style.zIndex=15-i}};dhtmlXTabBar.prototype._initScroller = function(row){var z=row._rowScroller;if (this._vMode)z.innerHTML="<img src='"+this._imgPath+"scrl_t.gif' style='display:block;'><img src='"+this._imgPath+"scrl_b.gif'>";else
z.innerHTML="<img src='"+this._imgPath+"scrl_l.gif'><img src='"+this._imgPath+"scrl_r.gif'>";if (this._align=="left"){z.childNodes[1].onclick=this._scrollRight;z.childNodes[0].onclick=this._scrollLeft}else
{z.childNodes[1].onclick=this._scrollLeft;z.childNodes[0].onclick=this._scrollRight};z.className='dhx_tablist_scroll';z._init=1};dhtmlXTabBar.prototype._scrollLeft=function(){var that=this.parentNode.parentNode.parentNode.parentNode.tabbar;var row=this.parentNode.parentNode;if (!row.scrollIndex)row.scrollIndex=0;row.scrollIndex--;if (row.scrollIndex<0){row.scrollIndex=0;return};var shift=row.childNodes[row.scrollIndex]._offsetSize+that._margin*1;that._offset+=shift;that._redrawRow(row);return shift};dhtmlXTabBar.prototype._scrollTo=function(tab){var that=this;var row=tab.parentNode;if (!row._rowScroller._init)this._initScroller(row);if (this._vMode)var z=parseInt(tab.style[that._align=="left"?"top":"bottom"])+tab._offsetSize-parseInt(that.height);else
var z=parseInt(tab.style[that._align])+tab._offsetSize-parseInt(that.width);while (z>0)if (that._align=="left")z-=row._rowScroller.childNodes[1].onclick();else
z-=row._rowScroller.childNodes[0].onclick();if (this._vMode)var z=parseInt(tab.style[that._align=="left"?"top":"bottom"])-tab._offsetSize;else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -