Guest User

Bootstrap carousel play-pause buttons

a guest
Jun 29th, 2016
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*!
  2.  * Bootstrap v3.3.5 (http://getbootstrap.com)
  3.  * Copyright 2011-2016 Twitter, Inc.
  4.  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  5.  */
  6.  
  7. /*!
  8.  * Generated using the Bootstrap Customizer (http://getbootstrap.com/customize/?id=f1641f54eb280da6932c5bfa5cdfdb0f)
  9.  * Config saved to config.json and https://gist.github.com/f1641f54eb280da6932c5bfa5cdfdb0f
  10.  */
  11. if (typeof jQuery === 'undefined') {
  12.   throw new Error('Bootstrap\'s JavaScript requires jQuery')
  13. }
  14. +function ($) {
  15.   'use strict';
  16.   var version = $.fn.jquery.split(' ')[0].split('.')
  17.   if ((version[0] < 2 && version[1] < 9) || (version[0] == 1 && version[1] == 9 && version[2] < 1) || (version[0] > 2)) {
  18.     throw new Error('Bootstrap\'s JavaScript requires jQuery version 1.9.1 or higher, but lower than version 3')
  19.   }
  20. }(jQuery);
  21.  
  22. /* ========================================================================
  23.  * Bootstrap: carousel.js v3.3.6
  24.  * http://getbootstrap.com/javascript/#carousel
  25.  * ========================================================================
  26.  * Copyright 2011-2015 Twitter, Inc.
  27.  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  28.  * ======================================================================== */
  29.  
  30.  
  31. +function ($) {
  32.   'use strict';
  33.  
  34.   // CAROUSEL CLASS DEFINITION
  35.   // =========================
  36.  
  37.   var Carousel = function (element, options) {
  38.     this.$element    = $(element)
  39.     this.$indicators = this.$element.find('.carousel-indicators')
  40.     this.options     = options
  41.     this.paused      = null
  42.     this.sliding     = null
  43.     this.interval    = null
  44.     this.$active     = null
  45.     this.$items      = null
  46.  
  47.     this.options.keyboard && this.$element.on('keydown.bs.carousel', $.proxy(this.keydown, this))
  48.  
  49.     this.options.pause == 'hover' && !('ontouchstart' in document.documentElement) && this.$element
  50.       .on('mouseenter.bs.carousel', $.proxy(this.pause, this))
  51.       .on('mouseleave.bs.carousel', $.proxy(this.cycle, this))
  52.   }
  53.  
  54.   Carousel.VERSION  = '3.3.6'
  55.  
  56.   Carousel.TRANSITION_DURATION = 600
  57.  
  58.   Carousel.DEFAULTS = {
  59.     interval: 5000,
  60.     pause: 'hover',
  61.     wrap: true,
  62.     keyboard: true
  63.   }
  64.  
  65.   Carousel.prototype.keydown = function (e) {
  66.     if (/input|textarea/i.test(e.target.tagName)) return
  67.     switch (e.which) {
  68.       case 37: this.prev(); break
  69.       case 39: this.next(); break
  70.       default: return
  71.     }
  72.  
  73.     e.preventDefault()
  74.   }
  75.  
  76.   Carousel.prototype.cycle = function (e) {
  77.     e || (this.paused = false)
  78.  
  79.     this.interval && clearInterval(this.interval)
  80.  
  81.     this.options.interval
  82.       && !this.paused
  83.       && (this.interval = setInterval($.proxy(this.next, this), this.options.interval))
  84.  
  85.     return this
  86.   }
  87.  
  88.   Carousel.prototype.getItemIndex = function (item) {
  89.     this.$items = item.parent().children('.item')
  90.     return this.$items.index(item || this.$active)
  91.   }
  92.  
  93.   Carousel.prototype.getItemForDirection = function (direction, active) {
  94.     var activeIndex = this.getItemIndex(active)
  95.     var willWrap = (direction == 'prev' && activeIndex === 0)
  96.                 || (direction == 'next' && activeIndex == (this.$items.length - 1))
  97.     if (willWrap && !this.options.wrap) return active
  98.     var delta = direction == 'prev' ? -1 : 1
  99.     var itemIndex = (activeIndex + delta) % this.$items.length
  100.     return this.$items.eq(itemIndex)
  101.   }
  102.  
  103.   Carousel.prototype.to = function (pos) {
  104.     var that        = this
  105.     var activeIndex = this.getItemIndex(this.$active = this.$element.find('.item.active'))
  106.  
  107.     if (pos > (this.$items.length - 1) || pos < 0) return
  108.  
  109.     if (this.sliding)       return this.$element.one('slid.bs.carousel', function () { that.to(pos) }) // yes, "slid"
  110.     if (activeIndex == pos) return this.pause().cycle()
  111.  
  112.     return this.slide(pos > activeIndex ? 'next' : 'prev', this.$items.eq(pos))
  113.   }
  114.  
  115.   Carousel.prototype.pause = function (e) {
  116.     e || (this.paused = true)
  117.  
  118.     if (this.$element.find('.next, .prev').length && $.support.transition) {
  119.       this.$element.trigger($.support.transition.end)
  120.       this.cycle(true)
  121.     }
  122.  
  123.     this.interval = clearInterval(this.interval)
  124.  
  125.     return this
  126.   }
  127.  
  128.   Carousel.prototype.next = function () {
  129.     if (this.sliding) return
  130.     return this.slide('next')
  131.   }
  132.  
  133.   Carousel.prototype.prev = function () {
  134.     if (this.sliding) return
  135.     return this.slide('prev')
  136.   }
  137.  
  138.   Carousel.prototype.slide = function (type, next) {
  139.     var $active   = this.$element.find('.item.active')
  140.     var $next     = next || this.getItemForDirection(type, $active)
  141.     var isCycling = this.interval
  142.     var direction = type == 'next' ? 'left' : 'right'
  143.     var that      = this
  144.  
  145.     if ($next.hasClass('active')) return (this.sliding = false)
  146.  
  147.     var relatedTarget = $next[0]
  148.     var slideEvent = $.Event('slide.bs.carousel', {
  149.       relatedTarget: relatedTarget,
  150.       direction: direction
  151.     })
  152.     this.$element.trigger(slideEvent)
  153.     if (slideEvent.isDefaultPrevented()) return
  154.  
  155.     this.sliding = true
  156.  
  157.     isCycling && this.pause()
  158.  
  159.     if (this.$indicators.length) {
  160.       this.$indicators.find('.active').removeClass('active')
  161.       var $nextIndicator = $(this.$indicators.children()[this.getItemIndex($next)])
  162.       $nextIndicator && $nextIndicator.addClass('active')
  163.     }
  164.  
  165.     var slidEvent = $.Event('slid.bs.carousel', { relatedTarget: relatedTarget, direction: direction }) // yes, "slid"
  166.     if ($.support.transition && this.$element.hasClass('slide')) {
  167.       $next.addClass(type)
  168.       $next[0].offsetWidth // force reflow
  169.       $active.addClass(direction)
  170.       $next.addClass(direction)
  171.       $active
  172.         .one('bsTransitionEnd', function () {
  173.           $next.removeClass([type, direction].join(' ')).addClass('active')
  174.           $active.removeClass(['active', direction].join(' '))
  175.           that.sliding = false
  176.           setTimeout(function () {
  177.             that.$element.trigger(slidEvent)
  178.           }, 0)
  179.         })
  180.         .emulateTransitionEnd(Carousel.TRANSITION_DURATION)
  181.     } else {
  182.       $active.removeClass('active')
  183.       $next.addClass('active')
  184.       this.sliding = false
  185.       this.$element.trigger(slidEvent)
  186.     }
  187.  
  188.     isCycling && this.cycle()
  189.  
  190.     return this
  191.   }
  192.  
  193.  
  194.   // CAROUSEL PLUGIN DEFINITION
  195.   // ==========================
  196.  
  197.   function Plugin(option) {
  198.     return this.each(function () {
  199.       var $this   = $(this)
  200.       var data    = $this.data('bs.carousel')
  201.       var options = $.extend({}, Carousel.DEFAULTS, $this.data(), typeof option == 'object' && option)
  202.       var action  = typeof option == 'string' ? option : options.slide
  203.  
  204.       if (!data) $this.data('bs.carousel', (data = new Carousel(this, options)))
  205.       if (typeof option == 'number') data.to(option)
  206.       else if (action) data[action]()
  207.       else if (options.interval) data.pause().cycle()
  208.     })
  209.   }
  210.  
  211.   var old = $.fn.carousel
  212.  
  213.   $.fn.carousel             = Plugin
  214.   $.fn.carousel.Constructor = Carousel
  215.  
  216.  
  217.   // CAROUSEL NO CONFLICT
  218.   // ====================
  219.  
  220.   $.fn.carousel.noConflict = function () {
  221.     $.fn.carousel = old
  222.     return this
  223.   }
  224.  
  225.  
  226.   // CAROUSEL DATA-API
  227.   // =================
  228.  
  229.   var clickHandler = function (e) {
  230.     var href
  231.     var $this   = $(this)
  232.     var $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) // strip for ie7
  233.     if (!$target.hasClass('carousel')) return
  234.     var options = $.extend({}, $target.data(), $this.data())
  235.     var slideIndex = $this.attr('data-slide-to')
  236.     if (slideIndex) options.interval = false
  237.  
  238.     Plugin.call($target, options)
  239.  
  240.     if (slideIndex) {
  241.       $target.data('bs.carousel').to(slideIndex)
  242.     }
  243.  
  244.     e.preventDefault()
  245.   }
  246.  
  247.   $(document)
  248.     .on('click.bs.carousel.data-api', '[data-slide]', clickHandler)
  249.     .on('click.bs.carousel.data-api', '[data-slide-to]', clickHandler)
  250.  
  251.   $(window).on('load', function () {
  252.     $('[data-ride="carousel"]').each(function () {
  253.       var $carousel = $(this)
  254.       Plugin.call($carousel, $carousel.data())
  255.     })
  256.   })
  257.  
  258. }(jQuery);
  259.  
  260. /* ========================================================================
  261.  * Bootstrap: transition.js v3.3.6
  262.  * http://getbootstrap.com/javascript/#transitions
  263.  * ========================================================================
  264.  * Copyright 2011-2015 Twitter, Inc.
  265.  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  266.  * ======================================================================== */
  267.  
  268.  
  269. +function ($) {
  270.   'use strict';
  271.  
  272.   // CSS TRANSITION SUPPORT (Shoutout: http://www.modernizr.com/)
  273.   // ============================================================
  274.  
  275.   function transitionEnd() {
  276.     var el = document.createElement('bootstrap')
  277.  
  278.     var transEndEventNames = {
  279.       WebkitTransition : 'webkitTransitionEnd',
  280.       MozTransition    : 'transitionend',
  281.       OTransition      : 'oTransitionEnd otransitionend',
  282.       transition       : 'transitionend'
  283.     }
  284.  
  285.     for (var name in transEndEventNames) {
  286.       if (el.style[name] !== undefined) {
  287.         return { end: transEndEventNames[name] }
  288.       }
  289.     }
  290.  
  291.     return false // explicit for ie8 (  ._.)
  292.   }
  293.  
  294.   // http://blog.alexmaccaw.com/css-transitions
  295.   $.fn.emulateTransitionEnd = function (duration) {
  296.     var called = false
  297.     var $el = this
  298.     $(this).one('bsTransitionEnd', function () { called = true })
  299.     var callback = function () { if (!called) $($el).trigger($.support.transition.end) }
  300.     setTimeout(callback, duration)
  301.     return this
  302.   }
  303.  
  304.   $(function () {
  305.     $.support.transition = transitionEnd()
  306.  
  307.     if (!$.support.transition) return
  308.  
  309.     $.event.special.bsTransitionEnd = {
  310.       bindType: $.support.transition.end,
  311.       delegateType: $.support.transition.end,
  312.       handle: function (e) {
  313.         if ($(e.target).is(this)) return e.handleObj.handler.apply(this, arguments)
  314.       }
  315.     }
  316.   })
  317.  
  318. }(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment