Skip to content

Commit

Permalink
improve alert api - $("#fat").alert("close") should just work.
Browse files Browse the repository at this point in the history
  • Loading branch information
fat committed Nov 16, 2011
1 parent 0c7a80c commit a6f055e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bootstrap.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* http://www.apache.org/licenses/LICENSE-2.0
*
* Designed and built with all the love in the world @twitter by @mdo and @fat.
* Date: Sat Nov 5 17:07:48 PDT 2011
* Date: Sat Nov 12 20:22:29 PST 2011
*/
/* Reset.less
* 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).
Expand Down
13 changes: 11 additions & 2 deletions js/bootstrap-alerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
* ====================== */

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

close: function (e) {
var $element = $(this).parent('.alert-message')
var $element = $(this)
, className = 'alert-message'

$element = $element.hasClass(className) ? $element : $element.parent()

e && e.preventDefault()
$element.removeClass('in')
Expand Down Expand Up @@ -92,7 +96,12 @@
var $this = $(this)

if ( typeof options == 'string' ) {
return $this.data('alert')[options]()
var data = $this.data('alert')

if (typeof data == 'object') {
return data[options].call( $this )
}

}

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

0 comments on commit a6f055e

Please sign in to comment.