Advertisement
bpoole

Turn a gallery into a colorbox gallery gracefully

Aug 7th, 2012
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. use this function on gallery_container or whatever the class name is of your gallery's surrounding element to turn a gallery whose link does not go directly to the image as expected by colorbox
  3.  
  4. this effectively creates a colorbox for any set of images with only slight modifications made to the function if required
  5. */
  6.  
  7. init_colorbox( );
  8.  
  9. function init_colorbox( ){
  10.     $('.gallery_container img').unwrap('a');
  11.  
  12.     //replace the thumbnail indicator ('_t') + extension in an image with the file extension
  13.     // so that the image that is displayed in colorbox is the large image and not the thumbnail
  14.     //eg: foo_t.bar becomes foo.bar
  15.     $('.gallery_container img').each(function( ){
  16.         $(this).wrap('<a href="' + $(this).attr('src').replace(/_t\.(\w+)$/, '.$1') + '" rel="cb-gallery" />');
  17.     });
  18.  
  19.     $(".gallery_container a[rel='cb-gallery']").colorbox({maxHeight: '100%'});
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement