transition.js 1.67 KB
Newer Older
1
/* ========================================================================
Mark Otto's avatar
Mark Otto committed
2
 * Bootstrap: transition.js v3.1.1
3
 * http://getbootstrap.com/javascript/#transitions
4
 * ========================================================================
5
 * Copyright 2011-2014 Twitter, Inc.
6
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
7
 * ======================================================================== */
8

9

Katie Zhu's avatar
Katie Zhu committed
10
11
12
13
14
(function (o_o) {
  typeof define  === 'function' && define.amd ? define(['jquery'], o_o) :
  typeof exports === 'object' ? o_o(require('jquery')) : o_o(this.jQuery)
})(function ($) {

Zlatan Vasović's avatar
Zlatan Vasović committed
15
  'use strict';
16

fat's avatar
fat committed
17
18
  // CSS TRANSITION SUPPORT (Shoutout: http://www.modernizr.com/)
  // ============================================================
19

fat's avatar
fat committed
20
  function transitionEnd() {
fat's avatar
fat committed
21
    var el = document.createElement('bootstrap')
22

fat's avatar
fat committed
23
    var transEndEventNames = {
XhmikosR's avatar
XhmikosR committed
24
25
26
27
      WebkitTransition : 'webkitTransitionEnd',
      MozTransition    : 'transitionend',
      OTransition      : 'oTransitionEnd otransitionend',
      transition       : 'transitionend'
fat's avatar
fat committed
28
    }
Jacob Thornton's avatar
Jacob Thornton committed
29

fat's avatar
fat committed
30
31
    for (var name in transEndEventNames) {
      if (el.style[name] !== undefined) {
fat's avatar
fat committed
32
        return { end: transEndEventNames[name] }
Jacob Thornton's avatar
Jacob Thornton committed
33
      }
fat's avatar
fat committed
34
    }
fat's avatar
fat committed
35
36

    return false // explicit for ie8 (  ._.)
fat's avatar
fat committed
37
  }
38

39
40
  // http://blog.alexmaccaw.com/css-transitions
  $.fn.emulateTransitionEnd = function (duration) {
XhmikosR's avatar
XhmikosR committed
41
42
    var called = false
    var $el = this
liuyl's avatar
liuyl committed
43
44
    $(this).one($.support.transition.end, function () { called = true })
    var callback = function () { if (!called) $($el).trigger($.support.transition.end) }
45
    setTimeout(callback, duration)
46
    return this
47
48
  }

fat's avatar
fat committed
49
  $(function () {
fat's avatar
fat committed
50
51
    $.support.transition = transitionEnd()
  })
52

Katie Zhu's avatar
Katie Zhu committed
53
});