Zen Cart Logo
Forums / All Other Contributions/Addons / JS Error in additional images with Lightbox and ImageHandler2

JS Error in additional images with Lightbox and ImageHandler2

Locked

Views: 2,005

Results 1 to 6 of 6
This thread is locked. New replies are disabled.
23 Oct 2007, 2:35 AM
#1
possum avatar

possum

New Zenner

Join Date:
Sep 2007
Posts:
58
Plugin Contributions:
0

JS Error in additional images with Lightbox and ImageHandler2

Hi,

Not sure exactly where this posts belongs, but it is about problems with additional images, so here goes.

I'm actually writing with both a problem and a solution ... first time I've actually provided anything useful on this forum :smartalec:. It's just not the greatest solution in the world and I'm hoping that a guru out there might be able to help.

I've had problems with additional images in which I always receive an error message saying:

missing ) after argument list in index.php line xxx

At first I thought the problem was something to do with Image Handler 2 so I raised this question in that forum. I know that edwinlloyd reported the same problem there.

Now I know that it's got nothing to do with IH2. Instead it seems to be in /includes/modules/additional_images.php. I've pasted the excerpt below.

// Link Preparation:
$script_link = '<script language="javascript" type="text/javascript"><!--' . "\n" . 'document.write(\'' . ($flag_display_large ? '<a href="javascript:popupWindow(\\\'' . $large_link . '\\\')">' . $thumb_slashes . '<br />' . TEXT_CLICK_TO_ENLARGE . '</a>' : $thumb_slashes) . '\');' . "\n" . '//--></script>';

$noscript_link = '<noscript>' . ($flag_display_large ? '<a href="' . zen_href_link(FILENAME_POPUP_IMAGE_ADDITIONAL, 'pID=' . $_GET['products_id'] . '&pic=' . $i . '&products_image_large_additional=' . $products_image_large) . '" target="_blank">' . $thumb_regular . '<br /><span class="imgLinkAdditional">' . TEXT_CLICK_TO_ENLARGE . '</span></a>' : $thumb_regular ) . '</noscript>';

//$alternate_link = '<a href="' . $products_image_large . '" onclick="javascript:popupWindow(\''. $large_link . '\') return false;" title="' . $products_name . '" target="_blank">' . $thumb_regular . '<br />' . TEXT_CLICK_TO_ENLARGE . '</a>';

$link = $script_link . "\n " . $noscript_link;
// $link = $alternate_link;

When I remove the comments in front of the $alternate_link, the additional images display. I don't understand the $script_link and $no_script_link enough to find out what the problem is. Can anyone help? Presumably there was a good reason for not using the "alternate" version in the first place, so I'd like to see the intended version working.

Thanks,

Possum.

23 Oct 2007, 5:52 AM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: JS Error in additional images with Lightbox and ImageHandler2

<script> tags are used to process the javascript popups. <noscript> tags are used to handle cases where javascript is disabled. The $alternate_link uses no javascript to do a popup, and instead opens a different browser session with all its headers and other junk.
24 Oct 2007, 12:13 PM
#3
possum avatar

possum

New Zenner

Join Date:
Sep 2007
Posts:
58
Plugin Contributions:
0

Re: JS Error in additional images with Lightbox and ImageHandler2

Thanks Doc,

Honoured to have you on the case!

I have experimented with enabling/disabling Javascript, as well as with the use of the alternate link and this is what I've found:

I get one "missing ) after argument list" for every additional image I have whenever I use Javascript. Without Javascript it works OK (although obviously without the niceties of the javascript). This happens independent of whether I have the Zen Lightbox functionality turned on or off. (It happened before I installed Lighbox as well).

Here's the code that is giving me grief:

if (ZEN_LIGHTBOX_STATUS == 'true') {
$script_link = '<script language="javascript" type="text/javascript"><!--' . "\n" . 'document.write(\'' . ($flag_display_large ? '<a href="' . zen_lightbox($products_image_large, addslashes($products_name), LARGE_IMAGE_WIDTH, LARGE_IMAGE_HEIGHT) . '" rel="lightbox[gallery]" title="' . addslashes($products_name) . '">' . $thumb_slashes . '<br />' . TEXT_CLICK_TO_ENLARGE . '</a>' : $thumb_slashes) . '\');' . "\n" . '//--></script>';
} else {
$script_link = '<script language="javascript" type="text/javascript"><!--' . "\n" . 'document.write(\'' . ($flag_display_large ? '<a href="javascript:popupWindow(\\\'' . $large_link . '\\\')">' . $thumb_slashes . '<br />' . TEXT_CLICK_TO_ENLARGE . '</a>' : $thumb_slashes) . '\');' . "\n" . '//--></script>';
}

and here's a link to the example where it's happening. (You can see the small dotted vertical lines separating where the images are supposed to be:

http://test.possumbooks.com/index.php?main_page=product_book_info&cPath=49&products_id=232

Finally, here's an excerpt from the resulting page source code that shows what the final script looked like:

<script language="javascript" type="text/javascript"><!--
document.write('<a href="javascript:popupWindow(\'http://test.possumbooks.com/index.php?main_page=popup_image_additional&pID=232&pic=0&products_image_large_additional=images/Illustrated Fairytales_01.jpg\')"><img src="bmz_cache/e/ef2387c104eb5dbe00217b48e5e57cd2.image.100x63.jpg" alt="Illustrated Fairy Tales" title=" Illustrated Fairy Tales " width="100" height="63" style="position:relative" onmouseover="showtrail('bmz_cache/d/d75abaa72c100a305044756fcc6d7193.image.180x113.jpg','Illustrated Fairy Tales',100,63,180,113,this,0,0,100,63);" onmouseout="hidetrail();"  /><br />larger image</a>');
//--></script>
      <noscript><a href="http://test.possumbooks.com/index.php?main_page=popup_image_additional&pID=232&pic=0&products_image_large_additional=images/Illustrated Fairytales_01.jpg" target="_blank"><img src="bmz_cache/e/ef2387c104eb5dbe00217b48e5e57cd2.image.100x63.jpg" alt="Illustrated Fairy Tales" title=" Illustrated Fairy Tales " width="100" height="63" style="position:relative" onmouseover="showtrail('bmz_cache/d/d75abaa72c100a305044756fcc6d7193.image.180x113.jpg','Illustrated Fairy Tales',100,63,180,113,this,0,0,100,63);" onmouseout="hidetrail();"  /><br /><span class="imgLinkAdditional">larger image</span></a></noscript></div></td>

Can you see any errors in there?

Really appreciate your thoughts on this one.

Possum.

24 Oct 2007, 2:31 PM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: JS Error in additional images with Lightbox and ImageHandler2

Your lightbox code in conjunction with Image Handler seem to not be escaping ' marks properly.

document.write('<a href="javascript:popupWindow(\'http://test.possumbooks.com/index.php?main_page=popup_image_additional&pID=232&pic=0&products_image_large_additional=images/Illustrated Fairytales_01.jpg\')"><img src="bmz_cache/e/ef2387c104eb5dbe00217b48e5e57cd2.image.100x63.jpg" alt="Illustrated Fairy Tales" title=" Illustrated Fairy Tales " width="100" height="63" style="position:relative" onmouseover="showtrail('bmz_cache/d/d75abaa72c100a305044756fcc6d7193.image.180x113.jpg','Illustrated Fairy Tales',100,63,180,113,this,0,0,100,63);" onmouseout="hidetrail();" /><br />larger image</a>');

The whole document.write line is inside single quotes, which means any use of single-quotes in the rest of the document.write command must be escaped.

ie: good escaping:

javascript:popupWindow([B]\'[/B]http://test.possumbo

ie: bad escaping:```
onmouseover="showtrail([B]'[/B]bmz_cache/d/d75abaa72c100a305044756fcc6d7193.image.180x113.jpg','Illustrated Fairy Tales',


One or both of those mods isn't doing everything correctly.
26 Oct 2007, 11:53 AM
#5
possum avatar

possum

New Zenner

Join Date:
Sep 2007
Posts:
58
Plugin Contributions:
0

Re: JS Error in additional images with Lightbox and ImageHandler2

Hi again,

Just thought I'd write back to say thanks to Dr Byte for his help and to let everyone know how this was resolved.

The problem was apparently in includes/classes/bmz_image_handler_class.php

Line 702 should read

 return $parameters . 'style="position:relative" onmouseover="showtrail(' . "\'$products_image_zoom\',\'$alt\',$width,$height,$zoomwidth,$zoomheight,this," . $this->zoom['startx'].','.$this->zoom['starty'].','.$this->zoom['width'].','.$this->zoom['height'].');" onmouseout="hidetrail();" ';

Note the extra backslashes around $products_image_zoom and $alt

Thanks again. The lightbox effect looks fab.

Possum.

3 Nov 2007, 4:56 AM
#6
possum avatar

possum

New Zenner

Join Date:
Sep 2007
Posts:
58
Plugin Contributions:
0

Re: JS Error in additional images with Lightbox and ImageHandler2

Hi,

Possum again. Just writing back to say ignore my previous message. The real solution is here ...

http://www.zen-cart.com/forum/showpost.php?p=340701&postcount=986

My solution meant that the additional images worked but it broke the hover-zoom effect. Jettrue's conditional solution works with both.

Possum