Skip to content

Commit a6f055e

Browse files
committed
improve alert api - $("#fat").alert("close") should just work.
1 parent 0c7a80c commit a6f055e

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

bootstrap.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* http://www.apache.org/licenses/LICENSE-2.0
77
*
88
* Designed and built with all the love in the world @twitter by @mdo and @fat.
9-
* Date: Sat Nov 5 17:07:48 PDT 2011
9+
* Date: Sat Nov 12 20:22:29 PST 2011
1010
*/
1111
/* Reset.less
1212
* Props to Eric Meyer (meyerweb.com) for his CSS reset file. We're using an adapted version here that cuts out some of the reset HTML elements we will never need here (i.e., dfn, samp, etc).

js/bootstrap-alerts.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
* ====================== */
5555

5656
var Alert = function ( content, options ) {
57+
if (options == 'close') return this.close.call(content)
5758
this.settings = $.extend({}, $.fn.alert.defaults, options)
5859
this.$element = $(content)
5960
.delegate(this.settings.selector, 'click', this.close)
@@ -62,7 +63,10 @@
6263
Alert.prototype = {
6364

6465
close: function (e) {
65-
var $element = $(this).parent('.alert-message')
66+
var $element = $(this)
67+
, className = 'alert-message'
68+
69+
$element = $element.hasClass(className) ? $element : $element.parent()
6670

6771
e && e.preventDefault()
6872
$element.removeClass('in')
@@ -92,7 +96,12 @@
9296
var $this = $(this)
9397

9498
if ( typeof options == 'string' ) {
95-
return $this.data('alert')[options]()
99+
var data = $this.data('alert')
100+
101+
if (typeof data == 'object') {
102+
return data[options].call( $this )
103+
}
104+
96105
}
97106

98107
$(this).data('alert', new Alert( this, options ))

0 commit comments

Comments
 (0)