blob: d17f44e150238fd403b3ff4e5f6e2753b821bf8f [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/* ==========================================================
2 * bootstrap-alert.js v2.0.2
3 * http://twitter.github.com/bootstrap/javascript.html#alerts
4 * ==========================================================
5 * Copyright 2012 Twitter, Inc.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ========================================================== */
19
20
21!function( $ ){
22
23 "use strict"
24
25 /* ALERT CLASS DEFINITION
26 * ====================== */
27
28 var dismiss = '[data-dismiss="alert"]'
29 , Alert = function ( el ) {
30 $(el).on('click', dismiss, this.close)
31 }
32
33 Alert.prototype = {
34
35 constructor: Alert
36
37 , close: function ( e ) {
38 var $this = $(this)
39 , selector = $this.attr('data-target')
40 , $parent
41
42 if (!selector) {
43 selector = $this.attr('href')
44 selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
45 }
46
47 $parent = $(selector)
48 $parent.trigger('close')
49
50 e && e.preventDefault()
51
52 $parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent())
53
54 $parent
55 .trigger('close')
56 .removeClass('in')
57
58 function removeElement() {
59 $parent
60 .trigger('closed')
61 .remove()
62 }
63
64 $.support.transition && $parent.hasClass('fade') ?
65 $parent.on($.support.transition.end, removeElement) :
66 removeElement()
67 }
68
69 }
70
71
72 /* ALERT PLUGIN DEFINITION
73 * ======================= */
74
75 $.fn.alert = function ( option ) {
76 return this.each(function () {
77 var $this = $(this)
78 , data = $this.data('alert')
79 if (!data) $this.data('alert', (data = new Alert(this)))
80 if (typeof option == 'string') data[option].call($this)
81 })
82 }
83
84 $.fn.alert.Constructor = Alert
85
86
87 /* ALERT DATA-API
88 * ============== */
89
90 $(function () {
91 $('body').on('click.alert.data-api', dismiss, Alert.prototype.close)
92 })
93
94}( window.jQuery );