Created
March 6, 2013 07:37
-
-
Save pal/5097447 to your computer and use it in GitHub Desktop.
bootstrap-carousel-slide.js with fix for IE
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
var extensionMethods = { | |
slide: function (type, next) { | |
var $active = this.$element.find('.item.active') | |
, $next = next || $active[type]() | |
, isCycling = this.interval | |
, direction = type == 'next' ? 'left' : 'right' | |
, fallback = type == 'next' ? 'first' : 'last' | |
, that = this | |
, e | |
this.sliding = true | |
isCycling && this.pause() | |
$next = $next.length ? $next : this.$element.find('.item')[fallback]() | |
e = $.Event('slide', { | |
relatedTarget: $next[0] | |
, direction: direction | |
}) | |
if ($next.hasClass('active')) return | |
if (this.$indicators.length) { | |
this.$indicators.find('.active').removeClass('active') | |
this.$element.one('slid', function () { | |
var $nextIndicator = $(that.$indicators.children()[that.getActiveIndex()]) | |
$nextIndicator && $nextIndicator.addClass('active') | |
}) | |
} | |
if ($.support.transition && this.$element.hasClass('slide')) { | |
this.$element.trigger(e) | |
if (e.isDefaultPrevented()) return | |
$next.addClass(type) | |
$next[0].offsetWidth // force reflow | |
$active.addClass(direction) | |
$next.addClass(direction) | |
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 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 { | |
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 | |
} | |
}; | |
$.extend(true, $[ "fn" ][ "carousel" ][ "Constructor" ].prototype, extensionMethods);// JavaScript Document |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment