aboutsummaryrefslogtreecommitdiff
path: root/js/bootstrap-alerts.js
diff options
context:
space:
mode:
authorJacob Thornton <[email protected]>2011-09-11 21:03:17 -0700
committerJacob Thornton <[email protected]>2011-09-11 21:03:17 -0700
commit200f5817ba7eb4c9ccafed3faad45b06ba89dfa7 (patch)
tree5ad41601586f7a96a74ae4d8979a755680febc24 /js/bootstrap-alerts.js
parente255b4f51dd690cbdcf75a1a7e93ddc5c07499f2 (diff)
downloadbootstrap-200f5817ba7eb4c9ccafed3faad45b06ba89dfa7.tar.xz
bootstrap-200f5817ba7eb4c9ccafed3faad45b06ba89dfa7.zip
method invocation jqueryui style
Diffstat (limited to 'js/bootstrap-alerts.js')
-rw-r--r--js/bootstrap-alerts.js41
1 files changed, 26 insertions, 15 deletions
diff --git a/js/bootstrap-alerts.js b/js/bootstrap-alerts.js
index dbce13466..9e8b30712 100644
--- a/js/bootstrap-alerts.js
+++ b/js/bootstrap-alerts.js
@@ -51,30 +51,25 @@
/* ALERT CLASS DEFINITION
* ====================== */
- var Alert = function ( content ) {
- var that = this
+ var Alert = function ( content, selector ) {
this.$element = $(content)
- .bind('alert:hide', $.proxy(this.close, this))
- .delegate('.close', 'click', function (e) {
- e.preventDefault()
- that.close()
- })
+ .delegate(selector || '.close', 'click', this.close)
}
Alert.prototype = {
- close: function () {
- var that = this
+ close: function (e) {
+ var $element = $(this).parent('.alert-message')
- this.$element.removeClass('in')
+ e && e.preventDefault()
+ $element.removeClass('in')
function removeElement () {
- that.$element.remove()
- that.$element = null
+ $element.remove()
}
- $.support.transition && this.$element.hasClass('fade') ?
- this.$element.bind(transitionEnd, removeElement) :
+ $.support.transition && $element.hasClass('fade') ?
+ $element.bind(transitionEnd, removeElement) :
removeElement()
}
@@ -85,9 +80,25 @@
* ======================= */
$.fn.alert = function ( options ) {
+
+ if ( options === true ) {
+ return this.data('alert')
+ }
+
return this.each(function () {
- new Alert(this)
+ var $this = $(this)
+
+ if ( typeof options == 'string' ) {
+ return $this.data('alert')[options]()
+ }
+
+ $(this).data('alert', new Alert( this ))
+
})
}
+ $(function () {
+ new Alert($('body'), '.alert-message[data-alert] .close')
+ })
+
})( jQuery || ender ) \ No newline at end of file