/*****************************************************************************/ /* tips.js Tooltips, includes both the tooltip code and the tip text. COPYRIGHT --------- Copyright (C) 2017 Mark G.Daniel This program, comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under the conditions of the GNU GENERAL PUBLIC LICENSE, version 3, or any later version. http://www.gnu.org/licenses/gpl.txt VERSION ------- 30-JAN-2017 MGD initial */ /*****************************************************************************/ var intrsp_ToolTipDisabled = false, // set to true to disable tooltips intrsp_ToolTipDelay = 800, // mSecs intrsp_ToolTipOutDelay = 200; // mSecs ////////// // TIPS // ////////// function intrspToolTipInit () { if (intrsp_ToolTipDisabled) return; if (intrsp_ToolTipArray.length) return; ///////////// // control // ///////////// intrspToolTipAdd('controlCollect','Collect server data.'); intrspToolTipAdd('controlUpdate', 'Update displayed data. Deselecting this option allows the displayed data \ to be examined without change while maintaining collection for update \ when reselected.'); } ///////////// // TOOLTIP // ///////////// var intrsp_ToolTipArray = new Array(); var intrsp_ToolTipTimer = null, intrsp_ToolTipCurrent = null; var intrsp_ToolTipX = 0, intrsp_ToolTipY = 0, intrsp_ToolTipXguard = 20, intrsp_ToolTipYguard = 10; // add an element's tip to the lookup array function intrspToolTipAdd (id,tip) { if (tip.substr(0,1) == '[') intrspToolTipSet(id,intrsp_ToolTipArray[tip.substr(1,tip.length-2)]); else intrspToolTipSet(id,(intrsp_ToolTipArray[id] = tip)); } // set a tool tip against an element function intrspToolTipSet (id,tip) { if (typeof tip == 'undefined') tip = '[' + id + ']'; var idobj = $byId(id); if (!idobj) { alert('TIP ' + id + ' undefined!'); return; } idobj.setAttribute('onmousemove','intrspToolTip(event,"' + tip + '")'); idobj.setAttribute('onmouseout','intrspToolTip(event)'); } // the mouse event on the element triggers a tooltip function intrspToolTip(evnt,tip) { if (!$byId("checkboxTooltips").checked) return; var div = document.getElementById('divToolTip'); if (div == null) { // create the div for the tooltip text just the once var body = document.getElementsByTagName('body')[0]; var div = document.createElement('div'); div.setAttribute('id','divToolTip'); div.setAttribute('style','display:none;'); // makes it easier on touch devices (e.g. iPad) div.setAttribute('onclick','this.style.display="none";'); body.appendChild(div); } if (evnt.type == 'mousemove') { intrsp_ToolTipX = evnt.pageX; intrsp_ToolTipY = evnt.pageY; if (div && div.style.display == 'none') { // tooltip is not (yet) displayed if (intrsp_ToolTipTimer) return; // delay the appearance of the tooltip var callback = function(tip) { // timeout for initial tooltip just expired intrsp_ToolTipTimer = null; div.style.display = 'inline-block'; var pseudoEvent = { type : 'mousemove', pageX : intrsp_ToolTipX, pageY : intrsp_ToolTipY }; setTimeout(intrspToolTip, 10, pseudoEvent, tip); intrsp_ToolTipCurrent = tip; if (tip.substr(0,1) == '[') tip = intrsp_ToolTipArray[tip.substr(1,tip.length-2)]; document.getElementById('divToolTip').innerHTML = tip; }; intrsp_ToolTipTimer = setTimeout(callback, intrsp_ToolTipDelay, tip); } else { // tooltip is currently displayed, just move it if (div.scrollWidth + intrsp_ToolTipX + intrsp_ToolTipXguard > window.innerWidth) div.style.left = (intrsp_ToolTipX - div.scrollWidth - 5) + 'px'; else div.style.left = (intrsp_ToolTipX + 5) + 'px'; if (div.scrollHeight + intrsp_ToolTipY + intrsp_ToolTipYguard > window.innerHeight) div.style.top = (intrsp_ToolTipY - div.scrollHeight - 5) + 'px'; else div.style.top = (intrsp_ToolTipY + 5) + 'px'; if (tip != intrsp_ToolTipCurrent) { intrsp_ToolTipCurrent = tip; if (tip.substr(0,1) == '[') tip = intrsp_ToolTipArray[tip.substr(1,tip.length-2)]; div.innerHTML = tip; } if (intrsp_ToolTipTimer) clearTimeout(intrsp_ToolTipTimer); intrsp_ToolTipTimer = null; } } else if (evnt.type == 'mouseout') { // delay the disappearance of the tooltip just slightly var callback = function (tip) { clearTimeout(intrsp_ToolTipTimer); intrsp_ToolTipTimer = null; div.style.display = 'none'; } clearTimeout(intrsp_ToolTipTimer); intrsp_ToolTipTimer = setTimeout(callback, intrsp_ToolTipOutDelay, tip); } else { // tooltip no longer current clearTimeout(intrsp_ToolTipTimer); intrsp_ToolTipTimer = intrsp_ToolTipCurrent = null; div.style.display = 'none'; } } /*****************************************************************************/