bootstrap-transition.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import jQuery from 'jquery';
  2. +(function($) {
  3. 'use strict';
  4. // CSS TRANSITION SUPPORT (Shoutout: http://www.modernizr.com/)
  5. // ============================================================
  6. function transitionEnd() {
  7. var el = document.createElement('bootstrap');
  8. var transEndEventNames = {
  9. WebkitTransition: 'webkitTransitionEnd',
  10. MozTransition: 'transitionend',
  11. OTransition: 'oTransitionEnd otransitionend',
  12. transition: 'transitionend'
  13. };
  14. for (var name in transEndEventNames) {
  15. if (el.style[name] !== undefined) {
  16. return { end: transEndEventNames[name] };
  17. }
  18. }
  19. return false; // explicit for ie8 ( ._.)
  20. }
  21. // http://blog.alexmaccaw.com/css-transitions
  22. $.fn.emulateTransitionEnd = function(duration) {
  23. var called = false;
  24. var $el = this;
  25. $(this).one('bsTransitionEnd', function() { called = true; });
  26. var callback = function() { if (!called) $($el).trigger($.support.transition.end); };
  27. setTimeout(callback, duration);
  28. return this;
  29. };
  30. $(function() {
  31. $.support.transition = transitionEnd();
  32. if (!$.support.transition) return;
  33. $.event.special.bsTransitionEnd = {
  34. bindType: $.support.transition.end,
  35. delegateType: $.support.transition.end,
  36. handle: function(e) {
  37. if ($(e.target).is(this)) return e.handleObj.handler.apply(this, arguments);
  38. }
  39. };
  40. });
  41. }(jQuery));