github.com/kayoticsully/syncthing@v0.8.9-0.20140724133906-c45a2fdc03f8/assets/bootstrap-3.1.1/js/carousel.js (about) 1 /* ======================================================================== 2 * Bootstrap: carousel.js v3.1.1 3 * http://getbootstrap.com/javascript/#carousel 4 * ======================================================================== 5 * Copyright 2011-2014 Twitter, Inc. 6 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) 7 * ======================================================================== */ 8 9 10 +function ($) { 11 'use strict'; 12 13 // CAROUSEL CLASS DEFINITION 14 // ========================= 15 16 var Carousel = function (element, options) { 17 this.$element = $(element) 18 this.$indicators = this.$element.find('.carousel-indicators') 19 this.options = options 20 this.paused = 21 this.sliding = 22 this.interval = 23 this.$active = 24 this.$items = null 25 26 this.options.pause == 'hover' && this.$element 27 .on('mouseenter', $.proxy(this.pause, this)) 28 .on('mouseleave', $.proxy(this.cycle, this)) 29 } 30 31 Carousel.DEFAULTS = { 32 interval: 5000, 33 pause: 'hover', 34 wrap: true 35 } 36 37 Carousel.prototype.cycle = function (e) { 38 e || (this.paused = false) 39 40 this.interval && clearInterval(this.interval) 41 42 this.options.interval 43 && !this.paused 44 && (this.interval = setInterval($.proxy(this.next, this), this.options.interval)) 45 46 return this 47 } 48 49 Carousel.prototype.getActiveIndex = function () { 50 this.$active = this.$element.find('.item.active') 51 this.$items = this.$active.parent().children() 52 53 return this.$items.index(this.$active) 54 } 55 56 Carousel.prototype.to = function (pos) { 57 var that = this 58 var activeIndex = this.getActiveIndex() 59 60 if (pos > (this.$items.length - 1) || pos < 0) return 61 62 if (this.sliding) return this.$element.one('slid.bs.carousel', function () { that.to(pos) }) 63 if (activeIndex == pos) return this.pause().cycle() 64 65 return this.slide(pos > activeIndex ? 'next' : 'prev', $(this.$items[pos])) 66 } 67 68 Carousel.prototype.pause = function (e) { 69 e || (this.paused = true) 70 71 if (this.$element.find('.next, .prev').length && $.support.transition) { 72 this.$element.trigger($.support.transition.end) 73 this.cycle(true) 74 } 75 76 this.interval = clearInterval(this.interval) 77 78 return this 79 } 80 81 Carousel.prototype.next = function () { 82 if (this.sliding) return 83 return this.slide('next') 84 } 85 86 Carousel.prototype.prev = function () { 87 if (this.sliding) return 88 return this.slide('prev') 89 } 90 91 Carousel.prototype.slide = function (type, next) { 92 var $active = this.$element.find('.item.active') 93 var $next = next || $active[type]() 94 var isCycling = this.interval 95 var direction = type == 'next' ? 'left' : 'right' 96 var fallback = type == 'next' ? 'first' : 'last' 97 var that = this 98 99 if (!$next.length) { 100 if (!this.options.wrap) return 101 $next = this.$element.find('.item')[fallback]() 102 } 103 104 if ($next.hasClass('active')) return this.sliding = false 105 106 var e = $.Event('slide.bs.carousel', { relatedTarget: $next[0], direction: direction }) 107 this.$element.trigger(e) 108 if (e.isDefaultPrevented()) return 109 110 this.sliding = true 111 112 isCycling && this.pause() 113 114 if (this.$indicators.length) { 115 this.$indicators.find('.active').removeClass('active') 116 this.$element.one('slid.bs.carousel', function () { 117 var $nextIndicator = $(that.$indicators.children()[that.getActiveIndex()]) 118 $nextIndicator && $nextIndicator.addClass('active') 119 }) 120 } 121 122 if ($.support.transition && this.$element.hasClass('slide')) { 123 $next.addClass(type) 124 $next[0].offsetWidth // force reflow 125 $active.addClass(direction) 126 $next.addClass(direction) 127 $active 128 .one($.support.transition.end, function () { 129 $next.removeClass([type, direction].join(' ')).addClass('active') 130 $active.removeClass(['active', direction].join(' ')) 131 that.sliding = false 132 setTimeout(function () { that.$element.trigger('slid.bs.carousel') }, 0) 133 }) 134 .emulateTransitionEnd($active.css('transition-duration').slice(0, -1) * 1000) 135 } else { 136 $active.removeClass('active') 137 $next.addClass('active') 138 this.sliding = false 139 this.$element.trigger('slid.bs.carousel') 140 } 141 142 isCycling && this.cycle() 143 144 return this 145 } 146 147 148 // CAROUSEL PLUGIN DEFINITION 149 // ========================== 150 151 var old = $.fn.carousel 152 153 $.fn.carousel = function (option) { 154 return this.each(function () { 155 var $this = $(this) 156 var data = $this.data('bs.carousel') 157 var options = $.extend({}, Carousel.DEFAULTS, $this.data(), typeof option == 'object' && option) 158 var action = typeof option == 'string' ? option : options.slide 159 160 if (!data) $this.data('bs.carousel', (data = new Carousel(this, options))) 161 if (typeof option == 'number') data.to(option) 162 else if (action) data[action]() 163 else if (options.interval) data.pause().cycle() 164 }) 165 } 166 167 $.fn.carousel.Constructor = Carousel 168 169 170 // CAROUSEL NO CONFLICT 171 // ==================== 172 173 $.fn.carousel.noConflict = function () { 174 $.fn.carousel = old 175 return this 176 } 177 178 179 // CAROUSEL DATA-API 180 // ================= 181 182 $(document).on('click.bs.carousel.data-api', '[data-slide], [data-slide-to]', function (e) { 183 var $this = $(this), href 184 var $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 185 var options = $.extend({}, $target.data(), $this.data()) 186 var slideIndex = $this.attr('data-slide-to') 187 if (slideIndex) options.interval = false 188 189 $target.carousel(options) 190 191 if (slideIndex = $this.attr('data-slide-to')) { 192 $target.data('bs.carousel').to(slideIndex) 193 } 194 195 e.preventDefault() 196 }) 197 198 $(window).on('load', function () { 199 $('[data-ride="carousel"]').each(function () { 200 var $carousel = $(this) 201 $carousel.carousel($carousel.data()) 202 }) 203 }) 204 205 }(jQuery);