Ciao a tutti!
Ho scaricato da qualche giorno un javascript gratuito per creare dei tooltips dinamicamente e popolati con ajax. Lo script originario non prevede la possibilità di mantenere visibili i tooltips quando il mouse è sopra il tooltip stesso, cosa che invece a me interessa, visto che vorrei poter inserire dei link all'interno. Così ho provato a modificare lo script di base aggiungendo un setTimeout() e dei clearTimeout() in punti opporutni, almeno secondo me, ma purtroppo non conosco molto bene javascript...
Pensavo di aver trovato la soluzione, visto che in Firefox e Opera tutto funziona come vorrei, ma purtroppo in Internet Explorer (6 e 7) non funziona! Sembra che il timeout proceda e che il cleartimeout venga totalmente ignorato... Dove sbaglio? C'è forse qualche particolare differenza di istruzioni da utilizzare con i browser di Microsoft??
Vi inserisco il codice: è un po' disordinato perchè ci ho pasticciato un bel po' tentando varie diverse soluzioni (molte delle quali funzionano sempre in Firefox e Opera e non in IE!!).
Vi ringrazio per l'aiuto che potrete darmi.
Ciao
codice:
/************************************************************************************************************
Ajax tooltip
Copyright (C) 2006 DTHMLGoodies.com, Alf Magne Kalleland
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Dhtmlgoodies.com., hereby disclaims all copyright interest in this script
written by Alf Magne Kalleland.
Alf Magne Kalleland, 2006
Owner of DHTMLgoodies.com
************************************************************************************************************/
/* Custom variables */
/* Offset position of tooltip */
var x_offset_tooltip = 5;
var y_offset_tooltip = 0;
/* Don't change anything below here */
var ajax_tooltipObj = false;
var ajax_tooltipObj_iframe = false;
var timer;
var ajax_tooltip_MSIE = false;
if(navigator.userAgent.indexOf('MSIE')>=0)ajax_tooltip_MSIE=true;
function ajax_showTooltip(externalFile,inputObj) {
clearTimeout(timer);
if(!ajax_tooltipObj) {
/* Tooltip div not created yet ? */
ajax_tooltipObj = document.createElement('DIV');
ajax_tooltipObj.style.position = 'absolute';
//ajax_tooltipObj.setAttribute('onmouseover', 'clearTimeout(timer)');
ajax_tooltipObj.setAttribute('onmouseover', 'keep_tooltip()');
ajax_tooltipObj.setAttribute('onmouseout', 'ajax_hideTooltip()');
ajax_tooltipObj.id = 'ajax_tooltipObj';
document.body.appendChild(ajax_tooltipObj);
var leftDiv = document.createElement('DIV'); /* Create arrow div */
leftDiv.className='ajax_tooltip_arrow';
leftDiv.id = 'ajax_tooltip_arrow';
ajax_tooltipObj.appendChild(leftDiv);
var contentDiv = document.createElement('DIV'); /* Create tooltip content div */
contentDiv.className = 'ajax_tooltip_content';
ajax_tooltipObj.appendChild(contentDiv);
contentDiv.id = 'ajax_tooltip_content';
if(ajax_tooltip_MSIE) { /* Create iframe object for MSIE in order to make the tooltip cover select boxes */
ajax_tooltipObj_iframe = document.createElement('<IFRAME frameborder="0">');
ajax_tooltipObj_iframe.style.position = 'absolute';
ajax_tooltipObj_iframe.border='0';
ajax_tooltipObj_iframe.frameborder=0;
ajax_tooltipObj_iframe.style.backgroundColor='#FFF';
ajax_tooltipObj_iframe.src = 'about:blank';
//ajax_tooltipObj_iframe.setAttribute('onmouseover', 'clearTimeout(timer)');
ajax_tooltipObj_iframe.setAttribute('onmouseover', 'keep_tooltip()');
ajax_tooltipObj_iframe.setAttribute('onmouseout', 'ajax_hideTooltip()');
contentDiv.appendChild(ajax_tooltipObj_iframe);
ajax_tooltipObj_iframe.style.left = '0px';
ajax_tooltipObj_iframe.style.top = '0px';
}
}
// Find position of tooltip
ajax_tooltipObj.style.display='block';
ajax_loadContent('ajax_tooltip_content',externalFile);
if(ajax_tooltip_MSIE){
ajax_tooltipObj_iframe.style.width = ajax_tooltipObj.clientWidth + 'px';
ajax_tooltipObj_iframe.style.height = ajax_tooltipObj.clientHeight + 'px';
}
ajax_positionTooltip(inputObj);
}
function ajax_positionTooltip(inputObj) {
var leftPos = (ajaxTooltip_getLeftPos(inputObj) + inputObj.offsetWidth);
var topPos = ajaxTooltip_getTopPos(inputObj);
var tooltipWidth = document.getElementById('ajax_tooltip_content').offsetWidth + document.getElementById('ajax_tooltip_arrow').offsetWidth;
ajax_tooltipObj.style.left = leftPos + 'px';
ajax_tooltipObj.style.top = topPos + 'px';
}
function keep_tooltip() { clearTimeout(timer); document.getElementById('ajax_tooltipObj').style.display="block"; }
function ajax_hideTooltip() { timer = setTimeout('ajax_tooltipObj.style.display=\'none\'',1000); }
function ajaxTooltip_getTopPos(inputObj) {
var returnValue = inputObj.offsetTop;
while((inputObj = inputObj.offsetParent) != null) {
if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
}
return returnValue;
}
function ajaxTooltip_getLeftPos(inputObj) {
var returnValue = inputObj.offsetLeft;
while((inputObj = inputObj.offsetParent) != null){
if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft;
}
return returnValue;
}
Questo è invece il codice con cui attivo il tooltip