bootstrap-alert.js 2.06 KB
Newer Older
Jacob Thornton's avatar
Jacob Thornton committed
1
/* ==========================================================
2
 * bootstrap-alert.js v2.0.0
Jacob Thornton's avatar
Jacob Thornton committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 * http://twitter.github.com/bootstrap/javascript.html#alerts
 * ==========================================================
 * Copyright 2011 Twitter, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ========================================================== */

20
21
22
23
24

!function( $ ){

  "use strict"

25
26
27
 /* ALERT CLASS DEFINITION
  * ====================== */

28
  var dismiss = '[data-dismiss="alert"]'
29
    , Alert = function ( el ) {
30
31
        $(el).delegate(dismiss, 'click', this.close)
      }
32
33
34

  Alert.prototype = {

35
36
37
    constructor: Alert

  , close: function ( e ) {
38
39
      var $element = $(this)

40
      $element = $element.hasClass('alert-message') ? $element : $element.parent()
41
42
      e && e.preventDefault()
      $element.removeClass('in')
43

44
      function removeElement() {
45
46
        $element.remove()
      }
47

48
      $.support.transition && $element.hasClass('fade') ?
49
        $element.bind($.support.transition.end, removeElement) :
50
        removeElement()
51
52
53
54
55
56
57
58
    }

  }


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

59
  $.fn.alert = function ( option ) {
60
61
    return this.each(function () {
      var $this = $(this)
62
63
        , data = $this.data('alert')
      if (!data) $this.data('alert', (data = new Alert(this)))
64
      if (typeof option == 'string') data[option].call($this)
65
66
67
    })
  }

68
69
70
71
72
  $.fn.alert.Alert = Alert


 /* ALERT DATA-API
  * ============== */
73

74
  $(function () {
75
    $('body').delegate(dismiss, 'click.alert.data-api', Alert.prototype.close)
76
77
  })

78
}( window.jQuery || window.ender )