info@54: /* ======================================================================== info@54: * Bootstrap: carousel.js v3.0.3 info@54: * http://getbootstrap.com/javascript/#carousel info@54: * ======================================================================== info@54: * Copyright 2013 Twitter, Inc. info@54: * info@54: * Licensed under the Apache License, Version 2.0 (the "License"); info@54: * you may not use this file except in compliance with the License. info@54: * You may obtain a copy of the License at info@54: * info@54: * http://www.apache.org/licenses/LICENSE-2.0 info@54: * info@54: * Unless required by applicable law or agreed to in writing, software info@54: * distributed under the License is distributed on an "AS IS" BASIS, info@54: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. info@54: * See the License for the specific language governing permissions and info@54: * limitations under the License. info@54: * ======================================================================== */ info@54: info@54: info@54: +function ($) { "use strict"; info@54: info@54: // CAROUSEL CLASS DEFINITION info@54: // ========================= info@54: info@54: var Carousel = function (element, options) { info@54: this.$element = $(element) info@54: this.$indicators = this.$element.find('.carousel-indicators') info@54: this.options = options info@54: this.paused = info@54: this.sliding = info@54: this.interval = info@54: this.$active = info@54: this.$items = null info@54: info@54: this.options.pause == 'hover' && this.$element info@54: .on('mouseenter', $.proxy(this.pause, this)) info@54: .on('mouseleave', $.proxy(this.cycle, this)) info@54: } info@54: info@54: Carousel.DEFAULTS = { info@54: interval: 5000 info@54: , pause: 'hover' info@54: , wrap: true info@54: } info@54: info@54: Carousel.prototype.cycle = function (e) { info@54: e || (this.paused = false) info@54: info@54: this.interval && clearInterval(this.interval) info@54: info@54: this.options.interval info@54: && !this.paused info@54: && (this.interval = setInterval($.proxy(this.next, this), this.options.interval)) info@54: info@54: return this info@54: } info@54: info@54: Carousel.prototype.getActiveIndex = function () { info@54: this.$active = this.$element.find('.item.active') info@54: this.$items = this.$active.parent().children() info@54: info@54: return this.$items.index(this.$active) info@54: } info@54: info@54: Carousel.prototype.to = function (pos) { info@54: var that = this info@54: var activeIndex = this.getActiveIndex() info@54: info@54: if (pos > (this.$items.length - 1) || pos < 0) return info@54: info@54: if (this.sliding) return this.$element.one('slid.bs.carousel', function () { that.to(pos) }) info@54: if (activeIndex == pos) return this.pause().cycle() info@54: info@54: return this.slide(pos > activeIndex ? 'next' : 'prev', $(this.$items[pos])) info@54: } info@54: info@54: Carousel.prototype.pause = function (e) { info@54: e || (this.paused = true) info@54: info@54: if (this.$element.find('.next, .prev').length && $.support.transition.end) { info@54: this.$element.trigger($.support.transition.end) info@54: this.cycle(true) info@54: } info@54: info@54: this.interval = clearInterval(this.interval) info@54: info@54: return this info@54: } info@54: info@54: Carousel.prototype.next = function () { info@54: if (this.sliding) return info@54: return this.slide('next') info@54: } info@54: info@54: Carousel.prototype.prev = function () { info@54: if (this.sliding) return info@54: return this.slide('prev') info@54: } info@54: info@54: Carousel.prototype.slide = function (type, next) { info@54: var $active = this.$element.find('.item.active') info@54: var $next = next || $active[type]() info@54: var isCycling = this.interval info@54: var direction = type == 'next' ? 'left' : 'right' info@54: var fallback = type == 'next' ? 'first' : 'last' info@54: var that = this info@54: info@54: if (!$next.length) { info@54: if (!this.options.wrap) return info@54: $next = this.$element.find('.item')[fallback]() info@54: } info@54: info@54: this.sliding = true info@54: info@54: isCycling && this.pause() info@54: info@54: var e = $.Event('slide.bs.carousel', { relatedTarget: $next[0], direction: direction }) info@54: info@54: if ($next.hasClass('active')) return info@54: info@54: if (this.$indicators.length) { info@54: this.$indicators.find('.active').removeClass('active') info@54: this.$element.one('slid.bs.carousel', function () { info@54: var $nextIndicator = $(that.$indicators.children()[that.getActiveIndex()]) info@54: $nextIndicator && $nextIndicator.addClass('active') info@54: }) info@54: } info@54: info@54: if ($.support.transition && this.$element.hasClass('slide')) { info@54: this.$element.trigger(e) info@54: if (e.isDefaultPrevented()) return info@54: $next.addClass(type) info@54: $next[0].offsetWidth // force reflow info@54: $active.addClass(direction) info@54: $next.addClass(direction) info@54: $active info@54: .one($.support.transition.end, function () { info@54: $next.removeClass([type, direction].join(' ')).addClass('active') info@54: $active.removeClass(['active', direction].join(' ')) info@54: that.sliding = false info@54: setTimeout(function () { that.$element.trigger('slid.bs.carousel') }, 0) info@54: }) info@54: .emulateTransitionEnd(600) info@54: } else { info@54: this.$element.trigger(e) info@54: if (e.isDefaultPrevented()) return info@54: $active.removeClass('active') info@54: $next.addClass('active') info@54: this.sliding = false info@54: this.$element.trigger('slid.bs.carousel') info@54: } info@54: info@54: isCycling && this.cycle() info@54: info@54: return this info@54: } info@54: info@54: info@54: // CAROUSEL PLUGIN DEFINITION info@54: // ========================== info@54: info@54: var old = $.fn.carousel info@54: info@54: $.fn.carousel = function (option) { info@54: return this.each(function () { info@54: var $this = $(this) info@54: var data = $this.data('bs.carousel') info@54: var options = $.extend({}, Carousel.DEFAULTS, $this.data(), typeof option == 'object' && option) info@54: var action = typeof option == 'string' ? option : options.slide info@54: info@54: if (!data) $this.data('bs.carousel', (data = new Carousel(this, options))) info@54: if (typeof option == 'number') data.to(option) info@54: else if (action) data[action]() info@54: else if (options.interval) data.pause().cycle() info@54: }) info@54: } info@54: info@54: $.fn.carousel.Constructor = Carousel info@54: info@54: info@54: // CAROUSEL NO CONFLICT info@54: // ==================== info@54: info@54: $.fn.carousel.noConflict = function () { info@54: $.fn.carousel = old info@54: return this info@54: } info@54: info@54: info@54: // CAROUSEL DATA-API info@54: // ================= info@54: info@54: $(document).on('click.bs.carousel.data-api', '[data-slide], [data-slide-to]', function (e) { info@54: var $this = $(this), href info@54: var $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 info@54: var options = $.extend({}, $target.data(), $this.data()) info@54: var slideIndex = $this.attr('data-slide-to') info@54: if (slideIndex) options.interval = false info@54: info@54: $target.carousel(options) info@54: info@54: if (slideIndex = $this.attr('data-slide-to')) { info@54: $target.data('bs.carousel').to(slideIndex) info@54: } info@54: info@54: e.preventDefault() info@54: }) info@54: info@54: $(window).on('load', function () { info@54: $('[data-ride="carousel"]').each(function () { info@54: var $carousel = $(this) info@54: $carousel.carousel($carousel.data()) info@54: }) info@54: }) info@54: info@54: }(jQuery);