joaoduarte Posted July 12, 2010 Posted July 12, 2010 Hi, I am trying intensively for about 3 days, and without much sleep :) to resolve this problem. I am using IMAGE WITH DESCRIPTION TOOLTIP (http://addons.oscommerce.com/info/4594) in my OSC product_listing.php file, but it won't work because my file is not the standard one, I am using product listing in a grid or columns layout, so the correct tip image doesn't show on all products, instead it repeats the same image across the columns. I will appreciate very much if someone can pointing me out what should I modify in product_listing.php code in order to work properly. I post here the product_listing.php code entirely. Sorry about my poor English. Thank you very much in advance :) product_listing.php code ------------------------------------------------------------------------------ <?php /* $Id: product_listing.php 1739 2007-12-20 00:52:16Z hpdl $ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright © 2003 osCommerce Released under the GNU General Public License */ define('PRODUCT_LIST_COLUMNS', 3); $listing_split = new splitPageResults($listing_sql, MAX_DISPLAY_SEARCH_RESULTS, 'p.products_id'); if ( ($listing_split->number_of_rows > 0) && ( (PREV_NEXT_BAR_LOCATION == '1') || (PREV_NEXT_BAR_LOCATION == '3') ) ) { ?> <table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr> <td class="smallText"><?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></td> <td class="smallText" align="right"><?php echo TEXT_RESULT_PAGE . ' ' . $listing_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></td> </tr> </table> <?php } if (tep_not_null($_GET['manufacturers_id'])) { $manufacturer_query = tep_db_query( "select manufacturers_name from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . tep_db_input($_GET['manufacturers_id']) . "';" ); $manufacturer = tep_db_fetch_array($manufacturer_query); $info_box_header = $manufacturer['manufacturers_name']; if (tep_not_null($_GET['filter_id'])) { $category_query = tep_db_query( "select cd.categories_name from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = '" . tep_db_input($_GET['filter_id']) . "' and cd.categories_id = '" . tep_db_input($_GET['filter_id']) . "' and cd.language_id = '" . (int)$languages_id . "'" ); $category = tep_db_fetch_array($category_query); $info_box_header .= ' > '. $category['categories_name']; } } if (tep_not_null($current_category_id)) { $category_query = tep_db_query( "select cd.categories_name from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = '" . (int)$current_category_id . "' and cd.categories_id = '" . (int)$current_category_id . "' and cd.language_id = '" . (int)$languages_id . "'" ); $category = tep_db_fetch_array($category_query); $info_box_header = $category['categories_name']; } $info_box_contents = array(); // $info_box_contents[] = array('text' => $info_box_header); // new contentBoxHeading($info_box_contents); $row = 0; $col = 0; $list_box_contents = array(); if ($listing_split->number_of_rows > 0) { $listing_query = tep_db_query($listing_split->sql_query); $cnt = 0; ?> <script language="javascript" type="text/javascript"> <!-- /* Image w/ description tooltip- By Dynamic Web Coding (www.dyn-web.com) Copyright 2002 by Sharon Paine Visit http://www.dynamicdrive.com for this script */ /* IMPORTANT: Put script after tooltip div or put tooltip div just before </BODY>. */ var dom = (document.getElementById) ? true : false; var ns5 = ((navigator.userAgent.indexOf("Gecko")>-1) && dom) ? true: false; var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false; var ns4 = (document.layers && !dom) ? true : false; var ie4 = (document.all && !dom) ? true : false; var nodyn = (!ns5 && !ns4 && !ie4 && !ie5) ? true : false; // resize fix for ns4 var origWidth, origHeight; if (ns4) { origWidth = window.innerWidth; origHeight = window.innerHeight; window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); } } // 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= 0; 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= ""; var tipBorderColor= ""; var tipBorderWidth= 0; var tipBorderStyle= "none"; var tipPadding= 0; // 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 <? $listing_query2 = tep_db_query($listing_split->sql_query); while ($listings = tep_db_fetch_array($listing_query2)) { $wer=explode('"',tep_image(DIR_WS_IMAGES . $listings['products_image'], $listings['products_name'])); ?> messages[<?=$cnt?>] = new Array('<?=$wer[1]?>','<?=addslashes($listings['products_name'])?>',"#FFFFFF"); <? $cnt++; } ?> //////////////////// 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 = new Image(); theImgs.src = messages[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="1"></td></tr><tr><td valign="top">'; var endStr = '</td></tr></table>'; //////////////////////////////////////////////////////////// // initTip - initialization for tooltip. // Global variables for tooltip. // Set styles for all but ns4. // Set up mousemove capture if tipFollowMouse set true. //////////////////////////////////////////////////////////// var tooltip, tipcss; function initTip() { if (nodyn) return; tooltip = (ns4)? document.tipDiv.document: (ie4)? document.all['tipDiv']: (ie5||ns5)? document.getElementById('tipDiv'): null; tipcss = (ns4)? document.tipDiv: 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) { if (ns4) document.captureEvents(Event.MOUSEMOVE); 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 (ns4) { var tip = '<table bgcolor="' + tipBorderColor + '" width="' + tipWidth + '" cellspacing="0" cellpadding="' + tipBorderWidth + '" border="0"><tr><td><table bgcolor="' + curBgColor + '" width="100%" cellspacing="0" cellpadding="' + tipPadding + '" border="0"><tr><td>'+ startStr + messages[num][0] + midStr + '<span style="font-family:' + tipFontFamily + '; font-size:' + tipFontSize + '; background:#FFFFFF; color:' + curFontColor + ';">' + messages[num][1] + '</span>' + endStr + '</td></tr></table></td></tr></table>'; tooltip.write(tip); tooltip.close(); } else if (ie4||ie5||ns5) { var tip = '<table bgcolor="0" bgcolor="#FFFFFF"><tr><td>' + startStr + messages[num][0] + midStr + '<span style="font-family:' + tipFontFamily + '; background:#000000; font-size:' + tipFontSize + '; color:#FFFFFF;">' + messages[num][1] + '</span>' + endStr + '</tr></td></table>'; tipcss.backgroundColor = curBgColor; tooltip.innerHTML = tip; } if (!tipFollowMouse) positionTip(evt); else t1=setTimeout("tipcss.visibility='visible'",100); } var mouseX, mouseY; function trackMouse(evt) { mouseX = (ns4||ns5)? evt.pageX: window.event.clientX + document.body.scrollLeft; mouseY = (ns4||ns5)? evt.pageY: window.event.clientY + document.body.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) { mouseX = (ns4||ns5)? evt.pageX: window.event.clientX + document.body.scrollLeft; mouseY = (ns4||ns5)? evt.pageY: window.event.clientY + document.body.scrollTop; } // tooltip width and height var tpWd = (ns4)? tooltip.width: (ie4||ie5)? tooltip.clientWidth: tooltip.offsetWidth; var tpHt = (ns4)? tooltip.height: (ie4||ie5)? tooltip.clientHeight: tooltip.offsetHeight; // document area in view (subtract scrollbar width for ns) var winWd = (ns4||ns5)? window.innerWidth-20+window.pageXOffset: document.body.clientWidth+document.body.scrollLeft; var winHt = (ns4||ns5)? window.innerHeight-20+window.pageYOffset: document.body.clientHeight+document.body.scrollTop; // check mouse position against tip and window dimensions // and position the tooltip if ((mouseX+offX+tpWd)>winWd) tipcss.left = (ns4)? mouseX-(tpWd+offX): mouseX-(tpWd+offX)+"px"; else tipcss.left = (ns4)? mouseX+offX: mouseX+offX+"px"; if ((mouseY+offY+tpHt)>winHt) tipcss.top = (ns4)? winHt-(tpHt+offY): winHt-(tpHt+offY)+"px"; else tipcss.top = (ns4)? mouseY+offY: mouseY+offY+"px"; if (!tipFollowMouse) t1=setTimeout("tipcss.visibility='visible'",100); } function hideTip() { if (!tooltip) return; t2=setTimeout("tipcss.visibility='hidden'",100); tipOn = false; } //--> </script> <? while ($listing = tep_db_fetch_array($listing_query)) { $lc_align = 'center'; $lc_text = '<table cellpadding="2" cellspacing="0" border="0">' . "\r\n"; foreach ($column_list as $column) { switch($column) { // Row: Products model case 'PRODUCT_LIST_MODEL': $lc_text .= ' <tr>' . "\r\n" . ' <td align="center"></td>' . "\r\n" . ' </tr>' . "\r\n"; break; // Row: Product's image case 'PRODUCT_LIST_IMAGE': $lc_text .= ' <tr>' . "\r\n" . ' <td align="center" height="170" valign="bottom"><div class="linephoto"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, (isset($_GET['manufacturers_id']) ? 'manufacturers_id=' . $_GET['manufacturers_id'] : ($cPath ? 'cPath=' . $cPath : '')) . '&products_id=' . $listing['products_id']) . '" onmouseover="doTooltip(event,'.($rows-1).')" onmouseout="hideTip()">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['Aproducts_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a></div></td>' . "\r\n" . ' </tr>' . "\r\n"; break; // Row: Product's name case 'PRODUCT_LIST_NAME': $lc_text .= ' <tr>' . "\r\n" . ' <td align="center" height="30" valign="top"><div class="TextHome"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, (isset($_GET['manufacturers_id']) ? 'manufacturers_id=' . $_GET['manufacturers_id'] : ($cPath ? 'cPath=' . $cPath : '')) . '&products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a><div></td>' . "\r\n" . ' </tr>' . "\r\n"; break; // Row: Manufacturer's name case 'PRODUCT_LIST_MANUFACTURER': $lc_text .= ' <tr>' . "\r\n" . ' <td align="center"></td>' . "\r\n" . ' </tr>' . "\r\n"; break; // Row: Price case 'PRODUCT_LIST_PRICE': if (tep_not_null($listing['specials_new_products_price'])) { $lc_text .= ' <tr>' . "\r\n" . ' <td align="center"></td>' . "\r\n" . ' </tr>' . "\r\n"; } else { $lc_text .= ' <tr>' . "\r\n" . ' <td align="center"></td>' . "\r\n" . ' </tr>' . "\r\n"; } break; // Row: Product's quantity case 'PRODUCT_LIST_QUANTITY': $lc_text .= ' <tr>' . "\r\n" . ' <td align="center"></td>' . "\r\n" . ' </tr>' . "\r\n"; break; // Row: Product's weight case 'PRODUCT_LIST_WEIGHT': $lc_text .= ' <tr>' . "\r\n" . ' <td align="center"></td>' . "\r\n" . ' </tr>' . "\r\n"; break; // Row: Buy now button case 'PRODUCT_LIST_BUY_NOW': $lc_text .= ' <tr>' . "\r\n" . ' <td align="center"></td>' . "\r\n" . ' </tr>' . "\r\n"; break; } } $lc_text .= '</table>' . "\r\n"; $list_box_contents[$row][$col] = array( 'align' => $lc_align, 'params' => 'width="'. round(100/PRODUCT_LIST_COLUMNS) .'%" class="productListing-data"', 'text' => $lc_text ); $col ++; if ($col > (PRODUCT_LIST_COLUMNS-1)) { $col = 0; $row ++; } } while ($col != 0 && sizeof($list_box_contents[$row]) < PRODUCT_LIST_COLUMNS) { $list_box_contents[$row][$col] = array( 'align' => 'center', 'params' => 'width="'. round(100/PRODUCT_LIST_COLUMNS) .'%"', 'text' => ' ' ); $col ++; } new productListingBox($list_box_contents); } else { $list_box_contents = array(); $list_box_contents[0] = array('params' => 'class="productListing-odd"'); $list_box_contents[0][] = array('params' => 'class="productListing-data"', 'text' => TEXT_NO_PRODUCTS); new productListingBox($list_box_contents); } if ( ($listing_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3')) ) { ?> <table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr> <td class="smallText"><?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></td> <td class="smallText" align="right"><?php echo TEXT_RESULT_PAGE . ' ' . $listing_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></td> </tr> </table> <?php } ?> <div id="tipDiv" style="position:absolute; visibility:hidden; z-index:100"></div> ------------------------------------------------------------------------------ Quote
joaoduarte Posted July 13, 2010 Author Posted July 13, 2010 I forgot to add, The relevant code I think its the Javascript and ..." onmouseover="doTooltip(event,'.($rows-1).')" onmouseout="hideTip() "... I already changed for " onmouseover="doTooltip(event,'.($col).')" onmouseout="hideTip() " but it won't work either. In this way it only shows the correct tooltip in the first horizontal row. In the second and third rows it repeats the same tooltip from the first row. I also would like to know if it is possible to add the following to this code and how? (is useful for reducing the original image): POPUP_IMAGE_WIDTH, POPUP_IMAGE_HEIGHT To: onmouseover="doTooltip(event,\'images/' .$listing['products_image'].'\')" Like this, but it won't work, maybe I am missing some ponctuation: onmouseover="doTooltip(event,\'images/' .$listing['products_image'], POPUP_IMAGE_WIDTH, POPUP_IMAGE_HEIGHT .'\')" Thanks Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.