/* Product Name: dhtmlxSuite Version: 5.2.0 Edition: Professional License: content of this file is covered by DHTMLX Commercial or Enterprise license. Usage without proper license is prohibited. To obtain it contact sales@dhtmlx.com Copyright UAB Dinamenta http://www.dhtmlx.com */ function dhtmlXTabBar(conf, mode) { // skin? data? // console.log("context menu for tabs?"); // console.log("first tab open event?"); var that = this; this.conf = { skin: (window.dhx4.skin||(typeof(dhtmlx)!="undefined"?dhtmlx.skin:null)||window.dhx4.skinDetect("dhxtabbar")||"material"), css: "dhxtabbar", // css prefix for topcell mtb lastActive: null, closeButton: false, align: "left", // tabs aligned to right side, inversed, default "right" align tabsMode: (mode=="bottom"?"bottom":"top"), // top/bottom tabsContCss: "", // fix for Safari 5.1.7 desktop or Safari iOS 7.x mobile contZone: true, transSpeed: "0.15s", arwMode: "always", // always (def), auto tabsOfs: 1, // dhx_skyblue and dhx_terrace have margin-left:-1px for tabs, should be included tabsTop: 0, // tabs top position, used in attachObject to hide border url_demand: false, urls: {}, autoload: {}, tabsWidth: {dhx_terrace: [44,14], dhx_web: [35,9], dhx_skyblue: [35,9], material: [44,14]} // extra width for tabs/tab_with_close_icon, for tab width detect, since 4.2.1 }; if (this.conf.skin == "material") this.conf.arwMode = "auto"; // safari fix var a = navigator.userAgent; if (a.indexOf("Safari") >= 0 && (a.indexOf("5.1.7") >= 0 || (a.match(/7[\.\d]* mobile/gi) != null && a.match(/AppleWebKit/gi) != null))) { this.conf.tabsContCss = " safari_517_fix"; } var base; // check if api init if (conf != null && typeof(conf) == "object" && typeof(conf.tagName) == "undefined") { base = conf.parent; if (typeof(conf.skin) != "undefined") this.conf.skin = conf.skin; if (typeof(conf.mode) != "undefined") this.conf.tabsMode = (conf.mode=="bottom"?"bottom":"top"); if (typeof(conf.align) != "undefined") this.conf.align = (conf.align=="right"?"right":"left"); if (typeof(conf.close_button) != "undefined") this.conf.closeButton = window.dhx4.s2b(conf.close_button); if (typeof(conf.content_zone) != "undefined") this.conf.contZone = window.dhx4.s2b(conf.content_zone); if (typeof(conf.xml) != "undefined") this.conf.autoload.xml = conf.xml; if (typeof(conf.json) != "undefined") this.conf.autoload.xml = conf.json; // new in 4.0 if (typeof(conf.tabs) != "undefined") this.conf.autoload.tabs = conf.tabs; if (typeof(conf.onload) != "undefined") this.conf.autoload.onload = conf.onload; // new in 4.0 if (typeof(conf.arrows_mode) != "undefined") this.conf.autoload.arrows_mode = conf.arrows_mode; // new in 4.1.2 // deprecated from 4.0 // conf { height, offset, margin, image_path, href_mode, scroll, forced, size_by_content, auto_size } } else { base = conf; } // init top container window.dhtmlXCellTop.apply(this, [base, conf.offsets]); // tabsTop override if (this.base._ofs != null && this.base._ofs.t != null) this.conf.tabsTop = this.base._ofs.t; this.tabsMode = document.createElement("DIV"); this.tabsMode.className = "dhxtabbar_tabs_"+this.conf.tabsMode; this.cont.appendChild(this.tabsMode); this.tabsArea = document.createElement("DIV"); this.tabsArea.className = "dhxtabbar_tabs dhxtabbar_tabs_"+this.conf.tabsMode; this.tabsArea.innerHTML = "
"+ "
"+ "
"+ "
"+ "
"+ "
"+ "
"; this.tabsArea.style.top = (this.conf.tabsMode=="top"?this.conf.tabsTop+"px":"auto"); this.tabsMode.appendChild(this.tabsArea); // area to move tabs this.tabsArea.childNodes[1].childNodes[0].style[this.conf.align] = "0px"; this.tabsArea.childNodes[0].onclick = function() { if (that.conf.align == "left") { that._moveTabs(1); } else { that._moveTabs(-1); } } this.tabsArea.childNodes[2].onclick = function() { if (that.conf.align == "left") { that._moveTabs(-1); } else { that._moveTabs(1); } } this._onTabsAreaClick = function(id) { return this._callMainEvent("onTabClose",[id]); } this.tabsArea.onclick = function(e) { e = e||event; var t = (e.target||e.srcElement); while (t != null) { if (typeof(t._tabCloseId) != "undefined") { if (that._onTabsAreaClick(t._tabCloseId) !== true) return; that.t[t._tabCloseId].conf.remove = true; that._hideTab(t._tabCloseId); t = null; } else if (typeof(t._tabId) != "undefined") { that._doOnClick(t._tabId); t = null; } if (t != null) { t = t.parentNode; if (t == this) t = null; } } } this.tabsArea.onselectstart = function(e) { e = e||event; if (e.preventDefault) e.preventDefault(); else e.returnValue = false; } this._doOnClick = function(id) { // onBeforeEvent here this.callEvent("onTabClick", [id, this.conf.lastActive]); if (this.t[id].conf.enabled) this._setTabActive(id); } this.t = {}; this.addTab = function(id, text, width, position, active, close) { // close = show close button, false by default // true - show_closeButton // false - do not show (ignoring enableTabCloseButton) // not set - depending on enableTabCloseButton close = (typeof(close)=="undefined"?(this.conf.closeButton==true):window.dhx4.s2b(close)); active = window.dhx4.s2b(active); var tab = document.createElement("DIV"); tab.className = "dhxtabbar_tab"; tab.innerHTML = "
"+text+"
"+ (close?"
":""); tab._tabId = id; if (close) tab.childNodes[1]._tabCloseId = id; // close button var p = this.tabsArea.childNodes[1].firstChild; if (position != null && position+1 > 0 && position+1 < p.childNodes.length) { // 1st item - line p.insertBefore(tab, p.childNodes[position+1]); } else { p.appendChild(tab); } // width var autowidth = false; if (typeof(width) == "undefined" || width == null || width == "*") { width = this._getLabelWidth(text, close); autowidth = true; } else { width = parseInt(width); } tab.style.width = width+"px"; var cell = new dhtmlXTabBarCell(id, this); this.tabsMode.appendChild(cell.cell); this.t[id] = { tab: tab, cell: cell, conf: { text: text, visible: true, active: false, enabled: true, close: close, width: width, autowidth: autowidth } }; p = cell = null; if (active) { this._setTabActive(id); } else { this._adjustCell(id); } if (this.conf.initSeq != true && this.conf.arwMode == "auto") this.setSizes(); } this.setSizes = function() { // celltop this._adjustCont(); if (this.conf.tabsAreaOfs == null) { this.tabsArea.style.width = this.cont.offsetWidth+"px"; this.conf.tabsAreaOfs = parseInt(this.tabsArea.style.width)-this.tabsArea.offsetWidth; } this.tabsArea.style.width = this.cont.offsetWidth+this.conf.tabsAreaOfs+"px"; this._adjustCell(this.conf.lastActive); this._adjustTabs(true); this.callEvent("_onSetSizes", []); } this._adjustCell = function(id) { // adjust specified cell or active if (!this.conf.contZone || id == null) return; var y = (this.conf.tabsMode=="top"?this.tabsArea.offsetHeight:0)+this.conf.tabsTop; var h = this.cont.offsetHeight-this.tabsArea.offsetHeight-this.conf.tabsTop; // if layout attached - move a bit var t = this.t[id].cell.dataType; if (this.conf.skin == "dhx_skyblue" && (t == "layout" || t == "tabbar" || t == "acc")) { if (this.conf.tabsMode == "top") y = y - 1; // only for top h = h + 1; // always } if (id != this.conf.lastActive) { y = -5000; this.t[id].cell.cell.style.visibility = "hidden"; this.t[id].cell.cell.style.zIndex = 0; } this.t[id].cell._setSize(0, y, this.cont.offsetWidth, h); } this.setTabsMode = function(mode) { // new this.conf.tabsMode = (mode=="bottom"?"bottom":"top"); this.tabsMode.className = "dhxtabbar_tabs_"+this.conf.tabsMode; this.tabsArea.className = "dhxtabbar_tabs dhxtabbar_tabs_"+this.conf.tabsMode; this.tabsArea.style.top = (this.conf.tabsMode=="top"?this.conf.tabsTop+"px":"auto"); this.setSizes(); } // generate tab css depending on actv/en state this._tabCss = function(id, hidden) { var a = this.t[id].conf.active; var d = !this.t[id].conf.enabled; var h = !this.t[id].conf.visible; return "dhxtabbar_tab"+(h?" dhxtabbar_tab_hidden":(a||d?" dhxtabbar_tab"+(a?"_actv":"")+(d?"_dis":""):"")); } // calculate tab width depending on text and close button this._getLabelWidth = function(text, close) { if (this.tabsTextTest == null) { this.tabsTextTest = document.createElement("SPAN"); this.tabsTextTest.className = "dhxtabbar_tabs_text_test_"+this.conf.skin; } document.body.appendChild(this.tabsTextTest); this.tabsTextTest.innerHTML = text; var w = this.tabsTextTest.offsetWidth; if (window.dhx4.isIE && w == 0) w = this.tabsTextTest.offsetWidth; // strange IE bug // some extra width w += this.conf.tabsWidth[this.conf.skin][0]; if (close == true) w += this.conf.tabsWidth[this.conf.skin][1]; // document.body.removeChild(this.tabsTextTest); return w; } // if tabs overflow left/right side, adjust active tab position this._adjustTabs = function(fixTabsArea) { if (this._checkArrows() == true || fixTabsArea == true) { this.tabsArea.childNodes[1].style.left = this.tabsArea.childNodes[0].offsetWidth-1+"px"; this.tabsArea.childNodes[1].style.width = Math.max(0, this.tabsArea.clientWidth-this.tabsArea.childNodes[0].offsetWidth-this.tabsArea.childNodes[2].offsetWidth)+this.conf.tabsOfs*2+"px"; // minus 2 arrows } var p = this.tabsArea.childNodes[1]; if (p.offsetWidth < 5) { p = null; return; } var x = parseInt(p.childNodes[0].style[this.conf.align]); var k = null; for (var q=0; q