Posted by linksunten on May 13, 2009 at 3:39pm
| Project: | Lightbox2 |
| Version: | 6.x-1.9 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (won't fix) |
Issue Summary
We use Lightbox2 together with Image module version 6.x-1.0-alpha4. Lightbox2 replaces the links to the image nodes created by Image module with links to the image files. If we set the display size to "preview" the Lightbox2 creates links to the preview version of the image files. But Image module does only create preview versions if the original image size is bigger than the preview size. Lightbox2 works alright (some "magic detecting thing" seems to be integrated) but people tend to open images in new tabs which does not work if the preview image doesn't exist. A workaround is to set the display size to "original" which slows down the site enormously.
Comments
#1
#2
This is really important for us (and probably others, too) as it uses up a lot of our bandwidth and slows down the site enormously. Could someone please point us to the right code region, then we may try to solve it on our own.
#3
We created a patch which should fix the issue.
#4
We must admit: it's a bit trial and error but with this patch it works. Could someone please tell us if we broke something and it the patch fixes the problem for someone else, too?
#5
...
#6
Now this is not a trial and error patch, we really thought a lot about this module. We patched two files and this is what we did in detail:
After a node is loaded, all links to images (image module) are corrected, i.e. every infix display_image_size (e.g. ".preview") is deleted. This is done in auto_image_handling.js:
<?php// Change the link to images from display size to original size
// A click with the middle mouse button then opens the original image
if (settings.display_image_size != "") {
href = href.replace(new RegExp("."+settings.display_image_size), "");
}
?>
The function must be called again after the lightbox is closed which is done in end() in lightbox.js:
<?php// Call auto image handling again when lightbox is closed
lightbox2_image_nodes();
?>
We do not want lightbox to show the original size of the image so we have to have a mechanism to find out which image has a display_image_size and which has not. We simply load the display_image_size first by adding an infix (e.g. ".preview") to all image links:
<?php// Always try to load images in display size
// Else, imgNodeLoadingError() loads the images in original size
var s = Drupal.settings.lightbox2;
if (s.display_image_size !== "") {
var ii = anchor.href.lastIndexOf(".");
anchor.href = anchor.href.substr(0,ii+1) + s.display_image_size + anchor.href.substr(ii,anchor.href.length);
}
?>
If a display_image_size does not exist then the error handler imgNodeLoadingError() loads the original size:
<?phpif (s.display_image_size !== "") {
original_image = original_image.replace(new RegExp("."+s.display_image_size), "");
}
?>
We hope that someone tests our patches and that the patches afterwards are merged into the next release.
#7
Thats magic, many thanks... it's working for me... not fully tested, but I'm getting images now which I wasn't before... seems like a huge oversight that this occured at all.
Steve
#8
I can't reproduce this issue with the latest dev version of the module with image module 6.x-1.0-beta5. Can you check out the latest code and confirm whether or not the problem persists?
#9
No more info forthcoming