closed.bs.alert fires before remove()
Created by: EnsignR
As mentioned in #10199 the event closed.bs.alert fires before elements are removed from the DOM.
I have made a jsfiddle to illustrate this here http://jsfiddle.net/ensignr/NFrFc/
- 3x div.alert are created in a div#cont
- event listener for 'close.bs.alert' and 'closed.bs.alert' attached to div.alert's
- the event listener counts the number of elements in #cont and reports them
- it's expected for the coupled close/closed events the count should be one less for closed. This is not the case.
- the count can also be checked by clicking the div.out, which shows the count is actually reduced if you click after closed event fires.
I believe the problem lies in Alert.removeElement() in /js/alert.js:45 Here remove() is called after the trigger() in the chain. The following change, where I detach() first, seem to fix things.
function removeElement() {
$parent.detach().trigger('closed.bs.alert')
}
I managed to quickly patch the 3.0.3 minified version bootrap.min.js which seems to work. You can see it here http://jsfiddle.net/ensignr/6VjPP/ (for as long as I keep the modified code hosted)
I've tried both the patched and non patched jsfiddles (as well as the project that lead me to discover this) in both Chrome 32.0.1700.76 and IE11 on Win7.
[Apols if I've missed/messed up the markup or something else, but I've had to join all the things to submit this bug report. It's been quite an effort :) ]