Created
          October 15, 2012 12:27 
        
      - 
      
- 
        Save iamnodev/3892204 to your computer and use it in GitHub Desktop. 
    Bootstrap carousel custom functions
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | (function( $ ) { | |
| /* | |
| * Carousel functions | |
| * extending bootstrap carousel | |
| * url: http://twitter.github.com/bootstrap/javascript.html#carousel | |
| */ | |
| $.fn.linkToCarousel = function( options ) { | |
| var settings = $.extend( { | |
| 'carousel' : 'div.carousel', // you'd better indicate an id if multiple carousel on the page | |
| 'slide' : 'div.item', | |
| }, options); | |
| return this.each( function () { | |
| var thumbnails = $(this).children(); | |
| var slides = [settings.carousel,settings.slide].join(' '); | |
| // clicking on a thumbnail will make the carousel slide | |
| thumbnails.click( function () { | |
| $(settings.carousel).carousel(thumbnails.siblings().andSelf().index( $(this) )) | |
| }); | |
| // after sliding, the new current slide's thumbnail will get the active class | |
| $(settings.carousel).bind('slid', function (event) { | |
| var index = $(slides).index($(slides+'.active')); | |
| thumbnails.removeClass('active'); | |
| thumbnails.eq(index).addClass('active'); | |
| }); | |
| }); | |
| }; | |
| // adds slide animation support to carousel to IE | |
| $.fn.addJQueryAnimate = function( options ) { | |
| return this.each( function () { | |
| $('#realisations-carousel').data().carousel.slide = function (type, next) { | |
| if(!$.support.transition && this.$element.hasClass('slide')) { | |
| this.$element.find('.item').stop(true, true); //Finish animation and jump to end. | |
| } | |
| var $active = this.$element.find('.active') | |
| , $next = next || $active[type]() | |
| , isCycling = this.interval | |
| , direction = type == 'next' ? 'left' : 'right' | |
| , fallback = type == 'next' ? 'first' : 'last' | |
| , that = this | |
| this.sliding = true | |
| isCycling && this.pause() | |
| $next = $next.length ? $next : this.$element.find('.item')[fallback]() | |
| if ($next.hasClass('active')) return | |
| if (!$.support.transition && this.$element.hasClass('slide')) { | |
| // this.$element.trigger(e) | |
| // if (e.isDefaultPrevented()) return | |
| $active.animate({left: (direction == 'right' ? '100%' : '-100%')}, 600, function(){ | |
| $active.removeClass('active') | |
| that.sliding = false | |
| setTimeout(function () { that.$element.trigger('slid') }, 0) | |
| }) | |
| $next.addClass(type).css({left: (direction == 'right' ? '-100%' : '100%')}).animate({left: '0'}, 600, function(){ | |
| $next.removeClass(type).addClass('active') | |
| }) | |
| } else if($.support.transition && this.$element.hasClass('slide')) { | |
| $next.addClass(type) | |
| $next[0].offsetWidth // force reflow | |
| $active.addClass(direction) | |
| $next.addClass(direction) | |
| this.$element.trigger('slide') | |
| this.$element.one($.support.transition.end, function () { | |
| $next.removeClass([type, direction].join(' ')).addClass('active') | |
| $active.removeClass(['active', direction].join(' ')) | |
| that.sliding = false | |
| setTimeout(function () { that.$element.trigger('slid') }, 0) | |
| }) | |
| } else { | |
| this.$element.trigger(e) | |
| if (e.isDefaultPrevented()) return | |
| $active.removeClass('active') | |
| $next.addClass('active') | |
| this.sliding = false | |
| this.$element.trigger('slid') | |
| } | |
| isCycling && this.cycle() | |
| return this | |
| } | |
| }); | |
| }; | |
| })( jQuery ); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment