Using Fancybox for photo thumbnails to view larger image

geek_girl posted 2nd of April 2013 in Community Voice. 8 comments.

Boonex added Fancybox jquery lightbox to the distribution but seems to only be using it for viewing the blog attached image thing.  What a waste.  However, with a bit of rewriting the code, we can use fancybox to view the larger image of a thumbnail.  We will maintain the link under the thumbnail so we can still visit the photo page to leave comments.

We need to load the fancybox js and css files.  We will do that in the header file, /templates/base/_header.html, or in the corresponding template in case the _header.html file is being rewritten by a template.

<script type="text/javascript" src="<bx_url_root />plugins/fancybox/jquery.fancybox.pack.js"></script>
<link rel="stylesheet" href="<bx_url_root />plugins/fancybox/jquery.fancybox.css" type="text/css" />

We also need to add our fancybox control to the _header.html as well.

    <script type="text/javascript" language="javascript">
$(document).on('click', '.single_image', function() {
  // remove the class to ensure this will only run once
  $(this).removeClass('single_image');
  // now attach fancybox and click to open it
  $(this).fancybox().click();
  // prevent default action
  return false;
});
</script>

In the fancybox control this only opens one image in a lightbox;  hopefully slideshows will be possible as well.

Now we need to make some changes to the BxBaseSearchResultSharedMedia.php file found in /templates/base/scripts

In the file find the function:

    function _getSharedThumb ($iId, $sFileLink, $sHash = '')
    {
        $sIdent = strlen($sHash) > 0 ? $sHash : $iId;
        $aUnit = array(
            'imgUrl' => $this->getImgUrl($sIdent),
            'fancyUrl' => str_replace("browse","file",$this->getImgUrl($sIdent)),
            'spacer' => getTemplateIcon('spacer.gif'),
            'fileLink' => $sFileLink,
            'bx_if:admin' => array(
                'condition' => $this->bAdminMode,
                'content' => array('id' => $iId)
            )
        );
        return $this->oModule->_oTemplate->parseHtmlByName('thumb.html', $aUnit);
    }

Add the bits in red; this will create our URL we need for the resized image stored when a photo is uploaded.

Now we need to make a change to the code that creates the thumbnail.  In /modules/boonex/photos/templates/base, find thumb.html.

<div class="sys_file_search_pic bx_photos_file_search_pic" style="background-image: url('__imgUrl__');">
    <bx_if:admin>
        <div class="bx_sys_unit_checkbox">
            <input type="checkbox" name="entry[]" value="__id__"/>
        </div>
    </bx_if:admin>
    <a class="single_image" href="__fancyUrl__"><img src="__spacer__"></a>
</div>

make the changes in red above.

Clear the caches and reload the page.  Now when you click on the thumnail image, you will open the resized imaged in a lightbox.  The URL under the thumbnail will take you to the image page.  This will also work on the album page.  For the album I also want to include a slideshow; that will be coming soon.

Note: there is a change to the fancybox attachment to work with the dynamically loaded browse boxes from my earlier post.  Currently this attachment will work to just load a single image.  I hope to have galleries/slideshows at a later time.

 

 
Recommended by
 
 
Comments
·Oldest
·Top
Please login to post a comment.
crack_foo
Didn't seem to make a difference for me... nothing gets popped up... hrmm
delmike
Hey,

Thx for the mod... that's exactly what I was looking for...
now, is it possible to apply this mod to members avatars so it loads avatar image in fancybox when clicking on the avatar and keep loading the profile when clicking on nicknames underneath each avatars??
geek_girl
I am not sure, have not looked at applying it to avatars. My next attempt will be to apply it to videos so they play in the popup without having to visit the video page.
moonsoon2u
how to make it work with the Outline... right now its only working with pictures in pictures module section
rocker
I know this is an old thread but looking for a way to zoom thumbnails and this code does absolutely nothing at all. It's like saying pour a cup of coffee add cream and sugar then your thunmbnails will zoom in. Not trying to be sarcastic, any helpful hints are appreciated but has anyone actually tested this code at all, besides me? Has anyone found a way to zoom thumnails yet?
geek_girl
Yes, it does work and it is implemented on my site. If you need assistance to get it to work let me know.
rocker
It'd be great if someone could integrate this http://jmar.github.io/jquery-hoverZoom/ into Dolphin software.
geek_girl
Personally I don't like things zooming at me unless I want them; better to give the use the control. You might hover over an image that you really don't want to zoom up and that can be annoying to the users. By clicking to zoom, they have control over which images they want to zoom. You could try posting a job and I might take it.
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.
PET:0.081412076950073