Pikachoose / Fancybox Integration - lightbox navigation arrows

I am using Fancybox integration with Pikachoose as described here: http://www.pikachoose.com/how-to-fancybox/

I am trying to get the lightbox to display the next and previous arrows, but not at the pikachoose stage, and I'm having problems. I tried to add showNavArrows: true options to the fancybox script section, but it will not work. So, I tried the navigation options on pikachoose to display using this: {text: {previous: "Previous", next: "Next" }} but I keep getting the error, maybe my syntax is not right in the right place? Can anyone help?

this is the code i use:

 $(document).ready(function () { var a = function (self) { self.anchor.fancybox({ transitionIn: elastic, transitionOut: elastic, speedIn: 600, speedOut: 200, overlayShow: false }); }; $("#pikame").PikaChoose({ showCaption: false, buildFinished: a, autoPlay: false, transition: [0], speed: 500, showCaption: false }); }); 
+6
jquery navigation integration fancybox arrows
source share
2 answers

The problem with the method described at http://www.pikachoose.com/how-to-fancybox/ is that you bind fancybox to the current pikachoose self.anchor element.

With this approach, there is no way to find out which group of images will belong to the fancybox gallery (you will need more than one element sharing the same rel attribute), because there is only one pikachoose image: each image dynamically displays its href and src attributes ( <a> and <img> respectively) inside the .pika-stage container.

As a workaround, you will need to create a fancybox BEF group of elements linking your html structure to pikachoose (pikachoose will change the DOM structure)

one). So, having this html structure:

  <div class="pikachoose"> <ul id="pikame"> <li> <a title="one" href="image01.jpg" id="single_1"><img alt="" src="thumb01.jpg" /></a> </li> <li> <a title="two" href="image02.jpg" id="single_2"><img alt="" src="thumb02.jpg" /></a> </li> <li> <a title="three" href="image03.jpg" id="single_3"><img alt="" src="thumb03.jpg" /></a> </li> </ul> </div> 

2). Create a group of fancybox elements, iterating through each anchor using this script:

 var fancyGallery = []; // fancybox gallery group $(document).ready(function () { $("#pikame").find("a").each(function(i){ // buidl fancybox gallery group fancyGallery[i] = {"href" : this.href, "title" : this.title}; }); }); // ready 

3). Then bind pikachoose to the same #pikame selector. You can use the .end() method to do this on the first slow selector without duplicating it;)

 var fancyGallery = []; // fancybox gallery group $(document).ready(function () { // build fancybox group $("#pikame").find("a").each(function(i){ // buidl fancybox gallery fancyGallery[i] = {"href" : this.href, "title" : this.title}; }).end().PikaChoose({ autoPlay : false, // optional // bind fancybox to big images element after pikachoose is built buildFinished: fancy }); // PikaChoose }); // ready 

Note that we used the pikachoose buildFinished: fancy option, which will actually launch the fancybox gallery when we click on the large image.

4). Here is the function:

  var fancy = function (self) { // bind click event to big image self.anchor.on("click", function(e){ // find index of corresponding thumbnail var pikaindex = $("#pikame").find("li.active").index(); // open fancybox gallery starting from corresponding index $.fancybox(fancyGallery,{ // fancybox options "cyclic": true, // optional for fancybox v1.3.4 ONLY, use "loop" for v2.x "index": pikaindex // start with the corresponding thumb index }); return false; // prevent default and stop propagation }); // on click } 

Note that we linked the click event using the .on() (jQuery v1.7 + required) element of pikachoose self.anchor to launch the fancybox gallery using the manual $.fancybox([group]) method.

This workaround works equally well for fancybox v1.3.4 or v2.x. See DEMO using v1.3.4, which seems to work just fine even with IE7;)

+6
source share

JFK's answer is great, but there is something to fix:

if the carousel is included in Pikachoose, the calculated index using this method will give you invalid code, beakause pikachoose will manipulate the DOM by adding the existing li to ul :

 var pikaindex = $("#pikame").find("li.active").index(); 

Decision:

 function getCurrentIndex(fancyGallery) { var activeLi = $(""#pikame").find("li.active"); if (activeLi.length != 1) { console.error('(getCurrentIndex) - only one image must have an active class set by Pikachoose'); return -1; } var activeLiHtml0 = activeLi[0]; var activeHref = $(activeLiHtml0).find('img').attr('src'); // do not look for <a> tags, PikaChoose will remove them if (activeHref === null || activeHref.length == 0) { console.error('(getCurrentIndex) - can not get href attribute from selected image'); return -1; } for (var i=0 ; i<fancyGallery.length ;i++) { var obj = fancyGallery[i]; if (obj.href.indexOf(activeHref) >= 0){ console.debug('(getCurrentIndex) - found index: ' + i); return i; } } console.error('(getCurrentIndex) - this href: <' + activeHref + '> was not found in configured table'); return -1; }; 
0
source share

All Articles