/* *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| IBM Cognos Products: Viewer *| (C) Copyright IBM Corp. 2001, 2011 *| *| US Government Users Restricted Rights - Use, duplication or *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *| *+------------------------------------------------------------------------+ */ /*----------------------------------------------------------------------------------------------------- Class : CBar Description : -----------------------------------------------------------------------------------------------------*/ var cHorizonalBar = 0; var cVerticalBar = 1; function CBar(containerId, style, sId, imagePath, showTooltip, hideTooltip, cookieVar, cookieName) { this.m_align = 'left'; this.m_items = []; this.m_htmlContainerId = containerId; this.m_htmlContainer = null; this.m_id = 'cbar'+containerId; this.m_menuType = cVerticalBar; this.m_style = style; this.m_parent = null; this.m_observers = new CObserver(this); this.m_cookieVar = cookieVar; this.m_cookieName = cookieName; //reference to the object name this.m_sId = (sId) ? sId : null; this.m_display = DISPLAY_INLINE; this.m_imagePath = (imagePath) ? imagePath : '../common/images/toolbar/'; this.m_imgCollapseSrc = this.m_imagePath + 'toolbar_collapse.gif'; this.m_imgExpandSrc = this.m_imagePath + 'toolbar_expand.gif'; this.m_showTooltip = showTooltip ? showTooltip : null; this.m_hideTooltip = hideTooltip ? hideTooltip : null; } function CBar_hideBar() { var bar = document.getElementById('bar'+ this.m_id); var barToggleIcon = document.getElementById('barIcon'+ this.m_id); barToggleIcon.src= this.m_imgExpandSrc; if (this.m_showTooltip != null) { barToggleIcon.alt = this.m_showTooltip; barToggleIcon.title = this.m_showTooltip; } bar.style.display = DISPLAY_NONE; if (typeof setQSCookie == "function") { setQSCookie(this.m_cookieVar, this.m_cookieName, 0); } } function CBar_showBar() { var bar = document.getElementById('bar'+ this.m_id); var barToggleIcon = document.getElementById('barIcon'+ this.m_id); barToggleIcon.src= this.m_imgCollapseSrc; if (this.m_hideTooltip != null) { barToggleIcon.alt = this.m_hideTooltip; barToggleIcon.title = this.m_hideTooltip; } bar.style.display = this.m_display; if (typeof setQSCookie == "function") { setQSCookie(this.m_cookieVar, this.m_cookieName, 1); } } function CBar_toggleBar(){ var bar = document.getElementById('bar'+ this.m_id); var barDisplay = bar.style.display; if ( (barDisplay == this.m_display) || (barDisplay=='')) { this.hideBar(); } else { this.showBar(); } } function CBar_getParent() { return this.m_parent; } function CBar_setParent(parent) { this.m_parent = parent; } function CBar_draw() { if(this.m_htmlContainer == null) { this.m_htmlContainer = document.getElementById(this.m_htmlContainerId); if(this.m_htmlContainer == null) { // if we can't find the container, return return; } } var html = ''; html += ''; } else { var marginStyle = ''; if (this.m_htmlContainer.style.textAlign == 'right') { marginStyle = 'margin-left:auto; margin-right: 0;'; } else if (this.m_htmlContainer.style.textAlign == 'left') { marginStyle = 'margin-left:0; margin-right: auto;'; } else if (this.m_htmlContainer.style.textAlign == 'center') { marginStyle = 'margin-left:auto; margin-right: auto;'; } if (marginStyle != '') { html += ' style="'+marginStyle+'"'; } html += '>'; } html += ''; html += '
'; html += ''; html += this.drawItems(); html += '
'; this.m_htmlContainer.innerHTML = html; this.m_htmlContainer.style.textAlign = this.m_align; //initialize any items for(var i = 0; i < this.m_items.length; ++i) { if(typeof this.m_items[i].init == 'function') { this.m_items[i].init(); } } this.attachEvents(); } function CBar_drawItems() { var html = ''; for(var i = 0; i < this.m_items.length; ++i) { if(typeof this.m_items[i].draw == 'function') { if(this.m_menuType == cHorizonalBar && !(this.m_items[i] instanceof CSeperator) ) { html += ''; } if(this.m_items[i].isVisible()) { html += this.m_items[i].draw(); } if(this.m_menuType == cHorizonalBar && !(this.m_items[i] instanceof CSeperator) ) { html += ''; } } } return html; } function CBar_attachEvents() { for(var i = 0; i < this.m_items.length; ++i) { if(typeof this.m_items[i].attachEvents == 'function' && this.m_items[i].isVisible()) { this.m_items[i].attachEvents(); } } } function CBar_add(item) { if(typeof item.getObservers == "function" && typeof item.getObservers() == "object" && typeof item.onmouseover == "function" && item instanceof CMenuItem) { item.getObservers().attach(this, this.closeMenus, item.onmouseover); } this.m_items[this.m_items.length] = item; } function CBar_getNumItems() { return this.m_items.length; } function CBar_getId() { return this.m_id; } function CBar_get(index) { if(index >= 0 && index < this.getNumItems()) { return this.m_items[index]; } return null; } function CBar_hide(index) { if(index > 0 && index < this.getNumItems()) { if(typeof this.m_items[i].hide == "function") { this.m_items[i].hide(); } } } function CBar_show(index) { if(index > 0 && index < this.getNumItems()) { if(typeof this.m_items[i].show == "function") { this.m_items[i].show(); } } } function CBar_enable(index) { if(index > 0 && index < this.getNumItems()) { if(typeof this.m_items[i].enable == "function") { this.m_items[i].enable(); } } } function CBar_disable(index) { if(index > 0 && index < this.getNumItems()) { if(typeof this.m_items[i].disable == "function") { this.m_items[i].disable(); } } } function CBar_getState(index) { if(index > 0 && index < this.getNumItems()) { if(typeof this.m_items[i].getState == "function") { this.m_items[i].getState(); } } } function CBar_setMenuType(menuType) { this.m_menuType = menuType; } function CBar_getMenuType() { return this.m_menuType; } function CBar_setStyle(style) { this.m_style = style; } function CBar_setAlign(align) { this.m_align = align; } function CBar_getStyle() { return this.m_style; } function CBar_closeMenus(state) { // make sure we hide any submenus which have been opened. for(var i = 0; i < this.getNumItems(); i++) { var currentItem = this.get(i); if(typeof state == 'object') { if(state.getSubject() == currentItem) { continue; } } if(typeof currentItem.getMenu == "function") { var currentMenu = currentItem.getMenu(); if (currentMenu != null && currentMenu.isVisible()) { currentMenu.remove(); } } } } function CBar_getHTMLContainer() { return this.m_htmlContainer; } function CBar_getObservers() { return this.m_observers; } function CBar_onmouseover(evt) { //get the event in a cross-browser fashion evt = (evt) ? evt : ((event) ? event : null); // notify our parent (if one exists) of this event var parent = this.getParent(); if(parent != null && typeof parent.onmouseover == 'function') { parent.onmouseover(evt); } // notify observers of this event this.getObservers().notify(CBar_onmouseover); } function CBar_onmouseout(evt) { //get the event in a cross-browser fashion evt = (evt) ? evt : ((event) ? event : null); // notify our parent (if one exists) of this event var parent = this.getParent(); if(parent != null && typeof parent.onmouseout == 'function') { parent.onmouseout(evt); } // notify observers of this event this.getObservers().notify(CBar_onmouseout); } function CBar_onmouseup(evt) { //get the event in a cross-browser fashion evt = (evt) ? evt : ((event) ? event : null); // notify our parent (if one exists) of this event var parent = this.getParent(); if(parent != null && typeof parent.onmouseup == 'function') { parent.onmouseup(evt); } // notify observers of this event this.getObservers().notify(CBar_onmouseup); } function CBar_onkeypress(evt) { //get the event in a cross-browser fashion evt = (evt) ? evt : ((event) ? event : null); // notify our parent (if one exists) of this event var parent = this.getParent(); if(parent != null && typeof parent.onkeypress == 'function') { parent.onkeypress(evt); } // notify observers of this event this.getObservers().notify(CBar_onkeypress); } CBar.prototype.draw = CBar_draw; CBar.prototype.add = CBar_add; CBar.prototype.get = CBar_get; CBar.prototype.hide = CBar_hide; CBar.prototype.show = CBar_show; CBar.prototype.enable = CBar_enable; CBar.prototype.disable = CBar_disable; CBar.prototype.getState = CBar_getState; CBar.prototype.attachEvents = CBar_attachEvents; CBar.prototype.drawItems = CBar_drawItems; CBar.prototype.getId = CBar_getId; CBar.prototype.setMenuType = CBar_setMenuType; CBar.prototype.getMenuType = CBar_getMenuType; CBar.prototype.getNumItems = CBar_getNumItems; CBar.prototype.setStyle = CBar_setStyle; CBar.prototype.getStyle = CBar_getStyle; CBar.prototype.setAlign = CBar_setAlign; CBar.prototype.closeMenus = CBar_closeMenus; CBar.prototype.setParent = CBar_setParent; CBar.prototype.getParent = CBar_getParent; CBar.prototype.getHTMLContainer = CBar_getHTMLContainer; CBar.prototype.getObservers = CBar_getObservers; CBar.prototype.update = new Function("return true"); CBar.prototype.getObservers = CBar_getObservers; CBar.prototype.onmouseover = CBar_onmouseover; CBar.prototype.onmouseout = CBar_onmouseout; CBar.prototype.onmouseup = CBar_onmouseup; CBar.prototype.onkeypress = CBar_onkeypress; CBar.prototype.hideBar = CBar_hideBar; CBar.prototype.showBar = CBar_showBar; CBar.prototype.toggleBar = CBar_toggleBar; /* Constants */ var DISPLAY_INLINE = 'inline'; var DISPLAY_NONE = 'none'; var DISPLAY_BLOCK = 'block';