0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-01 13:24:25 +01:00

Merge pull request #842 from jonathaningram/patch-2

Add close and closed hooks for alert
This commit is contained in:
Jacob Thornton 2011-12-24 22:16:48 -08:00
commit a3822cfa84
2 changed files with 28 additions and 0 deletions

View File

@ -718,6 +718,30 @@ $('a[data-toggle="tab"]').on('shown', function (e) {
<h4>.alert('close')</h4> <h4>.alert('close')</h4>
<p>Closes an alert.</p> <p>Closes an alert.</p>
<pre class="prettyprint linenums">$(".alert-message").alert('close')</pre> <pre class="prettyprint linenums">$(".alert-message").alert('close')</pre>
<h3>Events</h3>
<p>Bootstrap's alert class exposes a few events for hooking into alert functionality. </p>
<table class="zebra-striped">
<thead>
<tr>
<th style="width: 150px;">Event</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>close</td>
<td>This event fires immediately when the <code>close</code> instance method is called.</td>
</tr>
<tr>
<td>closed</td>
<td>This event is fired when the alert has been closed (will wait for css transitions to complete).</td>
</tr>
</tbody>
</table>
<pre class="prettyprint linenums">
$('#my-alert').bind('closed', function () {
// do something ...
})</pre>
<h3>Demo</h3> <h3>Demo</h3>
<div class="alert-message warning fade in"> <div class="alert-message warning fade in">
<a class="close" data-dismiss="alert" href="#">&times;</a> <a class="close" data-dismiss="alert" href="#">&times;</a>

View File

@ -39,6 +39,8 @@
, selector = $this.attr('data-target') || $this.attr('href') , selector = $this.attr('data-target') || $this.attr('href')
, $parent = $(selector) , $parent = $(selector)
$parent.trigger('close')
e && e.preventDefault() e && e.preventDefault()
$parent.length || ($parent = $this.hasClass('alert-message') ? $this : $this.parent()) $parent.length || ($parent = $this.hasClass('alert-message') ? $this : $this.parent())
@ -47,6 +49,8 @@
function removeElement() { function removeElement() {
$parent.remove() $parent.remove()
$parent.trigger('closed')
} }
$.support.transition && $parent.hasClass('fade') ? $.support.transition && $parent.hasClass('fade') ?