//******************************************************** // Class Tooltip // Display a tooltip // // obj param: {target, [strContent], [msDelay] } // dom target: Beside wich dom object display the tooltip // [str strContent]: text to display in the tooltip // [int msDelay]: delay in millisecond to display the tooltip //******************************************************** var Tooltip = Class.create( { initialize: function( param ) { this.parent = window.document.body; this.target = param.target; var safeLanguage = false; if( "undefined" != typeof(language) ) { safeLanguage = language; } this.language = param.language || safeLanguage || "en"; this.content = param.content || false; this.msDelay = 100; if( param.msDelay != undefined ) this.msDelay = param.msDelay; this.sizeX = param.sizeX || false; this.sizeY = param.sizeY || false; this.isDisplayed = false; this.isDisabled = false; this.timerDelay = false; this.moveX = 0; this.moveY = 2; this.margin = 2; this.position = param.position || "bottom"; this.align = param.align || "ltr"; // Save callback as Event.observe needs the exact callback to be destroyed this.onMouseOverObserver = this.onMouseHover.bindAsEventListener( this ); this.onMouseOutObserver = this.onMouseOut.bindAsEventListener( this ); Event.observe( this.target, 'mouseover', this.onMouseOverObserver ); Event.observe( this.target, 'mouseout', this.onMouseOutObserver ); }, // Public Actions ******************************************************** enable : function() { this.isDisabled = false; }, disable : function() { this.isDisabled = true; }, show: function() { }, hide: function() { }, setContent : function( content ) { this.content = content; }, destroyTooltip : function() { if( this.timerDelay ) clearTimeout( this.timerDelay ); Event.stopObserving( this.target, 'mouseover', this.onMouseOverObserver ); Event.stopObserving( this.target, 'mouseout', this.onMouseOutObserver ); this.removeToolTip(); }, // Private Actions ******************************************************** removeToolTip : function() { if( this.displayed == false ) return; this.displayed = false; if( this.container ) this.parent.removeChild( this.container ); }, createToolTip : function( event ) { if( this.isDisabled == true || this.content == false ) return; if( event ) this.event = event; this.displayed = true; this.container = document.createElement( "table" ); this.container.className = "container_toolTip"; this.container.atMe = this; this.parent.appendChild( this.container ); setTableBorderToZero( this.container ); if( this.sizeX ) this.container.style.width = this.sizeX + "px"; if( this.sizeY ) this.container.style.height = this.sizeY + "px"; var containerBody = document.createElement( "tbody" ); this.container.appendChild( containerBody ); // Display Top var top = document.createElement( "tr" ); containerBody.appendChild( top ); var top_left = document.createElement( "td" ); top_left.className = "toolTip_top_left"; top.appendChild( top_left ); var top_middle = document.createElement( "td" ); top_middle.className = "toolTip_top_middle"; top.appendChild( top_middle ); var top_right = document.createElement( "td" ); top_right.className = "toolTip_top_right"; top.appendChild( top_right ); // Display Middle var middle = document.createElement( "tr" ); containerBody.appendChild( middle ); var middle_left = document.createElement( "td" ); middle_left.className = "toolTip_middle_left"; middle.appendChild( middle_left ); this.middle_middle = document.createElement( "td" ); this.middle_middle.className = "toolTip_middle_middle"; if( this.content ) this.middle_middle.innerHTML = this.content; middle.appendChild( this.middle_middle ); var middle_right = document.createElement( "td" ); middle_right.className = "toolTip_middle_right"; middle.appendChild( middle_right ); // Display Bottom var bottom = document.createElement( "tr" ); containerBody.appendChild( bottom ); var bottom_left = document.createElement( "td" ); bottom_left.className = "toolTip_bottom_left"; bottom.appendChild( bottom_left ); var bottom_middle = document.createElement( "td" ); bottom_middle.className = "toolTip_bottom_middle"; bottom.appendChild( bottom_middle ); var bottom_right = document.createElement( "td" ); bottom_right.className = "toolTip_bottom_right"; bottom.appendChild( bottom_right ); // Display the tooltips on a element var offset = Element.cumulativeOffset( this.target ); var positionX = offset[0]; var positionY = offset[1]; var moveLeft = 0; var moveTop = 2; var elementHeight = this.target.getHeight(); var elementWidth = this.target.getWidth(); // Display the tooltips on a element this.setPosition( this.position, this.align ); this.container.style.visibility = "visible"; }, // setPosition : positions the toolip depending on two parameters // @position : either "bottom" or "side" // @align : either "rtl" or "ltr" setPosition: function( position, align ) { var offset = Element.cumulativeOffset( this.target ); var screenSize = getScreenSize(); var positionX = 0; var positionY = 0; if( "bottom" == position ) { // x position if( "ltr" == align ) { positionX = offset[0]; if( positionX + this.container.getWidth() > screenSize[0] ) // tooltip goes out of the screen positionX -= (positionX + this.container.getWidth() - screenSize[0]) } else { positionX = offset[0] - this.container.getWidth() + this.target.getWidth(); if( positionX < 0 ) // tooltip goes out of the screen positionX = 0; } // y position positionY = offset[1] + this.target.getHeight() + this.margin; if( positionY + this.container.getHeight() > screenSize[1] ) positionY = offset[1] - this.container.getHeight() - this.margin; } else // position = "side" { var positionX = 0; // x position if( "ltr" == align ) { positionX = offset[0] + this.target.getWidth() + this.margin; if( (positionX + this.container.getWidth() + this.margin) > screenSize[0] ) // tooltip goes out of the screen positionX = offset[0] - this.container.getWidth() - this.margin; } else { positionX = offset[0] - this.container.getWidth() - this.margin; if( (positionX + this.container.getWidth() + this.margin) < 0 ) // tooltip goes out of the screen positionX = offset[0] + this.target.getWidth() + this.margin; } // y position var positionY = offset[1] + this.margin; if( (positionY + this.container.getHeight()) > screenSize[1] ) // tooltip goes out of the screen positionY -= (positionY + this.container.getHeight() - screenSize[1]); if( positionY < 0 ) positionY = 0; } this.container.style.left = "100px"; this.container.style.top = "100px"; // this.container.style.left = positionX + "px"; // // this.container.style.top = positionY + "px"; }, // ** setPositionBottomLTR : deprecated ** setPositionBottomLTR: function() { var offset = Element.cumulativeOffset( this.target ); var screenSize = getScreenSize(); var positionX = offset[0] + this.moveX; var positionY = offset[1] + this.target.getHeight() + this.moveY; if( screenSize[0] > (positionX + this.container.getWidth() + this.moveX) ) { this.container.style.left = positionX + "px"; } else { this.container.style.left = screenSize[0] - this.container.getWidth() - this.moveX + "px"; } if( screenSize[1] > (positionY + this.container.getHeight()) ) { this.container.style.top = positionY + "px"; } else { this.container.style.top = offset[1] - this.container.getHeight() - this.moveY + "px"; } }, // ** setPositionBottomRTL : deprecated ** setPositionBottomRTL: function() { var offset = Element.cumulativeOffset( this.target ); var screenSize = getScreenSize(); var positionX = offset[0] - this.container.getWidth() + this.target.getWidth() - this.moveX; var positionY = offset[1] + this.target.getHeight() + this.moveY; if( 0 < positionX ) { this.container.style.left = positionX + "px"; } else { this.container.style.left = this.moveX + "px"; } if( screenSize[1] > (positionY + this.container.getHeight()) ) { this.container.style.top = positionY + "px"; } else { this.container.style.top = offset[1] - this.container.getHeight() - this.moveY + "px"; } }, // Events ******************************************************** onMouseHover : function( event ) { this.event = event; if( this.msDelay ) this.timerDelay = setTimeout( this.createToolTip.bind( this ), this.msDelay ); else this.createToolTip(); }, onMouseOut : function() { if( this.timerDelay ) clearTimeout( this.timerDelay ); this.removeToolTip(); } } ); // Functions which destroy all toolTips in the webpage function hideAllTooltips() { $$( ".container_toolTip" ).each( function ( divContainer ) { if( divContainer && divContainer.atMe ) divContainer.atMe.removeToolTip(); } ); } //******************************************************** // Class FormatProperties // Format properties of items // // dom item: Beside wich dom object display the tooltip // str content: text to display in the tooltip // [int msDelay]: delay in millisecond to display the tooltip // [bool isAlignRight]: side from the item where to display the tooltip //******************************************************** var FormatProperties = Class.create( { initialize: function() { // Init this.arrayExcludeCriterias = $A( [ "Class" ] ); this.units = { "MET_arms_CurrentLactate": "item.percent", "MET_legs_CurrentLactate": "item.percent", "MET_CurrentGlucose": "item.percent", "MET_CurrentFat": "item.percent", "MET_CurrentWater": "item.percent" }; this.valueScale = { "MET_arms_CurrentLactate":{min:0,max:100}, "MET_legs_CurrentLactate":{min:0,max:100}, "MET_CurrentGlucose":{min:0,max:100}, "MET_CurrentFat":{min:0,max:1000}, "MET_CurrentWater":{min:0,max:10} }; // Set sorter this.sorter = new Sort(); this.sorter.addCriteria( "asc", this.criteriaTranslatedCode.bind( this ) ); }, criteriaTranslatedCode: function( x ) { return x.translatedCode; }, sortProperties: function( arrayProperties ) { var arrayResult = $A(); // Exclude properties not displayed $H( arrayProperties ).each( function( objProperty ) { // Does not display empty properties if( 0 == objProperty.value ) return; // Exclude properties if( 0 == this.arrayExcludeCriterias.indexOf( objProperty.key ) ) return; arrayResult.push( objProperty.value ); }.bind( this ) ); // Sort properties return this.sorter.sort( arrayResult ); }, formatProperties: function( arrayProperties ) { arrayProperties.each( function( objProperty ) { var value = this.scalePropertyValue( objProperty.code, objProperty.value ); var unit = this.concatSuffix( objProperty.code ); var sign = this.concatSign( objProperty.value ); objProperty.bonus = sign + value + unit; }.bind( this ) ); return arrayProperties; }, toString: function( arrayProperties ) { var string = ""; arrayProperties.each( function( objProperty ) { string += translate( "item.carac", objProperty.translatedCode, "", objProperty.bonus ); }.bind( this ) ); return string; }, // Private ******************************************************************* scalePropertyValue: function( propertyCode, propertyValue ) { // Special conversion for MET item if( this.valueScale[propertyCode] && propertyCode.include( "MET_" ) ) { var scaleGui = 100; var scaleDB = this.valueScale[propertyCode].max - this.valueScale[propertyCode].min; propertyValue = propertyValue * scaleGui / scaleDB; propertyValue = this.valueScale[propertyCode].min + propertyValue; } return propertyValue; }, concatSuffix: function( propertyCode ) { if( this.units[propertyCode] ) return translate( this.units[propertyCode] ); else return ""; }, concatSign: function( propertyValue ) { if( 0 < propertyValue ) return "+"; else return ""; } } );