File indexing completed on 2024-12-22 05:33:16

0001 /* ==========================================================
0002  * bootstrap-carousel.js v2.0.4
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"; // jshint ;_;
0024 
0025 
0026  /* CAROUSEL CLASS DEFINITION
0027   * ========================= */
0028 
0029   var Carousel = function (element, options) {
0030     this.$element = $(element)
0031     this.options = options
0032     this.options.slide && this.slide(this.options.slide)
0033     this.options.pause == 'hover' && this.$element
0034       .on('mouseenter', $.proxy(this.pause, this))
0035       .on('mouseleave', $.proxy(this.cycle, this))
0036   }
0037 
0038   Carousel.prototype = {
0039 
0040     cycle: function (e) {
0041       if (!e) this.paused = false
0042       this.options.interval
0043         && !this.paused
0044         && (this.interval = setInterval($.proxy(this.next, this), this.options.interval))
0045       return this
0046     }
0047 
0048   , to: function (pos) {
0049       var $active = this.$element.find('.active')
0050         , children = $active.parent().children()
0051         , activePos = children.index($active)
0052         , that = this
0053 
0054       if (pos > (children.length - 1) || pos < 0) return
0055 
0056       if (this.sliding) {
0057         return this.$element.one('slid', function () {
0058           that.to(pos)
0059         })
0060       }
0061 
0062       if (activePos == pos) {
0063         return this.pause().cycle()
0064       }
0065 
0066       return this.slide(pos > activePos ? 'next' : 'prev', $(children[pos]))
0067     }
0068 
0069   , pause: function (e) {
0070       if (!e) this.paused = true
0071       clearInterval(this.interval)
0072       this.interval = null
0073       return this
0074     }
0075 
0076   , next: function () {
0077       if (this.sliding) return
0078       return this.slide('next')
0079     }
0080 
0081   , prev: function () {
0082       if (this.sliding) return
0083       return this.slide('prev')
0084     }
0085 
0086   , slide: function (type, next) {
0087       var $active = this.$element.find('.active')
0088         , $next = next || $active[type]()
0089         , isCycling = this.interval
0090         , direction = type == 'next' ? 'left' : 'right'
0091         , fallback  = type == 'next' ? 'first' : 'last'
0092         , that = this
0093         , e = $.Event('slide')
0094 
0095       this.sliding = true
0096 
0097       isCycling && this.pause()
0098 
0099       $next = $next.length ? $next : this.$element.find('.item')[fallback]()
0100 
0101       if ($next.hasClass('active')) return
0102 
0103       if ($.support.transition && this.$element.hasClass('slide')) {
0104         this.$element.trigger(e)
0105         if (e.isDefaultPrevented()) return
0106         $next.addClass(type)
0107         $next[0].offsetWidth // force reflow
0108         $active.addClass(direction)
0109         $next.addClass(direction)
0110         this.$element.one($.support.transition.end, function () {
0111           $next.removeClass([type, direction].join(' ')).addClass('active')
0112           $active.removeClass(['active', direction].join(' '))
0113           that.sliding = false
0114           setTimeout(function () { that.$element.trigger('slid') }, 0)
0115         })
0116       } else {
0117         this.$element.trigger(e)
0118         if (e.isDefaultPrevented()) return
0119         $active.removeClass('active')
0120         $next.addClass('active')
0121         this.sliding = false
0122         this.$element.trigger('slid')
0123       }
0124 
0125       isCycling && this.cycle()
0126 
0127       return this
0128     }
0129 
0130   }
0131 
0132 
0133  /* CAROUSEL PLUGIN DEFINITION
0134   * ========================== */
0135 
0136   $.fn.carousel = function (option) {
0137     return this.each(function () {
0138       var $this = $(this)
0139         , data = $this.data('carousel')
0140         , options = $.extend({}, $.fn.carousel.defaults, typeof option == 'object' && option)
0141       if (!data) $this.data('carousel', (data = new Carousel(this, options)))
0142       if (typeof option == 'number') data.to(option)
0143       else if (typeof option == 'string' || (option = options.slide)) data[option]()
0144       else if (options.interval) data.cycle()
0145     })
0146   }
0147 
0148   $.fn.carousel.defaults = {
0149     interval: 5000
0150   , pause: 'hover'
0151   }
0152 
0153   $.fn.carousel.Constructor = Carousel
0154 
0155 
0156  /* CAROUSEL DATA-API
0157   * ================= */
0158 
0159   $(function () {
0160     $('body').on('click.carousel.data-api', '[data-slide]', function ( e ) {
0161       var $this = $(this), href
0162         , $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
0163         , options = !$target.data('modal') && $.extend({}, $target.data(), $this.data())
0164       $target.carousel(options)
0165       e.preventDefault()
0166     })
0167   })
0168 
0169 }(window.jQuery);