/* 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 dhtmlXSideBar(conf) { var that = this; this.conf = { skin: (conf.skin||window.dhx4.skin||(typeof(dhtmlx)!="undefined"?dhtmlx.skin:null)||window.dhx4.skinDetect("dhxsidebar")||"material"), css: "dhxsidebar", width: conf.width||200, scroll_size: 12, scroll_mult: 20, close_button: false, icons_path: conf.icons_path||"", selected: null, // single cell mode, added in 4.3 single_cell: (typeof(conf.single_cell)=="undefined"?false:window.dhx4.s2b(conf.single_cell)), cell: null, // cells header, added in 4.5 header: window.dhx4.s2b(conf.header), // autohide side, added in 4.5 autohide: window.dhx4.s2b(conf.autohide), animate_items: true }; // template this.setTemplate(conf.template); // init base window.dhtmlXCellTop.apply(this, [conf.parent, (conf==null?null:conf.offsets)]); // common event system window.dhx4._eventable(this); this.conf.touch_ms = false; this.conf.touch_start = "touchstart", this.conf.touch_end = "touchend" // init bars area this.side = document.createElement("DIV"); this.side.className = "dhxsidebar_side dhxsidebar_tpl_"+this.conf.tpl_name; this.side.innerHTML = "
"; this.cont.appendChild(this.side); // overflow arrows this.arw = document.createElement("DIV"); this.arw.className = "dhxsidebar_arrows dhxsidebar_arrows_hidden"; this.arw.innerHTML = ""+ ""; this.cont.appendChild(this.arw); // autohide mode if (this.conf.autohide == true) { this.hideSide(); // for cells left border this.cont.className += " dhxsidebar_autohide"; // hide on click this._doOnBodyClick = function() { if (that.conf.clear_click == true) { that.conf.clear_click = false; return; } that.hideSide(); } this._doOnEscDown = function(e) { e = e||event; if (e.keyCode == 27) { that.conf.clear_click = false; that.hideSide(); } } if (typeof(window.addEventListener) == "function") { window.addEventListener(this.conf.touch_start, this._doOnBodyClick, false); window.addEventListener("click", this._doOnBodyClick, false); window.addEventListener("keydown", this._doOnEscDown, false); } else { document.body.attachEvent("onclick", this._doOnBodyClick); document.body.attachEvent("onkeydown", this._doOnEscDown); } } window.setTimeout(function(){ if (that != null && that.side != null) { that.side.firstChild.style.top = "0px"; } },1); this._doOnArwClick = function(e) { e = e||event; if (e.type != "click" && e.preventDefault) { e.preventDefault(); // this will prevent touchmove and click events } e.cancelBubble = true; var t = e.target||e.srcElement; if (t.className.match(/dhxsidebar_arrow_image/) != null) t = t.parentNode; if (t.className.match(/dhxsidebar_arrow_left/) != null) { that._scrollSide(-that.conf.scroll_size); } else if (t.className.match(/dhxsidebar_arrow_right/) != null) { that._scrollSide(that.conf.scroll_size); } t = null; } if (typeof(window.addEventListener) == "function") { this.arw.addEventListener(this.conf.touch_start, this._doOnArwClick, false); this.arw.addEventListener("click", this._doOnArwClick, false); } else { this.arw.attachEvent("onclick", this._doOnArwClick); } // side click this._doOnSideClick = function(e) { e = e||event; var t = e.target||e.srcElement; var id = null; var b = false; that.conf.clear_click = true; if (e.type == "touchstart" || e.type == "pointerdown" || e.type == "MSPointerDown") { if (e.preventDefault) { e.preventDefault(); // this will prevent touchmove and click events } if (this.className.match(/dhxsidebar_touch/gi) == null) { if (e.type == "touchstart" || (e.type == "pointerdown" && e.pointerType == "touch")) { this.className += " dhxsidebar_touch"; } } return } while (t != null && id == null && e.type != "pointerdown" && e.type != "MSPointerDown") { if (typeof(t.className) != "undefined") { if (t.className.match(/^dhxsidebar_item/) != null && typeof(t._idd) != "undefined") { id = t._idd; } else if (t.className.match(/^dhxsidebar_bubble/) != null) { b = true; id = t.parentNode._idd; } } t = t.parentNode; } if (id != null) { if (b == false || (b == true && that.callEvent("onBubbleClick", [id, that.t[id].conf.bubble]) == true)) { that._setItemActive(id, true); } } t = null; } if (typeof(window.addEventListener) == "function") { this.side.addEventListener(this.conf.touch_start, this._doOnSideClick, false); this.side.addEventListener(this.conf.touch_end, this._doOnSideClick, false); this.side.addEventListener("mouseup", this._doOnSideClick, false); } else { this.side.attachEvent("onclick", this._doOnSideClick); } this.side.onmouseover = function() { this.className = this.className.replace(/\s*dhxsidebar_touch/gi,""); } // side scroll this._doOnSideScroll = function(e) { e = e||event; var y = (e.type=="mousewheel"?-e.wheelDelta:e.deltaY); that._scrollSide(y/Math.abs(y)*3); } this._scrollSide = function(dir) { // dir => -1/1 var top = parseInt(this.side.firstChild.style.top||0)-dir*this.conf.scroll_mult; // first check down if (top + this.side.firstChild.offsetHeight < this.side.clientHeight) top = this.side.clientHeight - this.side.firstChild.offsetHeight; // also check top if (top > 0) top = 0; this.side.firstChild.style.top = top+"px"; } if (typeof(window.addEventListener) == "function") { this.side.addEventListener("wheel", this._doOnSideScroll, false); } else { this.side.attachEvent("onmousewheel", this._doOnSideScroll); } // items this.t = {}; this.s = {}; this._adjustCell = function(id, force) { if (this.conf.single_cell != true && id == null) return; var x = (this.conf.autohide==true?0:this.conf.width); var w = this.cont.offsetWidth-x; var y = 0; var h = this.cont.offsetHeight; if (this.conf.single_cell == true) { if (force == true) this.conf.cell._setSize(x, y, w, h); // only call from setSizes } else { if (id != this.conf.selected) { y = -5000; this.t[id].cell.cell.style.visibility = "hidden"; this.t[id].cell.cell.style.zIndex = 0; } this.t[id].cell._setSize(x, y, w, h); } } // transition support if any var k = window.dhx4.transDetect(); this.conf.transProp = k.transProp; this.conf.transEv = k.transEv; this.conf.transValue = "all 0.1s"; this._doOnTrEnd = function(e) { var id = this._idd; // this points to an item if (that.t[id] == null) return; var t = that.t[id]; var actvId = t.conf.transActvId; if (t.conf.transMode == "hide") { if (t.conf.remove == true) { that._removeItem(id); } else { t.item.style[t.conf.transProp] = ""; if (that.conf.single_cell != true) { t.cell.cell.style.visibility = "hidden"; t.cell.cell.style.top = "-5000px"; } t.conf.transActv = false; } } else if (t.conf.transMode == "show") { t.item.style[t.conf.transProp] = ""; t.item.style.visibility = "visible"; t.conf.transMode = null; t.conf.transActv = false; } if (actvId != null) { that._setItemActive(actvId); } else { that._checkHeight(); } t = null; } // data loading this._initObj = function(data) { this.clearAll(); if (data.items != null) this.addItem(data.items); } this._xmlToObj = function(data) { var items = []; var r = data.getElementsByTagName("sidebar"); if (r != null && r[0] != null) { var t = r[0].getElementsByTagName("item"); for (var q=0; q