I am working on a flow where we are using Bootstrap styled accordion (NOT jQuery UI accordion). The requirement is to call a service when the user expands the accordion. Here's the HTML:
<div class="accordion-dashboard">
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading row-white" data-toggle="collapse" data-parent="#accordion" href="#runtimeValue">
<table>
<tr>
<td><span class="badge blue">A</span></td>
<td><strong>Aenean ultricies est lorem,id feugiat velit euismod ut.Nullam inia.Prasent vel nu Sed ante mauris, eu lacus..</strong></td>
<td><i class="icon8 icon-paperclip"></i></td>
<td><span class="time">5 mins</span></td>
</tr>
</table>
</div>
<div id="runtimeValue" class="panel-collapse collapse ">
<div class="panel-body">
<div class="row">
<div class="col-lg-9 col-lg-offset-1">
<table>
<tr>
<td class="text-muted">By</td>
<td><img width="24px" src="images/company-logo.png"> Company Admin</td>
</tr>
<tr>
<td class="text-muted">On</td>
<td class="text-muted">Friday- 7 Aug 2014, 9.00PM</td>
</tr>
<tr>
<td><i class="icon8 icon-paperclip"></i></td>
<td>dummyfile.pdf</td>
</tr>
<tr>
<td colspan="2">
<h5>Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid.</h5>
<p>Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.</p>
</td>
</tr>
</table>
</div>
<div class="col-lg-1 pull-right">
<span data-toggle="collapse" data-parent="#accordion" href="#collapseOne" class="btn-close icon8"></span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
HREF
attribute and the correspoding id
attributes will be decided at runtime and I am aware of the pattern of them. One approach could be binding an event on click of the accordion, but I want to have it as a last resort.
Is there any other way I can call a service when the user clicks and expands the accordion?
According to the Bootstrap source (admittedly for the most current version, 3.3.0), there should be a shown.bs.collapse
event emitted once the transition is complete. You can hook into that.
EDIT (July 2024): The event still exists in the source. You can see it emitted here and defined a few lines above, with the same name, so this event should still be safe to use.