This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/components/transition_helper.js.coffee
2013-02-07 16:45:24 +01:00

26 lines
728 B
CoffeeScript

# CSS transitions are a PITA, often we need to queue some js after a transition, this helper ensures
# it happens after the transition
#
# SO: http://stackoverflow.com/questions/9943435/css3-animation-end-techniques
dummy = document.createElement("div")
eventNameHash =
webkit: "webkitTransitionEnd"
Moz: "transitionend"
O: "oTransitionEnd"
ms: "MSTransitionEnd"
transitionEnd = (_getTransitionEndEventName = ->
retValue = "transitionend"
Object.keys(eventNameHash).some (vendor) ->
if vendor + "TransitionProperty" of dummy.style
retValue = eventNameHash[vendor]
true
retValue
)()
window.Discourse.TransitionHelper =
after: (element, callback) ->
$(element).on(transitionEnd, callback)