/* 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 this.side.parentNode.clientHeight-this.conf.side_hfix) { if (arrowsHidden == true) { this.arw.className = "dhxsidebar_arrows"; this._adjustSide(); } } else { if (arrowsHidden == false) { this.arw.className = "dhxsidebar_arrows dhxsidebar_arrows_hidden"; this.side.firstChild.style.top = "0px"; this._adjustSide(); } } }; dhtmlXSideBar.prototype.removeSep = function(id) { if (this.s[id] == null) return; this.side.firstChild.removeChild(this.s[id].sep); this.s[id].sep = null; this.s[id] = null; try { delete this.s[id]; } catch(e){}; }; // show/hide side, added in 4.5 dhtmlXSideBar.prototype.showSide = function() { if (this.conf.autohide != true) return; if (this.sideCover == null) this._sideCoverAttach(); if (this.conf.animate_items == true) { var animate = function(item, tmTime, prop) { window.setTimeout(function(){ item.style[prop] = "transform 0.3s"; item.style.transform = "translate(0px,0px)"; item = null; }, tmTime); }; if (this.conf.transProp !== false) { var q = 100; for (var a in this.t) { this.t[a].item.style[this.conf.transProp] = ""; this.t[a].item.style.transform = "translate(-"+(this.conf.width+20)+"px,0px)"; animate(this.t[a].item, q+=50, this.conf.transProp); } } } var t = this; window.setTimeout(function(){ t.arw.style.left = t.side.style.left = "0px"; t.sideCover.className = "dhxsidebar_side_cover dhxsidebar_side_cover_actv"; t = null; },50); }; dhtmlXSideBar.prototype.hideSide = function(ef) { if (this.conf.autohide != true) return; this.arw.style.left = this.side.style.left = -this.conf.width-10+"px"; if (this.sideCover != null) { if (this.conf.transProp !== false) { this.sideCover.className = "dhxsidebar_side_cover"; } else { this._sideCoverDetach(); } } }; dhtmlXSideBar.prototype._sideCoverAttach = function() { var that = this; this.sideCover = document.createElement("DIV"); this.sideCover.className = "dhxsidebar_side_cover"; if (this.arw.nextSibling != null) { this.cont.insertBefore(this.sideCover, this.arw.nextSibling); } else { this.cont.appendChild(this.sideCover); } this._sideCoverOnTrEnd = function() { if (this.className.match(/dhxsidebar_side_cover_actv/) == null) { that._sideCoverDetach(); } } this._sideCoverDetach = function() { if (this.sideCover == null) return; if (this.conf.transProp !== false) this.sideCover.removeEventListener(this.conf.transEv, this._sideCoverOnTrEnd, false); this.sideCover.parentNode.removeChild(this.sideCover); this.sideCover = null; that = null; } if (this.conf.transProp !== false) { this.sideCover.addEventListener(this.conf.transEv, this._sideCoverOnTrEnd, false); } }; // selection dhtmlXSideBar.prototype._setItemActive = function(id, callEvent) { if (this.conf.selected == id) { if (this.conf.autohide == true) this.hideSide(); return; } if (typeof(callEvent) == "undefined") callEvent = false; if (callEvent == true && this.callEvent("onBeforeSelect", [id, this.conf.selected]) !== true) { return; } var lastSelected = null; if (this.conf.selected != null) { lastSelected = this.conf.selected; this._setItemInactive(this.conf.selected); } if (this.t[id] != null) { this.conf.selected = id; this.t[id].selected = true; this.t[id].item.className += " dhxsidebar_item_selected"; if (this.conf.single_cell != true) { this.t[id].cell.cell.style.visibility = "visible"; this.t[id].cell.cell.style.top = "0px"; this.t[id].cell.cell.style.zIndex = 1; } } else { this.conf.selected = null; } this._adjustCell(id); if (callEvent == true) { this.callEvent("onSelect", [id, lastSelected]); } if (this.conf.autohide == true) { this.hideSide(); } }; dhtmlXSideBar.prototype._setItemInactive = function(id) { if (this.t[id] == null) return; this.t[id].selected = false; this.t[id].item.className = this.t[id].item.className.replace(/\s{0,}dhxsidebar_item_selected/gi,""); if (this.conf.single_cell != true) { this.t[id].cell.cell.style.visibility = "hidden"; this.t[id].cell.cell.style.top = "-5000px"; this.t[id].cell.cell.style.zIndex = 0; } }; dhtmlXSideBar.prototype._isItemActive = function(id) { return (this.conf.selected == id); }; dhtmlXSideBar.prototype._getNextVisible = function(id, getFirst) { return this._getNearVisible(id, getFirst, "next"); }; dhtmlXSideBar.prototype._getPrevVisible = function(id, getFirst) { return this._getNearVisible(id, getFirst, "previous"); }; dhtmlXSideBar.prototype._getFirstVisible = function() { return this._getNearVisible(null, false, "first"); }; dhtmlXSideBar.prototype._getNearVisible = function(id, getFirst, mode) { if (mode == "first") { var node = this.side.firstChild.firstChild; // 1st item mode = "next"; } else { if (id == null || this.t[id] == null) return (getFirst?this._getFirstVisible():null); var node = this.t[id].item[mode+"Sibling"]; } var itemId = null; while (node != null && itemId == null) { var k = node._idd; if (k != null && itemId == null && this.t[k].conf.visible) { itemId = k; } else { node = node[mode+"Sibling"]; } } node = null; return itemId; }; dhtmlXSideBar.prototype.goToNextItem = function(callEvent) { var id = this._getNextVisible(this.conf.selected, true); if (id != null) this._setItemActive(id, callEvent); }; dhtmlXSideBar.prototype.goToPrevItem = function(callEvent) { var id = this._getPrevVisible(this.conf.selected, true); if (id != null) this._setItemActive(id, callEvent); }; dhtmlXSideBar.prototype.getActiveItem = function() { return this.conf.selected; }; // templates dhtmlXSideBar.prototype.setTemplate = function(template, iconsPath) { // conf this.conf.tpl_name = (template!=null&&this.templates[template]!=null?template:"details"); this.conf.tpl_str = this.templates[this.conf.tpl_name]; // icons path if any if (iconsPath != null) this.conf.icons_path = iconsPath; // update loaded items for (var a in this.t) { this.t[a].init.icons_path = this.conf.icons_path; this.t[a].item.innerHTML = window.dhx4.template(this.conf.tpl_str, this.t[a].init); } // side area if (this.side != null) { this.side.className = "dhxsidebar_side dhxsidebar_tpl_"+this.conf.tpl_name; } if (this._scrollSide != null) { this._scrollSide(0); // fix top position this._checkHeight(); } }; dhtmlXSideBar.prototype.templates = { details: "
#text#
", tiles: "
#text#
", icons: "", icons_text: "
#text#
", text: "
#text#
" }; dhtmlXSideBar.prototype.tpl_bubble = "
#value#
"; dhtmlXSideBar.prototype.tpl_header = "#text#"; window.dhtmlXSideBarCell = function(id, sidebar) { dhtmlXCellObject.apply(this, [id, "_sidebar"]); var that = this; this.sidebar = sidebar; this.conf.skin = this.sidebar.conf.skin; // sidebar calls this.conf.sidebar_funcs = { show: "_showItem", hide: "_hideItem", isVisible: "_isItemVisible", setActive: "_setItemActive", isActive: "_isItemActive", setText: "_setItemText", getText: "_getItemText", remove: "_removeItem", setBubble: "_setItemBubble", getBubble: "_getItemBubble", clearBubble: "_clearItemBubble" }; this._sidebarCall = function(name) { return function(){ var t = [this._idd]; for (var q=0; q":"")+ "
"; this.cell.insertBefore(t, this.cell.childNodes[this.conf.idx.cont]); t = null; // include into content top offset calculation this.conf.ofs_nodes.t._getHdrHeight = "func"; // show/hide this.conf.hdr = {visible: true}; // include into index this.conf.idx_data.hdr = "dhx_cell_sidebar_hdr"; this._updateIdx(); }; dhtmlXSideBarCell.prototype._getHdrHeight = function() { return this.cell.childNodes[this.conf.idx.hdr].offsetHeight; }; // visibility dhtmlXSideBarCell.prototype.showHeader = function() { if (this.conf.hdr.visible == true) return; this.conf.hdr.visible = true; this.cell.childNodes[this.conf.idx.hdr].className = "dhx_cell_sidebar_hdr"; this._adjustCont(this._idd); }; dhtmlXSideBarCell.prototype.hideHeader = function() { if (this.conf.hdr.visible != true) return; this.conf.hdr.visible = false; this.cell.childNodes[this.conf.idx.hdr].className = "dhx_cell_sidebar_hdr dhx_cell_sidebar_hdr_hidden"; this._adjustCont(this._idd); }; dhtmlXSideBarCell.prototype.isHeaderVisible = function() { return (this.conf.hdr.visible==true); }; // text dhtmlXSideBarCell.prototype.setHeaderText = function(text) { this.conf.text = text; var t = this.cell.childNodes[this.conf.idx.hdr]; t.childNodes[(t.firstChild.className=="dhx_cell_sidebar_hdr_icon"?1:0)].innerHTML = ""+text+""; t = null; }; dhtmlXSideBarCell.prototype.getHeaderText = function() { return this.conf.text; };