123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397 |
- /*
- *+------------------------------------------------------------------------+
- *| 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 += '<table role="presentation" cellpadding="0" cellspacing="0" border="0"';
- if (this.m_sId != null)
- {
- html += 'style="display: inline;"><tr>';
- /*The height of 26 is chosen so that the collapse/expand icons will always line up in Firefox. Bug #483255*/
- html += '<td'+(document.all ? ' style="vertical-align:bottom"':'')+' style="height:26px"><img id="barIcon'+ this.m_id +'" border="0" src="'+ this.m_imgCollapseSrc + '"';
- if (this.m_hideTooltip != null) {
- html += ' alt="'+this.m_hideTooltip+'" title="'+this.m_hideTooltip+'"';
- }
- html +=' onclick="'+this.m_sId +'.toggleBar();" style="cursor:pointer;cursor:hand;"></td>';
- }
- 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 += '><tr>';
- }
- html += '<td id="bar'+ this.m_id +'">';
- html += '<table role="presentation" cellpadding="0" cellspacing="0" border="0" class="';
- if(this.getStyle() != null)
- {
- html += this.getStyle().getNormalState();
- }
- html += '" id="';
- html += this.m_id;
- html += '" style="'+ this.m_style +'"><tr>';
- html += this.drawItems();
- html += '</tr></table></td>';
- html += '</tr></table>';
- 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 += '<td style="white-space:nowrap;">';
- }
- if(this.m_items[i].isVisible()) {
- html += this.m_items[i].draw();
- }
- if(this.m_menuType == cHorizonalBar && !(this.m_items[i] instanceof CSeperator) ) {
- html += '</td>';
- }
- }
- }
- 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';
|