Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

feat(transition): emulateTransitionEnd implementation (BLOCKS #934) #991

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/transition/test/transition.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ describe('$transition', function() {
expect(triggerFunction).toHaveBeenCalledWith(element);
});

// transitionend emulation
describe('emulateTransitionEnd', function() {
it('should emit transition end-event after the specified duration', function() {
var element = angular.element('<div></div>');
var transitionEndHandler = jasmine.createSpy('transitionEndHandler');

// There is no transition property, so transitionend could not be fired
// on its own.
var promise = $transition(element, {height: '100px'});
promise.then(transitionEndHandler);
promise.emulateTransitionEnd(1);

$timeout.flush();
expect(transitionEndHandler).toHaveBeenCalledWith(element);
});
});

// Versions of Internet Explorer before version 10 do not have CSS transitions
if ( !ie || ie > 9 ) {
describe('transitionEnd event', function() {
Expand Down
25 changes: 25 additions & 0 deletions src/transition/transition.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,31 @@ angular.module('ui.bootstrap.transition', [])
deferred.reject('Transition cancelled');
};

// Emulate transitionend event, useful when support is assumed to be
// available, but may not actually be used due to a transition property
// not being used in CSS (for example, in versions of firefox prior to 16,
// only -moz-transition is supported -- and is not used in Bootstrap3's CSS
// -- As such, no transitionend event would be fired due to no transition
// ever taking place. This method allows a fallback for such browsers.)
deferred.promise.emulateTransitionEnd = function(duration) {
var called = false;
deferred.promise.then(
function() { called = true; },
function() { called = true; }
);

var callback = function() {
if ( !called ) {
// If we got here, we probably aren't going to get a real
// transitionend event. Emit a dummy to the handler.
element.triggerHandler(endEventName);
}
};

$timeout(callback, duration);
return deferred.promise;
};

return deferred.promise;
};

Expand Down