From a6f055ee5e74e14ce28a5f3246d8132f680e63f5 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Wed, 16 Nov 2011 00:27:04 -0800 Subject: [PATCH] improve alert api - $("#fat").alert("close") should just work. --- bootstrap.css | 2 +- js/bootstrap-alerts.js | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/bootstrap.css b/bootstrap.css index ac267a0284..91216cc32d 100644 --- a/bootstrap.css +++ b/bootstrap.css @@ -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). diff --git a/js/bootstrap-alerts.js b/js/bootstrap-alerts.js index 37bb430aa2..7c4b919f70 100644 --- a/js/bootstrap-alerts.js +++ b/js/bootstrap-alerts.js @@ -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) @@ -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') @@ -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 ))