bootstrap-source/bootstrap-3.0.3/js/carousel.js
branchlanding-page-2014
changeset 78 b28d5c14c5c2
parent 54 0ded9d7748b7
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/bootstrap-source/bootstrap-3.0.3/js/carousel.js	Fri Jan 17 11:59:43 2014 +0100
     1.3 @@ -0,0 +1,217 @@
     1.4 +/* ========================================================================
     1.5 + * Bootstrap: carousel.js v3.0.3
     1.6 + * http://getbootstrap.com/javascript/#carousel
     1.7 + * ========================================================================
     1.8 + * Copyright 2013 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 ($) { "use strict";
    1.25 +
    1.26 +  // CAROUSEL CLASS DEFINITION
    1.27 +  // =========================
    1.28 +
    1.29 +  var Carousel = function (element, options) {
    1.30 +    this.$element    = $(element)
    1.31 +    this.$indicators = this.$element.find('.carousel-indicators')
    1.32 +    this.options     = options
    1.33 +    this.paused      =
    1.34 +    this.sliding     =
    1.35 +    this.interval    =
    1.36 +    this.$active     =
    1.37 +    this.$items      = null
    1.38 +
    1.39 +    this.options.pause == 'hover' && this.$element
    1.40 +      .on('mouseenter', $.proxy(this.pause, this))
    1.41 +      .on('mouseleave', $.proxy(this.cycle, this))
    1.42 +  }
    1.43 +
    1.44 +  Carousel.DEFAULTS = {
    1.45 +    interval: 5000
    1.46 +  , pause: 'hover'
    1.47 +  , wrap: true
    1.48 +  }
    1.49 +
    1.50 +  Carousel.prototype.cycle =  function (e) {
    1.51 +    e || (this.paused = false)
    1.52 +
    1.53 +    this.interval && clearInterval(this.interval)
    1.54 +
    1.55 +    this.options.interval
    1.56 +      && !this.paused
    1.57 +      && (this.interval = setInterval($.proxy(this.next, this), this.options.interval))
    1.58 +
    1.59 +    return this
    1.60 +  }
    1.61 +
    1.62 +  Carousel.prototype.getActiveIndex = function () {
    1.63 +    this.$active = this.$element.find('.item.active')
    1.64 +    this.$items  = this.$active.parent().children()
    1.65 +
    1.66 +    return this.$items.index(this.$active)
    1.67 +  }
    1.68 +
    1.69 +  Carousel.prototype.to = function (pos) {
    1.70 +    var that        = this
    1.71 +    var activeIndex = this.getActiveIndex()
    1.72 +
    1.73 +    if (pos > (this.$items.length - 1) || pos < 0) return
    1.74 +
    1.75 +    if (this.sliding)       return this.$element.one('slid.bs.carousel', function () { that.to(pos) })
    1.76 +    if (activeIndex == pos) return this.pause().cycle()
    1.77 +
    1.78 +    return this.slide(pos > activeIndex ? 'next' : 'prev', $(this.$items[pos]))
    1.79 +  }
    1.80 +
    1.81 +  Carousel.prototype.pause = function (e) {
    1.82 +    e || (this.paused = true)
    1.83 +
    1.84 +    if (this.$element.find('.next, .prev').length && $.support.transition.end) {
    1.85 +      this.$element.trigger($.support.transition.end)
    1.86 +      this.cycle(true)
    1.87 +    }
    1.88 +
    1.89 +    this.interval = clearInterval(this.interval)
    1.90 +
    1.91 +    return this
    1.92 +  }
    1.93 +
    1.94 +  Carousel.prototype.next = function () {
    1.95 +    if (this.sliding) return
    1.96 +    return this.slide('next')
    1.97 +  }
    1.98 +
    1.99 +  Carousel.prototype.prev = function () {
   1.100 +    if (this.sliding) return
   1.101 +    return this.slide('prev')
   1.102 +  }
   1.103 +
   1.104 +  Carousel.prototype.slide = function (type, next) {
   1.105 +    var $active   = this.$element.find('.item.active')
   1.106 +    var $next     = next || $active[type]()
   1.107 +    var isCycling = this.interval
   1.108 +    var direction = type == 'next' ? 'left' : 'right'
   1.109 +    var fallback  = type == 'next' ? 'first' : 'last'
   1.110 +    var that      = this
   1.111 +
   1.112 +    if (!$next.length) {
   1.113 +      if (!this.options.wrap) return
   1.114 +      $next = this.$element.find('.item')[fallback]()
   1.115 +    }
   1.116 +
   1.117 +    this.sliding = true
   1.118 +
   1.119 +    isCycling && this.pause()
   1.120 +
   1.121 +    var e = $.Event('slide.bs.carousel', { relatedTarget: $next[0], direction: direction })
   1.122 +
   1.123 +    if ($next.hasClass('active')) return
   1.124 +
   1.125 +    if (this.$indicators.length) {
   1.126 +      this.$indicators.find('.active').removeClass('active')
   1.127 +      this.$element.one('slid.bs.carousel', function () {
   1.128 +        var $nextIndicator = $(that.$indicators.children()[that.getActiveIndex()])
   1.129 +        $nextIndicator && $nextIndicator.addClass('active')
   1.130 +      })
   1.131 +    }
   1.132 +
   1.133 +    if ($.support.transition && this.$element.hasClass('slide')) {
   1.134 +      this.$element.trigger(e)
   1.135 +      if (e.isDefaultPrevented()) return
   1.136 +      $next.addClass(type)
   1.137 +      $next[0].offsetWidth // force reflow
   1.138 +      $active.addClass(direction)
   1.139 +      $next.addClass(direction)
   1.140 +      $active
   1.141 +        .one($.support.transition.end, function () {
   1.142 +          $next.removeClass([type, direction].join(' ')).addClass('active')
   1.143 +          $active.removeClass(['active', direction].join(' '))
   1.144 +          that.sliding = false
   1.145 +          setTimeout(function () { that.$element.trigger('slid.bs.carousel') }, 0)
   1.146 +        })
   1.147 +        .emulateTransitionEnd(600)
   1.148 +    } else {
   1.149 +      this.$element.trigger(e)
   1.150 +      if (e.isDefaultPrevented()) return
   1.151 +      $active.removeClass('active')
   1.152 +      $next.addClass('active')
   1.153 +      this.sliding = false
   1.154 +      this.$element.trigger('slid.bs.carousel')
   1.155 +    }
   1.156 +
   1.157 +    isCycling && this.cycle()
   1.158 +
   1.159 +    return this
   1.160 +  }
   1.161 +
   1.162 +
   1.163 +  // CAROUSEL PLUGIN DEFINITION
   1.164 +  // ==========================
   1.165 +
   1.166 +  var old = $.fn.carousel
   1.167 +
   1.168 +  $.fn.carousel = function (option) {
   1.169 +    return this.each(function () {
   1.170 +      var $this   = $(this)
   1.171 +      var data    = $this.data('bs.carousel')
   1.172 +      var options = $.extend({}, Carousel.DEFAULTS, $this.data(), typeof option == 'object' && option)
   1.173 +      var action  = typeof option == 'string' ? option : options.slide
   1.174 +
   1.175 +      if (!data) $this.data('bs.carousel', (data = new Carousel(this, options)))
   1.176 +      if (typeof option == 'number') data.to(option)
   1.177 +      else if (action) data[action]()
   1.178 +      else if (options.interval) data.pause().cycle()
   1.179 +    })
   1.180 +  }
   1.181 +
   1.182 +  $.fn.carousel.Constructor = Carousel
   1.183 +
   1.184 +
   1.185 +  // CAROUSEL NO CONFLICT
   1.186 +  // ====================
   1.187 +
   1.188 +  $.fn.carousel.noConflict = function () {
   1.189 +    $.fn.carousel = old
   1.190 +    return this
   1.191 +  }
   1.192 +
   1.193 +
   1.194 +  // CAROUSEL DATA-API
   1.195 +  // =================
   1.196 +
   1.197 +  $(document).on('click.bs.carousel.data-api', '[data-slide], [data-slide-to]', function (e) {
   1.198 +    var $this   = $(this), href
   1.199 +    var $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
   1.200 +    var options = $.extend({}, $target.data(), $this.data())
   1.201 +    var slideIndex = $this.attr('data-slide-to')
   1.202 +    if (slideIndex) options.interval = false
   1.203 +
   1.204 +    $target.carousel(options)
   1.205 +
   1.206 +    if (slideIndex = $this.attr('data-slide-to')) {
   1.207 +      $target.data('bs.carousel').to(slideIndex)
   1.208 +    }
   1.209 +
   1.210 +    e.preventDefault()
   1.211 +  })
   1.212 +
   1.213 +  $(window).on('load', function () {
   1.214 +    $('[data-ride="carousel"]').each(function () {
   1.215 +      var $carousel = $(this)
   1.216 +      $carousel.carousel($carousel.data())
   1.217 +    })
   1.218 +  })
   1.219 +
   1.220 +}(jQuery);
Impressum Datenschutzerklärung