//*** This code is copyright 2003 by Gavin Kistner, !@phrogz.net //*** It is covered under the license viewable at http://phrogz.net/JS/_ReuseLicense.txt //*** Reuse or modification is free provided you abide by the terms of that license. //*** (Including the first two lines above in your source code satisfies the conditions.) // REQUIRES AttachEvent library -- see http://phrogz.net/JS/AttachEvent_js.txt // ************************************************************************************************** // Causes elements of a specific type, or with a specific attribute value, to create their own title // 'tooltip' which stays open as long as the mouse is over the element (or tooltip). // // The created div has the ID 'persistentTitle', allowing you to use CSS to style it as you see fit. // // The PersistentTitles_Init() function, called when the page loads, takes three parameters: // tags - a comma-delimited list of tag names to apply this script to; // use '*' or null to match any type of tag. // attr - the attribute whose value needs to contain the value in the third parameter; // leave blank, or use null, to not limit on any attribute. // val - if 'attr' is passed, ensure that the attribute contains this value (case-insensitive) // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Examples: // PersistentTitles_Init(); // ^^^ apply to every element (which has a title="..." attribute) // // PersistentTitles_Init('p,div'); // ^^^ apply only to
and
element whose ID is 'description'
// **************************************************************************************************
AttachEvent(window,'load',function(){
PersistentTitles_Init(null,'class','truncated');
},false);
function PersistentTitles_Init(tags,attr,val){
var valTest;
if (attr) valTest = new RegExp('\\b'+val+'\\b',i);
if (!tags) tags='*';
tags=tags.split(',');
for (var i=0,len=tags.length;i
');
div.style.display='block';
var xy=FindXY(el);
div.style.left=xy.x+8+'px';
div.style.top=xy.y+8+'px';
div.style.width='auto';
StopPropagation(evt);
setTimeout('PersistentTitles_FixWidth()',1);
}
function PersistentTitles_HideTitle(){
PersistentTitles_div.style.display='none';
}
function PersistentTitles_CreateDiv(){
var div=window.PersistentTitles_div=document.body.appendChild(document.createElement('div'));
div.id='persistentTitle';
div.style.position='absolute';
div.onmouseover = function(){ PersistentTitles_div.style.display='block' };
div.onmouseout = PersistentTitles_HideTitle;
}
function PersistentTitles_FixWidth(){
var div=window.PersistentTitles_div;
var x = parseInt(div.style.left);
var w = div.offsetWidth;
if ((x+w)>=document.body.scrollWidth) div.style.width=document.body.scrollWidth-x-30;
}
//**** See http://phrogz.net/JS/FindXY_js.txt for license and latest
function FindXY(obj){
var x=0,y=0;
while (obj!=null){
x+=obj.offsetLeft-obj.scrollLeft;
y+=obj.offsetTop-obj.scrollTop;
obj=obj.offsetParent;
}
return {x:x,y:y};
}
//**** See http://phrogz.net/JS/StopPropagation_js.txt for license and latest
function StopPropagation(evt){
if (!evt) return false;
evt.cancelBubble=true;
if (evt.stopPropagation) evt.stopPropagation();
return true;
}