[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/libraries/bootstrap/js/ -> bootstrap-carousel.js (source)

   1  /* ==========================================================
   2   * bootstrap-carousel.js v2.0.1
   3   * http://twitter.github.com/bootstrap/javascript.html#carousel
   4   * ==========================================================
   5   * Copyright 2012 Twitter, Inc.
   6   *
   7   * Licensed under the Apache License, Version 2.0 (the "License");
   8   * you may not use this file except in compliance with the License.
   9   * You may obtain a copy of the License at
  10   *
  11   * http://www.apache.org/licenses/LICENSE-2.0
  12   *
  13   * Unless required by applicable law or agreed to in writing, software
  14   * distributed under the License is distributed on an "AS IS" BASIS,
  15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16   * See the License for the specific language governing permissions and
  17   * limitations under the License.
  18   * ========================================================== */
  19  
  20  
  21  !function( $ ){
  22  
  23    "use strict"
  24  
  25   /* CAROUSEL CLASS DEFINITION
  26    * ========================= */
  27  
  28    var Carousel = function (element, options) {
  29      this.$element = $(element)
  30      this.options = $.extend({}, $.fn.carousel.defaults, options)
  31      this.options.slide && this.slide(this.options.slide)
  32    }
  33  
  34    Carousel.prototype = {
  35  
  36      cycle: function () {
  37        this.interval = setInterval($.proxy(this.next, this), this.options.interval)
  38        return this
  39      }
  40  
  41    , to: function (pos) {
  42        var $active = this.$element.find('.active')
  43          , children = $active.parent().children()
  44          , activePos = children.index($active)
  45          , that = this
  46  
  47        if (pos > (children.length - 1) || pos < 0) return
  48  
  49        if (this.sliding) {
  50          return this.$element.one('slid', function () {
  51            that.to(pos)
  52          })
  53        }
  54  
  55        if (activePos == pos) {
  56          return this.pause().cycle()
  57        }
  58  
  59        return this.slide(pos > activePos ? 'next' : 'prev', $(children[pos]))
  60      }
  61  
  62    , pause: function () {
  63        clearInterval(this.interval)
  64        this.interval = null
  65        return this
  66      }
  67  
  68    , next: function () {
  69        if (this.sliding) return
  70        return this.slide('next')
  71      }
  72  
  73    , prev: function () {
  74        if (this.sliding) return
  75        return this.slide('prev')
  76      }
  77  
  78    , slide: function (type, next) {
  79        var $active = this.$element.find('.active')
  80          , $next = next || $active[type]()
  81          , isCycling = this.interval
  82          , direction = type == 'next' ? 'left' : 'right'
  83          , fallback  = type == 'next' ? 'first' : 'last'
  84          , that = this
  85  
  86        if (!$next.length) return
  87  
  88        this.sliding = true
  89  
  90        isCycling && this.pause()
  91  
  92        $next = $next.length ? $next : this.$element.find('.item')[fallback]()
  93  
  94        if (!$.support.transition && this.$element.hasClass('slide')) {
  95          this.$element.trigger('slide')
  96          $active.removeClass('active')
  97          $next.addClass('active')
  98          this.sliding = false
  99          this.$element.trigger('slid')
 100        } else {
 101          $next.addClass(type)
 102          $next[0].offsetWidth // force reflow
 103          $active.addClass(direction)
 104          $next.addClass(direction)
 105          this.$element.trigger('slide')
 106          this.$element.one($.support.transition.end, function () {
 107            $next.removeClass([type, direction].join(' ')).addClass('active')
 108            $active.removeClass(['active', direction].join(' '))
 109            that.sliding = false
 110            setTimeout(function () { that.$element.trigger('slid') }, 0)
 111          })
 112        }
 113  
 114        isCycling && this.cycle()
 115  
 116        return this
 117      }
 118  
 119    }
 120  
 121  
 122   /* CAROUSEL PLUGIN DEFINITION
 123    * ========================== */
 124  
 125    $.fn.carousel = function ( option ) {
 126      return this.each(function () {
 127        var $this = $(this)
 128          , data = $this.data('carousel')
 129          , options = typeof option == 'object' && option
 130        if (!data) $this.data('carousel', (data = new Carousel(this, options)))
 131        if (typeof option == 'number') data.to(option)
 132        else if (typeof option == 'string' || (option = options.slide)) data[option]()
 133        else data.cycle()
 134      })
 135    }
 136  
 137    $.fn.carousel.defaults = {
 138      interval: 5000
 139    }
 140  
 141    $.fn.carousel.Constructor = Carousel
 142  
 143  
 144   /* CAROUSEL DATA-API
 145    * ================= */
 146  
 147    $(function () {
 148      $('body').on('click.carousel.data-api', '[data-slide]', function ( e ) {
 149        var $this = $(this), href
 150          , $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
 151          , options = !$target.data('modal') && $.extend({}, $target.data(), $this.data())
 152        $target.carousel(options)
 153        e.preventDefault()
 154      })
 155    })
 156  
 157  }( window.jQuery );


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1