ckentq
9/10/2014 - 7:16 AM

gistfile1.coffee

function sliderHandler(){
        slider = $('#bxslider').bxSlider({
          pagerCustom: '#bx-pager'
          <?php if($i==1) echo ', autoStart:false'; if(!$i) echo ', pager:false'; ?>
          , onSlideNext:function(){
                console.log('next');
          }, onSlidePrev:function(){
                console.log('prev');
          }, onSlideBefore:function($slideElement, oldIndex, newIndex){
                changeRealThumb(thumbSlider,newIndex);
          }
        });
     
        var thumbSlider=$("#bx-pager ul").bxSlider({
            minSlides: 14,
            maxSlides: 14,
            slideWidth: 60,
            slideMargin: 3,
            moveSlides: 1,
            pager:false,
            speed:1000,
            infiniteLoop:false,
            hideControlOnEnd:true,
            nextText:'<span></span>',
            prevText:'<span></span>',
            onSlideBefore:function($slideElement, oldIndex, newIndex){
                    /*$j("#sliderThumbReal ul .active").removeClass("active");
                    $slideElement.addClass("active"); */

            }
        });
        linkRealSliders(slider,thumbSlider);
            
        if($("#bx-pager li").length<14){
            $("#bx-pager .bx-next").hide();
            $("#bx-pager .bx-prev").hide();
        }
    }

    // sincronizza sliders realizzazioni
    function linkRealSliders(bigS,thumbS){      
        $("#bx-pager ul").on("click","a",function(event){
            event.preventDefault();
            var newIndex=$(this).parent().attr("slideIndex");
            console.log('newIndex:', newIndex);
            bigS.goToSlide(newIndex);
        }); 
    }

    //slider!=$thumbSlider. slider is the realslider
    function changeRealThumb(slider,newIndex){       
        var $thumbS=$("#bx-pager");
        $thumbS.find('.active').removeClass("active");
        $thumbS.find('li[slideIndex="'+newIndex+'"]').addClass("active");  
        if(slider.getSlideCount()-newIndex>=14)slider.goToSlide(newIndex);
        else slider.goToSlide(slider.getSlideCount()-14);
    }
    sliderHandler();