Blame view

app/bower_components/bootstrap/js/carousel.js 6.97 KB
f986e111b   TRUONG   add libs
1
  /* ========================================================================
87c93a029   Dang YoungWorld   add modal
2
   * Bootstrap: carousel.js v3.3.7
f986e111b   TRUONG   add libs
3
4
   * http://getbootstrap.com/javascript/#carousel
   * ========================================================================
87c93a029   Dang YoungWorld   add modal
5
6
   * Copyright 2011-2016 Twitter, Inc.
   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
f986e111b   TRUONG   add libs
7
   * ======================================================================== */
87c93a029   Dang YoungWorld   add modal
8
9
  +function ($) {
    'use strict';
f986e111b   TRUONG   add libs
10
11
12
13
14
15
16
17
  
    // CAROUSEL CLASS DEFINITION
    // =========================
  
    var Carousel = function (element, options) {
      this.$element    = $(element)
      this.$indicators = this.$element.find('.carousel-indicators')
      this.options     = options
87c93a029   Dang YoungWorld   add modal
18
19
20
21
      this.paused      = null
      this.sliding     = null
      this.interval    = null
      this.$active     = null
f986e111b   TRUONG   add libs
22
      this.$items      = null
87c93a029   Dang YoungWorld   add modal
23
24
25
26
27
      this.options.keyboard && this.$element.on('keydown.bs.carousel', $.proxy(this.keydown, this))
  
      this.options.pause == 'hover' && !('ontouchstart' in document.documentElement) && this.$element
        .on('mouseenter.bs.carousel', $.proxy(this.pause, this))
        .on('mouseleave.bs.carousel', $.proxy(this.cycle, this))
f986e111b   TRUONG   add libs
28
    }
87c93a029   Dang YoungWorld   add modal
29
30
31
    Carousel.VERSION  = '3.3.7'
  
    Carousel.TRANSITION_DURATION = 600
f986e111b   TRUONG   add libs
32
    Carousel.DEFAULTS = {
87c93a029   Dang YoungWorld   add modal
33
34
35
36
      interval: 5000,
      pause: 'hover',
      wrap: true,
      keyboard: true
f986e111b   TRUONG   add libs
37
    }
87c93a029   Dang YoungWorld   add modal
38
39
40
41
42
43
44
45
46
47
48
49
    Carousel.prototype.keydown = function (e) {
      if (/input|textarea/i.test(e.target.tagName)) return
      switch (e.which) {
        case 37: this.prev(); break
        case 39: this.next(); break
        default: return
      }
  
      e.preventDefault()
    }
  
    Carousel.prototype.cycle = function (e) {
f986e111b   TRUONG   add libs
50
51
52
53
54
55
56
57
58
59
      e || (this.paused = false)
  
      this.interval && clearInterval(this.interval)
  
      this.options.interval
        && !this.paused
        && (this.interval = setInterval($.proxy(this.next, this), this.options.interval))
  
      return this
    }
87c93a029   Dang YoungWorld   add modal
60
61
62
63
    Carousel.prototype.getItemIndex = function (item) {
      this.$items = item.parent().children('.item')
      return this.$items.index(item || this.$active)
    }
f986e111b   TRUONG   add libs
64

87c93a029   Dang YoungWorld   add modal
65
66
67
68
69
70
71
72
    Carousel.prototype.getItemForDirection = function (direction, active) {
      var activeIndex = this.getItemIndex(active)
      var willWrap = (direction == 'prev' && activeIndex === 0)
                  || (direction == 'next' && activeIndex == (this.$items.length - 1))
      if (willWrap && !this.options.wrap) return active
      var delta = direction == 'prev' ? -1 : 1
      var itemIndex = (activeIndex + delta) % this.$items.length
      return this.$items.eq(itemIndex)
f986e111b   TRUONG   add libs
73
74
75
76
    }
  
    Carousel.prototype.to = function (pos) {
      var that        = this
87c93a029   Dang YoungWorld   add modal
77
      var activeIndex = this.getItemIndex(this.$active = this.$element.find('.item.active'))
f986e111b   TRUONG   add libs
78
79
  
      if (pos > (this.$items.length - 1) || pos < 0) return
87c93a029   Dang YoungWorld   add modal
80
      if (this.sliding)       return this.$element.one('slid.bs.carousel', function () { that.to(pos) }) // yes, "slid"
f986e111b   TRUONG   add libs
81
      if (activeIndex == pos) return this.pause().cycle()
87c93a029   Dang YoungWorld   add modal
82
      return this.slide(pos > activeIndex ? 'next' : 'prev', this.$items.eq(pos))
f986e111b   TRUONG   add libs
83
84
85
86
    }
  
    Carousel.prototype.pause = function (e) {
      e || (this.paused = true)
87c93a029   Dang YoungWorld   add modal
87
      if (this.$element.find('.next, .prev').length && $.support.transition) {
f986e111b   TRUONG   add libs
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
        this.$element.trigger($.support.transition.end)
        this.cycle(true)
      }
  
      this.interval = clearInterval(this.interval)
  
      return this
    }
  
    Carousel.prototype.next = function () {
      if (this.sliding) return
      return this.slide('next')
    }
  
    Carousel.prototype.prev = function () {
      if (this.sliding) return
      return this.slide('prev')
    }
  
    Carousel.prototype.slide = function (type, next) {
      var $active   = this.$element.find('.item.active')
87c93a029   Dang YoungWorld   add modal
109
      var $next     = next || this.getItemForDirection(type, $active)
f986e111b   TRUONG   add libs
110
111
      var isCycling = this.interval
      var direction = type == 'next' ? 'left' : 'right'
f986e111b   TRUONG   add libs
112
      var that      = this
87c93a029   Dang YoungWorld   add modal
113
114
115
116
117
118
119
120
121
      if ($next.hasClass('active')) return (this.sliding = false)
  
      var relatedTarget = $next[0]
      var slideEvent = $.Event('slide.bs.carousel', {
        relatedTarget: relatedTarget,
        direction: direction
      })
      this.$element.trigger(slideEvent)
      if (slideEvent.isDefaultPrevented()) return
f986e111b   TRUONG   add libs
122
123
124
125
  
      this.sliding = true
  
      isCycling && this.pause()
f986e111b   TRUONG   add libs
126
127
      if (this.$indicators.length) {
        this.$indicators.find('.active').removeClass('active')
87c93a029   Dang YoungWorld   add modal
128
129
        var $nextIndicator = $(this.$indicators.children()[this.getItemIndex($next)])
        $nextIndicator && $nextIndicator.addClass('active')
f986e111b   TRUONG   add libs
130
      }
87c93a029   Dang YoungWorld   add modal
131
      var slidEvent = $.Event('slid.bs.carousel', { relatedTarget: relatedTarget, direction: direction }) // yes, "slid"
f986e111b   TRUONG   add libs
132
      if ($.support.transition && this.$element.hasClass('slide')) {
f986e111b   TRUONG   add libs
133
134
135
136
137
        $next.addClass(type)
        $next[0].offsetWidth // force reflow
        $active.addClass(direction)
        $next.addClass(direction)
        $active
87c93a029   Dang YoungWorld   add modal
138
          .one('bsTransitionEnd', function () {
f986e111b   TRUONG   add libs
139
140
141
            $next.removeClass([type, direction].join(' ')).addClass('active')
            $active.removeClass(['active', direction].join(' '))
            that.sliding = false
87c93a029   Dang YoungWorld   add modal
142
143
144
            setTimeout(function () {
              that.$element.trigger(slidEvent)
            }, 0)
f986e111b   TRUONG   add libs
145
          })
87c93a029   Dang YoungWorld   add modal
146
          .emulateTransitionEnd(Carousel.TRANSITION_DURATION)
f986e111b   TRUONG   add libs
147
      } else {
f986e111b   TRUONG   add libs
148
149
150
        $active.removeClass('active')
        $next.addClass('active')
        this.sliding = false
87c93a029   Dang YoungWorld   add modal
151
        this.$element.trigger(slidEvent)
f986e111b   TRUONG   add libs
152
153
154
155
156
157
158
159
160
161
      }
  
      isCycling && this.cycle()
  
      return this
    }
  
  
    // CAROUSEL PLUGIN DEFINITION
    // ==========================
87c93a029   Dang YoungWorld   add modal
162
    function Plugin(option) {
f986e111b   TRUONG   add libs
163
164
165
166
167
168
169
170
171
172
173
174
      return this.each(function () {
        var $this   = $(this)
        var data    = $this.data('bs.carousel')
        var options = $.extend({}, Carousel.DEFAULTS, $this.data(), typeof option == 'object' && option)
        var action  = typeof option == 'string' ? option : options.slide
  
        if (!data) $this.data('bs.carousel', (data = new Carousel(this, options)))
        if (typeof option == 'number') data.to(option)
        else if (action) data[action]()
        else if (options.interval) data.pause().cycle()
      })
    }
87c93a029   Dang YoungWorld   add modal
175
176
177
    var old = $.fn.carousel
  
    $.fn.carousel             = Plugin
f986e111b   TRUONG   add libs
178
179
180
181
182
183
184
185
186
187
188
189
190
191
    $.fn.carousel.Constructor = Carousel
  
  
    // CAROUSEL NO CONFLICT
    // ====================
  
    $.fn.carousel.noConflict = function () {
      $.fn.carousel = old
      return this
    }
  
  
    // CAROUSEL DATA-API
    // =================
87c93a029   Dang YoungWorld   add modal
192
193
194
195
196
    var clickHandler = function (e) {
      var href
      var $this   = $(this)
      var $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) // strip for ie7
      if (!$target.hasClass('carousel')) return
f986e111b   TRUONG   add libs
197
198
199
      var options = $.extend({}, $target.data(), $this.data())
      var slideIndex = $this.attr('data-slide-to')
      if (slideIndex) options.interval = false
87c93a029   Dang YoungWorld   add modal
200
      Plugin.call($target, options)
f986e111b   TRUONG   add libs
201

87c93a029   Dang YoungWorld   add modal
202
      if (slideIndex) {
f986e111b   TRUONG   add libs
203
204
205
206
        $target.data('bs.carousel').to(slideIndex)
      }
  
      e.preventDefault()
87c93a029   Dang YoungWorld   add modal
207
208
209
210
211
    }
  
    $(document)
      .on('click.bs.carousel.data-api', '[data-slide]', clickHandler)
      .on('click.bs.carousel.data-api', '[data-slide-to]', clickHandler)
f986e111b   TRUONG   add libs
212
213
214
215
  
    $(window).on('load', function () {
      $('[data-ride="carousel"]').each(function () {
        var $carousel = $(this)
87c93a029   Dang YoungWorld   add modal
216
        Plugin.call($carousel, $carousel.data())
f986e111b   TRUONG   add libs
217
218
219
220
      })
    })
  
  }(jQuery);