From a6f055ee5e74e14ce28a5f3246d8132f680e63f5 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Wed, 16 Nov 2011 00:27:04 -0800 Subject: improve alert api - $("#fat").alert("close") should just work. --- js/bootstrap-alerts.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'js') diff --git a/js/bootstrap-alerts.js b/js/bootstrap-alerts.js index 37bb430aa..7c4b919f7 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 )) -- cgit v1.2.3