Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit c53d4c9

Browse files
matskoIgorMinar
authored andcommitted
feat($animator): provide support for custom animation events
1 parent 24ed61c commit c53d4c9

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

src/ng/animator.js

+14
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,20 @@ var $AnimatorProvider = function() {
253253
* @param {jQuery/jqLite element} element the element that will be rendered visible or hidden
254254
*/
255255
animator.hide = animateActionFactory('hide', noop, hide);
256+
257+
/**
258+
* @ngdoc function
259+
* @name ng.animator#animate
260+
* @methodOf ng.$animator
261+
*
262+
* @description
263+
* Triggers a custom animation event to be executed on the given element
264+
*
265+
* @param {jQuery/jqLite element} element that will be animated
266+
*/
267+
animator.animate = function(event, element) {
268+
animateActionFactory(event, noop, noop)(element);
269+
}
256270
return animator;
257271

258272
function animateActionFactory(type, beforeFn, afterFn) {

test/ng/animatorSpec.js

+70
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,18 @@ describe("$animator", function() {
352352
expect(element.hasClass('animation-cancelled')).toBe(true);
353353
}));
354354

355+
356+
it("should properly animate custom animation events", inject(function($animator, $rootScope) {
357+
$animator.enabled(true);
358+
animator = $animator($rootScope, {
359+
ngAnimate : '{custom: \'setup-memo\'}'
360+
});
361+
362+
element.text('123');
363+
animator.animate('custom',element);
364+
window.setTimeout.expect(1).process();
365+
expect(element.text()).toBe('memento');
366+
}));
355367
});
356368

357369
describe("with CSS3", function() {
@@ -368,6 +380,64 @@ describe("$animator", function() {
368380
})
369381
});
370382

383+
it("should properly animate custom animations for specific animation events",
384+
inject(function($animator, $rootScope, $compile, $sniffer) {
385+
386+
$animator.enabled(true);
387+
var element = $compile(html('<div></div>'))($rootScope);
388+
389+
animator = $animator($rootScope, {
390+
ngAnimate : '{custom: \'special\'}'
391+
});
392+
393+
animator.animate('custom',element);
394+
if($sniffer.transitions) {
395+
expect(element.hasClass('special')).toBe(true);
396+
window.setTimeout.expect(1).process();
397+
expect(element.hasClass('special-active')).toBe(true);
398+
}
399+
else {
400+
expect(window.setTimeout.queue.length).toBe(0);
401+
}
402+
}));
403+
404+
it("should not animate custom animations if not specifically defined",
405+
inject(function($animator, $rootScope, $compile) {
406+
407+
$animator.enabled(true);
408+
var element = $compile(html('<div></div>'))($rootScope);
409+
410+
animator = $animator($rootScope, {
411+
ngAnimate : '{custom: \'special\'}'
412+
});
413+
414+
expect(window.setTimeout.queue.length).toBe(0);
415+
animator.animate('custom1',element);
416+
expect(element.hasClass('special')).toBe(false);
417+
expect(window.setTimeout.queue.length).toBe(0);
418+
}));
419+
420+
it("should properly animate custom animations for general animation events",
421+
inject(function($animator, $rootScope, $compile, $sniffer) {
422+
423+
$animator.enabled(true);
424+
var element = $compile(html('<div></div>'))($rootScope);
425+
426+
animator = $animator($rootScope, {
427+
ngAnimate : "'special'"
428+
});
429+
430+
animator.animate('custom',element);
431+
if($sniffer.transitions) {
432+
expect(element.hasClass('special-custom')).toBe(true);
433+
window.setTimeout.expect(1).process();
434+
expect(element.hasClass('special-custom-active')).toBe(true);
435+
}
436+
else {
437+
expect(window.setTimeout.queue.length).toBe(0);
438+
}
439+
}));
440+
371441
describe("Animations", function() {
372442
it("should properly detect and make use of CSS Animations",
373443
inject(function($animator, $rootScope, $compile, $sniffer) {

0 commit comments

Comments
 (0)