With fancyBox 2, how do I avoid duplication of thumbnail helper images in a gallery on a page containing multiple links to multiple different images in that gallery?
Live example: http://publications.iodp.org/proceedings/349/101/349_101.html
See section "Introduction", first sentence, "Figures F1, F2" for sample links.
Assets: jQuery 1.8.3, Twitter Bootstrap 2.2.2, fancyBox 2.1.5
Sample link code:
<a class="fancybox-xtitle Link" rel="fancybox-xtitle" data-title-id="F1title" href="figures/01_F01.png">F1,</a> <a class="fancybox-xtitle Link" rel="fancybox-xtitle" data-title-id="F2title" href="figures/01_F02.png">F2</a>
Sample JavaScript:
$(".fancybox-xtitle")
.attr('rel', 'gallery')
.fancybox({
openEffect : 'none',
closeEffect : 'none',
prevEffect : 'none',
nextEffect : 'none',
closeBtn : false,
arrows : false,
padding : [15, 15, 55, 15],
minWidth : 300,
maxWidth : 1200,
helpers : {
thumbs : {
width : 50,
height : 50
},
title : {
type : 'inside',
position : 'top'
},
buttons : {},
},
beforeLoad: function() {
var el, id = $(this.element).data('title-id');
if (id) {
el = $('#' + id);
if (el.length) {
this.title = el.html();
}
}
}
});
I haven't seen this specific question answered anywhere, and I'm hoping the answer will be useful to anyone who wants to use fancyBox to create a gallery with multiple callouts on a page. I also checked the list of "Questions that may already have your answer" when authoring this question, and found no answer. Articles I have searched for solutions over the past three weeks: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
Background information:
The page may have from 1 to 500+ figures (images plus captions).
There are three ways in which figures are referenced on the page:
From text (e.g. "F1. First figure caption.") In the list of figures in the fixed navigation to the right—each figure is referenced once, rel="navfigures"; no thumbnail helper duplication problem.
From an image in a grey box () in the text following the first mention of a figure in text—again each figure is referenced once, rel="thumb"; no thumbnail helper duplication problem.
From text (e.g. "F1", "F14", etc.) in the text on the page, which may contain one or more links to any one of these images (e.g. Figure F1 may be called out in text from 1 to x times); thumbnail helper creates thumbnail for every referenced figure in the order they are called out.
The first two ways do not involve multiple references to any one figure and therefore do not cause duplication of thumbnails. The third way, however, does involve multiple references and therefore causes duplication. For example, a page containing text that calls out Figures F1, F2, F3, F3, F3, F1, F4, will result in a gallery where the thumbnail helper displays F1, F2, F3, F3, F3, F1, F4, instead of just F1, F2, F3, F4.
The figure captions are pulled from a hidden div containing the caption in HTML using a beforeLoad callback (per fancyBox documentation, Tips & Tricks, 2. Title - Use element instead of attribute).
Using the rel attribute to define a gallery works great as long as there is only one link to each image, as with the thumbnail figure images in text, and the list of figures in the side navigation. Using the rel attribute on links to figures in the main body of text results in extreme duplication of thumbnails.
Please note the following when answering: I have experience with HTML and CSS but not much with JavaScript and virtually none with jQuery; I am self-training as fast as possible.