PDA

View Full Version : Image w/ Description Tooltip IE6 .png fix and Joomla



Plaidfox
05-05-2008, 02:48 PM
1) Script Title: Image w/ Description Tooltip

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex4/imagetooltip.htm

3) Describe problem: Love the script, it's really useful.
I'm currently using the script on a joomla website. I'm using .png images, and they are not working correctly in IE6, like all .png files do. I've tried installing the iepngfix.htc, and even installed a joomla mambot to fix the problem. Nothing seems to be working. Can anyone help me out?

-Plaidfox

jscheuer1
05-06-2008, 05:49 AM
Since the tool tip script writes out the HTML for the tip each time it is triggered, you would have to edit the script to make it write png fixed code for .png images in IE 5.5 through 6.

Here's where it happens in the script (more or less):


if (ie4||ie5||ns5) {
var tip = startStr + messages[num][0] + midStr + '<span style="font-family:' + tipFontFamily + '; font-size:' + tipFontSize + '; color:' + curFontColor + ';">' + messages[num][1] + '</span>' + endStr;
tipcss.backgroundColor = curBgColor;
tooltip.innerHTML = tip;

Notice the highlighted section, it is using this code (the end of the startStr and the beginning of the midStr, both also highlighted):


// to layout image and text, 2-row table, image centered in top cell
// these go in var tip in doTooltip function
// startStr goes before image, midStr goes between image and text
var startStr = '<table width="' + tipWidth + '"><tr><td align="center" width="100%"><img src="';
var midStr = '" border="0"></td></tr><tr><td valign="top">';
var endStr = '</td></tr></table>';

to create the image tag, by inserting the image filenames into its src attribute.

Some sort of test would have to be made at either of those two points in the code to determine if different markup should be used for IE 5.5 through IE 6, and if so, supply it. Earlier IE can't do png fix and IE 7 usually doesn't need to, it handles png images just fine in most cases.

Here's a version of the script that takes care of it:


<script type="text/javascript">

/***********************************************
* Image w/ description tooltip- By Dynamic Web Coding (www.dyn-web.com)
* Copyright 2002-2007 by Sharon Paine
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

/* IMPORTANT: Put script after tooltip div or
put tooltip div just before </BODY>. */

var dom = (document.getElementById) ? true : false;
var ns5 = (!document.all && dom || window.opera) ? true: false;
var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
var ie4 = (document.all && !dom) ? true : false;
var nodyn = (!ns5 && !ie4 && !ie5 && !dom) ? true : false;

var origWidth, origHeight;

// avoid error of passing event object in older browsers
if (nodyn) { event = "nope" }

/////////////////////// CUSTOMIZE HERE ////////////////////
// settings for tooltip
// Do you want tip to move when mouse moves over link?
var tipFollowMouse= true;
// Be sure to set tipWidth wide enough for widest image
var tipWidth= 160;
var offX= 20; // how far from mouse to show tip
var offY= 12;
var tipFontFamily= "Verdana, arial, helvetica, sans-serif";
var tipFontSize= "8pt";
// set default text color and background color for tooltip here
// individual tooltips can have their own (set in messages arrays)
// but don't have to
var tipFontColor= "#000000";
var tipBgColor= "#DDECFF";
var tipBorderColor= "#000080";
var tipBorderWidth= 3;
var tipBorderStyle= "ridge";
var tipPadding= 4;

// tooltip content goes here (image, description, optional bgColor, optional textcolor)
var messages = new Array();
// multi-dimensional arrays containing:
// image and text for tooltip
// optional: bgColor and color to be sent to tooltip
messages[0] = new Array('images/dot-com-btn.png','Here is a red balloon on a white background',"#FFFFFF");
messages[1] = new Array('images/sm-duck.gif','Here is a duck on a light blue background.',"#DDECFF");
messages[2] = new Array('test.gif','Test description','black','white');

//////////////////// END OF CUSTOMIZATION AREA ///////////////////

// preload images that are to appear in tooltip
// from arrays above
if (document.images) {
var theImgs = new Array();
for (var i=0; i<messages.length; i++) {
theImgs[i] = new Image();
theImgs[i].src = messages[i][0];
}
}

// to layout image and text, 2-row table, image centered in top cell
// these go in var tip in doTooltip function
// startStr goes before image, midStr goes between image and text
var startStr = '<table width="' + tipWidth + '"><tr><td align="center" width="100%"><img src="';
var midStr = '" border="0"></td></tr><tr><td valign="top">';
var endStr = '</td></tr></table>';

////////////////////////////////////////////////////////////
// initTip - initialization for tooltip.
// Global variables for tooltip.
// Set styles
// Set up mousemove capture if tipFollowMouse set true.
////////////////////////////////////////////////////////////
var tooltip, tipcss;
function initTip() {
if (nodyn) return;
tooltip = (ie4)? document.all['tipDiv']: (ie5||ns5)? document.getElementById('tipDiv'): null;
tipcss = tooltip.style;
if (ie4||ie5||ns5) { // ns4 would lose all this on rewrites
tipcss.width = tipWidth+"px";
tipcss.fontFamily = tipFontFamily;
tipcss.fontSize = tipFontSize;
tipcss.color = tipFontColor;
tipcss.backgroundColor = tipBgColor;
tipcss.borderColor = tipBorderColor;
tipcss.borderWidth = tipBorderWidth+"px";
tipcss.padding = tipPadding+"px";
tipcss.borderStyle = tipBorderStyle;
}
if (tooltip&&tipFollowMouse) {
document.onmousemove = trackMouse;
}
}

window.onload = initTip;

/////////////////////////////////////////////////
// doTooltip function
// Assembles content for tooltip and writes
// it to tipDiv
/////////////////////////////////////////////////
var t1,t2; // for setTimeouts
var tipOn = false; // check if over tooltip link
function doTooltip(evt,num) {
if (!tooltip) return;
if (t1) clearTimeout(t1); if (t2) clearTimeout(t2);
tipOn = true;
// set colors if included in messages array
if (messages[num][2]) var curBgColor = messages[num][2];
else curBgColor = tipBgColor;
if (messages[num][3]) var curFontColor = messages[num][3];
else curFontColor = tipFontColor;
if (ie4||ie5||ns5) {
var tip = startStr + messages[num][0] + midStr + '<span style="font-family:' + tipFontFamily + '; font-size:' + tipFontSize + '; color:' + curFontColor + ';">' + messages[num][1] + '</span>' + endStr;
tipcss.backgroundColor = curBgColor;
tooltip.innerHTML = tip;
if(typeof iepngfixtestspan != 'undefined' && /\.png$/i.test(messages[num][0]))
pngFixOnFly(tooltip.getElementsByTagName('img')[0]);
}
if (!tipFollowMouse) positionTip(evt);
else t1=setTimeout("tipcss.visibility='visible'",100);
}

function pngFixOnFly(el){
var i=new Image();
i.onload=function(){
var pDiv=document.createElement('div');
pDiv.style.height=i.height+'px';
pDiv.style.width=i.width+'px';
pDiv.style.display='inline-block';
pDiv.style.filter='progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod = "scale", src = "'+i.src+'")';
el.parentNode.replaceChild(pDiv, el);
}
i.src=el.src;
}

var mouseX, mouseY;
function trackMouse(evt) {
standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
mouseX = (ns5)? evt.pageX: window.event.clientX + standardbody.scrollLeft;
mouseY = (ns5)? evt.pageY: window.event.clientY + standardbody.scrollTop;
if (tipOn) positionTip(evt);
}

/////////////////////////////////////////////////////////////
// positionTip function
// If tipFollowMouse set false, so trackMouse function
// not being used, get position of mouseover event.
// Calculations use mouseover event position,
// offset amounts and tooltip width to position
// tooltip within window.
/////////////////////////////////////////////////////////////
function positionTip(evt) {
if (!tipFollowMouse) {
standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
mouseX = (ns5)? evt.pageX: window.event.clientX + standardbody.scrollLeft;
mouseY = (ns5)? evt.pageY: window.event.clientY + standardbody.scrollTop;
}
// tooltip width and height
var tpWd = (ie4||ie5)? tooltip.clientWidth: tooltip.offsetWidth;
var tpHt = (ie4||ie5)? tooltip.clientHeight: tooltip.offsetHeight;
// document area in view (subtract scrollbar width for ns)
var winWd = (ns5)? window.innerWidth-20+window.pageXOffset: standardbody.clientWidth+standardbody.scrollLeft;
var winHt = (ns5)? window.innerHeight-20+window.pageYOffset: standardbody.clientHeight+standardbody.scrollTop;
// check mouse position against tip and window dimensions
// and position the tooltip
if ((mouseX+offX+tpWd)>winWd)
tipcss.left = mouseX-(tpWd+offX)+"px";
else tipcss.left = mouseX+offX+"px";
if ((mouseY+offY+tpHt)>winHt)
tipcss.top = winHt-(tpHt+offY)+"px";
else tipcss.top = mouseY+offY+"px";
if (!tipFollowMouse) t1=setTimeout("tipcss.visibility='visible'",100);
}

function hideTip() {
if (!tooltip) return;
t2=setTimeout("tipcss.visibility='hidden'",100);
tipOn = false;
}

document.write('<div id="tipDiv" style="position:absolute; visibility:hidden; z-index:100"></div>')
document.write('<!--[if gte IE 5.5]><![if lte IE 6]><span style="display:none;" id="iepngfixtestspan"></span><![endif]><![endif]-->');
</script>

Plaidfox
05-14-2008, 04:18 PM
Well, I tried using your code by copying and pasting it over, and replacing all of the customization, but all it seemed to do is break the javascript (the tooltips didn't show up in any browser when tested.)

jscheuer1
05-14-2008, 06:39 PM
You either misunderstood, did something wrong, or both. The code tested out flawlessly here. You often can troubleshoot server generated code by using the browser's 'view source'. It at least shows what is being served.

If you want more help:

Please post a link to the page on your site that contains the problematic code so we can check it out.

Plaidfox
05-15-2008, 03:35 PM
Hmmm... well, something worked, because it's now working... sort of. I got the .png files to be transparent, but now they all have the same set height, which isn't a problem in any other browser. Any ideas? Here's the link:

http://www.kernandlead.com/~blueprin/index.php?option=com_content&view=article&id=11&Itemid=50

jscheuer1
05-15-2008, 05:20 PM
You haven't implemented the code from my post, so I have little idea what's happening. Here is what your tip division in IE 6 looks like:


<DIV id=tipDiv style="BORDER-RIGHT: #cccccc 0px solid; PADDING-RIGHT: 4px; BORDER-TOP: #cccccc 0px solid; PADDING-LEFT: 4px; FONT-SIZE: 8pt; Z-INDEX: 100; LEFT: 651px; VISIBILITY: hidden; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 0px solid; WIDTH: 352px; COLOR: #000000; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 0px solid; FONT-FAMILY: Verdana, arial, helvetica, sans-serif; POSITION: absolute; TOP: 418px">
<TABLE width=352>
<TBODY>
<TR>
<TD align=middle width="100%"><IMG style="FILTER: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://www.kernandlead.com/~blueprin/images/how/iformula.png',sizingMethod='scale'); WIDTH: 290px" src="blank.gif" border=0></TD></TR>
<TR>
<TD vAlign=top><SPAN style="FONT-SIZE: 8pt; COLOR: #000000; FONT-FAMILY: Verdana, arial, helvetica, sans-serif"></SPAN></TD></TR></TBODY></TABLE></DIV>

Notice the highlighted img tag here broken out a bit for easier viewing:


<IMG
style="FILTER: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://www.kernandlead.com/~blueprin/images/how/iformula.png',sizingMethod='scale'); WIDTH: 290px"
src="blank.gif"
border=0>

Now, I don't know how you made it. But at the very least it should have both the width and the height specified, and it should probably be a div element, not an img element.

I will poke around a bit more to see if I can discover what you are doing, but the code I supplied does work. You may have had a problem with it because you were also doing caused the above code at the same time. The two approaches will PROBABLY NOT work together.

jscheuer1
05-15-2008, 05:48 PM
I see now that you are using:

iepngfix.htc

and getting it to modyfy the tag for you. Where it has:


if (tagName == 'IMG')
{
if ((/\.png$/i).test(src))
{
if (currentStyle.width == 'auto' && currentStyle.height == 'auto')
style.width = offsetWidth + 'px';
filt(src, 'scale');
src = blankImg;
}
else if (src.indexOf(blankImg) < 0) filt();
}

It should be:


if (tagName == 'IMG')
{
if ((/\.png$/i).test(src))
{
if (currentStyle.width == 'auto' && currentStyle.height == 'auto'){
style.width = offsetWidth + 'px';
style.height = offsetHeight + 'px';
}
filt(src, 'scale');
src = blankImg;
}
else if (src.indexOf(blankImg) < 0) filt();
}

But this may or may not be good for other uses of iepngfix.htc on your site, if it isn't, you may be able to make a separate file, call it iepngfix2.htc and use it only for the:


#tipDiv img {
behavior: url(iepngfix2.htc);
}

selector in your stylesheet.

Once again, works here.