js/bootstrap-carousel.js
changeset 0 ba8ab09f730e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/bootstrap-carousel.js	Fri Jul 04 16:42:41 2014 +0400
     1.3 @@ -0,0 +1,207 @@
     1.4 +/* ==========================================================
     1.5 + * bootstrap-carousel.js v2.3.1
     1.6 + * http://twitter.github.com/bootstrap/javascript.html#carousel
     1.7 + * ==========================================================
     1.8 + * Copyright 2012 Twitter, Inc.
     1.9 + *
    1.10 + * Licensed under the Apache License, Version 2.0 (the "License");
    1.11 + * you may not use this file except in compliance with the License.
    1.12 + * You may obtain a copy of the License at
    1.13 + *
    1.14 + * http://www.apache.org/licenses/LICENSE-2.0
    1.15 + *
    1.16 + * Unless required by applicable law or agreed to in writing, software
    1.17 + * distributed under the License is distributed on an "AS IS" BASIS,
    1.18 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.19 + * See the License for the specific language governing permissions and
    1.20 + * limitations under the License.
    1.21 + * ========================================================== */
    1.22 +
    1.23 +
    1.24 +!function ($) {
    1.25 +
    1.26 +  "use strict"; // jshint ;_;
    1.27 +
    1.28 +
    1.29 + /* CAROUSEL CLASS DEFINITION
    1.30 +  * ========================= */
    1.31 +
    1.32 +  var Carousel = function (element, options) {
    1.33 +    this.$element = $(element)
    1.34 +    this.$indicators = this.$element.find('.carousel-indicators')
    1.35 +    this.options = options
    1.36 +    this.options.pause == 'hover' && this.$element
    1.37 +      .on('mouseenter', $.proxy(this.pause, this))
    1.38 +      .on('mouseleave', $.proxy(this.cycle, this))
    1.39 +  }
    1.40 +
    1.41 +  Carousel.prototype = {
    1.42 +
    1.43 +    cycle: function (e) {
    1.44 +      if (!e) this.paused = false
    1.45 +      if (this.interval) clearInterval(this.interval);
    1.46 +      this.options.interval
    1.47 +        && !this.paused
    1.48 +        && (this.interval = setInterval($.proxy(this.next, this), this.options.interval))
    1.49 +      return this
    1.50 +    }
    1.51 +
    1.52 +  , getActiveIndex: function () {
    1.53 +      this.$active = this.$element.find('.item.active')
    1.54 +      this.$items = this.$active.parent().children()
    1.55 +      return this.$items.index(this.$active)
    1.56 +    }
    1.57 +
    1.58 +  , to: function (pos) {
    1.59 +      var activeIndex = this.getActiveIndex()
    1.60 +        , that = this
    1.61 +
    1.62 +      if (pos > (this.$items.length - 1) || pos < 0) return
    1.63 +
    1.64 +      if (this.sliding) {
    1.65 +        return this.$element.one('slid', function () {
    1.66 +          that.to(pos)
    1.67 +        })
    1.68 +      }
    1.69 +
    1.70 +      if (activeIndex == pos) {
    1.71 +        return this.pause().cycle()
    1.72 +      }
    1.73 +
    1.74 +      return this.slide(pos > activeIndex ? 'next' : 'prev', $(this.$items[pos]))
    1.75 +    }
    1.76 +
    1.77 +  , pause: function (e) {
    1.78 +      if (!e) this.paused = true
    1.79 +      if (this.$element.find('.next, .prev').length && $.support.transition.end) {
    1.80 +        this.$element.trigger($.support.transition.end)
    1.81 +        this.cycle(true)
    1.82 +      }
    1.83 +      clearInterval(this.interval)
    1.84 +      this.interval = null
    1.85 +      return this
    1.86 +    }
    1.87 +
    1.88 +  , next: function () {
    1.89 +      if (this.sliding) return
    1.90 +      return this.slide('next')
    1.91 +    }
    1.92 +
    1.93 +  , prev: function () {
    1.94 +      if (this.sliding) return
    1.95 +      return this.slide('prev')
    1.96 +    }
    1.97 +
    1.98 +  , slide: function (type, next) {
    1.99 +      var $active = this.$element.find('.item.active')
   1.100 +        , $next = next || $active[type]()
   1.101 +        , isCycling = this.interval
   1.102 +        , direction = type == 'next' ? 'left' : 'right'
   1.103 +        , fallback  = type == 'next' ? 'first' : 'last'
   1.104 +        , that = this
   1.105 +        , e
   1.106 +
   1.107 +      this.sliding = true
   1.108 +
   1.109 +      isCycling && this.pause()
   1.110 +
   1.111 +      $next = $next.length ? $next : this.$element.find('.item')[fallback]()
   1.112 +
   1.113 +      e = $.Event('slide', {
   1.114 +        relatedTarget: $next[0]
   1.115 +      , direction: direction
   1.116 +      })
   1.117 +
   1.118 +      if ($next.hasClass('active')) return
   1.119 +
   1.120 +      if (this.$indicators.length) {
   1.121 +        this.$indicators.find('.active').removeClass('active')
   1.122 +        this.$element.one('slid', function () {
   1.123 +          var $nextIndicator = $(that.$indicators.children()[that.getActiveIndex()])
   1.124 +          $nextIndicator && $nextIndicator.addClass('active')
   1.125 +        })
   1.126 +      }
   1.127 +
   1.128 +      if ($.support.transition && this.$element.hasClass('slide')) {
   1.129 +        this.$element.trigger(e)
   1.130 +        if (e.isDefaultPrevented()) return
   1.131 +        $next.addClass(type)
   1.132 +        $next[0].offsetWidth // force reflow
   1.133 +        $active.addClass(direction)
   1.134 +        $next.addClass(direction)
   1.135 +        this.$element.one($.support.transition.end, function () {
   1.136 +          $next.removeClass([type, direction].join(' ')).addClass('active')
   1.137 +          $active.removeClass(['active', direction].join(' '))
   1.138 +          that.sliding = false
   1.139 +          setTimeout(function () { that.$element.trigger('slid') }, 0)
   1.140 +        })
   1.141 +      } else {
   1.142 +        this.$element.trigger(e)
   1.143 +        if (e.isDefaultPrevented()) return
   1.144 +        $active.removeClass('active')
   1.145 +        $next.addClass('active')
   1.146 +        this.sliding = false
   1.147 +        this.$element.trigger('slid')
   1.148 +      }
   1.149 +
   1.150 +      isCycling && this.cycle()
   1.151 +
   1.152 +      return this
   1.153 +    }
   1.154 +
   1.155 +  }
   1.156 +
   1.157 +
   1.158 + /* CAROUSEL PLUGIN DEFINITION
   1.159 +  * ========================== */
   1.160 +
   1.161 +  var old = $.fn.carousel
   1.162 +
   1.163 +  $.fn.carousel = function (option) {
   1.164 +    return this.each(function () {
   1.165 +      var $this = $(this)
   1.166 +        , data = $this.data('carousel')
   1.167 +        , options = $.extend({}, $.fn.carousel.defaults, typeof option == 'object' && option)
   1.168 +        , action = typeof option == 'string' ? option : options.slide
   1.169 +      if (!data) $this.data('carousel', (data = new Carousel(this, options)))
   1.170 +      if (typeof option == 'number') data.to(option)
   1.171 +      else if (action) data[action]()
   1.172 +      else if (options.interval) data.pause().cycle()
   1.173 +    })
   1.174 +  }
   1.175 +
   1.176 +  $.fn.carousel.defaults = {
   1.177 +    interval: 5000
   1.178 +  , pause: 'hover'
   1.179 +  }
   1.180 +
   1.181 +  $.fn.carousel.Constructor = Carousel
   1.182 +
   1.183 +
   1.184 + /* CAROUSEL NO CONFLICT
   1.185 +  * ==================== */
   1.186 +
   1.187 +  $.fn.carousel.noConflict = function () {
   1.188 +    $.fn.carousel = old
   1.189 +    return this
   1.190 +  }
   1.191 +
   1.192 + /* CAROUSEL DATA-API
   1.193 +  * ================= */
   1.194 +
   1.195 +  $(document).on('click.carousel.data-api', '[data-slide], [data-slide-to]', function (e) {
   1.196 +    var $this = $(this), href
   1.197 +      , $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
   1.198 +      , options = $.extend({}, $target.data(), $this.data())
   1.199 +      , slideIndex
   1.200 +
   1.201 +    $target.carousel(options)
   1.202 +
   1.203 +    if (slideIndex = $this.attr('data-slide-to')) {
   1.204 +      $target.data('carousel').pause().to(slideIndex).cycle()
   1.205 +    }
   1.206 +
   1.207 +    e.preventDefault()
   1.208 +  })
   1.209 +
   1.210 +}(window.jQuery);
   1.211 \ No newline at end of file