File indexing completed on 2024-05-19 06:00:15

0001 /* ==========================================================
0002  * bootstrap-carousel.js v2.0.1
0003  * http://twitter.github.com/bootstrap/javascript.html#carousel
0004  * ==========================================================
0005  * Copyright 2012 Twitter, Inc.
0006  *
0007  * Licensed under the Apache License, Version 2.0 (the "License");
0008  * you may not use this file except in compliance with the License.
0009  * You may obtain a copy of the License at
0010  *
0011  * http://www.apache.org/licenses/LICENSE-2.0
0012  *
0013  * Unless required by applicable law or agreed to in writing, software
0014  * distributed under the License is distributed on an "AS IS" BASIS,
0015  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0016  * See the License for the specific language governing permissions and
0017  * limitations under the License.
0018  * ========================================================== */
0019 
0020 
0021 !function( $ ){
0022 
0023   "use strict"
0024 
0025  /* CAROUSEL CLASS DEFINITION
0026   * ========================= */
0027 
0028   var Carousel = function (element, options) {
0029     this.$element = $(element)
0030     this.options = $.extend({}, $.fn.carousel.defaults, options)
0031     this.options.slide && this.slide(this.options.slide)
0032   }
0033 
0034   Carousel.prototype = {
0035 
0036     cycle: function () {
0037       this.interval = setInterval($.proxy(this.next, this), this.options.interval)
0038       return this
0039     }
0040 
0041   , to: function (pos) {
0042       var $active = this.$element.find('.active')
0043         , children = $active.parent().children()
0044         , activePos = children.index($active)
0045         , that = this
0046 
0047       if (pos > (children.length - 1) || pos < 0) return
0048 
0049       if (this.sliding) {
0050         return this.$element.one('slid', function () {
0051           that.to(pos)
0052         })
0053       }
0054 
0055       if (activePos == pos) {
0056         return this.pause().cycle()
0057       }
0058 
0059       return this.slide(pos > activePos ? 'next' : 'prev', $(children[pos]))
0060     }
0061 
0062   , pause: function () {
0063       clearInterval(this.interval)
0064       this.interval = null
0065       return this
0066     }
0067 
0068   , next: function () {
0069       if (this.sliding) return
0070       return this.slide('next')
0071     }
0072 
0073   , prev: function () {
0074       if (this.sliding) return
0075       return this.slide('prev')
0076     }
0077 
0078   , slide: function (type, next) {
0079       var $active = this.$element.find('.active')
0080         , $next = next || $active[type]()
0081         , isCycling = this.interval
0082         , direction = type == 'next' ? 'left' : 'right'
0083         , fallback  = type == 'next' ? 'first' : 'last'
0084         , that = this
0085 
0086       if (!$next.length) return
0087 
0088       this.sliding = true
0089 
0090       isCycling && this.pause()
0091 
0092       $next = $next.length ? $next : this.$element.find('.item')[fallback]()
0093 
0094       if (!$.support.transition && this.$element.hasClass('slide')) {
0095         this.$element.trigger('slide')
0096         $active.removeClass('active')
0097         $next.addClass('active')
0098         this.sliding = false
0099         this.$element.trigger('slid')
0100       } else {
0101         $next.addClass(type)
0102         $next[0].offsetWidth // force reflow
0103         $active.addClass(direction)
0104         $next.addClass(direction)
0105         this.$element.trigger('slide')
0106         this.$element.one($.support.transition.end, function () {
0107           $next.removeClass([type, direction].join(' ')).addClass('active')
0108           $active.removeClass(['active', direction].join(' '))
0109           that.sliding = false
0110           setTimeout(function () { that.$element.trigger('slid') }, 0)
0111         })
0112       }
0113 
0114       isCycling && this.cycle()
0115 
0116       return this
0117     }
0118 
0119   }
0120 
0121 
0122  /* CAROUSEL PLUGIN DEFINITION
0123   * ========================== */
0124 
0125   $.fn.carousel = function ( option ) {
0126     return this.each(function () {
0127       var $this = $(this)
0128         , data = $this.data('carousel')
0129         , options = typeof option == 'object' && option
0130       if (!data) $this.data('carousel', (data = new Carousel(this, options)))
0131       if (typeof option == 'number') data.to(option)
0132       else if (typeof option == 'string' || (option = options.slide)) data[option]()
0133       else data.cycle()
0134     })
0135   }
0136 
0137   $.fn.carousel.defaults = {
0138     interval: 5000
0139   }
0140 
0141   $.fn.carousel.Constructor = Carousel
0142 
0143 
0144  /* CAROUSEL DATA-API
0145   * ================= */
0146 
0147   $(function () {
0148     $('body').on('click.carousel.data-api', '[data-slide]', function ( e ) {
0149       var $this = $(this), href
0150         , $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
0151         , options = !$target.data('modal') && $.extend({}, $target.data(), $this.data())
0152       $target.carousel(options)
0153       e.preventDefault()
0154     })
0155   })
0156 
0157 }( window.jQuery );