bootstrap-alerts.js 1.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(function( $ ){

  /* CSS TRANSITION SUPPORT (https://gist.github.com/373874)
   * ======================================================= */

  $.support.transition = (function () {
    var thisBody = document.body || document.documentElement
      , thisStyle = thisBody.style
      , support = thisStyle.transition !== undefined || thisStyle.WebkitTransition !== undefined || thisStyle.MozTransition !== undefined || thisStyle.MsTransition !== undefined || thisStyle.OTransition !== undefined
    return support
  })()


 /* SHARED VARS
  * =========== */

   var transitionEnd

  // set CSS transition event type
  if ( $.support.transition ) {
    transitionEnd = "TransitionEnd"
    if ( $.browser.webkit ) {
    	transitionEnd = "webkitTransitionEnd"
    } else if ( $.browser.mozilla ) {
    	transitionEnd = "transitionend"
    } else if ( $.browser.opera ) {
    	transitionEnd = "oTransitionEnd"
    }
  }


 /* ALERT CLASS DEFINITION
  * ====================== */

  var Alert = function ( content ) {
    var that = this
    this.$element = $(content)
    this.$element.delegate('.close', 'click', function (e) {
      e.preventDefault()
      that.close()
    })
  }

  Alert.prototype = {

    close: function () {
      var that = this

      function removeElement () {
        that.$element.remove()
        that.$element = null
      }

54
      $.support.transition && this.$element.hasClass('fade') ?
55
56
57
        this.$element.bind(transitionEnd, removeElement) :
        removeElement()

58
      this.$element.removeClass('in')
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
    }

  }


 /* ALERT PLUGIN DEFINITION
  * ======================= */

  $.fn.alert = function ( options ) {
    return this.each(function () {
      new Alert(this)
    })
  }

})( jQuery || ender )