-
-
Notifications
You must be signed in to change notification settings - Fork 79k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bootstrap-collapse.js shouldn't rely only on transition end event #5462
Comments
Agreed - please open a pull request. thanks! |
Transition end event isn't reliable (browser may not fire it, or delay its firing until next transition, in many circumstances, read more in related issue twbs#5462 twbs#5462). In order to guarantee proper inner state of `Collapse` object (especially `Collapse#transitioning`, because its invalid state will block all successive transitions) additional callback invokation is added with `setTimeout()`. Timeout value for `setTimeout()` is equal to transition time from `component-animation.less` - I cannot find a better solution for now.
I recently ran into this issue as we have several applications that utilize both Prototype jQuery, and Bootstrap. For various reasons, it is not currently possible for us to completely remove the dependency on Prototype. We are using a web framework that uses Prototype. and have lots of legacy code that also uses Prototype. So, our goal was to coexist with the existing Prototype code, but not have to write any new Prototype code, even when interfacing with legacy client-side code. My solution was to create a "custom" event bridge that allows us to , from jQuery, trigger handlers that have been attached to elements using Prototype's "observe" function for "custom" event. The reverse is also, true, we are able to fire "custom" events using Prototype and hit any event handlers bound to the affected elements via jQuery. Note that a "custom" event is an event includes events with a name in the following format: "namespace:eventname". This is the only type of event you can fire using Prototype. As the creator of this issue pointed out, jQuery will invoke any function on an event target that matches the event type/name, provided I decided that I am not ever comfortable allowing jQuery to execute functions, contributed by Prototype to an element, that have the same name as a jQuery event type. The best way to prevent this is in the jQuery/Prototype event bridge I wrote. If we are handling a jQuery triggered event, and it is not a "custom" event, I remove the matching Prototype-contributed function from the event target if one exists before delegating to the jQuery trigger function. After jQuery's trigger function has executed, I re-attach the function to the element. If you are interested, you can see this drop-in at https://github.com/Widen/jquery-prototype-custom-event-bridge. I have written a full suite of QUnit tests that can be run by clicking on the URL near the top of the repo. I have also linked to the tests in the readme. |
Currently methods
Collapse#show()
,Collapse#hide()
,Collapse#transition()
rely only on transition end event, and will have broken inner state and stop work if such event wasn't fired for some reason:hide()
, which actually hides element, thus preventing transition (http://api.prototypejs.org/dom/Element/prototype/hide/).(for more info please read my answer to http://stackoverflow.com/questions/12715254/twitter-bootstrap-transition-conflict-prototypejs)
Invokation of callback
complete()
inCollapse#transition()
should be guaranteed even if transition event wasn't fired, e.g. viasetTimeout()
.The text was updated successfully, but these errors were encountered: